MCCI TweetNaCl
TweetNaCl library adapted for embedded use
Authenticated encryption
+ Collaboration diagram for Authenticated encryption:

Data Structures

struct  mcci_tweetnacl_box_beforenm_t
 Reference structure for precomputation bytes for box. More...
 
struct  mcci_tweetnacl_box_cipherzero_t
 Reference structure for bytes required to be zero at front of cihper text. More...
 
struct  mcci_tweetnacl_box_messagezero_t
 Reference structure for bytes required to be zero at front of plaintext. More...
 
struct  mcci_tweetnacl_box_nonce_t
 Reference structure for nonce bytes for box. More...
 
struct  mcci_tweetnacl_box_privatekey_t
 Reference structure for private key. More...
 
struct  mcci_tweetnacl_box_publickey_t
 Reference structure for public key. More...
 

Functions

static mcci_tweetnacl_result_t mcci_tweetnacl_box (unsigned char *pCipherText, const unsigned char *pPlainText, size_t sizeText, const mcci_tweetnacl_box_nonce_t *pNonce, const mcci_tweetnacl_box_publickey_t *pPublicKey, const mcci_tweetnacl_box_privatekey_t *pPrivateKey)
 Public-key authenticated encryption. More...
 
static mcci_tweetnacl_result_t mcci_tweetnacl_box_afternm (unsigned char *pCipherText, const unsigned char *pPlainText, size_t sizeText, const mcci_tweetnacl_box_nonce_t *pNonce, const mcci_tweetnacl_box_beforenm_t *pPrecomputed)
 Public-key authenticated encryption (precomputed) More...
 
static void mcci_tweetnacl_box_beforenm (mcci_tweetnacl_box_beforenm_t *k, const mcci_tweetnacl_box_publickey_t *pPublicKey, const mcci_tweetnacl_box_privatekey_t *pPrivateKey)
 Precompute for public-key authenticated cryptographic operations. More...
 
mcci_tweetnacl_randombytes_error_t mcci_tweetnacl_box_keypair (mcci_tweetnacl_box_publickey_t *pPublicKey, mcci_tweetnacl_box_privatekey_t *pPrivateKey)
 Generate a public/private key pair. More...
 
static mcci_tweetnacl_result_t mcci_tweetnacl_box_open (unsigned char *pPlainText, const unsigned char *pCipherText, size_t sizeText, const mcci_tweetnacl_box_nonce_t *pNonce, const mcci_tweetnacl_box_publickey_t *pPublicKey, const mcci_tweetnacl_box_privatekey_t *pPrivateKey)
 Public-key authenticated decryption. More...
 
static mcci_tweetnacl_result_t mcci_tweetnacl_box_open_afternm (unsigned char *pPlainText, const unsigned char *pCipherText, size_t sizeText, const mcci_tweetnacl_box_nonce_t *pNonce, const mcci_tweetnacl_box_beforenm_t *pPrecomputed)
 Public-key authenticated decryption (precomputed)) More...
 

Detailed Description

Function Documentation

◆ mcci_tweetnacl_box()

static mcci_tweetnacl_result_t mcci_tweetnacl_box ( unsigned char *  pCipherText,
const unsigned char *  pPlainText,
size_t  sizeText,
const mcci_tweetnacl_box_nonce_t pNonce,
const mcci_tweetnacl_box_publickey_t pPublicKey,
const mcci_tweetnacl_box_privatekey_t pPrivateKey 
)
inlinestatic

Public-key authenticated encryption.

Parameters
[out]pCipherTextpointer to buffer of size sizeText bytes.
[in]pPlainTextpointer to buffer of size sizeText bytes.
[in]sizeTextsize of the output text buffer
[in]pNoncepointer to 24-byte nonce
[in]pPublicKeypointer to 32-byte public key of receiver
[in]pPrivateKeypointer to 32-byte private key of sender
Returns
true for successful encryption, false for parameter validation failure.
Note
pPlainText must start with a string of sizeof(mcci_tweetnacl_box_messagezero_t::bytes) bytes of zero. The first sizeof(mcci_tweetnacl_box_cipherzero_t::bytes) bytes of pCipherText will be zero. Thus, the real ciphertext data is from pCipherText + sizeof(mcci_tweetnacl_box_cipherzero_t::bytes) to pCihperText + sizeText - 1.
See also
https://nacl.cr.yp.to/box.html

Definition at line 238 of file mcci_tweetnacl_box.h.

References mcci_tweetnacl_box_publickey_t::bytes, mcci_tweetnacl_box_privatekey_t::bytes, and mcci_tweetnacl_box_nonce_t::bytes.

◆ mcci_tweetnacl_box_afternm()

static mcci_tweetnacl_result_t mcci_tweetnacl_box_afternm ( unsigned char *  pCipherText,
const unsigned char *  pPlainText,
size_t  sizeText,
const mcci_tweetnacl_box_nonce_t pNonce,
const mcci_tweetnacl_box_beforenm_t pPrecomputed 
)
inlinestatic

Public-key authenticated encryption (precomputed)

