python-tweetnacl

Introduction

Python-tweetnacl is a Python wrapper around the C implementations of TweetNaCl (crypto library in 100 tweets).
Python-tweetnacl also replaces previous work Python-NaCl
See also: TweetNaCl

Usage

python
import tweetnacl as nacl
help(nacl)
Help on module tweetnacl:
NAME
    tweetnacl
FILE
    /home/jan/python-tweetnacl-20140106/build/python2.7/tweetnacl.so
FUNCTIONS
    crypto_box(...)
        crypto_box(m,n,pk,sk) -> c
        The crypto_box function encrypts and authenticates a message m
        using the sender's secret key sk, the receiver's public key pk,
        and a nonce n. The crypto_box function returns the resulting ciphertext c.
        The function raises an exception if len(sk) is not crypto_box_SECRETKEYBYTES
        or if len(pk) is not crypto_box_PUBLICKEYBYTES
        or if len(n) is not crypto_box_NONCEBYTES.
    crypto_box_afternm(...)
        crypto_box_afternm(m,n,k) -> c
        The crypto_box_afternm function encrypts and authenticates
        a message m using a secret key k and a nonce n. 
        The crypto_box_afternm function returns the resulting ciphertext c. 
        The function raises an exception if len(k) is not crypto_box_BEFORENMBYTES.
        The function also raises an exception if len(n) is not crypto_box_NONCEBYTES.
    crypto_box_beforenm(...)
        crypto_box_beforenm(pk,sk) -> s
        Function crypto_box_beforenm computes a shared secret s from 
        public key pk and secret key sk
        The function raises an exception if len(sk) is not crypto_box_SECRETKEYBYTES.
        It also raises an exception if len(pk) is not crypto_box_PUBLICKEYBYTES.
    crypto_box_curve25519xsalsa20poly1305(...)
        crypto_box_curve25519xsalsa20poly1305(m,n,pk,sk) -> c
        The crypto_box_curve25519xsalsa20poly1305 function encrypts and authenticates a message m
        using the sender's secret key sk, the receiver's public key pk,
        and a nonce n. The crypto_box_curve25519xsalsa20poly1305 function returns the resulting ciphertext c.
        The function raises an exception if len(sk) is not crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES
        or if len(pk) is not crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES
        or if len(n) is not crypto_box_curve25519xsalsa20poly1305_NONCEBYTES.
    crypto_box_curve25519xsalsa20poly1305_afternm(...)
        crypto_box_curve25519xsalsa20poly1305_afternm(m,n,k) -> c
        The crypto_box_curve25519xsalsa20poly1305_afternm function encrypts and authenticates
        a message m using a secret key k and a nonce n. 
        The crypto_box_curve25519xsalsa20poly1305_afternm function returns the resulting ciphertext c. 
        The function raises an exception if len(k) is not crypto_box_curve25519xsalsa20poly1305_BEFORENMBYTES.
        The function also raises an exception if len(n) is not crypto_box_curve25519xsalsa20poly1305_NONCEBYTES.
    crypto_box_curve25519xsalsa20poly1305_beforenm(...)
        crypto_box_curve25519xsalsa20poly1305_beforenm(pk,sk) -> s
        Function crypto_box_curve25519xsalsa20poly1305_beforenm computes a shared secret s from 
        public key pk and secret key sk
        The function raises an exception if len(sk) is not crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES.
        It also raises an exception if len(pk) is not crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES.
    crypto_box_curve25519xsalsa20poly1305_keypair(...)
        crypto_box_curve25519xsalsa20poly1305_keypair() -> (pk,sk)
        The crypto_box_curve25519xsalsa20poly1305_keypair function randomly generates a secret key and
        a corresponding public key. It returns tuple containing the secret key in sk and
        public key in pk.
        It guarantees that sk has crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES bytes
        and that pk has crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES bytes.
    crypto_box_curve25519xsalsa20poly1305_open(...)
        crypto_box_curve25519xsalsa20poly1305_open(c,n,pk,sk) -> m
        The crypto_box_curve25519xsalsa20poly1305_open function verifies and decrypts
        a ciphertext c using the receiver's secret key sk,
        the sender's public key pk, and a nonce n.
        The crypto_box_curve25519xsalsa20poly1305_open function returns the resulting plaintext m.
        The function raises an exception if len(sk) is not crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES
        or if len(pk) is not crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES
        or if len(n) is not crypto_box_curve25519xsalsa20poly1305_NONCEBYTES.
    crypto_box_curve25519xsalsa20poly1305_open_afternm(...)
        crypto_box_curve25519xsalsa20poly1305_open_afternm(c,n,k) -> m
        The crypto_box_curve25519xsalsa20poly1305_open_afternm function verifies and decrypts 
        a ciphertext c using a secret key k and a nonce n.
        The crypto_box_curve25519xsalsa20poly1305_open_afternm function returns the resulting plaintext m.
        If the ciphertext fails verification, crypto_box_curve25519xsalsa20poly1305_open_afternm raises an exception.
        The function also raises an exception if len(k) is not crypto_box_curve25519xsalsa20poly1305_BEFORENMBYTES,
        or if len(n) is not crypto_box_curve25519xsalsa20poly1305_NONCEBYTES.
    crypto_box_keypair(...)
        crypto_box_keypair() -> (pk,sk)
        The crypto_box_keypair function randomly generates a secret key and
        a corresponding public key. It returns tuple containing the secret key in sk and
        public key in pk.
        It guarantees that sk has crypto_box_SECRETKEYBYTES bytes
        and that pk has crypto_box_PUBLICKEYBYTES bytes.
    crypto_box_open(...)
        crypto_box_open(c,n,pk,sk) -> m
        The crypto_box_open function verifies and decrypts
        a ciphertext c using the receiver's secret key sk,
        the sender's public key pk, and a nonce n.
        The crypto_box_open function returns the resulting plaintext m.
        The function raises an exception if len(sk) is not crypto_box_SECRETKEYBYTES
        or if len(pk) is not crypto_box_PUBLICKEYBYTES
        or if len(n) is not crypto_box_NONCEBYTES.
    crypto_box_open_afternm(...)
        crypto_box_open_afternm(c,n,k) -> m
        The crypto_box_open_afternm function verifies and decrypts 
        a ciphertext c using a secret key k and a nonce n.
        The crypto_box_open_afternm function returns the resulting plaintext m.
        If the ciphertext fails verification, crypto_box_open_afternm raises an exception.
        The function also raises an exception if len(k) is not crypto_box_BEFORENMBYTES,
        or if len(n) is not crypto_box_NONCEBYTES.
    crypto_hash(...)
        crypto_hash(m) -> h
        The crypto_hash function hashes a message m.
        It returns a hash h. The output length len(h) is always crypto_hash_BYTES.
    crypto_hash_sha512(...)
        crypto_hash_sha512(m) -> h
        The crypto_hash_sha512 function hashes a message m.
        It returns a hash h. The output length len(h) is always crypto_hash_sha512_BYTES.
    crypto_onetimeauth(...)
        crypto_onetimeauth(m,k) -> a
        The crypto_onetimeauth function authenticates a message m
        using a secret key k. The function returns an authenticator a.
        The authenticator length is always crypto_onetimeauth_BYTES.
        The function raises an exception if len(k) is not crypto_onetimeauth_KEYBYTES.
    crypto_onetimeauth_poly1305(...)
        crypto_onetimeauth_poly1305(m,k) -> a
        The crypto_onetimeauth_poly1305 function authenticates a message m
        using a secret key k. The function returns an authenticator a.
        The authenticator length is always crypto_onetimeauth_poly1305_BYTES.
        The function raises an exception if len(k) is not crypto_onetimeauth_poly1305_KEYBYTES.
    crypto_onetimeauth_poly1305_verify(...)
        crypto_onetimeauth_poly1305_verify(a,m,k)
        The crypto_onetimeauth_poly1305_verify function checks that:
          len(k) is crypto_onetimeauth_poly1305_KEYBYTES;
          len(a) is crypto_onetimeauth_poly1305_BYTES;
          and a is a correct authenticator of a message m under the secret key k.
        If any of these checks fail, the function raises an exception.
    crypto_onetimeauth_verify(...)
        crypto_onetimeauth_verify(a,m,k)
        The crypto_onetimeauth_verify function checks that:
          len(k) is crypto_onetimeauth_KEYBYTES;
          len(a) is crypto_onetimeauth_BYTES;
          and a is a correct authenticator of a message m under the secret key k.
        If any of these checks fail, the function raises an exception.
    crypto_scalarmult(...)
        crypto_scalarmult(n) -> q
        This function multiplies a group element p by an integer n.
        It returns the resulting group element q of length crypto_scalarmult_BYTES.
        The function raises an exception if len(p) is not crypto_scalarmult_BYTES.
        It also raises an exception if len(n) is not crypto_scalarmult_SCALARBYTES.
    crypto_scalarmult_base(...)
        crypto_scalarmult_base(n,p) -> q
        The crypto_scalarmult_base function computes
        the scalar product of a standard group element and an integer n.
        It returns the resulting group element q of length crypto_scalarmult_BYTES.
        It raises an exception if len(n) is not crypto_scalarmult_SCALARBYTES.
    crypto_scalarmult_curve25519(...)
        crypto_scalarmult_curve25519(n) -> q
        This function multiplies a group element p by an integer n.
        It returns the resulting group element q of length crypto_scalarmult_curve25519_BYTES.
        The function raises an exception if len(p) is not crypto_scalarmult_curve25519_BYTES.
        It also raises an exception if len(n) is not crypto_scalarmult_curve25519_SCALARBYTES.
    crypto_scalarmult_curve25519_base(...)
        crypto_scalarmult_curve25519_base(n,p) -> q
        The crypto_scalarmult_curve25519_base function computes
        the scalar product of a standard group element and an integer n.
        It returns the resulting group element q of length crypto_scalarmult_curve25519_BYTES.
        It raises an exception if len(n) is not crypto_scalarmult_curve25519_SCALARBYTES.
    crypto_secretbox(...)
        crypto_secretbox(m,n,k) -> c
        The crypto_secretbox function encrypts and authenticates
        a message m using a secret key k and a nonce n. 
        The crypto_secretbox function returns the resulting ciphertext c. 
        The function raises an exception if len(k) is not crypto_secretbox_KEYBYTES.
        The function also raises an exception if len(n) is not crypto_secretbox_NONCEBYTES.
    crypto_secretbox_open(...)
        crypto_secretbox_open(c,n,k) -> m
        The crypto_secretbox_open function verifies and decrypts 
        a ciphertext c using a secret key k and a nonce n.
        The crypto_secretbox_open function returns the resulting plaintext m.
        If the ciphertext fails verification, crypto_secretbox_open raises an exception.
        The function also raises an exception if len(k) is not crypto_secretbox_KEYBYTES,
        or if len(n) is not crypto_secretbox_NONCEBYTES.
    crypto_secretbox_xsalsa20poly1305(...)
        crypto_secretbox_xsalsa20poly1305(m,n,k) -> c
        The crypto_secretbox_xsalsa20poly1305 function encrypts and authenticates
        a message m using a secret key k and a nonce n. 
        The crypto_secretbox_xsalsa20poly1305 function returns the resulting ciphertext c. 
        The function raises an exception if len(k) is not crypto_secretbox_xsalsa20poly1305_KEYBYTES.
        The function also raises an exception if len(n) is not crypto_secretbox_xsalsa20poly1305_NONCEBYTES.
    crypto_secretbox_xsalsa20poly1305_open(...)
        crypto_secretbox_xsalsa20poly1305_open(c,n,k) -> m
        The crypto_secretbox_xsalsa20poly1305_open function verifies and decrypts 
        a ciphertext c using a secret key k and a nonce n.
        The crypto_secretbox_xsalsa20poly1305_open function returns the resulting plaintext m.
        If the ciphertext fails verification, crypto_secretbox_xsalsa20poly1305_open raises an exception.
        The function also raises an exception if len(k) is not crypto_secretbox_xsalsa20poly1305_KEYBYTES,
        or if len(n) is not crypto_secretbox_xsalsa20poly1305_NONCEBYTES.
    crypto_sign(...)
        crypto_sign(m,sk) -> sm
        The crypto_sign function signs a message m using the sender's secret key sk.
        The crypto_sign function returns the resulting signed message sm.
        The function raises an exception if len(sk) is not crypto_sign_SECRETKEYBYTES.
    crypto_sign_ed25519(...)
        crypto_sign_ed25519(m,sk) -> sm
        The crypto_sign_ed25519 function signs a message m using the sender's secret key sk.
        The crypto_sign_ed25519 function returns the resulting signed message sm.
        The function raises an exception if len(sk) is not crypto_sign_ed25519_SECRETKEYBYTES.
    crypto_sign_ed25519_keypair(...)
        crypto_sign_ed25519_keypair() -> (pk,sk)
        The crypto_sign_ed25519_keypair function randomly generates a secret key and
        a corresponding public key. It returns tuple containing the secret key in sk and
        public key in pk.
        It guarantees that sk has crypto_sign_ed25519_SECRETKEYBYTES bytes
        and that pk has crypto_sign_ed25519_PUBLICKEYBYTES bytes.
    crypto_sign_ed25519_open(...)
        crypto_sign_ed25519_open(sm,pk) -> m
        The crypto_sign_ed25519_open function verifies the signature in
        sm using the receiver's secret key sk.
        The crypto_sign_ed25519_open function returns the message m.
        If the signature fails verification, crypto_sign_ed25519_open raises an exception.
        The function also raises an exception if len(pk) is not crypto_sign_ed25519_PUBLICKEYBYTES.
    crypto_sign_keypair(...)
        crypto_sign_keypair() -> (pk,sk)
        The crypto_sign_keypair function randomly generates a secret key and
        a corresponding public key. It returns tuple containing the secret key in sk and
        public key in pk.
        It guarantees that sk has crypto_sign_SECRETKEYBYTES bytes
        and that pk has crypto_sign_PUBLICKEYBYTES bytes.
    crypto_sign_open(...)
        crypto_sign_open(sm,pk) -> m
        The crypto_sign_open function verifies the signature in
        sm using the receiver's secret key sk.
        The crypto_sign_open function returns the message m.
        If the signature fails verification, crypto_sign_open raises an exception.
        The function also raises an exception if len(pk) is not crypto_sign_PUBLICKEYBYTES.
    crypto_stream(...)
        crypto_stream(clen,n,k) -> c
        The crypto_stream function produces a clen-byte stream c
        as a function of a secret key k and a nonce n.
        The function raises an exception:
          if len(k) is not crypto_stream_KEYBYTES;
          if len(n) is not crypto_stream_NONCEBYTES;
          if clen is smaller than 0.
    crypto_stream_salsa20(...)
        crypto_stream_salsa20(clen,n,k) -> c
        The crypto_stream_salsa20 function produces a clen-byte stream c
        as a function of a secret key k and a nonce n.
        The function raises an exception:
          if len(k) is not crypto_stream_salsa20_KEYBYTES;
          if len(n) is not crypto_stream_salsa20_NONCEBYTES;
          if clen is smaller than 0.
    crypto_stream_salsa20_xor(...)
        crypto_stream_salsa20_xor(m,n,k) -> c
        The crypto_stream_salsa20_xor function encrypts a message m using a secret key k
        and a nonce n. The crypto_stream_salsa20_xor function returns the ciphertext c.
        The function raises an exception:
          if len(k) is not crypto_stream_salsa20_KEYBYTES;
          if len(n) is not crypto_stream_salsa20_NONCEBYTES.
    crypto_stream_xor(...)
        crypto_stream_xor(m,n,k) -> c
        The crypto_stream_xor function encrypts a message m using a secret key k
        and a nonce n. The crypto_stream_xor function returns the ciphertext c.
        The function raises an exception:
          if len(k) is not crypto_stream_KEYBYTES;
          if len(n) is not crypto_stream_NONCEBYTES.
    crypto_stream_xsalsa20(...)
        crypto_stream_xsalsa20(clen,n,k) -> c
        The crypto_stream_xsalsa20 function produces a clen-byte stream c
        as a function of a secret key k and a nonce n.
        The function raises an exception:
          if len(k) is not crypto_stream_xsalsa20_KEYBYTES;
          if len(n) is not crypto_stream_xsalsa20_NONCEBYTES;
          if clen is smaller than 0.
    crypto_stream_xsalsa20_xor(...)
        crypto_stream_xsalsa20_xor(m,n,k) -> c
        The crypto_stream_xsalsa20_xor function encrypts a message m using a secret key k
        and a nonce n. The crypto_stream_xsalsa20_xor function returns the ciphertext c.
        The function raises an exception:
          if len(k) is not crypto_stream_xsalsa20_KEYBYTES;
          if len(n) is not crypto_stream_xsalsa20_NONCEBYTES.
    crypto_verify_16(...)
        crypto_verify_16(x,y)
        The crypto_verify_16 function checks that:
          len(x) is crypto_verify_16_BYTES;
          len(y) is crypto_verify_16_BYTES;
          and check if strings x and y has same content.
        If any of these checks fail, the function raises an exception.
        The time taken by crypto_verify_16 is independent of the contents of x and y.
    crypto_verify_32(...)
        crypto_verify_32(x,y)
        The crypto_verify_32 function checks that:
          len(x) is crypto_verify_32_BYTES;
          len(y) is crypto_verify_32_BYTES;
          and check if strings x and y has same content.
        If any of these checks fail, the function raises an exception.
        The time taken by crypto_verify_32 is independent of the contents of x and y.
    randombytes(...)
        randombytes(len) -> str
        Return a string of 'len' random bytes suitable for cryptographic use.
