19#define MAX_IV_LENGTH 16
21#define MAX_BLOCK_LENGTH 16
25#define CMAC_MAX_BLOCK_LENGTH (16)
29 uint8_t state[CMAC_MAX_BLOCK_LENGTH];
30 uint8_t unprocessed_block[CMAC_MAX_BLOCK_LENGTH];
31 size_t unprocessed_len;
51 cx_err_t (*
enc_func)(
const uint8_t *in_block, uint8_t *out_block);
52 cx_err_t (*
dec_func)(
const uint8_t *in_block, uint8_t *out_block);
56 uint8_t *nonce_counter,
57 uint8_t *stream_block,
72#if !defined(BOLOS_OS_UPGRADER_APP)
85 void (*
add_padding)(uint8_t *output,
size_t out_len,
size_t data_len);
97 cx_cmac_context_t *cmac_ctx;
232 const uint8_t *input,
294 const uint8_t *input,
AES (Advanced Encryption Standard).
void cx_cipher_reset(cx_cipher_context_t *ctx)
void add_one_and_zeros_padding(uint8_t *output, size_t out_len, size_t data_len)
WARN_UNUSED_RESULT cx_err_t cx_cipher_update(cx_cipher_context_t *ctx, const uint8_t *input, size_t in_len, uint8_t *output, size_t *out_len)
Encrypt or decrypt with the given context.
@ CX_CIPHER_AES_192
AES with a 192-bit key.
@ CX_CIPHER_NONE
No cipher.
@ CX_CIPHER_AES_256
AES with a 256-bit key.
@ CX_CIPHER_AES_128
AES with a 128-bit key.
WARN_UNUSED_RESULT cx_err_t cx_cipher_setkey(cx_cipher_context_t *ctx, const uint8_t *key, uint32_t key_bitlen, uint32_t operation)
Set the key to use.
WARN_UNUSED_RESULT cx_err_t cx_cipher_setiv(cx_cipher_context_t *ctx, const uint8_t *iv, size_t iv_len)
Set the initialization vector.
WARN_UNUSED_RESULT cx_err_t cx_cipher_init(cx_cipher_context_t *ctx)
Initialize a cipher context as NONE.
WARN_UNUSED_RESULT cx_err_t cx_cipher_finish(cx_cipher_context_t *ctx, uint8_t *output, size_t *out_len)
Finalize the operation.
WARN_UNUSED_RESULT cx_err_t cx_cipher_setup(cx_cipher_context_t *ctx, const cx_cipher_id_t type, uint32_t mode)
Initialize and fill the context structure given the cipher info.
WARN_UNUSED_RESULT cx_err_t cx_cipher_enc_dec(cx_cipher_context_t *ctx, const uint8_t *iv, size_t iv_len, const uint8_t *input, size_t in_len, uint8_t *output, size_t *out_len)
All-in-one encryption or decryption.
WARN_UNUSED_RESULT cx_err_t cx_cipher_set_padding(cx_cipher_context_t *ctx, uint32_t padding)
Set the padding type.
cx_err_t(* enc_func)(const uint8_t *in_block, uint8_t *out_block)
Encryption function.
cx_err_t(* dec_func)(const uint8_t *in_block, uint8_t *out_block)
Decryption function.
cx_err_t(* ctx_reset)(void)
Reset.
cx_err_t(* setkey_func)(const cipher_key_t *ctx_key, uint32_t operation, const uint8_t *key, uint32_t key_bitlen)
Set key for encryption or decryption.
cx_err_t(* ctr_func)(const cipher_key_t *ctx_key, size_t len, size_t *nc_off, uint8_t *nonce_counter, uint8_t *stream_block, const uint8_t *input, uint8_t *output)
Encryption in CTR mode.
uint32_t mode
Mode of operation: ECB, CBC, CTR.
size_t iv_size
Length of the initialization vector.
uint32_t operation
Operation: encryption or decryption.
uint8_t unprocessed_data[MAX_BLOCK_LENGTH]
Data to process.
void(* add_padding)(uint8_t *output, size_t out_len, size_t data_len)
Padding function.
uint32_t key_bitlen
Key size in bits.
const cipher_key_t * cipher_key
Cipher-specific context.
uint8_t iv[MAX_IV_LENGTH]
Initiaization vector.
cx_err_t(* get_padding)(uint8_t *input, size_t in_len, size_t *data_len)
Check the padding.
const cx_cipher_info_t * cipher_info
Cipher information.
size_t unprocessed_len
Length of data to process.
uint8_t sig[MAX_BLOCK_LENGTH]
Last block to be verified.
const cx_cipher_base_t * base
uint32_t iv_size
Initialization vector size.
uint32_t key_bitlen
Key size.
uint32_t block_size
Block size.