CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
Loading...
Searching...
No Matches
Crypto

Software crypto primitives and binary-to-text codecs. More...

Functions

int host_random (uint8_t *buf, size_t len)
 Fill buf with hardware-RNG bytes; may fall back to PRNG.
int host_random_strict (uint8_t *buf, size_t len)
 Fill buf with hardware-RNG bytes only; fails without TRNG.
int host_sha256 (const uint8_t *data, size_t len, uint8_t out[32])
 SHA-256 hash of data into the 32-byte out.
int host_hmac_sha256 (const uint8_t *key, size_t klen, const uint8_t *data, size_t dlen, uint8_t out[32])
 HMAC-SHA-256 of data under key into the 32-byte out.
int host_aes_gcm_encrypt (const uint8_t *key, const uint8_t *iv, const uint8_t *aad, size_t aad_len, const uint8_t *pt, size_t pt_len, uint8_t *ct, uint8_t tag[16])
 AES-256-GCM encrypt.
int host_aes_gcm_decrypt (const uint8_t *key, const uint8_t *iv, const uint8_t *aad, size_t aad_len, const uint8_t *ct, size_t ct_len, const uint8_t tag[16], uint8_t *pt)
 AES-256-GCM decrypt and verify.
int host_base32_encode (const uint8_t *in, size_t in_len, char *out, size_t out_size)
 Base32-encode in into NUL-terminated out.
int host_base32_decode (const char *in, size_t in_len, uint8_t *out, size_t out_size)
 Base32-decode in into raw bytes in out.
int host_base64_encode (const uint8_t *in, size_t in_len, char *out, size_t out_size)
 Base64-encode in into NUL-terminated out.
int host_base64_decode (const char *in, size_t in_len, uint8_t *out, size_t out_size)
 Base64-decode in into raw bytes in out.
int host_hex_encode (const uint8_t *in, size_t in_len, char *out, size_t out_size)
 Lowercase-hex-encode in into NUL-terminated out.
int host_hex_decode (const char *in, size_t in_len, uint8_t *out, size_t out_size)
 Hex-decode in (case-insensitive) into raw bytes in out.

Detailed Description

Software crypto primitives and binary-to-text codecs.

Hashing, AEAD and RNG. Asymmetric key operations live in the SecureElement / TROPIC01 group instead (they live in TROPIC01).

Function Documentation

◆ host_aes_gcm_decrypt()

int host_aes_gcm_decrypt ( const uint8_t * key,
const uint8_t * iv,
const uint8_t * aad,
size_t aad_len,
const uint8_t * ct,
size_t ct_len,
const uint8_t tag[16],
uint8_t * pt )

AES-256-GCM decrypt and verify.

Parameters
key32-byte key.
iv12-byte nonce.
aadAdditional authenticated data (may be NULL when aad_len == 0).
ctCiphertext input of ct_len bytes.
tag16-byte tag to verify.
ptPlaintext output buffer of at least ct_len bytes.

Definition at line 72 of file host_api_crypto.cpp.

References cdc::core::aesGcm256Open(), HOST_ERR_GENERIC, HOST_ERR_INVALID_ARG, and HOST_OK.

Referenced by cdc::plugin_manager::w_host_aes_gcm_decrypt().

◆ host_aes_gcm_encrypt()

int host_aes_gcm_encrypt ( const uint8_t * key,
const uint8_t * iv,
const uint8_t * aad,
size_t aad_len,
const uint8_t * pt,
size_t pt_len,
uint8_t * ct,
uint8_t tag[16] )

AES-256-GCM encrypt.

Parameters
key32-byte key.
iv12-byte nonce.
aadAdditional authenticated data (may be NULL when aad_len == 0).
ptPlaintext input of pt_len bytes.
ctCiphertext output buffer of at least pt_len bytes.
tag16-byte authentication tag output.

Definition at line 61 of file host_api_crypto.cpp.

References cdc::core::aesGcm256Seal(), HOST_ERR_GENERIC, HOST_ERR_INVALID_ARG, and HOST_OK.

Referenced by cdc::plugin_manager::w_host_aes_gcm_encrypt().

◆ host_base32_decode()

