llsec: Fixed style issues in CCM*

This commit is contained in:
Konrad Krentz 2015-07-01 07:00:14 -07:00 committed by kkrentz
parent b522c042ec
commit c656a4d1c5
7 changed files with 174 additions and 96 deletions

View file

@ -48,14 +48,11 @@
/*---------------------------------------------------------------------------*/
static void
set_nonce(uint8_t *iv,
set_iv(uint8_t *iv,
uint8_t flags,
const uint8_t *nonce,
uint8_t counter)
{
/* 1 byte|| 8 bytes || 4 bytes || 1 byte || 2 bytes */
/* flags || extended_source_address || frame_counter || sec_lvl || counter */
iv[0] = flags;
memcpy(iv + 1, nonce, CCM_STAR_NONCE_LENGTH);
iv[14] = 0;
@ -73,7 +70,7 @@ ctr_step(const uint8_t *nonce,
uint8_t a[AES_128_BLOCK_SIZE];
uint8_t i;
set_nonce(a, CCM_STAR_ENCRYPTION_FLAGS, nonce, counter);
set_iv(a, CCM_STAR_ENCRYPTION_FLAGS, nonce, counter);
AES_128.encrypt(a);
for(i = 0; (pos + i < m_len) && (i < AES_128_BLOCK_SIZE); i++) {
@ -82,9 +79,9 @@ ctr_step(const uint8_t *nonce,
}
/*---------------------------------------------------------------------------*/
static void
mic(const uint8_t *m, uint8_t m_len,
const uint8_t *nonce,
const uint8_t *a, uint8_t a_len,
mic(const uint8_t *nonce,
const uint8_t *m, uint8_t m_len,
const uint8_t *a, uint8_t a_len,
uint8_t *result,
uint8_t mic_len)
{
@ -92,10 +89,10 @@ mic(const uint8_t *m, uint8_t m_len,
uint8_t pos;
uint8_t i;
set_nonce(x, CCM_STAR_AUTH_FLAGS(a_len, mic_len), nonce, m_len);
set_iv(x, CCM_STAR_AUTH_FLAGS(a_len, mic_len), nonce, m_len);
AES_128.encrypt(x);
if(a_len > 0) {
if(a_len) {
x[1] = x[1] ^ a_len;
for(i = 2; (i - 2 < a_len) && (i < AES_128_BLOCK_SIZE); i++) {
x[i] ^= a[i - 2];
@ -113,7 +110,7 @@ mic(const uint8_t *m, uint8_t m_len,
}
}
if(m_len > 0) {
if(m_len) {
pos = 0;
while(pos < m_len) {
for(i = 0; (pos + i < m_len) && (i < AES_128_BLOCK_SIZE); i++) {
@ -130,7 +127,7 @@ mic(const uint8_t *m, uint8_t m_len,
}
/*---------------------------------------------------------------------------*/
static void
ctr(uint8_t *m, uint8_t m_len, const uint8_t* nonce)
ctr(const uint8_t *nonce, uint8_t *m, uint8_t m_len)
{
uint8_t pos;
uint8_t counter;
@ -143,8 +140,10 @@ ctr(uint8_t *m, uint8_t m_len, const uint8_t* nonce)
}
}
/*---------------------------------------------------------------------------*/
static void set_key(const uint8_t *key) {
AES_128.set_key((uint8_t*)key);
static void
set_key(const uint8_t *key)
{
AES_128.set_key(key);
}
/*---------------------------------------------------------------------------*/
const struct ccm_star_driver ccm_star_driver = {

View file

@ -54,33 +54,32 @@
* Structure of CCM* drivers.
*/
struct ccm_star_driver {
/**
* \brief Generates a MIC over the data supplied.
* \param data The data buffer to read.
* \param data_length The data buffer length.
* \param nonce The nonce to use. CCM_STAR_NONCE_LENGTH bytes long.
* \param result The generated MIC will be put here
* \param mic_len The size of the MIC to be generated. <= 16.
*/
void (* mic)(const uint8_t* data, uint8_t data_length,
const uint8_t* nonce,
const uint8_t* add, uint8_t add_len,
/**
* \brief Generates a MIC over the data supplied.
* \param nonce The nonce to use. CCM_STAR_NONCE_LENGTH bytes long.
* \param m Message to authenticate and encrypt
* \param a Additional authenticated data
* \param result The generated MIC will be put here
* \param mic_len The size of the MIC to be generated. <= 16.
*/
void (* mic)(const uint8_t* nonce,
const uint8_t* m, uint8_t m_len,
const uint8_t* a, uint8_t a_len,
uint8_t *result,
uint8_t mic_len);
/**
* \brief XORs the frame in the packetbuf with the key stream.
* \param data The data buffer to read.
* \param data_length The data buffer length.
* \param nonce The nonce to use. CCM_STAR_NONCE_LENGTH bytes long.
* \brief XORs m with the key stream.
* \param nonce The nonce to use. CCM_STAR_NONCE_LENGTH bytes long.
* \param m Message to authenticate and encrypt
*/
void (* ctr)( uint8_t* data, uint8_t data_length,
const uint8_t* nonce);
void (* ctr)(const uint8_t* nonce,
uint8_t* m, uint8_t m_len);
/**
* \brief Sets the key in use. Default implementation calls AES_128.set_key()
* \param key The key to use.
* \brief Sets the key in use. Default implementation calls AES_128.set_key().
* \param key The key to use.
*/
void (* set_key)(const uint8_t* key);
};