Crypto++
8.2
Free C++ class library of cryptographic schemes
|
Crypto++ interface to TweetNaCl library (20140917) More...
Go to the source code of this file.
Functions | |
int | crypto_box (byte *c, const byte *m, word64 d, const byte *n, const byte *y, const byte *x) |
Encrypt and authenticate a message. More... | |
int | crypto_box_open (byte *m, const byte *c, word64 d, const byte *n, const byte *y, const byte *x) |
Verify and decrypt a message. More... | |
int | crypto_box_keypair (byte *y, byte *x) |
Generate a keypair for encryption. More... | |
int | crypto_box_beforenm (byte *k, const byte *y, const byte *x) |
Encrypt and authenticate a message. More... | |
int | crypto_box_afternm (byte *c, const byte *m, word64 d, const byte *n, const byte *k) |
Encrypt and authenticate a message. More... | |
int | crypto_box_open_afternm (byte *m, const byte *c, word64 d, const byte *n, const byte *k) |
Verify and decrypt a message. More... | |
int | crypto_box_unchecked (byte *c, const byte *m, word64 d, const byte *n, const byte *y, const byte *x) |
Encrypt and authenticate a message. More... | |
int | crypto_box_open_unchecked (byte *m, const byte *c, word64 d, const byte *n, const byte *y, const byte *x) |
Verify and decrypt a message. More... | |
int | crypto_box_beforenm_unchecked (byte *k, const byte *y, const byte *x) |
Encrypt and authenticate a message. More... | |
int | crypto_core_salsa20 (byte *out, const byte *in, const byte *k, const byte *c) |
TODO. | |
int | crypto_core_hsalsa20 (byte *out, const byte *in, const byte *k, const byte *c) |
TODO. More... | |
int | crypto_hashblocks (byte *x, const byte *m, word64 n) |
Hash multiple blocks. More... | |
int | crypto_hash (byte *out, const byte *m, word64 n) |
Hash a message. More... | |
int | crypto_onetimeauth (byte *out, const byte *m, word64 n, const byte *k) |
Create an authentication tag for a message. More... | |
int | crypto_onetimeauth_verify (const byte *h, const byte *m, word64 n, const byte *k) |
Verify an authentication tag on a message. More... | |
int | crypto_scalarmult (byte *q, const byte *n, const byte *p) |
Scalar multiplication of a point. More... | |
int | crypto_scalarmult_base (byte *q, const byte *n) |
Scalar multiplication of base point. More... | |
int | crypto_secretbox (byte *c, const byte *m, word64 d, const byte *n, const byte *k) |
Encrypt and authenticate a message. More... | |
int | crypto_secretbox_open (byte *m, const byte *c, word64 d, const byte *n, const byte *k) |
Verify and decrypt a message. More... | |
int | crypto_sign (byte *sm, word64 *smlen, const byte *m, word64 n, const byte *sk) |
Sign a message. More... | |
int | crypto_sign_open (byte *m, word64 *mlen, const byte *sm, word64 n, const byte *pk) |
Verify a message. More... | |
int | crypto_sign_keypair (byte *pk, byte *sk) |
Generate a keypair for signing. More... | |
int | crypto_sign_sk2pk (byte *pk, const byte *sk) |
Calculate a public key from a secret key. More... | |
int | crypto_stream (byte *c, word64 d, const byte *n, const byte *k) |
Produce a keystream using XSalsa20. More... | |
int | crypto_stream_xor (byte *c, const byte *m, word64 d, const byte *n, const byte *k) |
Encrypt a message using XSalsa20. More... | |
int | crypto_stream_salsa20 (byte *c, word64 d, const byte *n, const byte *k) |
Produce a keystream using Salsa20. More... | |
int | crypto_stream_salsa20_xor (byte *c, const byte *m, word64 b, const byte *n, const byte *k) |
Encrypt a message using Salsa20. More... | |
int | crypto_verify_16 (const byte *x, const byte *y) |
Compare 16-byte buffers. More... | |
int | crypto_verify_32 (const byte *x, const byte *y) |
Compare 32-byte buffers. More... | |
Crypto++ interface to TweetNaCl library (20140917)
TweetNaCl is a compact reimplementation of the NaCl library by Daniel J. Bernstein, Bernard van Gastel, Wesley Janssen, Tanja Lange, Peter Schwabe and Sjaak Smetsers. The library is less than 20 KB in size and provides 25 of the NaCl library functions.
The compact library uses curve25519, XSalsa20, Poly1305 and SHA-512 as default primitives, and includes both x25519 key exchange and ed25519 signatures. The complete list of functions can be found in TweetNaCl: A crypto library in 100 tweets (20140917), Table 1, page 5.
Crypto++ rejects small order elements using libsodium's blacklist. The TweetNaCl library allowed them but the library predated the attack. If you wish to allow small elements then use the "unchecked" versions of crypto_box_unchecked, crypto_box_open_unchecked and crypto_box_beforenm_unchecked.
TweetNaCl is well written but not well optimzed. It runs about 10x slower than optimized routines from libsodium. However, the library is still 2x to 4x faster than the algorithms NaCl was designed to replace and allows cross-checking results from an independent implementation.
The Crypto++ wrapper for TweetNaCl requires OS features. That is, NO_OS_DEPENDENCE
cannot be defined. It is due to TweetNaCl's internal function randombytes
. Crypto++ used DefaultAutoSeededRNG
within randombytes
, so OS integration must be enabled. You can use another generator like RDRAND
to avoid the restriction.
Definition in file naclite.h.
int crypto_box | ( | byte * | c, |
const byte * | m, | ||
word64 | d, | ||
const byte * | n, | ||
const byte * | y, | ||
const byte * | x | ||
) |
Encrypt and authenticate a message.
c | output byte buffer |
m | input byte buffer |
d | size of the input byte buffer |
n | nonce byte buffer |
y | other's public key |
x | private key |
crypto_box() uses crypto_box_curve25519xsalsa20poly1305
Definition at line 542 of file tweetnacl.cpp.
int crypto_box_open | ( | byte * | m, |
const byte * | c, | ||
word64 | d, | ||
const byte * | n, | ||
const byte * | y, | ||
const byte * | x | ||
) |
Verify and decrypt a message.
m | output byte buffer |
c | input byte buffer |
d | size of the input byte buffer |
n | nonce byte buffer |
y | other's public key |
x | private key |
crypto_box_open() uses crypto_box_curve25519xsalsa20poly1305
Definition at line 556 of file tweetnacl.cpp.
int crypto_box_keypair | ( | byte * | y, |
byte * | x | ||
) |
Generate a keypair for encryption.
y | public key byte buffer |
x | private key byte buffer |
Definition at line 508 of file tweetnacl.cpp.
int crypto_box_beforenm | ( | byte * | k, |
const byte * | y, | ||
const byte * | x | ||
) |
Encrypt and authenticate a message.
k | shared secret byte buffer |
y | other's public key |
x | private key |
crypto_box_beforenm() performs message-independent precomputation to derive the key. Once the key is derived multiple calls to crypto_box_afternm() can be made to process the message.
Definition at line 516 of file tweetnacl.cpp.
int crypto_box_afternm | ( | byte * | c, |
const byte * | m, | ||
word64 | d, | ||
const byte * | n, | ||
const byte * | k | ||
) |
Encrypt and authenticate a message.
m | output byte buffer |
c | input byte buffer |
d | size of the input byte buffer |
n | nonce byte buffer |
k | shared secret byte buffer |
crypto_box_afternm() performs message-dependent computation using the derived the key. Once the key is derived using crypto_box_beforenm() multiple calls to crypto_box_afternm() can be made to process the message.
Definition at line 532 of file tweetnacl.cpp.
int crypto_box_open_afternm | ( | byte * | m, |
const byte * | c, | ||
word64 | d, | ||
const byte * | n, | ||
const byte * | k | ||
) |
Verify and decrypt a message.
m | output byte buffer |
c | input byte buffer |
d | size of the input byte buffer |
n | nonce byte buffer |
k | shared secret byte buffer |
crypto_box_afternm() performs message-dependent computation using the derived the key. Once the key is derived using crypto_box_beforenm() multiple calls to crypto_box_open_afternm() can be made to process the message.
Definition at line 537 of file tweetnacl.cpp.
int crypto_box_unchecked | ( | byte * | c, |
const byte * | m, | ||
word64 | d, | ||
const byte * | n, | ||
const byte * | y, | ||
const byte * | x | ||
) |
Encrypt and authenticate a message.
c | output byte buffer |
m | input byte buffer |
d | size of the input byte buffer |
n | nonce byte buffer |
y | other's public key |
x | private key |
crypto_box() uses crypto_box_curve25519xsalsa20poly1305.
This version of crypto_box() does not check for small order elements. It can be unsafe but it exists for backwards compatibility with downlevel clients. Without the compatibility interop with early versions of NaCl, libsodium and other libraries does not exist. The downlevel interop may also be needed of cryptocurrencies like Bitcoin, Ethereum, Monero and Zcash.
Definition at line 549 of file tweetnacl.cpp.
int crypto_box_open_unchecked | ( | byte * | m, |
const byte * | c, | ||
word64 | d, | ||
const byte * | n, | ||
const byte * | y, | ||
const byte * | x | ||
) |
Verify and decrypt a message.
m | output byte buffer |
c | input byte buffer |
d | size of the input byte buffer |
n | nonce byte buffer |
y | other's public key |
x | private key |
crypto_box_open() uses crypto_box_curve25519xsalsa20poly1305.
This version of crypto_box_open() does not check for small order elements. It can be unsafe but it exists for backwards compatibility with downlevel clients. Without the compatibility interop with early versions of NaCl, libsodium and other libraries does not exist. The downlevel interop may also be needed of cryptocurrencies like Bitcoin, Ethereum, Monero and Zcash.
Definition at line 563 of file tweetnacl.cpp.
int crypto_box_beforenm_unchecked | ( | byte * | k, |
const byte * | y, | ||
const byte * | x | ||
) |
Encrypt and authenticate a message.
k | shared secret byte buffer |
y | other's public key |
x | private key |
crypto_box_beforenm() performs message-independent precomputation to derive the key. Once the key is derived multiple calls to crypto_box_afternm() can be made to process the message.
This version of crypto_box_beforenm() does not check for small order elements. It can be unsafe but it exists for backwards compatibility with downlevel clients. Without the compatibility interop with early versions of NaCl, libsodium and other libraries does not exist. The downlevel interop may also be needed of cryptocurrencies like Bitcoin, Ethereum, Monero and Zcash.
Definition at line 525 of file tweetnacl.cpp.
int crypto_core_hsalsa20 | ( | byte * | out, |
const byte * | in, | ||
const byte * | k, | ||
const byte * | c | ||
) |
TODO.
Definition at line 140 of file tweetnacl.cpp.
int crypto_hashblocks | ( | byte * | x, |
const byte * | m, | ||
word64 | n | ||
) |
Hash multiple blocks.
crypto_hashblocks() uses crypto_hashblocks_sha512.
Definition at line 602 of file tweetnacl.cpp.
int crypto_hash | ( | byte * | out, |
const byte * | m, | ||
word64 | n | ||
) |
Hash a message.
crypto_hash() uses crypto_hash_sha512.
Definition at line 645 of file tweetnacl.cpp.
int crypto_onetimeauth | ( | byte * | out, |
const byte * | m, | ||
word64 | n, | ||
const byte * | k | ||
) |
Create an authentication tag for a message.
crypto_onetimeauth() uses crypto_onetimeauth_poly1305.
Definition at line 208 of file tweetnacl.cpp.
int crypto_onetimeauth_verify | ( | const byte * | h, |
const byte * | m, | ||
word64 | n, | ||
const byte * | k | ||
) |
Verify an authentication tag on a message.
Definition at line 261 of file tweetnacl.cpp.
int crypto_scalarmult | ( | byte * | q, |
const byte * | n, | ||
const byte * | p | ||
) |
Scalar multiplication of a point.
crypto_scalarmult() uses crypto_scalarmult_curve25519
Definition at line 452 of file tweetnacl.cpp.
int crypto_scalarmult_base | ( | byte * | q, |
const byte * | n | ||
) |
Scalar multiplication of base point.
crypto_scalarmult_base() uses crypto_scalarmult_curve25519
Definition at line 503 of file tweetnacl.cpp.
int crypto_secretbox | ( | byte * | c, |
const byte * | m, | ||
word64 | d, | ||
const byte * | n, | ||
const byte * | k | ||
) |
Encrypt and authenticate a message.
crypto_secretbox() uses a symmetric key to encrypt and authenticate a message.
Definition at line 268 of file tweetnacl.cpp.
int crypto_secretbox_open | ( | byte * | m, |
const byte * | c, | ||
word64 | d, | ||
const byte * | n, | ||
const byte * | k | ||
) |
Verify and decrypt a message.
Definition at line 278 of file tweetnacl.cpp.
int crypto_sign | ( | byte * | sm, |
word64 * | smlen, | ||
const byte * | m, | ||
word64 | n, | ||
const byte * | sk | ||
) |
Sign a message.
sm | output byte buffer |
smlen | size of the output byte buffer |
m | input byte buffer |
n | size of the input byte buffer |
sk | private key |
crypto_sign() uses crypto_sign_ed25519.
Definition at line 813 of file tweetnacl.cpp.
int crypto_sign_open | ( | byte * | m, |
word64 * | mlen, | ||
const byte * | sm, | ||
word64 | n, | ||
const byte * | pk | ||
) |
Verify a message.
m | output byte buffer |
mlen | size of the output byte buffer |
sm | input byte buffer |
n | size of the input byte buffer |
pk | public key |
Definition at line 881 of file tweetnacl.cpp.
int crypto_sign_keypair | ( | byte * | pk, |
byte * | sk | ||
) |
Generate a keypair for signing.
pk | public key byte buffer |
sk | private key byte buffer |
crypto_sign_keypair() creates an ed25519 keypair.
Definition at line 739 of file tweetnacl.cpp.
int crypto_sign_sk2pk | ( | byte * | pk, |
const byte * | sk | ||
) |
Calculate a public key from a secret key.
pk | public key byte buffer |
sk | private key byte buffer |
crypto_sign_sk2pk() creates an ed25519 public key from an existing 32-byte secret key. The function does not backfill the tail bytes of the secret key with the calculated public key.
crypto_sign_sk2pk() is not part of libsodium or Tweet API. It was added for interop with some anonymous routing protocols.
Definition at line 758 of file tweetnacl.cpp.
int crypto_stream | ( | byte * | c, |
word64 | d, | ||
const byte * | n, | ||
const byte * | k | ||
) |
Produce a keystream using XSalsa20.
crypto_stream() uses crypto_stream_xsalsa20
Definition at line 180 of file tweetnacl.cpp.
int crypto_stream_xor | ( | byte * | c, |
const byte * | m, | ||
word64 | d, | ||
const byte * | n, | ||
const byte * | k | ||
) |
Encrypt a message using XSalsa20.
Definition at line 187 of file tweetnacl.cpp.
int crypto_stream_salsa20 | ( | byte * | c, |
word64 | d, | ||
const byte * | n, | ||
const byte * | k | ||
) |
Produce a keystream using Salsa20.
Definition at line 175 of file tweetnacl.cpp.
int crypto_stream_salsa20_xor | ( | byte * | c, |
const byte * | m, | ||
word64 | b, | ||
const byte * | n, | ||
const byte * | k | ||
) |
Encrypt a message using Salsa20.
Definition at line 148 of file tweetnacl.cpp.
int crypto_verify_16 | ( | const byte * | x, |
const byte * | y | ||
) |
Compare 16-byte buffers.
Definition at line 84 of file tweetnacl.cpp.
int crypto_verify_32 | ( | const byte * | x, |
const byte * | y | ||
) |
Compare 32-byte buffers.
Definition at line 89 of file tweetnacl.cpp.