Parameters
[out]pCipherTextpointer to buffer of size sizeText bytes.
[in]pPlainTextpointer to buffer of size sizeText bytes.
[in]sizeTextsize of the output text buffer
[in]pNoncepointer to 24-byte nonce
[in]pPrecomputedpointer to 32-byte precomputed buffer.
Returns
true for successful encryption, false for parameter validation failure.
Note
pPlainText must start with a string of sizeof(mcci_tweetnacl_box_messagezero_t::bytes) bytes of zero. The first sizeof(mcci_tweetnacl_box_cipherzero_t::bytes) bytes of pCipherText will be zero. Thus, the real ciphertext data is from pCipherText + sizeof(mcci_tweetnacl_box_cipherzero_t::bytes) to pCipherText + sizeText - 1.
Returns
true if successful, false for failures [due to parameter problems only].
See also
https://nacl.cr.yp.to/box.html

Definition at line 157 of file mcci_tweetnacl_box.h.

References mcci_tweetnacl_box_nonce_t::bytes, and mcci_tweetnacl_box_beforenm_t::bytes.

◆ mcci_tweetnacl_box_beforenm()

static void mcci_tweetnacl_box_beforenm ( mcci_tweetnacl_box_beforenm_t k,
const mcci_tweetnacl_box_publickey_t pPublicKey,
const mcci_tweetnacl_box_privatekey_t pPrivateKey 
)
inlinestatic

Precompute for public-key authenticated cryptographic operations.

Parameters
[out]kis set to the context
[in]pPublicKey,pPrivateKeyare the public and private keys to be used for this operation.
See also
https://nacl.cr.yp.to/box.html

Definition at line 119 of file mcci_tweetnacl_box.h.

References mcci_tweetnacl_box_publickey_t::bytes, mcci_tweetnacl_box_privatekey_t::bytes, and mcci_tweetnacl_box_beforenm_t::bytes.

◆ mcci_tweetnacl_box_keypair()

mcci_tweetnacl_randombytes_error_t mcci_tweetnacl_box_keypair ( mcci_tweetnacl_box_publickey_t pPublicKey,
mcci_tweetnacl_box_privatekey_t pPrivateKey 
)

Generate a public/private key pair.

Parameters
[out]pPublicKeyis set to the public key
[in]pPrivateKeyis set to the private key
Returns
error code; zero for success, non-zero for failure.
Note
depends on an implementation of randombytes().
See also
https://nacl.cr.yp.to/box.html

◆ mcci_tweetnacl_box_open()

static mcci_tweetnacl_result_t mcci_tweetnacl_box_open ( unsigned char *  pPlainText,
const unsigned char *  pCipherText,
size_t  sizeText,
const mcci_tweetnacl_box_nonce_t pNonce,
const mcci_tweetnacl_box_publickey_t pPublicKey,
const mcci_tweetnacl_box_privatekey_t pPrivateKey 
)
inlinestatic

Public-key authenticated decryption.

Parameters
[out]pPlainTextpointer to buffer of size sizeText bytes.
[in]pCipherTextpointer to buffer of size sizeText bytes.
[in]sizeTextsize of the output text buffer
[in]pNoncepointer to 24-byte nonce
[in]pPublicKeypointer to 32-byte public key of sender
[in]pPrivateKeypointer to 32-byte private key of receiver
Returns
0 for successful decryption and authentication, -1 otherwise.
Note
pCipherText must start with a string of sizeof(mcci_tweetnacl_secretbox_cipherzero_t::bytes) bytes of zero. The first sizeof(mcci_tweetnacl_secretbox_messagezero_t::bytes) bytes of pPlainText will be zero. Thus, the real plaintext data is from pPlainText + sizeof(mcci_tweetnacl_secretbox_messagezero_t::bytes) to pPlainText + sizeText - 1.
See also
https://nacl.cr.yp.to/box.html

Definition at line 281 of file mcci_tweetnacl_box.h.

References mcci_tweetnacl_box_publickey_t::bytes, mcci_tweetnacl_box_privatekey_t::bytes, and mcci_tweetnacl_box_nonce_t::bytes.

◆ mcci_tweetnacl_box_open_afternm()

static mcci_tweetnacl_result_t mcci_tweetnacl_box_open_afternm ( unsigned char *  pPlainText,
const unsigned char *  pCipherText,
size_t  sizeText,
const mcci_tweetnacl_box_nonce_t pNonce,
const mcci_tweetnacl_box_beforenm_t pPrecomputed 
)
inlinestatic

Public-key authenticated decryption (precomputed))

Parameters
[out]pPlainTextpointer to buffer of size sizeText bytes.
[in]pCipherTextpointer to buffer of size sizeText bytes.
[in]sizeTextsize of the output text buffer
[in]pNoncepointer to 24-byte nonce
[in]pPrecomputedpointer to 32-byte precomputed buffer.
Returns
zero for successful decryption and authenticaion, -1 otherwise.
Note
pCipherText must start with a string of sizeof(mcci_tweetnacl_box_cipherzero_t::bytes) bytes of zero. The first sizeof(mcci_tweetnacl_box_messagezero_t::bytes) bytes of pPlainText will be zero. Thus, the real plaintext data is from pPlainText + sizeof(mcci_tweetnacl_box_messagezero_t::bytes) to pPlainText + sizeText - 1.
See also
https://nacl.cr.yp.to/box.html

Definition at line 197 of file mcci_tweetnacl_box.h.

References mcci_tweetnacl_box_nonce_t::bytes, and mcci_tweetnacl_box_beforenm_t::bytes.