Embedded SDK
Embedded SDK
Functions
crypto_helpers.h File Reference
#include <stdint.h>
#include "os.h"
#include "cx.h"
Include dependency graph for crypto_helpers.h:

Go to the source code of this file.

Functions

WARN_UNUSED_RESULT cx_err_t bip32_derive_with_seed_init_privkey_256 (unsigned int derivation_mode, cx_curve_t curve, const uint32_t *path, size_t path_len, cx_ecfp_256_private_key_t *privkey, uint8_t *chain_code, unsigned char *seed, size_t seed_len)
 Gets the private key from the device seed using the specified bip32 path and seed key. More...
 
WARN_UNUSED_RESULT cx_err_t bip32_derive_with_seed_get_pubkey_256 (unsigned int derivation_mode, cx_curve_t curve, const uint32_t *path, size_t path_len, uint8_t raw_pubkey[static 65], uint8_t *chain_code, cx_md_t hashID, unsigned char *seed, size_t seed_len)
 Gets the public key from the device seed using the specified bip32 path and seed key. More...
 
WARN_UNUSED_RESULT cx_err_t bip32_derive_with_seed_ecdsa_sign_hash_256 (unsigned int derivation_mode, cx_curve_t curve, const uint32_t *path, size_t path_len, uint32_t sign_mode, cx_md_t hashID, const uint8_t *hash, size_t hash_len, uint8_t *sig, size_t *sig_len, uint32_t *info, unsigned char *seed, size_t seed_len)
 Sign a hash with ecdsa using the device seed derived from the specified bip32 path and seed key. More...
 
WARN_UNUSED_RESULT cx_err_t bip32_derive_with_seed_ecdsa_sign_rs_hash_256 (unsigned int derivation_mode, cx_curve_t curve, const uint32_t *path, size_t path_len, uint32_t sign_mode, cx_md_t hashID, const uint8_t *hash, size_t hash_len, uint8_t sig_r[static 32], uint8_t sig_s[static 32], uint32_t *info, unsigned char *seed, size_t seed_len)
 Sign a hash with ecdsa using the device seed derived from the specified bip32 path and seed key. More...
 
WARN_UNUSED_RESULT cx_err_t bip32_derive_with_seed_eddsa_sign_hash_256 (unsigned int derivation_mode, cx_curve_t curve, const uint32_t *path, size_t path_len, cx_md_t hashID, const uint8_t *hash, size_t hash_len, uint8_t *sig, size_t *sig_len, unsigned char *seed, size_t seed_len)
 Sign a hash with eddsa using the device seed derived from the specified bip32 path and seed key. More...
 

Function Documentation

◆ bip32_derive_with_seed_ecdsa_sign_hash_256()

WARN_UNUSED_RESULT cx_err_t bip32_derive_with_seed_ecdsa_sign_hash_256 ( unsigned int  derivation_mode,
cx_curve_t  curve,
const uint32_t *  path,
size_t  path_len,
uint32_t  sign_mode,
cx_md_t  hashID,
const uint8_t hash,
size_t  hash_len,
uint8_t sig,
size_t *  sig_len,
uint32_t *  info,
unsigned char *  seed,
size_t  seed_len 
)

Sign a hash with ecdsa using the device seed derived from the specified bip32 path and seed key.

Parameters
[in]derivation_modeDerivation mode, one of HDW_NORMAL / HDW_ED25519_SLIP10 / HDW_SLIP21.
[in]curveCurve identifier.
[in]pathBip32 path to use for derivation.
[in]path_lenBip32 path length.
[in]hashIDMessage digest algorithm identifier.
[in]hashDigest of the message to be signed. The length of hash must be shorter than the group order size. Otherwise it is truncated.
[in]hash_lenLength of the digest in octets.
[out]sigBuffer where to store the signature. The signature is encoded in TLV: 30 || L || 02 || Lr || r || 02 || Ls || s
[in]sig_lenLength of the signature buffer, updated with signature length.
[out]infoSet with CX_ECCINFO_PARITY_ODD if the y-coordinate is odd when computing [k].G.
[in]seedSeed key to use for derivation.
[in]seed_lenSeed key length.
Returns
Error code:
  • CX_OK on success
  • CX_EC_INVALID_CURVE
  • CX_INTERNAL_ERROR

Definition at line 103 of file crypto_helpers.c.

◆ bip32_derive_with_seed_ecdsa_sign_rs_hash_256()

WARN_UNUSED_RESULT cx_err_t bip32_derive_with_seed_ecdsa_sign_rs_hash_256 ( unsigned int  derivation_mode,
cx_curve_t  curve,
const uint32_t *  path,
size_t  path_len,
uint32_t  sign_mode,
cx_md_t  hashID,
const uint8_t hash,
size_t  hash_len,
uint8_t  sig_r[static 32],
uint8_t  sig_s[static 32],
uint32_t *  info,
unsigned char *  seed,
size_t  seed_len 
)

