Crypto++
6.1
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 (uint8_t *c, const uint8_t *m, uint64_t d, const uint8_t *n, const uint8_t *y, const uint8_t *x) |
Encrypt and authenticate a message. More... | |
int | crypto_box_open (uint8_t *m, const uint8_t *c, uint64_t d, const uint8_t *n, const uint8_t *y, const uint8_t *x) |
Verify and decrypt a message. More... | |
int | crypto_box_keypair (uint8_t *y, uint8_t *x) |
Generate a keypair for encryption. More... | |
int | crypto_box_beforenm (uint8_t *k, const uint8_t *y, const uint8_t *x) |
Encrypt and authenticate a message. More... | |
int | crypto_box_afternm (uint8_t *c, const uint8_t *m, uint64_t d, const uint8_t *n, const uint8_t *k) |
Encrypt and authenticate a message. More... | |
int | crypto_box_open_afternm (uint8_t *m, const uint8_t *c, uint64_t d, const uint8_t *n, const uint8_t *k) |
Verify and decrypt a message. More... | |
int | crypto_box_unchecked (uint8_t *c, const uint8_t *m, uint64_t d, const uint8_t *n, const uint8_t *y, const uint8_t *x) |
Encrypt and authenticate a message. More... | |
int | crypto_box_open_unchecked (uint8_t *m, const uint8_t *c, uint64_t d, const uint8_t *n, const uint8_t *y, const uint8_t *x) |
Verify and decrypt a message. More... | |
int | crypto_box_beforenm_unchecked (uint8_t *k, const uint8_t *y, const uint8_t *x) |
Encrypt and authenticate a message. More... | |
int | crypto_core_salsa20 (uint8_t *out, const uint8_t *in, const uint8_t *k, const uint8_t *c) |
TODO. | |
int | crypto_core_hsalsa20 (uint8_t *out, const uint8_t *in, const uint8_t *k, const uint8_t *c) |
TODO. More... | |
int | crypto_hashblocks (uint8_t *x, const uint8_t *m, uint64_t n) |
Hash multiple blocks. More... | |
int | crypto_hash (uint8_t *out, const uint8_t *m, uint64_t n) |
Hash a message. More... | |
int | crypto_onetimeauth (uint8_t *out, const uint8_t *m, uint64_t n, const uint8_t *k) |
Create an authentication tag for a message. More... | |
int | crypto_onetimeauth_verify (const uint8_t *h, const uint8_t *m, uint64_t n, const uint8_t *k) |
Verify an authentication tag on a message. More... | |
int | crypto_scalarmult (uint8_t *q, const uint8_t *n, const uint8_t *p) |
Scalar multiplication of a point. More... | |
int | crypto_scalarmult_base (uint8_t *q, const uint8_t *n) |
Scalar multiplication of base point. More... | |
int | crypto_secretbox (uint8_t *c, const uint8_t *m, uint64_t d, const uint8_t *n, const uint8_t *k) |
Encrypt and authenticate a message. More... | |
int | crypto_secretbox_open (uint8_t *m, const uint8_t *c, uint64_t d, const uint8_t *n, const uint8_t *k) |
Verify and decrypt a message. More... | |
int | crypto_sign (uint8_t *sm, uint64_t *smlen, const uint8_t *m, uint64_t n, const uint8_t *sk) |
Sign a message. More... | |
int | crypto_sign_open (uint8_t *m, uint64_t *mlen, const uint8_t *sm, uint64_t n, const uint8_t *pk) |
Verify a message. More... | |
int | crypto_sign_keypair (uint8_t *pk, uint8_t *sk) |
Generate a keypair for signing. More... | |
int | crypto_stream (uint8_t *c, uint64_t d, const uint8_t *n, const uint8_t *k) |
Produce a keystream using XSalsa20. More... | |
int | crypto_stream_xor (uint8_t *c, const uint8_t *m, uint64_t d, const uint8_t *n, const uint8_t *k) |
Encrypt a message using XSalsa20. More... | |
int | crypto_stream_salsa20 (uint8_t *c, uint64_t d, const uint8_t *n, const uint8_t *k) |
Produce a keystream using Salsa20. More... | |
int | crypto_stream_salsa20_xor (uint8_t *c, const uint8_t *m, uint64_t b, const uint8_t *n, const uint8_t *k) |
Encrypt a message using Salsa20. More... | |
int | crypto_verify_16 (const uint8_t *x, const uint8_t *y) |
Compare 16-byte buffers. More... | |
int | crypto_verify_32 (const uint8_t *x, const uint8_t *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++ retained the function names and signatures but switched to data types provided by <stdint.h> to promote interoperability with Crypto++ and avoid size problems on platforms like Cygwin. For example, NaCl typdef'd u64
as an unsigned long long
, but Cygwin, MinGW and MSYS are LP64
systems (not LLP64
systems). In addition, Crypto++ was missing NaCl's signed 64-bit integer i64
.
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 2x to 3x slower than optimized routines from libsodium. However, the library is still 2x to 4x faster than the algorithms NaCl was designed to replace.
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 | ( | uint8_t * | c, |
const uint8_t * | m, | ||
uint64_t | d, | ||
const uint8_t * | n, | ||
const uint8_t * | y, | ||
const uint8_t * | 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 | ( | uint8_t * | m, |
const uint8_t * | c, | ||
uint64_t | d, | ||
const uint8_t * | n, | ||
const uint8_t * | y, | ||
const uint8_t * | 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 | ( | uint8_t * | y, |
uint8_t * | 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 | ( | uint8_t * | k, |
const uint8_t * | y, | ||
const uint8_t * | 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 | ( | uint8_t * | c, |
const uint8_t * | m, | ||
uint64_t | d, | ||
const uint8_t * | n, | ||
const uint8_t * | 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 | ( | uint8_t * | m, |
const uint8_t * | c, | ||
uint64_t | d, | ||
const uint8_t * | n, | ||
const uint8_t * | 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 | ( | uint8_t * | c, |
const uint8_t * | m, | ||
uint64_t | d, | ||
const uint8_t * | n, | ||
const uint8_t * | y, | ||
const uint8_t * | 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 | ( | uint8_t * | m, |
const uint8_t * | c, | ||
uint64_t | d, | ||
const uint8_t * | n, | ||
const uint8_t * | y, | ||
const uint8_t * | 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 | ( | uint8_t * | k, |
const uint8_t * | y, | ||
const uint8_t * | 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 | ( | uint8_t * | out, |
const uint8_t * | in, | ||
const uint8_t * | k, | ||
const uint8_t * | c | ||
) |
TODO.
Definition at line 140 of file tweetnacl.cpp.
int crypto_hashblocks | ( | uint8_t * | x, |
const uint8_t * | m, | ||
uint64_t | n | ||
) |
Hash multiple blocks.
crypto_hashblocks() uses crypto_hashblocks_sha512.
Definition at line 602 of file tweetnacl.cpp.
int crypto_hash | ( | uint8_t * | out, |
const uint8_t * | m, | ||
uint64_t | n | ||
) |
Hash a message.
crypto_hash() uses crypto_hash_sha512.
Definition at line 645 of file tweetnacl.cpp.
int crypto_onetimeauth | ( | uint8_t * | out, |
const uint8_t * | m, | ||
uint64_t | n, | ||
const uint8_t * | 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 uint8_t * | h, |
const uint8_t * | m, | ||
uint64_t | n, | ||
const uint8_t * | k | ||
) |
Verify an authentication tag on a message.
Definition at line 261 of file tweetnacl.cpp.
int crypto_scalarmult | ( | uint8_t * | q, |
const uint8_t * | n, | ||
const uint8_t * | p | ||
) |
Scalar multiplication of a point.
crypto_scalarmult() uses crypto_scalarmult_curve25519
Definition at line 452 of file tweetnacl.cpp.
int crypto_scalarmult_base | ( | uint8_t * | q, |
const uint8_t * | n | ||
) |
Scalar multiplication of base point.
crypto_scalarmult_base() uses crypto_scalarmult_curve25519
Definition at line 503 of file tweetnacl.cpp.
int crypto_secretbox | ( | uint8_t * | c, |
const uint8_t * | m, | ||
uint64_t | d, | ||
const uint8_t * | n, | ||
const uint8_t * | 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 | ( | uint8_t * | m, |
const uint8_t * | c, | ||
uint64_t | d, | ||
const uint8_t * | n, | ||
const uint8_t * | k | ||
) |
Verify and decrypt a message.
Definition at line 278 of file tweetnacl.cpp.
int crypto_sign | ( | uint8_t * | sm, |
uint64_t * | smlen, | ||
const uint8_t * | m, | ||
uint64_t | n, | ||
const uint8_t * | 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 794 of file tweetnacl.cpp.
int crypto_sign_open | ( | uint8_t * | m, |
uint64_t * | mlen, | ||
const uint8_t * | sm, | ||
uint64_t | n, | ||
const uint8_t * | 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 862 of file tweetnacl.cpp.
int crypto_sign_keypair | ( | uint8_t * | pk, |
uint8_t * | 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_stream | ( | uint8_t * | c, |
uint64_t | d, | ||
const uint8_t * | n, | ||
const uint8_t * | k | ||
) |
Produce a keystream using XSalsa20.
crypto_stream() uses crypto_stream_xsalsa20
Definition at line 180 of file tweetnacl.cpp.
int crypto_stream_xor | ( | uint8_t * | c, |
const uint8_t * | m, | ||
uint64_t | d, | ||
const uint8_t * | n, | ||
const uint8_t * | k | ||
) |
Encrypt a message using XSalsa20.
Definition at line 187 of file tweetnacl.cpp.
int crypto_stream_salsa20 | ( | uint8_t * | c, |
uint64_t | d, | ||
const uint8_t * | n, | ||
const uint8_t * | k | ||
) |
Produce a keystream using Salsa20.
Definition at line 175 of file tweetnacl.cpp.
int crypto_stream_salsa20_xor | ( | uint8_t * | c, |
const uint8_t * | m, | ||
uint64_t | b, | ||
const uint8_t * | n, | ||
const uint8_t * | k | ||
) |
Encrypt a message using Salsa20.
Definition at line 148 of file tweetnacl.cpp.
int crypto_verify_16 | ( | const uint8_t * | x, |
const uint8_t * | y | ||
) |
Compare 16-byte buffers.
Definition at line 84 of file tweetnacl.cpp.
int crypto_verify_32 | ( | const uint8_t * | x, |
const uint8_t * | y | ||
) |
Compare 32-byte buffers.
Definition at line 89 of file tweetnacl.cpp.