46 #define CCM_STAR_AUTH_FLAGS(Adata, M) ((Adata ? (1u << 6) : 0) | (((M - 2u) >> 1) << 3) | 1u) 47 #define CCM_STAR_ENCRYPTION_FLAGS 1 57 memcpy(iv + 1, nonce, CCM_STAR_NONCE_LENGTH);
64 ctr_step(
const uint8_t *nonce,
66 uint8_t *m_and_result,
70 uint8_t a[AES_128_BLOCK_SIZE];
73 set_iv(a, CCM_STAR_ENCRYPTION_FLAGS, nonce, counter);
76 for(i = 0; (pos + i < m_len) && (i < AES_128_BLOCK_SIZE); i++) {
77 m_and_result[pos + i] ^= a[i];
82 mic(
const uint8_t *nonce,
83 const uint8_t *m, uint8_t m_len,
84 const uint8_t *a, uint8_t a_len,
88 uint8_t x[AES_128_BLOCK_SIZE];
92 set_iv(x, CCM_STAR_AUTH_FLAGS(a_len, mic_len), nonce, m_len);
97 for(i = 2; (i - 2 < a_len) && (i < AES_128_BLOCK_SIZE); i++) {
105 for(i = 0; (pos + i < a_len) && (i < AES_128_BLOCK_SIZE); i++) {
108 pos += AES_128_BLOCK_SIZE;
116 for(i = 0; (pos + i < m_len) && (i < AES_128_BLOCK_SIZE); i++) {
119 pos += AES_128_BLOCK_SIZE;
124 ctr_step(nonce, 0, x, AES_128_BLOCK_SIZE, 0);
126 memcpy(result, x, mic_len);
130 ctr(
const uint8_t *nonce, uint8_t *m, uint8_t m_len)
138 ctr_step(nonce, pos, m, m_len, counter++);
139 pos += AES_128_BLOCK_SIZE;
146 AES_128.set_key(key);
150 aead(
const uint8_t* nonce,
151 uint8_t* m, uint8_t m_len,
152 const uint8_t* a, uint8_t a_len,
153 uint8_t *result, uint8_t mic_len,
158 ctr(nonce, m, m_len);
169 ctr(nonce, m, m_len);
Structure of CCM* drivers.
void(* aead)(const uint8_t *nonce, uint8_t *m, uint8_t m_len, const uint8_t *a, uint8_t a_len, uint8_t *result, uint8_t mic_len, int forward)
Combines authentication and encryption.
void(* set_key)(const uint8_t *key)
Sets the key in use.
void(* set_key)(const uint8_t *key)
Sets the current key.