Sign a hash with ecdsa using the device seed derived from the specified bip32 path and seed key.

Parameters
[in]derivation_modeDerivation mode, one of HDW_NORMAL / HDW_ED25519_SLIP10 / HDW_SLIP21.
[in]curveCurve identifier.
[in]pathBip32 path to use for derivation.
[in]path_lenBip32 path length.
[in]hashIDMessage digest algorithm identifier.
[in]hashDigest of the message to be signed. The length of hash must be shorter than the group order size. Otherwise it is truncated.
[in]hash_lenLength of the digest in octets.
[out]sig_rBuffer where to store the signature r value.
[out]sig_sBuffer where to store the signature s value.
[out]infoSet with CX_ECCINFO_PARITY_ODD if the y-coordinate is odd when computing [k].G.
[in]seedSeed key to use for derivation.
[in]seed_lenSeed key length.
Returns
Error code:
  • CX_OK on success
  • CX_EC_INVALID_CURVE
  • CX_INTERNAL_ERROR

Definition at line 140 of file crypto_helpers.c.

◆ bip32_derive_with_seed_eddsa_sign_hash_256()

WARN_UNUSED_RESULT cx_err_t bip32_derive_with_seed_eddsa_sign_hash_256 ( unsigned int  derivation_mode,
cx_curve_t  curve,
const uint32_t *  path,
size_t  path_len,
cx_md_t  hashID,
const uint8_t hash,
size_t  hash_len,
uint8_t sig,
size_t *  sig_len,
unsigned char *  seed,
size_t  seed_len 
)

Sign a hash with eddsa using the device seed derived from the specified bip32 path and seed key.

Parameters
[in]derivation_modeDerivation mode, one of HDW_NORMAL / HDW_ED25519_SLIP10 / HDW_SLIP21.
[in]curveCurve identifier.
[in]pathBip32 path to use for derivation.
[in]path_lenBip32 path length.
[in]hashIDMessage digest algorithm identifier.
[in]hashDigest of the message to be signed. The length of hash must be shorter than the group order size. Otherwise it is truncated.
[in]hash_lenLength of the digest in octets.
[out]sigBuffer where to store the signature.
[in]sig_lenLength of the signature buffer, updated with signature length.
[in]seedSeed key to use for derivation.
[in]seed_lenSeed key length.
Returns
Error code:
  • CX_OK on success
  • CX_EC_INVALID_CURVE
  • CX_INTERNAL_ERROR

Definition at line 170 of file crypto_helpers.c.

◆ bip32_derive_with_seed_get_pubkey_256()

WARN_UNUSED_RESULT cx_err_t bip32_derive_with_seed_get_pubkey_256 ( unsigned int  derivation_mode,
cx_curve_t  curve,
const uint32_t *  path,
size_t  path_len,
uint8_t  raw_pubkey[static 65],
uint8_t chain_code,
cx_md_t  hashID,
unsigned char *  seed,
size_t  seed_len 
)

Gets the public key from the device seed using the specified bip32 path and seed key.

Parameters
[in]derivation_modeDerivation mode, one of HDW_NORMAL / HDW_ED25519_SLIP10 / HDW_SLIP21.
[in]curveCurve identifier.
[in]pathBip32 path to use for derivation.
[in]path_lenBip32 path length.
[out]raw_pubkeyBuffer where to store the public key.
[out]chain_codeBuffer where to store the chain code. Can be NULL.
[in]hashIDMessage digest algorithm identifier.
[in]seedSeed key to use for derivation.
[in]seed_lenSeed key length.
Returns
Error code:
  • CX_OK on success
  • CX_EC_INVALID_CURVE
  • CX_INTERNAL_ERROR

Definition at line 63 of file crypto_helpers.c.

◆ bip32_derive_with_seed_init_privkey_256()

WARN_UNUSED_RESULT cx_err_t bip32_derive_with_seed_init_privkey_256 ( unsigned int  derivation_mode,
cx_curve_t  curve,
const uint32_t *  path,
size_t  path_len,
cx_ecfp_256_private_key_t *  privkey,
uint8_t chain_code,
unsigned char *  seed,
size_t  seed_len 
)

Gets the private key from the device seed using the specified bip32 path and seed key.

Parameters
[in]derivation_modeDerivation mode, one of HDW_NORMAL / HDW_ED25519_SLIP10 / HDW_SLIP21.
[in]curveCurve identifier.
[in]pathBip32 path to use for derivation.
[in]path_lenBip32 path length.
[out]privkeyGenerated private key.
[out]chain_codeBuffer where to store the chain code. Can be NULL.
[in]seedSeed key to use for derivation.
[in]seed_lenSeed key length.
Returns
Error code:
  • CX_OK on success
  • CX_EC_INVALID_CURVE
  • CX_INTERNAL_ERROR

Definition at line 25 of file crypto_helpers.c.