MCCI TweetNaCl
TweetNaCl library adapted for embedded use
+ Collaboration diagram for Signatures:

Data Structures

struct  mcci_tweetnacl_sign_privatekey_t
 Private Key for TweetNaCl sign operations. More...
 
struct  mcci_tweetnacl_sign_publickey_t
 Public Key for TweetNaCl sign operations. More...
 
struct  mcci_tweetnacl_sign_signature_t
 Signature block for TweetNaCl sign operations. More...
 

Macros

#define mcci_tweetnacl_sign_signature_size()   sizeof(((mcci_tweetnacl_sign_signature_t *)NULL)->bytes)
 Return size of signature, in bytes. More...
 

Functions

mcci_tweetnacl_result_t mcci_tweetnacl_sign (unsigned char *pSignedMessage, size_t *pSignedMessageSize, const unsigned char *pMessage, size_t messageSize, const mcci_tweetnacl_sign_privatekey_t *pPrivateKey)
 sign a message (typically a hash of the real message) More...
 
mcci_tweetnacl_randombytes_error_t mcci_tweetnacl_sign_keypair (mcci_tweetnacl_sign_publickey_t *pPublicKey, mcci_tweetnacl_sign_privatekey_t *pPrivateKey)
 generate a private key and a corresponding public key More...
 
static mcci_tweetnacl_result_t mcci_tweetnacl_sign_open (unsigned char *pMessage, size_t *pMessageSize, const unsigned char *pSignedMessage, size_t messageSize, const mcci_tweetnacl_sign_publickey_t *pPublicKey)
 given a signed message, verify and output signed contents More...
 

Detailed Description

Macro Definition Documentation

◆ mcci_tweetnacl_sign_signature_size

#define mcci_tweetnacl_sign_signature_size ( )    sizeof(((mcci_tweetnacl_sign_signature_t *)NULL)->bytes)

Return size of signature, in bytes.

Definition at line 103 of file mcci_tweetnacl_sign.h.

Function Documentation

◆ mcci_tweetnacl_sign()

mcci_tweetnacl_result_t mcci_tweetnacl_sign ( unsigned char *  pSignedMessage,
size_t *  pSignedMessageSize,
const unsigned char *  pMessage,
size_t  messageSize,
const mcci_tweetnacl_sign_privatekey_t pPrivateKey 
)

sign a message (typically a hash of the real message)

Parameters
[out]pSignedMessagepoints to buffer to received signed message.
[out]pSignedMessageSizepoints to cell to receive size of signed message.
[in]pMessageinput message
[in]messageSizesize of input message, in bytes
[in]pPrivateKeyprivate key to be used to sign message.
Returns
zero if successfully signed; in which case *pSignedMessageSize is set to the size. Otherwise non-zero, in which case *pSignedMessageSize is zero.

This is a wrapper for TweetNaCl's crypto_sign(), enforcing a few adjustments. Size is a size_t rather than unsigned long long; if the input size is so large that it would wrap around, we refuse to sign, and return a failure. Because crypto_sign() productes an unsigned long long by reference, we have to stage the result and narrow it when copying back to the client. We are careful to avoid overflow, although overflow arguably is impossible.

Note
The buffer at pSignedMessage must be at least messageSize + mcci_tweetnacl_sign_signature_size() bytes long.

◆ mcci_tweetnacl_sign_keypair()

mcci_tweetnacl_randombytes_error_t mcci_tweetnacl_sign_keypair ( mcci_tweetnacl_sign_publickey_t pPublicKey,
mcci_tweetnacl_sign_privatekey_t pPrivateKey 
)

generate a private key and a corresponding public key

Parameters
[out]pPublicKeyis set to the generated public key.
[in]pPrivateKeyis set to the generated private key.
Returns
0 for success, non-zero error code for failure.
Note
this function requires that randombytes() be implemented and successful. Further, it requires a cryptographically secure string of bytes when randombytes() succeeds.
See also
https://nacl.cr.yp.to/sign.html

◆ mcci_tweetnacl_sign_open()

static mcci_tweetnacl_result_t mcci_tweetnacl_sign_open ( unsigned char *  pMessage,
size_t *  pMessageSize,
const unsigned char *  pSignedMessage,
size_t  messageSize,
const mcci_tweetnacl_sign_publickey_t pPublicKey 
)
inlinestatic

given a signed message, verify and output signed contents

Parameters
[out]pMessagepoints to buffer to received verified message.
[out]pMessageSizepoints to cell to receive size of verified message.
[in]pSignedMessageinput signed (opaque) message
[in]messageSizesize of signed message, in bytes
[in]pPublicKeypublic key to be used to verify message.
Returns
zero if successfully verified; in which case pMessage[] is set to the validated contents, and *pMessageSize is set to the size. Otherwise non-zero, in which case pMessage[] may be changed but should be ignored.

This is a wrapper for TweetNaCl's crypto_sign_open(), enforcing a few adjustments. Size is a size_t rather than unsigned long long. Because crypto_sign_out() productes an unsigned long long by reference, we have to stage the result and narrow it when copying back to the client.

Note
messageSize must be at least 64. The buffer at pMessage must be at least messageSize - 64 bytes long.

Definition at line 162 of file mcci_tweetnacl_sign.h.

References mcci_tweetnacl_sign_publickey_t::bytes.