BOLOS TEE
Functions
bolos_crypto.h File Reference

Generic Cryptographic API. More...

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

Go to the source code of this file.

Functions

uint8_t bls_rng_u8 (void)
 generate a random byte More...
 
int bls_rng (uint8_t *buffer, size_t len)
 generate a random buffer More...
 
int bls_ripemd160_init (bls_ripemd160_t *hash)
 Initialize a ripmd160 context. More...
 
int bls_sha1_init (bls_sha1_t *hash)
 Initialize a sha1 context. More...
 
int bls_sha256_init (bls_sha256_t *hash)
 Initialize a sha256 context. More...
 
int bls_sha512_init (bls_sha512_t *hash)
 Initialize a sha512 context. More...
 
int bls_hash (bls_hash_t *hash, int mode, const uint8_t WIDE *in, size_t len, uint8_t *out)
 Add more data to hash. More...
 
int bls_hmac_ripemd160_init (bls_hmac_ripemd160_t *hmac, const uint8_t WIDE *key, size_t key_len)
 Initialize a HMAC sha512 context. More...
 
int bls_hmac_sha256_init (bls_hmac_sha256_t *hmac, const uint8_t WIDE *key, size_t key_len)
 Initialize a HMAC sha256 context. More...
 
int bls_hmac_sha512_init (bls_hmac_sha512_t *hmac, const uint8_t WIDE *key, size_t key_len)
 Initialize a HMAC sha512 context. More...
 
int bls_hmac (bls_hmac_t *hmac, int mode, const uint8_t WIDE *in, size_t len, uint8_t *mac)
 Add more data to HMAC. More...
 
int bls_pbkdf2 (bls_md_t hash, const bls_area_t *password, const bls_area_t *salt, int iterations, uint8_t *out)
 Stretch a password using PBKDF2. More...
 
int bls_des_init_key (const uint8_t WIDE *rawkey, size_t key_len, bls_des_key_t *key)
 Initialize a DES Key. More...
 
int bls_des (bls_des_key_t WIDE *key, int mode, const bls_area_t *in, bls_area_t *out)
 Add data to a DES operation. More...
 
int bls_des_iv (bls_des_key_t WIDE *key, int mode, const bls_area_t *iv, const bls_area_t *in, bls_area_t *out)
 Add data to a DES operation using an Initialization Vector. More...
 
int bls_aes_init_key (const uint8_t WIDE *rawkey, size_t key_len, bls_aes_key_t *key)
 Initialize an AES Key. More...
 
int bls_aes (bls_aes_key_t WIDE *key, int mode, const bls_area_t *in, bls_area_t *out)
 Add data to an AES operation. More...
 
int bls_aes_iv (bls_aes_key_t WIDE *key, int mode, const bls_area_t *iv, const bls_area_t *in, bls_area_t *out)
 Add data to an AES operation using an Initialization Vector. More...
 
int bls_aes_iv_gcm (bls_aes_key_t WIDE *key, int mode, const bls_area_t *in, const bls_area_t *iv, const bls_area_t WIDE *aadTag, bls_area_t *out)
 Add data to an AES GCM operation. More...
 
int bls_rsa_init_public_key (const bls_rsa_keypair_data_t WIDE *keyData, bls_rsa_abstract_public_key_t *key)
 Initialize a public RSA Key. More...
 
int bls_rsa_init_private_key (const bls_rsa_keypair_data_t WIDE *keyData, bls_rsa_abstract_private_key_t *key)
 Initialize a private RSA Key. More...
 
int bls_rsa_init_private_key_crt (const bls_rsa_crt_t WIDE *crtParameters, bls_rsa_abstract_private_key_t *key)
 Initialize a private RSA Key with CRT parameters. More...
 
int bls_rsa_generate_keypair (int modulus_len, bls_rsa_abstract_private_key_t *privateKey, bls_rsa_abstract_public_key_t *publicKey, bls_rsa_keypair_data_t *generatedKeypairInfo)
 Generate a RSA keypair. More...
 
int bls_rsa_get_public_key_data (bls_rsa_abstract_public_key_t *publicKey, bls_rsa_keypair_data_t *keyInfo)
 Retrieve a RSA public key information. More...
 
int bls_rsa_pub (bls_rsa_abstract_public_key_t WIDE *key, int mode, bls_md_t hashID, const bls_area_t *src, const bls_area_t *dest)
 Perform a RSA public operation. More...
 
int bls_rsa_priv (bls_rsa_abstract_private_key_t WIDE *key, int mode, bls_md_t hashID, const bls_area_t *src, const bls_area_t *dest)
 Perform a RSA private operation. More...
 
