48#define CCM_STAR_AUTH_FLAGS(a_len, mic_len) (((a_len) ? 1u << 6 : 0) \
49 | ((((mic_len) - 2u) >> 1) << 3) \
51#define CCM_STAR_ENCRYPTION_FLAGS 1
53#define MIC_LEN_VALID(x) ((x) >= 4 && (x) <= 16 && (x) % 2 == 0)
63 memcpy(iv + 1, nonce, CCM_STAR_NONCE_LENGTH);
64 iv[14] = counter >> 8;
70ctr_step(
const uint8_t *nonce,
72 uint8_t *m_and_result, uint16_t m_len,
75 uint8_t a[AES_128_BLOCK_SIZE];
77 set_iv(a, CCM_STAR_ENCRYPTION_FLAGS, nonce, counter);
80 for(uint_fast8_t i = 0; (pos + i < m_len) && (i < AES_128_BLOCK_SIZE); i++) {
81 m_and_result[pos + i] ^= a[i];
86mic(
const uint8_t *nonce,
87 const uint8_t *m, uint16_t m_len,
88 const uint8_t *a, uint16_t a_len,
89 uint8_t *result, uint8_t mic_len)
91 uint8_t x[AES_128_BLOCK_SIZE];
93 set_iv(x, CCM_STAR_AUTH_FLAGS(a_len, mic_len), nonce, m_len);
100 for(pos = 0; (pos < a_len) && (pos < AES_128_BLOCK_SIZE - 2); pos++) {
101 x[2 + pos] ^= a[pos];
107 for(; pos < a_len; pos += AES_128_BLOCK_SIZE) {
108 for(uint_fast8_t i = 0;
109 (pos + i < a_len) && (i < AES_128_BLOCK_SIZE);
119 for(uint32_t pos = 0; pos < m_len; pos += AES_128_BLOCK_SIZE) {
120 for(uint_fast8_t i = 0;
121 (pos + i < m_len) && (i < AES_128_BLOCK_SIZE);
129 ctr_step(nonce, 0, x, AES_128_BLOCK_SIZE, 0);
131 memcpy(result, x, mic_len);
135ctr(
const uint8_t *nonce, uint8_t *m, uint16_t m_len)
137 uint16_t counter = 1;
139 for(uint32_t pos = 0; pos < m_len; pos += AES_128_BLOCK_SIZE) {
140 ctr_step(nonce, pos, m, m_len, counter++);
145set_key(
const uint8_t *key)
147 AES_128.set_key(key);
151aead(
const uint8_t *nonce,
152 uint8_t *m, uint16_t m_len,
153 const uint8_t *a, uint16_t a_len,
154 uint8_t *result, uint8_t mic_len,
157 if(!MIC_LEN_VALID(mic_len)) {
163 ctr(nonce, m, m_len);
174 ctr(nonce, m, m_len);
static volatile at86rf215_flags_t flags
The radio driver uses the following flags to keep track of the current state of the radio and IRQ eve...
Structure of CCM* drivers.
void(* aead)(const uint8_t *nonce, uint8_t *m, uint16_t m_len, const uint8_t *a, uint16_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.