BOLOS TEE
Macros | Functions
bolos_sodium.h File Reference

Limited libsodium/NaCl implementation. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define crypto_secretbox_MACBYTES   16
 
#define crypto_secretbox_NONCEBYTES   24
 
#define crypto_secretbox_KEYBYTES   32
 
#define crypto_auth_KEYBYTES   32
 
#define crypto_auth_BYTES   32
 
#define crypto_box_PUBLICKEYBYTES   32
 
#define crypto_box_SECRETKEYBYTES   32
 
#define crypto_box_NONCEBYTES   24
 
#define crypto_box_MACBYTES   16
 
#define crypto_box_SEALBYTES   (crypto_box_PUBLICKEYBYTES + crypto_box_MACBYTES)
 
#define crypto_sign_PUBLICKEYBYTES   32
 
#define crypto_sign_SECRETKEYBYTES   64
 
#define crypto_sign_BYTES   64
 

Functions

int crypto_secretbox_easy (unsigned char *c, const unsigned char *m, unsigned long mlen, const unsigned char *n, const unsigned char *k)
 Authenticated Encryption (XSalsa20 + Poly1305) of a message using a symmetric key. More...
 
int crypto_secretbox_open_easy (unsigned char *m, const unsigned char *c, unsigned long clen, const unsigned char *n, const unsigned char *k)
 Decrypt a message encrypted by crypto_secretbox_easy. More...
 
int crypto_auth (unsigned char *out, const unsigned char *in, unsigned long inlen, const unsigned char *k)
 Compute an authentication (HMAC) of a message using a symmetric key. More...
 
int crypto_auth_verify (const unsigned char *h, const unsigned char *in, unsigned long inlen, const unsigned char *k)
 Verify an authentication (HMAC) of a message generated by crypto_auth. More...
 
int crypto_box_keypair (unsigned char *pk, unsigned char *sk)
 Generate a keypair to be used for Authenticated Encryption with crypto_box functions. More...
 
int crypto_box_easy (unsigned char *c, const unsigned char *m, unsigned long mlen, const unsigned char *n, const unsigned char *pk, const unsigned char *sk)
 Authenticated Encryption (X25519 + XSalsa20 + Poly1305) of a message using an asymmetric keypair. More...
 
int crypto_box_open_easy (unsigned char *m, const unsigned char *c, unsigned long clen, const unsigned char *n, const unsigned char *pk, const unsigned char *sk)
 Decrypt a message encrypted by crypto_box_easy. More...
 
int crypto_box_seal (unsigned char *c, const unsigned char *m, unsigned long mlen, const unsigned char *pk)
 Anonymous encryption (X25519, XSalsa20, Poly1305) of a message using an asymmetric keypair. More...
 
int crypto_box_seal_open (unsigned char *m, const unsigned char *c, unsigned long clen, const unsigned char *pk, const unsigned char *sk)
 Decrypt a message encrypted by crypto_box_seal. More...
 
int crypto_sign_keypair (unsigned char *pk, unsigned char *sk)
 Generate a keypair to be used for Signature with crypto_sign functions. More...
 
int crypto_sign (unsigned char *sm, unsigned long *smlen_p, const unsigned char *m, unsigned long mlen, const unsigned char *sk)
 Generate a Combined Signature (Ed25519) of a message using an asymmetric keypair. More...
 
int crypto_sign_open (unsigned char *m, unsigned long *mlen_p, const unsigned char *sm, unsigned long smlen, const unsigned char *pk)
 Unwrap a message wrapped by crypto_sign. More...
 

Detailed Description

Limited libsodium/NaCl implementation.

Author
Ledger Firmware Team hello.nosp@m.@led.nosp@m.ger.f.nosp@m.r
Version
1.0
Date
29th of February 2016

Provide an interface to the box, secretbox, auth, and signature on ED25519 APIs from libsodium / NaCl

This API is specific to the TEE implementation. Support on other platforms is being added.

Function Documentation

int crypto_auth ( unsigned char *  out,
const unsigned char *  in,
unsigned long  inlen,
const unsigned char *  k 
)

Compute an authentication (HMAC) of a message using a symmetric key.

Parameters
[out]outDestination buffer, should be at least crypto_auth_BYTES bytes long
[in]inSource buffer
[in]inlenSize of the message to process
[in]kSymmetric key, should be crypto_auth_KEYBYTES bytes long
Returns
0 if success, different value if error
int crypto_auth_verify ( const unsigned char *  h,
const unsigned char *  in,
unsigned long  inlen,
const unsigned char *  k 
)

Verify an authentication (HMAC) of a message generated by crypto_auth.

Parameters
[in]hBuffer containing the tag returned by crypto_auth
[in]inSource buffer
[in]inlenSize of the message to process
[in]kSymmetric key used for crypto_auth
Returns
0 if success, different value if error
int crypto_box_easy ( unsigned char *  c,
const unsigned char *  m,
unsigned long  mlen,
const unsigned char *  n,
const unsigned char *  pk,
const unsigned char *  sk 
)

Authenticated Encryption (X25519 + XSalsa20 + Poly1305) of a message using an asymmetric keypair.