bls_curve_domain_t WIDE * bls_ecfp_get_domain (bls_curve_t curve)
 Retrieve the domain of the curve. More...
 
int bls_ecfp_is_valid_point (const bls_curve_domain_t WIDE *domain, const uint8_t WIDE *point)
 Verify that a given point is really on the specified curve. More...
 
int bls_ecfp_add_point (const bls_curve_domain_t WIDE *domain, uint8_t *R, const uint8_t WIDE *P, const uint8_t WIDE *Q)
 Add two affine point. More...
 
int bls_ecdsa_init_public_key (bls_curve_t curve, const uint8_t WIDE *rawkey, size_t key_len, bls_ecfp_public_key_t *key)
 Initialize a public ECFP Key. More...
 
int bls_ecdsa_init_private_key (bls_curve_t curve, const uint8_t WIDE *rawkey, size_t key_len, bls_ecfp_private_key_t *key)
 Initialize a private ECFP Key. More...
 
int bls_ecfp_generate_pair (bls_curve_t curve, bls_ecfp_public_key_t *public_key, bls_ecfp_private_key_t *private_key, uint8_t *d)
 Generate a ecfp key pair. More...
 
int bls_ecfp_get_public_component (const bls_ecfp_public_key_t *public_key, uint8_t *W)
 Return the uncompressed point of a public ECFP Key. More...
 
int bls_ecdsa_sign (bls_ecfp_private_key_t WIDE *key, int mode, bls_md_t hashID, const uint8_t WIDE *hash, size_t hash_len, uint8_t *sig)
 Sign a hash message according to ECDSA scheme. More...
 
int bls_ecdsa_verify (bls_ecfp_public_key_t WIDE *key, int mode, bls_md_t hashID, const uint8_t WIDE *hash, size_t hash_len, uint8_t *sig)
 Verify a hash message signature according to ECDSA scheme. More...
 
int bls_schnorr_sign (bls_ecfp_private_key_t WIDE *key, int mode, bls_md_t hashID, const uint8_t WIDE *hash, size_t hash_len, uint8_t *sig)
 Sign a hash message according to Schnorr scheme. More...
 
int bls_schnorr_verify (bls_ecfp_public_key_t WIDE *key, int mode, bls_md_t hashID, const uint8_t WIDE *hash, size_t hash_len, uint8_t *sig)
 Verify a hash message signature according to Schnorr scheme. More...
 
int bls_ecdh (bls_ecfp_private_key_t WIDE *key, int mode, const uint8_t WIDE *public_point, uint8_t *secret)
 Compute a shared secret according to ECDH specifiaction. More...
 
uint16_t bls_crc16 (const void WIDE *buffer, size_t len)
 Compute a 16 bits checksum value. More...
 
uint16_t bls_crc16_update (unsigned short crc, const void WIDE *buffer, size_t len)
 Update a 16 bits checksum value. More...
 
void bls_math_addm (uint8_t *r, const uint8_t WIDE *a, const uint8_t WIDE *b, const uint8_t WIDE *m, size_t len)
 Modular addition of tow big integer of the size: r = a+b mod m. More...
 
int bls_math_cmp (const uint8_t WIDE *a, const uint8_t WIDE *b, size_t len)
 Compare to unsigned long big-endian integer. More...
 
int bls_math_is_zero (const uint8_t WIDE *a, size_t len)
 Compare to unsigned long big-endian integer to zero. More...
 
void bls_math_modm (uint8_t *v, size_t len_v, const uint8_t WIDE *m, size_t len_m)
 Reduce in place (left zero padded) the given value : v = v mod m. More...
 

Detailed Description

Generic Cryptographic API.

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

Perform general purpose cryptographic operations

In this release, the API doesn't implement exceptions

Function Documentation

int bls_aes ( bls_aes_key_t WIDE *  key,
int  mode,
const bls_area_t in,
bls_area_t out 
)

Add data to an AES operation.

Parameters
[in]keyA aes key fully inited with 'bls_aes_init_key'
[in]mode16bits crypto mode flags. See above. Supported flags:
  • BLS_LAST
  • BLS_ENCRYPT
  • BLS_DECRYPT
  • BLS_SIGN
  • BLS_VERIFY
  • BLS_PAD_NONE
  • BLS_PAD_ISO9797M1
  • BLS_PAD_ISO9797M2
  • BLS_CHAIN_ECB
  • BLS_CHAIN_CBC
  • BLS_AES_PAD_CTR
  • BLS_AES_PAD_CFB
  • BLS_AES_PAD_OFB
