ndn-lite
Functions
tc_ccm_mode.c File Reference
#include "tc_ccm_mode.h"
#include "tc_constants.h"
#include "tc_utils.h"
#include <stdio.h>

Functions

int tc_ccm_config (TCCcmMode_t c, TCAesKeySched_t sched, uint8_t *nonce, unsigned int nlen, unsigned int mlen)
 CCM configuration procedure. More...
 
static void ccm_cbc_mac (uint8_t *T, const uint8_t *data, unsigned int dlen, unsigned int flag, TCAesKeySched_t sched)
 Variation of CBC-MAC mode used in CCM. More...
 
static int ccm_ctr_mode (uint8_t *out, unsigned int outlen, const uint8_t *in, unsigned int inlen, uint8_t *ctr, const TCAesKeySched_t sched)
 Variation of CTR mode used in CCM. More...
 
int tc_ccm_generation_encryption (uint8_t *out, unsigned int olen, const uint8_t *associated_data, unsigned int alen, const uint8_t *payload, unsigned int plen, TCCcmMode_t c)
 CCM tag generation and encryption procedure. More...
 
int tc_ccm_decryption_verification (uint8_t *out, unsigned int olen, const uint8_t *associated_data, unsigned int alen, const uint8_t *payload, unsigned int plen, TCCcmMode_t c)
 CCM decryption and tag verification procedure. More...
 

Function Documentation

◆ ccm_cbc_mac()

static void ccm_cbc_mac ( uint8_t *  T,
const uint8_t *  data,
unsigned int  dlen,
unsigned int  flag,
TCAesKeySched_t  sched 
)
static

Variation of CBC-MAC mode used in CCM.

◆ ccm_ctr_mode()

static int ccm_ctr_mode ( uint8_t *  out,
unsigned int  outlen,
const uint8_t *  in,
unsigned int  inlen,
uint8_t *  ctr,
const TCAesKeySched_t  sched 
)
static

Variation of CTR mode used in CCM.

The CTR mode used by CCM is slightly different than the conventional CTR mode (the counter is increased before encryption, instead of after encryption). Besides, it is assumed that the counter is stored in the last 2 bytes of the nonce.

◆ tc_ccm_config()

int tc_ccm_config ( TCCcmMode_t  c,
TCAesKeySched_t  sched,
uint8_t *  nonce,
unsigned int  nlen,
unsigned int  mlen 
)

CCM configuration procedure.

Returns
returns TC_CRYPTO_SUCCESS (1) returns TC_CRYPTO_FAIL (0) if: c == NULL or sched == NULL or nonce == NULL or mlen != {4, 6, 8, 10, 12, 16}
Parameters
c– CCM state
schedIN – AES key schedule
nonceIN - nonce
nlen– nonce length in bytes
mlen– mac length in bytes (parameter t in SP-800 38C)

◆ tc_ccm_decryption_verification()

int tc_ccm_decryption_verification ( uint8_t *  out,
unsigned int  olen,
const uint8_t *  associated_data,
unsigned int  alen,
const uint8_t *  payload,
unsigned int  plen,
TCCcmMode_t  c 
)

CCM decryption and tag verification procedure.

Returns
returns TC_CRYPTO_SUCCESS (1) returns TC_CRYPTO_FAIL (0) if: out == NULL or c == NULL or ((plen > 0) and (payload == NULL)) or ((alen > 0) and (associated_data == NULL)) or (alen >= TC_CCM_AAD_MAX_BYTES) or (plen >= TC_CCM_PAYLOAD_MAX_BYTES) or (olen < plen - c->mlen)
Parameters
outOUT – decrypted data
associated_dataIN – associated data
alenIN – associated data length in bytes
payloadIN – payload
plenIN – payload length in bytes
cIN – CCM state
Note
: out buffer should be at least (plen - c->mlen) bytes long.
: The sequence b for encryption is formatted as follows: b = [FLAGS | nonce | counter ], where: FLAGS is 1 byte long nonce is 13 bytes long counter is 2 bytes long The byte FLAGS is composed by the following 8 bits: 0-2 bits: used to represent the value of q-1 3-7 btis: always 0's
: The sequence b for authentication is formatted as follows: b = [FLAGS | nonce | length(mac length)], where: FLAGS is 1 byte long nonce is 13 bytes long length(mac length) is 2 bytes long The byte FLAGS is composed by the following 8 bits: 0-2 bits: used to represent the value of q-1 3-5 bits: mac length (encoded as: (mlen-2)/2) 6: Adata (0 if alen == 0, and 1 otherwise) 7: always 0

◆ tc_ccm_generation_encryption()

int tc_ccm_generation_encryption ( uint8_t *  out,
unsigned int  olen,
const uint8_t *  associated_data,
unsigned int  alen,
const uint8_t *  payload,
unsigned int  plen,
TCCcmMode_t  c 
)

CCM tag generation and encryption procedure.

Returns
returns TC_CRYPTO_SUCCESS (1) returns TC_CRYPTO_FAIL (0) if: out == NULL or c == NULL or ((plen > 0) and (payload == NULL)) or ((alen > 0) and (associated_data == NULL)) or (alen >= TC_CCM_AAD_MAX_BYTES) or (plen >= TC_CCM_PAYLOAD_MAX_BYTES) or (olen < plen + maclength)
Parameters
outOUT – encrypted data
olenIN – output length in bytes
associated_dataIN – associated data
alenIN – associated data length in bytes
payloadIN – payload
plenIN – payload length in bytes
cIN – CCM state
Note
: out buffer should be at least (plen + c->mlen) bytes long.
: The sequence b for encryption is formatted as follows: b = [FLAGS | nonce | counter ], where: FLAGS is 1 byte long nonce is 13 bytes long counter is 2 bytes long The byte FLAGS is composed by the following 8 bits: 0-2 bits: used to represent the value of q-1 3-7 btis: always 0's
: The sequence b for authentication is formatted as follows: b = [FLAGS | nonce | length(mac length)], where: FLAGS is 1 byte long nonce is 13 bytes long length(mac length) is 2 bytes long The byte FLAGS is composed by the following 8 bits: 0-2 bits: used to represent the value of q-1 3-5 bits: mac length (encoded as: (mlen-2)/2) 6: Adata (0 if alen == 0, and 1 otherwise) 7: always 0