Parameters
[out]cDestination buffer, should be at least crypto_box_SEALBYTES + mlen bytes long
[in]mSource buffer
[in]mlenSize of the message to process
[in]nNonce, should be crypto_box_NONCEBYTES bytes long
[in]pkPublic key of the recipient generated previously
[in]skPrivate key of the sender generated previously
Returns
0 if success, different value if error
int crypto_box_keypair ( unsigned char *  pk,
unsigned char *  sk 
)

Generate a keypair to be used for Authenticated Encryption with crypto_box functions.

Parameters
[out]pkDestination buffer for the public key, should be at least crypto_box_PUBLICKEYBYTES bytes long
[out]skDestination buffer for the private key, should be at least crypto_box_SECRETKEYBYTES bytes long
Returns
0 if success, different value if error
int crypto_box_open_easy ( unsigned char *  m,
const unsigned char *  c,
unsigned long  clen,
const unsigned char *  n,
const unsigned char *  pk,
const unsigned char *  sk 
)

Decrypt a message encrypted by crypto_box_easy.

Parameters
[out]mDestination buffer, should be at least clen - crypto_box_MACBYTES bytes long
[in]cSource buffer
[in]clenSize of the encrypted message to process
[in]nNonce used for crypto_box_easy
[in]pkPublic key of the sender generated previously
[in]skPrivate key of the recipient generated previously
Returns
0 if success, different value if error
int crypto_box_seal ( unsigned char *  c,
const unsigned char *  m,
unsigned long  mlen,
const unsigned char *  pk 
)

Anonymous encryption (X25519, XSalsa20, Poly1305) of a message using an asymmetric keypair.

Parameters
[out]cDestination buffer, should be at least crypto_box_SEALBYTES + mlen bytes long
[in]mSource buffer
[in]mlenSize of the message to process
[in]pkPublic key of the recipient generated previously
Returns
0 if success, different value if error
int crypto_box_seal_open ( unsigned char *  m,
const unsigned char *  c,
unsigned long  clen,
const unsigned char *  pk,
const unsigned char *  sk 
)

Decrypt a message encrypted by crypto_box_seal.

Parameters
[out]mDestination buffer, should be at least clen - crypto_box_SEALBYTES bytes long
[in]cSource buffer
[in]clenSize of the encrypted message to process
[in]pkPublic key of the recipient generated previously
[in]skPrivate key of the recipient generated previously
Returns
0 if success, different value if error
int crypto_secretbox_easy ( unsigned char *  c,
const unsigned char *  m,
unsigned long  mlen,
const unsigned char *  n,
const unsigned char *  k 
)

Authenticated Encryption (XSalsa20 + Poly1305) of a message using a symmetric key.

Parameters
[out]cDestination buffer, should be at least crypto_secretbox_MACBYTES + mlen bytes long
[in]mSource buffer
[in]mlenSize of the message to process
[in]nNonce, should be crypto_secretbox_NONCEBYTES bytes long
[in]kSymmetric key, should be crypto_secretbox_KEYBYTES bytes long
Returns
0 if success, different value if error
int crypto_secretbox_open_easy ( unsigned char *  m,
const unsigned char *  c,
unsigned long  clen,
const unsigned char *  n,
const unsigned char *  k 
)

Decrypt a message encrypted by crypto_secretbox_easy.

Parameters
[out]mDestination buffer, should be at least clen - crypto_secretbox_MACBYTES bytes long
[in]cSource buffer
[in]clenSize of the encrypted message to process
[in]nNonce used for crypto_secretbox_easy
[in]kSymmetric key used for crypto_secretbox_easy
Returns
0 if success, different value if error
int crypto_sign ( unsigned char *  sm,
unsigned long *  smlen_p,
const unsigned char *  m,
unsigned long  mlen,
const unsigned char *  sk 
)

Generate a Combined Signature (Ed25519) of a message using an asymmetric keypair.

Parameters
[out]smDestination buffer, should be at least crypto_sign_BYTES + mlen bytes long
[in,out]smlem_pPointer to the length of the destination buffer, filled with the actual length of the result
[in]mSource buffer
[in]mlenSize of the message to process
[in]skPrivate key of the sender generated previously
Returns
0 if success, different value if error
int crypto_sign_keypair ( unsigned char *  pk,
unsigned char *  sk 
)

Generate a keypair to be used for Signature with crypto_sign functions.

Parameters
[out]pkDestination buffer for the public key, should be at least crypto_sign_PUBLICKEYBYTES bytes long
[out]skDestination buffer for the private key, should be at least crypto_sign_SECRETKEYBYTES bytes long
Returns
0 if success, different value if error
int crypto_sign_open ( unsigned char *  m,
unsigned long *  mlen_p,
const unsigned char *  sm,
unsigned long  smlen,
const unsigned char *  pk 
)

Unwrap a message wrapped by crypto_sign.

Parameters
[out]mDestination buffer, should be at least smlen bytes long
[in,out]mlem_pPointer to the length of the destination buffer, filled with the actual length of the result
[in]smSource buffer
[in]smlenSize of the message to process
[in]pkPublic key of the sender generated previously
Returns
0 if success, different value if error