[in]inInput data to encrypt/decrypt and associated length If BLS_LAST is set, padding is automtically done according to 'mode'. Else 'len' shall be a multiple of AES_BLOCK_SIZE.
[out]outEither:
  • encrypted/decrypted ouput data
  • produced signature
  • signature to check 'out' buffer length is implicit, no check is done
Returns
  • In case of ENCRYPT, DECRYPT or SIGN mode: output length data
  • In case of VERIFY mode: 0 if signature is false, AES_BLOCK_SIZE if signature is correct
Exceptions
INVALID_PARAMETER
int bls_aes_init_key ( const uint8_t WIDE *  rawkey,
size_t  key_len,
bls_aes_key_t key 
)

Initialize an AES Key.

Once initialized, the key may be stored in non-volatile memory an reused 'as-is' for any AES processing

Parameters
[in]rawkeyraw key value
[in]key_lenkey bytes length: 16 or 32
[out]keyAES key to init
keyready to use key to init
Returns
1 if success, 0 if error
int bls_aes_iv ( bls_aes_key_t WIDE *  key,
int  mode,
const bls_area_t iv,
const bls_area_t in,
bls_area_t out 
)

Add data to an AES operation using an Initialization Vector.

Parameters
[in]keyA aes key fully inited with 'bls_aes_init_key'
[in]mode16bits crypto mode flags. See above. Supported flags:
  • BLS_LAST
  • BLS_ENCRYPT
  • BLS_DECRYPT
  • BLS_SIGN
  • BLS_VERIFY
  • BLS_PAD_NONE
  • BLS_PAD_ISO9797M1
  • BLS_PAD_ISO9797M2
  • BLS_CHAIN_ECB
  • BLS_CHAIN_CBC
  • BLS_AES_PAD_CTR
  • BLS_AES_PAD_CFB
  • BLS_AES_PAD_OFB
[in]ivInitialization Vector and associated length Only meaningful for the first block of a BLS_CHAIN_CBC, BLS_AES_PAD_CTR, BLS_AES_PAD_CFB, BLS_AES_PAD_OFB chaining. 'len' shall be a multiple of DES_BLOCK_SIZE.
[in]inInput data to encrypt/decrypt and associated length If BLS_LAST is set, padding is automtically done according to 'mode'. Else 'len' shall be a multiple of AES_BLOCK_SIZE.
[out]outEither:
  • encrypted/decrypted ouput data
  • produced signature
  • signature to check 'out' buffer length is implicit, no check is done
Returns
  • In case of ENCRYPT, DECRYPT or SIGN mode: output length data
  • In case of VERIFY mode: 0 if signature is false, AES_BLOCK_SIZE if signature is correct
Exceptions
INVALID_PARAMETER
int bls_aes_iv_gcm ( bls_aes_key_t WIDE *  key,
int  mode,
const bls_area_t in,
const bls_area_t iv,
const bls_area_t WIDE *  aadTag,
bls_area_t out 
)

Add data to an AES GCM operation.

Warning
THIS METHOD IS NOT SUPPORTED IN THE CURRENT RELEASE
Parameters
[in]keyA aes key fully inited with 'bls_aes_init_key'
[in]mode16bits crypto mode flags. See above. Supported flags:
  • BLS_LAST
  • BLS_ENCRYPT
  • BLS_DECRYPT
[in]inInput data to encrypt/decrypt and associated length If BLS_LAST is set, padding is automtically done according to 'mode'. Else 'len' shall be a multiple of AES_BLOCK_SIZE.
[in]ivInitialization Vector and associated length 'len' shall be a multiple of DES_BLOCK_SIZE.
[in,out]aadTag
  • In case of ENCRYPT mode : AAD in, tag out
  • In case of DECRYPT mode : tag in
[out]outEither:
  • encrypted/decrypted ouput data 'out' buffer length is implicit, no check is done
Returns
  • In case of ENCRYPT, DECRYPT : output length data
Exceptions
INVALID_PARAMETER
uint16_t bls_crc16 ( const void WIDE *  buffer,
size_t  len 
)

Compute a 16 bits checksum value.

The 16 bits value is computed according to the CRC16 CCITT definition.

Warning
THIS METHOD IS NOT SUPPORTED IN THE CURRENT RELEASE
Parameters
[in]bufferThe buffer to compute the crc over.
[in]BytesLength of the 'buffer'
Returns
CRC value
uint16_t bls_crc16_update ( unsigned short  crc,
const void WIDE *  buffer,
size_t  len 
)

Update a 16 bits checksum value.

The 16 bits value is computed according to the CRC16 CCITT definition.

