3 #include "app_config.h"
13 cx_err_t cx_aes_init_key_no_throw(
const uint8_t *raw_key,
size_t key_len, cx_aes_key_t *key)
15 memset(key, 0,
sizeof(cx_aes_key_t));
21 memmove(key->keys, raw_key, key_len);
24 return CX_INVALID_PARAMETER;
28 cx_err_t cx_aes_enc_block(
const cx_aes_key_t *key,
const uint8_t *inblock,
uint8_t *outblock)
31 cx_err_t err_reset = CX_INTERNAL_ERROR;
33 CX_CHECK(cx_aes_block_hw(inblock, outblock));
35 err_reset = cx_aes_reset_hw();
36 return error == CX_OK ? err_reset : error;
39 cx_err_t cx_aes_dec_block(
const cx_aes_key_t *key,
const uint8_t *inblock,
uint8_t *outblock)
42 cx_err_t err_reset = CX_INTERNAL_ERROR;
45 CX_CHECK(cx_aes_block_hw(inblock, outblock));
47 err_reset = cx_aes_reset_hw();
48 return error == CX_OK ? err_reset : error;
51 cx_err_t cx_aes_iv_no_throw(
const cx_aes_key_t *key,
76 return CX_INVALID_PARAMETER;
83 return CX_INVALID_PARAMETER_VALUE;
92 CX_CHECK(cx_aes_set_key_hw(key, operation));
101 cx_err_t cx_aes_no_throw(
const cx_aes_key_t *key,
108 return cx_aes_iv_no_throw(key, mode, NULL, 0, in, in_len, out, out_len);
111 cx_err_t aes_ctr(cx_aes_key_t *ctx_key,
121 cx_err_t error = CX_INVALID_PARAMETER;
126 CX_CHECK(cx_aes_block_hw(nonce_counter, stream_block));
127 for (
int i = CX_AES_BLOCK_SIZE; i > 0; i--) {
128 if (++nonce_counter[i - 1] != 0) {
134 *output++ = c ^ stream_block[n];
144 cx_err_t aes_setkey(cx_aes_key_t *ctx_key,
150 CX_CHECK(cx_aes_init_key_no_throw(key, key_bitlen / 8, ctx_key));
151 CX_CHECK(cx_aes_set_key_hw(ctx_key, operation));
157 (cx_err_t(*)(
const uint8_t *inblock,
uint8_t *outblock)) cx_aes_block_hw,
158 (cx_err_t(*)(
const uint8_t *inblock,
uint8_t *outblock)) cx_aes_block_hw,
169 uint32_t key_bitlen)) aes_setkey,
170 (cx_err_t(*)(
void)) cx_aes_reset_hw,
176 #ifdef BOLOS_OS_UPGRADER_APP
184 #ifdef BOLOS_OS_UPGRADER_APP
192 #ifdef BOLOS_OS_UPGRADER_APP
@ CX_CIPHER_AES_192
AES with a 192-bit key.
@ 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_init(cx_cipher_context_t *ctx)
Initialize a cipher context as NONE.
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.
uint32_t operation
Operation: encryption or decryption.
uint32_t key_bitlen
Key size in bits.
const cipher_key_t * cipher_key
Cipher-specific context.
cx_cipher_context_t cipher