int host_base32_decode ( const char * in,
size_t in_len,
uint8_t * out,
size_t out_size )

Base32-decode in into raw bytes in out.

Definition at line 109 of file host_api_crypto.cpp.

References HOST_ERR_INVALID_ARG, and HOST_ERR_NO_MEMORY.

Referenced by cdc::plugin_manager::w_host_base32_decode().

◆ host_base32_encode()

int host_base32_encode ( const uint8_t * in,
size_t in_len,
char * out,
size_t out_size )

Base32-encode in into NUL-terminated out.

Definition at line 83 of file host_api_crypto.cpp.

References HOST_ERR_INVALID_ARG, HOST_ERR_NO_MEMORY, and HOST_OK.

Referenced by cdc::plugin_manager::w_host_base32_encode().

◆ host_base64_decode()

int host_base64_decode ( const char * in,
size_t in_len,
uint8_t * out,
size_t out_size )

Base64-decode in into raw bytes in out.

Definition at line 148 of file host_api_crypto.cpp.

References HOST_ERR_GENERIC, and HOST_ERR_INVALID_ARG.

Referenced by cdc::plugin_manager::w_host_base64_decode().

◆ host_base64_encode()

int host_base64_encode ( const uint8_t * in,
size_t in_len,
char * out,
size_t out_size )

Base64-encode in into NUL-terminated out.

Definition at line 134 of file host_api_crypto.cpp.

References HOST_ERR_INVALID_ARG, HOST_ERR_NO_MEMORY, and HOST_OK.

Referenced by cdc::plugin_manager::w_host_base64_encode().

◆ host_hex_decode()

int host_hex_decode ( const char * in,
size_t in_len,
uint8_t * out,
size_t out_size )

Hex-decode in (case-insensitive) into raw bytes in out.

Definition at line 184 of file host_api_crypto.cpp.

References cdc::plugin_manager::hex_val(), HOST_ERR_INVALID_ARG, and HOST_ERR_NO_MEMORY.

Referenced by cdc::plugin_manager::w_host_hex_decode().

◆ host_hex_encode()

int host_hex_encode ( const uint8_t * in,
size_t in_len,
char * out,
size_t out_size )

Lowercase-hex-encode in into NUL-terminated out.

Definition at line 171 of file host_api_crypto.cpp.

References HOST_ERR_INVALID_ARG, HOST_ERR_NO_MEMORY, and HOST_OK.

Referenced by cdc::plugin_manager::w_host_hex_encode().

◆ host_hmac_sha256()

int host_hmac_sha256 ( const uint8_t * key,
size_t klen,
const uint8_t * data,
size_t dlen,
uint8_t out[32] )

HMAC-SHA-256 of data under key into the 32-byte out.

Definition at line 51 of file host_api_crypto.cpp.

References HOST_ERR_GENERIC, HOST_ERR_INVALID_ARG, and HOST_OK.

Referenced by cdc::plugin_manager::w_host_hmac_sha256().

◆ host_random()

int host_random ( uint8_t * buf,
size_t len )

Fill buf with hardware-RNG bytes; may fall back to PRNG.

Definition at line 29 of file host_api_crypto.cpp.

References HOST_ERR_INVALID_ARG, and HOST_OK.

Referenced by cdc::plugin_manager::w_host_random().

◆ host_random_strict()

int host_random_strict ( uint8_t * buf,
size_t len )

Fill buf with hardware-RNG bytes only; fails without TRNG.

Definition at line 36 of file host_api_crypto.cpp.

References cdc::hal::getSecureElementInstance(), HOST_ERR_INVALID_ARG, HOST_ERR_NOT_SUPPORTED, and HOST_OK.

Referenced by cdc::plugin_manager::w_host_random_strict().

◆ host_sha256()

int host_sha256 ( const uint8_t * data,
size_t len,
uint8_t out[32] )

SHA-256 hash of data into the 32-byte out.

Definition at line 44 of file host_api_crypto.cpp.

References HOST_ERR_GENERIC, HOST_ERR_INVALID_ARG, and HOST_OK.

Referenced by cdc::plugin_manager::w_host_sha256().