Warning
THIS METHOD IS NOT SUPPORTED IN THE CURRENT RELEASE
Parameters
[in]crcInitial CRC value
[in]bufferThe buffer to compute the crc over.
[in]BytesLength of the 'buffer'
Returns
CRC value
int bls_des ( bls_des_key_t WIDE *  key,
int  mode,
const bls_area_t in,
bls_area_t out 
)

Add data to a DES operation.

Parameters
[in]keyA des key fully inited with 'bls_des_init_key'
[in]mode16bits crypto mode flags. See above. Supported flags:
  • BLS_LAST
  • BLS_ENCRYPT
  • BLS_DECRYPT
  • BLS_SIGN
  • BLS_VERIFY
  • BLS_PAD_NONE
  • BLS_PAD_ISO9797M1
  • BLS_PAD_ISO9797M2
  • BLS_CHAIN_ECB
  • BLS_CHAIN_CBC
[in]inInput data to encrypt/decrypt and associated length If BLS_LAST is set, padding is automatically done according to 'mode'. Else 'len' shall be a multiple of DES_BLOCK_SIZE.
[out]outEither:
  • encrypted/decrypted ouput data
  • produced signature
  • signature to check
Returns
  • In case of ENCRYPT, DECRYPT or SIGN mode: output length data
  • In case of VERIFY mode: 0 if signature is false, DES_BLOCK_SIZE if signature is correct
Exceptions
INVALID_PARAMETER
int bls_des_init_key ( const uint8_t WIDE *  rawkey,
size_t  key_len,
bls_des_key_t key 
)

Initialize a DES Key.

Once initialized, the key may be stored in non-volatile memory an reused 'as-is' for any DES processing

Parameters
[in]rawkeyraw key value
[in]key_lenkey bytes length: 8,16 or 24
[out]keyDES key to init
keyready to use key to init
Returns
1 if success, 0 if error
int bls_des_iv ( bls_des_key_t WIDE *  key,
int  mode,
const bls_area_t iv,
const bls_area_t in,
bls_area_t out 
)

Add data to a DES operation using an Initialization Vector.

Parameters
[in]keyA des key fully inited with 'bls_des_init_key'
[in]mode16bits crypto mode flags. See above. Supported flags:
  • BLS_LAST
  • BLS_ENCRYPT
  • BLS_DECRYPT
  • BLS_SIGN
  • BLS_VERIFY
  • BLS_PAD_NONE
  • BLS_PAD_ISO9797M1
  • BLS_PAD_ISO9797M2
  • BLS_CHAIN_ECB
  • BLS_CHAIN_CBC
[in]ivInitialization Vector and associated length Only meaningful for the first block of a BLS_CHAIN_CBC chaining. 'len' shall be a multiple of DES_BLOCK_SIZE.
[in]inInput data to encrypt/decrypt and associated length If BLS_LAST is set, padding is automatically done according to 'mode'. Else 'len' shall be a multiple of DES_BLOCK_SIZE.
[out]outEither:
  • encrypted/decrypted ouput data
  • produced signature
  • signature to check
Returns
  • In case of ENCRYPT, DECRYPT or SIGN mode: output length data
  • In case of VERIFY mode: 0 if signature is false, DES_BLOCK_SIZE if signature is correct
Exceptions
INVALID_PARAMETER
int bls_ecdh ( bls_ecfp_private_key_t WIDE *  key,
int  mode,
const uint8_t WIDE *  public_point,
uint8_t *  secret 
)

Compute a shared secret according to ECDH specifiaction.

Depending on the mode, the shared secret is either the full point, a hash of the x coordinate or only the x coordinate

Parameters
[in]keyA private ecfp key fully inited with 'bls_ecdsa_init_private_key'
[in]mode16bits crypto mode flags. See above. Supported flags:
  • BLS_ECDH_POINT
  • BLS_ECDH_X
  • BLS_ECDH_HASHED
[in]public_pointOther party public point encoded as: 04 x y, where x and y are encoded as big endian raw value and have bits length equals to the curve size.
[out]secretGenerated shared secret.
Returns
size of secret
Exceptions
INVALID_PARAMETER
int bls_ecdsa_init_private_key ( bls_curve_t  curve,
const uint8_t WIDE *  rawkey,
size_t  key_len,
bls_ecfp_private_key_t key 
)

Initialize a private ECFP Key.

Once initialized, the key may be stored in non-volatile memory and reused 'as-is' for any ECDSA processing Passing NULL as raw key initializes the key without value. The key may be used as parameter for bls_ecfp_generate_pair.

