Microchip® Advanced Software Framework

aes-ccm.c File Reference
#include "contiki.h"
#include "net/ip/uip.h"
#include "aes-ccm.h"
#include "aes.h"
#include "dev/watchdog.h"
#include <stdio.h>
#include <string.h>

Macros

#define aes_ccm_memcpy   memcpy
 
#define BLOCK_SIZE   16
 
#define CBCMAC_PRINTF(...)
 
#define CTR_MIC_PRINTF(...)
 
#define CTR_PRINTF(...)
 
#define L_SIZELEN   2 /* Size field length: 2 to 8 bytes */
 
#define NONCE_LEN   (15-L_SIZELEN) /* Nonce length: fixed to 13 bytes */
 
#define PRINT_CBCMAC_BLOCKS   0
 
#define PRINT_CTR_BLOCKS   0
 
#define PRINT_CTR_MIC_BLOCKS   0
 
#define PRINTF(...)
 

Functions

long aes_ccm_decrypt (const unsigned char *key, const unsigned char *nonce, const unsigned char *adata, unsigned long adata_len, const unsigned char *ciphermic, signed long ciphermic_len, int mic_len, unsigned char *outbuf)
 
long aes_ccm_encrypt (const unsigned char *key, const unsigned char *nonce, const unsigned char *adata, unsigned long adata_len, const unsigned char *payload, unsigned long payload_len, int mic_len, unsigned char *outbuf)
 
void aes_ccm_memcpy (const unsigned char *dest, const unsigned char *from, int len)
 
int aes_ccm_verify (const unsigned char *key, const unsigned char *nonce, const unsigned char *adata, unsigned long adata_len, const unsigned char *ciphermic, unsigned long ciphermic_len, int mic_len)
 
static void cbcmac_append (const unsigned char *key, unsigned char *block)
 
static int cbcmac_calc (const unsigned char *key, const unsigned char *nonce, const unsigned char *adata, unsigned long adata_len, const unsigned char *payload, unsigned long payload_len, int mic_len, unsigned char *outbuf)
 
static void cbcmac_clear (void)
 
static int cbcmac_verify (const unsigned char *key, const unsigned char *nonce, const unsigned char *adata, unsigned long adata_len, const unsigned char *cipher, unsigned long cipher_len, int mic_len, unsigned char *outbuf)
 
static int ctr_mic (const unsigned char *key, const unsigned char *nonce, const unsigned char *cbcmac, int mic_len, unsigned char *outbuf)
 
static void ctr_next_ctr_block (const unsigned char *key, const unsigned char *nonce, uint16_t counter, unsigned char *outbuf)
 
static unsigned long ctr_payload (const unsigned char *key, const unsigned char *nonce, const unsigned char *payload, unsigned long payload_len, unsigned char *outbuf)
 

Variables

static unsigned char cbcmac_xor [BLOCK_SIZE]
 

#define aes_ccm_memcpy   memcpy

Referenced by ctr_payload().

#define BLOCK_SIZE   16
#define CBCMAC_PRINTF (   ...)
#define CTR_MIC_PRINTF (   ...)

Referenced by ctr_mic().

#define CTR_PRINTF (   ...)

Referenced by ctr_next_ctr_block(), and ctr_payload().

#define L_SIZELEN   2 /* Size field length: 2 to 8 bytes */
#define NONCE_LEN   (15-L_SIZELEN) /* Nonce length: fixed to 13 bytes */
#define PRINT_CBCMAC_BLOCKS   0
#define PRINT_CTR_BLOCKS   0
#define PRINT_CTR_MIC_BLOCKS   0
#define PRINTF (   ...)

long aes_ccm_decrypt ( const unsigned char *  key,
const unsigned char *  nonce,
const unsigned char *  adata,
unsigned long  adata_len,
const unsigned char *  ciphermic,
signed long  ciphermic_len,
int  mic_len,
unsigned char *  outbuf 
)
long aes_ccm_encrypt ( const unsigned char *  key,
const unsigned char *  nonce,
const unsigned char *  adata,
unsigned long  adata_len,
const unsigned char *  payload,
unsigned long  payload_len,
int  mic_len,
unsigned char *  outbuf 
)
void aes_ccm_memcpy ( const unsigned char *  dest,
const unsigned char *  from,
int  len 
)
int aes_ccm_verify ( const unsigned char *  key,
const unsigned char *  nonce,
const unsigned char *  adata,
unsigned long  adata_len,
const unsigned char *  ciphermic,
unsigned long  ciphermic_len,
int  mic_len 
)

References cbcmac_verify(), ctr_mic(), i, and PRINTF.

Referenced by netstack_aes_verify().

static void cbcmac_append ( const unsigned char *  key,
unsigned char *  block 
)
static
static int cbcmac_calc ( const unsigned char *  key,
const unsigned char *  nonce,
const unsigned char *  adata,
unsigned long  adata_len,
const unsigned char *  payload,
unsigned long  payload_len,
int  mic_len,
unsigned char *  outbuf 
)
static
static void cbcmac_clear ( void  )
static

References cbcmac_xor.

Referenced by cbcmac_calc(), and cbcmac_verify().

static int cbcmac_verify ( const unsigned char *  key,
const unsigned char *  nonce,
const unsigned char *  adata,
unsigned long  adata_len,
const unsigned char *  cipher,
unsigned long  cipher_len,
int  mic_len,
unsigned char *  outbuf 
)
static
static int ctr_mic ( const unsigned char *  key,
const unsigned char *  nonce,
const unsigned char *  cbcmac,
int  mic_len,
unsigned char *  outbuf 
)
static
static void ctr_next_ctr_block ( const unsigned char *  key,
const unsigned char *  nonce,
uint16_t  counter,
unsigned char *  outbuf 
)
static
static unsigned long ctr_payload ( const unsigned char *  key,
const unsigned char *  nonce,
const unsigned char *  payload,
unsigned long  payload_len,
unsigned char *  outbuf 
)
static

unsigned char cbcmac_xor[BLOCK_SIZE]
static

Referenced by cbcmac_append(), and cbcmac_clear().