DATA
    crypto_box_BEFORENMBYTES = 32
    crypto_box_BOXZEROBYTES = 16
    crypto_box_IMPLEMENTATION = 'crypto_box/curve25519xsalsa20poly1305/twe...
    crypto_box_NONCEBYTES = 24
    crypto_box_PRIMITIVE = 'curve25519xsalsa20poly1305'
    crypto_box_PUBLICKEYBYTES = 32
    crypto_box_SECRETKEYBYTES = 32
    crypto_box_VERSION = '-'
    crypto_box_ZEROBYTES = 32
    crypto_box_curve25519xsalsa20poly1305_BEFORENMBYTES = 32
    crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES = 16
    crypto_box_curve25519xsalsa20poly1305_IMPLEMENTATION = 'crypto_box/cur...
    crypto_box_curve25519xsalsa20poly1305_NONCEBYTES = 24
    crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES = 32
    crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES = 32
    crypto_box_curve25519xsalsa20poly1305_VERSION = '-'
    crypto_box_curve25519xsalsa20poly1305_ZEROBYTES = 32
    crypto_hash_BYTES = 64
    crypto_hash_IMPLEMENTATION = 'crypto_hash/sha512/tweet'
    crypto_hash_PRIMITIVE = 'sha512'
    crypto_hash_VERSION = '-'
    crypto_hash_sha512_BYTES = 64
    crypto_hash_sha512_IMPLEMENTATION = 'crypto_hash/sha512/tweet'
    crypto_hash_sha512_VERSION = '-'
    crypto_onetimeauth_BYTES = 16
    crypto_onetimeauth_IMPLEMENTATION = 'crypto_onetimeauth/poly1305/tweet...
    crypto_onetimeauth_KEYBYTES = 32
    crypto_onetimeauth_PRIMITIVE = 'poly1305'
    crypto_onetimeauth_VERSION = '-'
    crypto_onetimeauth_poly1305_BYTES = 16
    crypto_onetimeauth_poly1305_IMPLEMENTATION = 'crypto_onetimeauth/poly1...
    crypto_onetimeauth_poly1305_KEYBYTES = 32
    crypto_onetimeauth_poly1305_VERSION = '-'
    crypto_scalarmult_BYTES = 32
    crypto_scalarmult_IMPLEMENTATION = 'crypto_scalarmult/curve25519/tweet...
    crypto_scalarmult_PRIMITIVE = 'curve25519'
    crypto_scalarmult_SCALARBYTES = 32
    crypto_scalarmult_VERSION = '-'
    crypto_scalarmult_curve25519_BYTES = 32
    crypto_scalarmult_curve25519_IMPLEMENTATION = 'crypto_scalarmult/curve...
    crypto_scalarmult_curve25519_SCALARBYTES = 32
    crypto_scalarmult_curve25519_VERSION = '-'
    crypto_secretbox_BOXZEROBYTES = 16
    crypto_secretbox_IMPLEMENTATION = 'crypto_secretbox/xsalsa20poly1305/t...
    crypto_secretbox_KEYBYTES = 32
    crypto_secretbox_NONCEBYTES = 24
    crypto_secretbox_PRIMITIVE = 'xsalsa20poly1305'
    crypto_secretbox_VERSION = '-'
    crypto_secretbox_ZEROBYTES = 32
    crypto_secretbox_xsalsa20poly1305_BOXZEROBYTES = 16
    crypto_secretbox_xsalsa20poly1305_IMPLEMENTATION = 'crypto_secretbox/x...
    crypto_secretbox_xsalsa20poly1305_KEYBYTES = 32
    crypto_secretbox_xsalsa20poly1305_NONCEBYTES = 24
    crypto_secretbox_xsalsa20poly1305_VERSION = '-'
    crypto_secretbox_xsalsa20poly1305_ZEROBYTES = 32
    crypto_sign_BYTES = 64
    crypto_sign_IMPLEMENTATION = 'crypto_sign/ed25519/tweet'
    crypto_sign_PRIMITIVE = 'ed25519'
    crypto_sign_PUBLICKEYBYTES = 32
    crypto_sign_SECRETKEYBYTES = 64
    crypto_sign_VERSION = '-'
    crypto_sign_ed25519_BYTES = 64
    crypto_sign_ed25519_IMPLEMENTATION = 'crypto_sign/ed25519/tweet'
    crypto_sign_ed25519_PUBLICKEYBYTES = 32
    crypto_sign_ed25519_SECRETKEYBYTES = 64
    crypto_sign_ed25519_VERSION = '-'
    crypto_stream_IMPLEMENTATION = 'crypto_stream/xsalsa20/tweet'
    crypto_stream_KEYBYTES = 32
    crypto_stream_NONCEBYTES = 24
    crypto_stream_PRIMITIVE = 'xsalsa20'
    crypto_stream_VERSION = '-'
    crypto_stream_salsa20_IMPLEMENTATION = 'crypto_stream/salsa20/tweet'
    crypto_stream_salsa20_KEYBYTES = 32
    crypto_stream_salsa20_NONCEBYTES = 8
    crypto_stream_salsa20_VERSION = '-'
    crypto_stream_xsalsa20_IMPLEMENTATION = 'crypto_stream/xsalsa20/tweet'
    crypto_stream_xsalsa20_KEYBYTES = 32
    crypto_stream_xsalsa20_NONCEBYTES = 24
    crypto_stream_xsalsa20_VERSION = '-'
    crypto_verify_16_BYTES = 16
    crypto_verify_16_IMPLEMENTATION = 'crypto_verify/16/tweet'
    crypto_verify_16_VERSION = '-'
    crypto_verify_32_BYTES = 32
    crypto_verify_32_IMPLEMENTATION = 'crypto_verify/32/tweet'
    crypto_verify_32_VERSION = '-'