Parameters
[in]curveThe curve domain parameters to work with.
[in]rawkeyRaw key value or NULL. The value shall be the private key big endian raw value.
[in]key_lenKey bytes length
[out]keyPrivate ecfp key to init.
Returns
1 if success, 0 if error
Exceptions
INVALID_PARAMETER
int bls_ecdsa_init_public_key ( bls_curve_t  curve,
const uint8_t WIDE *  rawkey,
size_t  key_len,
bls_ecfp_public_key_t key 
)

Initialize a public ECFP Key.

Once initialized, the key may be stored in non-volatile memory an reused 'as-is' for any ECDSA processing Passing NULL as raw key initializes the key without value. The key may be used as parameter for bls_ecfp_generate_pair.

Parameters
[in]curveThe curve domain parameters to work with.
[in]rawkeyRaw key value or NULL. The value shall be the public point encoded as: 04 x y, where x and y are encoded as big endian raw value and have bits length equals to the curve size.
[in]key_lenKey bytes length
[out]keyPublic ecfp key to init.
Returns
1 if success, 0 if error
Exceptions
INVALID_PARAMETER
int bls_ecdsa_sign ( bls_ecfp_private_key_t WIDE *  key,
int  mode,
bls_md_t  hashID,
const uint8_t WIDE *  hash,
size_t  hash_len,
uint8_t *  sig 
)

Sign a hash message according to ECDSA scheme.

Parameters
[in]keyA private ecfp key fully inited with 'bls_ecdsa_init_private_key'
[in]mode16bits crypto mode flags. See above. Supported flags:
  • BLS_LAST
  • BLS_RND_TRNG
  • BLS_RND_RFC6979
[in]hashIDHash to use for nonce generation when using BLS_RND_RFC6979 (shall be BLS_SHA256)
[in]hashInput data to sign. The data should be the hash of the original message. The data length must be lesser than the curve size.
[in]hash_lenLength of the hash
[out]sigECDSA signature encoded as TLV: 30 L 02 Lr r 02 Ls s
Returns
Full length of signature
Exceptions
INVALID_PARAMETER
int bls_ecdsa_verify ( bls_ecfp_public_key_t WIDE *  key,
int  mode,
bls_md_t  hashID,
const uint8_t WIDE *  hash,
size_t  hash_len,
uint8_t *  sig 
)

Verify a hash message signature according to ECDSA scheme.

Parameters
[in]keyA public ecfp key fully inited with 'bls_ecdsa_init_public_key'
[in]mode16bits crypto mode flags. See above. Supported flags:
  • BLS_LAST
[in]hashIDIgnored
[in]hashSigned input data to verify the signature. The data should be the hash of the original message. The data length must be lesser than the curve size.
[in]hash_lenLength of the hash
[in]sigECDSA signature to verify encoded as TLV: 30 L 02 Lr r 02 Ls s
Returns
1 if signature is verified 0 is signarure is not verified
Exceptions
INVALID_PARAMETER
int bls_ecfp_add_point ( const bls_curve_domain_t WIDE *  domain,
uint8_t *  R,
const uint8_t WIDE *  P,
const uint8_t WIDE *  Q 
)

Add two affine point.

Warning
THIS METHOD IS NOT SUPPORTED IN THE CURRENT RELEASE
Parameters
[in]domainThe curve domain parameters to work with.
[out]RP+Q encoded as: 04 x y, where x and y are encoded as big endian raw value and have bits length equals to the curve size.
[in]PFirst point to add * The value shall be a point encoded as: 04 x y, where x and y are encoded as big endian raw value and have bits length equals to the curve size.
[in]QSecond point to add
[in]public_pointThe point to test encoded as: 04 x y
Returns
R encoding length, if add success -1 if failed
Exceptions
INVALID_PARAMETER
int bls_ecfp_generate_pair ( bls_curve_t  curve,
bls_ecfp_public_key_t public_key,
bls_ecfp_private_key_t private_key,
uint8_t *  d 
)

Generate a ecfp key pair.

Parameters
[in]curveThe curve domain parameters to work with.
[out]public_keyA public ecfp key to generate.
[out]private_keyA private ecfp key to initialize.
[out]dIf set to non NULL, return the generated private key value
Returns
1 if success, 0 if error
Exceptions
INVALID_PARAMETER
bls_curve_domain_t WIDE* bls_ecfp_get_domain ( bls_curve_t  curve)

Retrieve the domain of the curve.

Warning
THIS METHOD IS NOT SUPPORTED IN THE CURRENT RELEASE
Parameters
[in]curveThe curve reference
Returns
The curve domain
Exceptions
INVALID_PARAMETER
int bls_ecfp_get_public_component ( const bls_ecfp_public_key_t public_key,
uint8_t *  W 
)

Return the uncompressed point of a public ECFP Key.

Parameters
[out]public_keyA public ecfp key
[out]WBuffer to store uncompressed point
Returns
1 if success, 0 if error
Exceptions
INVALID_PARAMETER
int bls_ecfp_is_valid_point ( const bls_curve_domain_t WIDE *  domain,
const uint8_t WIDE *  point 
)

Verify that a given point is really on the specified curve.

Warning
THIS METHOD IS NOT SUPPORTED IN THE CURRENT RELEASE
Parameters
[in]domainThe curve domain parameters to work with.
[in]pointThe point to test encoded as: 04 x y
Returns
1 if point is on the curve 0 if point is not on the curve -1 if undefined (function not implemented)
Exceptions
INVALID_PARAMETER
int bls_hash ( bls_hash_t *  hash,
int  mode,
const uint8_t WIDE *  in,
size_t  len,
uint8_t *  out 
)

Add more data to hash.

Parameters
[in,out]hashHash context The hash context pointer shall point to either a bls_ripemd160_t, either a bls_sha256_t or bls_sha512_t . The hash context shall be inited with 'bls_xxx_init' The hash context shall be in RAM The function should be called with a nice cast.
[in]mode16bits flags. See Above If BLS_LAST is set, context is automatically re-inited. Supported flags:
  • BLS_LAST
[in]inInput data to add to current hash
[in]lenLength of input to data.
[out]outEither:
  • NULL (ignored) if BLS_LAST is NOT set
  • produced hash if BLS_LAST is set 'out' length is implicit, no check is done
Returns
1 if success, not finished. Hash size if success, finished. 0 if error
int bls_hmac ( bls_hmac_t hmac,
int  mode,
const uint8_t WIDE *  in,
size_t  len,
uint8_t *  mac 
)

Add more data to HMAC.

Parameters
[in,out]hmacHmac context The hmac context pointer shall point to either a bls_ripemd160_t, either a bls_sha256_t or bls_sha512_t . The hmac context shall be inited with 'bls_xxx_init' The hmac context shall be in RAM The function should be called with a nice cast.
[in]mode16bits flags. See Above If BLS_LAST is set and BLS_DISCARD is not set, context is automatically re-inited. Supported flags:
  • BLS_LAST
  • BLS_DISCARD
[in]inInput data to add to current hmac
[in]lenLength of input to data.
[out]macEither:
  • NULL (ignored) if BLS_LAST is NOT set
  • produced hmac if BLS_LAST is set 'out' length is implicit, no check is done
Returns
1 if success, not finished. Hmac size if success, finished. 0 if error
int bls_hmac_ripemd160_init ( bls_hmac_ripemd160_t hmac,
const uint8_t WIDE *  key,
size_t  key_len 
)

Initialize a HMAC sha512 context.

Parameters
[out]hmacthe context to init. The context shall be in RAM
[in]keyhmac key value Passing a NULL pointeur, will reinit the context with the previously set key. If no key has already been set, passing NULL will lead into an undefined behavior.
[in]key_lenhmac key length The key length shall be less than 64 bytes
Returns
1 if success, 0 if error
int bls_hmac_sha256_init ( bls_hmac_sha256_t hmac,
const uint8_t WIDE *  key,
size_t  key_len 
)

Initialize a HMAC sha256 context.

Parameters
[out]hmacthe context to init. The context shall be in RAM
[in]keyhmac key value Passing a NULL pointeur, will reinit the context with the previously set key. If no key has already been set, passing NULL will lead into an undefined behavior.
[in]key_lenhmac key length The key length shall be less than 64 bytes
Returns
1 if success, 0 if error
int bls_hmac_sha512_init ( bls_hmac_sha512_t hmac,
const uint8_t WIDE *  key,
size_t  key_len 
)

Initialize a HMAC sha512 context.

Parameters
[out]hmacthe context to init. The context shall be in RAM
[in]keyhmac key value Passing a NULL pointeur, will reinit the context with the previously set key. If no key has already been set, passing NULL will lead into an undefined behavior.
[in]key_lenhmac key length The key length shall be less than 128 bytes
Returns
1 if success, 0 if error
void bls_math_addm ( uint8_t *  r,
const uint8_t WIDE *  a,
const uint8_t WIDE *  b,
const uint8_t WIDE *  m,
size_t  len 
)

Modular addition of tow big integer of the size: r = a+b mod m.

Warning
THIS METHOD IS NOT SUPPORTED IN THE CURRENT RELEASE

The maximum length supported is 64.

Parameters
rwhere to put result
afirst operand
bsecond operand
mmodulo
lenbyte length of r, a, b, m
int bls_math_cmp ( const uint8_t WIDE *  a,
const uint8_t WIDE *  b,
size_t  len 
)

Compare to unsigned long big-endian integer.

Warning
THIS METHOD IS NOT SUPPORTED IN THE CURRENT RELEASE

The maximum length supported is 64.

Parameters
afirst operand
bsecond operand
lenbyte length of a, b
Returns
0 if a==b, negative value if a<b, positive value if a>b
int bls_math_is_zero ( const uint8_t WIDE *  a,
size_t  len 
)

Compare to unsigned long big-endian integer to zero.

Warning
THIS METHOD IS NOT SUPPORTED IN THE CURRENT RELEASE
Parameters
avalue to compare to zero
lenbyte length of a
Returns
1 if a==0, 0 else
void bls_math_modm ( uint8_t *  v,
size_t  len_v,
const uint8_t WIDE *  m,
size_t  len_m 
)

Reduce in place (left zero padded) the given value : v = v mod m.

Warning
THIS METHOD IS NOT SUPPORTED IN THE CURRENT RELEASE
Parameters
vvalue to reduce
len_vshall be >= len_m
mmodulus
len_mlength of modulus
int bls_pbkdf2 ( bls_md_t  hash,
const bls_area_t password,
const bls_area_t salt,
int  iterations,
uint8_t *  out 
)

Stretch a password using PBKDF2.

Parameters
[in]hashHash Algorithm Supported algorithms : BLS_SHA512
[in]passwordPassword buffer and length
[in]saltSalt buffer and length The salt buffer shall include 4 extra pdding bytes
[in]iterationsNumber of PBKDF2 iterations to perform
[out]outOutput buffer containing the PBKDF2 streched password The output buffer shall be as long as the hash output
Returns
1 if success, 0 if error
int bls_ripemd160_init ( bls_ripemd160_t hash)

Initialize a ripmd160 context.

Parameters
[out]hashthe context to init. The context shall be in RAM
Returns
1 if success, 0 if error
int bls_rng ( uint8_t *  buffer,
size_t  len 
)

generate a random buffer

Parameters
[out]bufferthe buffer containing the random data
[in]lenlength of the random buffer to generate
Returns
1 if success, 0 if error
uint8_t bls_rng_u8 ( void  )

generate a random byte

Returns
random byte
int bls_rsa_generate_keypair ( int  modulus_len,
bls_rsa_abstract_private_key_t privateKey,
bls_rsa_abstract_public_key_t publicKey,
bls_rsa_keypair_data_t generatedKeypairInfo 
)

Generate a RSA keypair.

Parameters
[in]modulus_lenLength of the modulus to generate, in bits
[out]privateKeyPointer to a previously initialized RSA private key
[out]publicKeyPointer to a previously initialized RSA public key
[out]generatedKeypairInfoPointer to a structure that will contain the generated key information including the private key value or NULL
Returns
1 if success, 0 if error
Exceptions
INVALID_PARAMETER
int bls_rsa_get_public_key_data ( bls_rsa_abstract_public_key_t publicKey,
bls_rsa_keypair_data_t keyInfo 
)

Retrieve a RSA public key information.

Parameters
[in]publicKeyPointer to a previously initialized RSA public key
[out]keyInfoPointer to a structure that will contain the public key information
Returns
1 if success, 0 if error
Exceptions
INVALID_PARAMETER
int bls_rsa_init_private_key ( const bls_rsa_keypair_data_t WIDE *  keyData,
bls_rsa_abstract_private_key_t key 
)

Initialize a private RSA Key.

Once initialized, the key may be stored in non-volatile memory an reused 'as-is' for any RSA processing Passing NULL as raw key initializes the key without value. The key can not be used

Parameters
[in]keyDataKey parameters value or NULL. Key parameters shall include the modulus and private exponent encoded as big endian raw value
[out]keyPrivate RSA key to initialize.
Returns
1 if success, 0 if error
Exceptions
INVALID_PARAMETER
int bls_rsa_init_private_key_crt ( const bls_rsa_crt_t WIDE *  crtParameters,
bls_rsa_abstract_private_key_t key 
)

Initialize a private RSA Key with CRT parameters.

Warning
THIS METHOD IS NOT SUPPORTED IN THE CURRENT RELEASE

Once initialized, the key may be stored in non-volatile memory an reused 'as-is' for any RSA processing Passing NULL as raw key initializes the key without value. The key can not be used

Parameters
[in]keyDataKey parameters value or NULL. Key parameters shall include Q, P, DP, DQ, QInv encoded as big endian raw value
[out]keyPublic RSA key to initialize.
Returns
1 if success, 0 if error
Exceptions
INVALID_PARAMETER
int bls_rsa_init_public_key ( const bls_rsa_keypair_data_t WIDE *  keyData,
bls_rsa_abstract_public_key_t key 
)

Initialize a public RSA Key.

Once initialized, the key may be stored in non-volatile memory an reused 'as-is' for any RSA processing Passing NULL as raw key initializes the key without value. The key can not be used

Parameters
[in]keyDataKey parameters value or NULL. Key parameters shall include the modulus and public exponent encoded as big endian raw value
[out]keyPublic RSA key to initialize.
Returns
1 if success, 0 if error
Exceptions
INVALID_PARAMETER
int bls_rsa_priv ( bls_rsa_abstract_private_key_t WIDE *  key,
int  mode,
bls_md_t  hashID,
const bls_area_t src,
const bls_area_t dest 
)

Perform a RSA private operation.

Parameters
[in]keyPointer to a previously initialized RSA private key
[in]mode16bits crypto mode flags. See above. Supported flags:
  • BLS_LAST
  • BLS_ENCRYPT
  • BLS_DECRYPT
  • BLS_PAD_NONE
  • BLS_PAD_PKCS1_1o5
  • BLS_PAD_PSS
[in]hashIDHash identifier used to compute the input data.
[in]srcInput buffer and length to process
[in,out]destDestination buffer and length. Length is modified by ENCRYPT, DECRYPT, SIGN operations
Returns
  • In case of ENCRYPT, DECRYPT or SIGN mode: 1 if success, 0 if error
  • In case of VERIFY mode: 0 if signature is false, 1 if signature is correct
Exceptions
INVALID_PARAMETER
int bls_rsa_pub ( bls_rsa_abstract_public_key_t WIDE *  key,
int  mode,
bls_md_t  hashID,
const bls_area_t src,
const bls_area_t dest 
)

Perform a RSA public operation.

Parameters
[in]keyPointer to a previously initialized RSA public key
[in]mode16bits crypto mode flags. See above. Supported flags:
  • BLS_LAST
  • BLS_ENCRYPT
  • BLS_DECRYPT
  • BLS_PAD_NONE
  • BLS_PAD_PKCS1_1o5
  • BLS_PAD_PSS
[in]hashIDHash identifier used to compute the input data.
[in]srcInput buffer and length to process
[in,out]destDestination buffer and length. Length is modified by ENCRYPT, DECRYPT, SIGN operations
Returns
  • In case of ENCRYPT, DECRYPT or SIGN mode: 1 if success, 0 if error
  • In case of VERIFY mode: 0 if signature is false, 1 if signature is correct
Exceptions
INVALID_PARAMETER
int bls_schnorr_sign ( bls_ecfp_private_key_t WIDE *  key,
int  mode,
bls_md_t  hashID,
const uint8_t WIDE *  hash,
size_t  hash_len,
uint8_t *  sig 
)

Sign a hash message according to Schnorr scheme.

Parameters
[in]keyA private ecfp key fully inited with 'bls_ecdsa_init_private_key'
[in]mode16bits crypto mode flags. See above. Supported flags:
  • BLS_LAST
[in]hashIDIgnored
[in]hashInput data to sign. The data should be the hash of the original message. The data length must be lesser than the curve size.
[in]hash_lenLength of the hash
[out]sigSchnorr signature
Returns
Full length of signature
Exceptions
INVALID_PARAMETER
int bls_schnorr_verify ( bls_ecfp_public_key_t WIDE *  key,
int  mode,
bls_md_t  hashID,
const uint8_t WIDE *  hash,
size_t  hash_len,
uint8_t *  sig 
)

Verify a hash message signature according to Schnorr scheme.

Parameters
[in]keyA public ecfp key fully inited with 'bls_ecdsa_init_public_key'
[in]mode16bits crypto mode flags. See above. Supported flags:
  • BLS_LAST
[in]hashIDIgnored
[in]hashSigned input data to verify the signature. The data should be the hash of the original message. The data length must be lesser than the curve size.
[in]hash_lenLength of the hash
[in]sigSchnorr signature
Returns
1 if signature is verified 0 is signarure is not verified
Exceptions
INVALID_PARAMETER
int bls_sha1_init ( bls_sha1_t hash)

Initialize a sha1 context.

Parameters
[out]hashthe context to init. The context shall be in RAM
Returns
1 if success, 0 if error
int bls_sha256_init ( bls_sha256_t hash)

Initialize a sha256 context.

Parameters
[out]hashthe context to init. The context shall be in RAM
Returns
1 if success, 0 if error
int bls_sha512_init ( bls_sha512_t hash)

Initialize a sha512 context.

Parameters
[out]hashthe context to init. The context shall be in RAM
Returns
1 if success, 0 if error