tinydtls  0.8.1
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
Macros | Functions
ccm.c File Reference
#include <string.h>
#include "dtls_config.h"
#include "global.h"
#include "numeric.h"
#include "ccm.h"
#include <assert.h>

Go to the source code of this file.

Macros

#define CCM_FLAGS(A, M, L)   (((A > 0) << 6) | (((M - 2)/2) << 3) | (L - 1))
 
#define MASK_L(_L)   ((1 << 8 * _L) - 1)
 
#define SET_COUNTER(A, L, cnt, C)
 

Functions

static void block0 (size_t M, size_t L, size_t la, size_t lm, unsigned char nonce[DTLS_CCM_BLOCKSIZE], unsigned char *result)
 
static void add_auth_data (rijndael_ctx *ctx, const unsigned char *msg, size_t la, unsigned char B[DTLS_CCM_BLOCKSIZE], unsigned char X[DTLS_CCM_BLOCKSIZE])
 
static void encrypt (rijndael_ctx *ctx, size_t L, unsigned long counter, unsigned char *msg, size_t len, unsigned char A[DTLS_CCM_BLOCKSIZE], unsigned char S[DTLS_CCM_BLOCKSIZE])
 
static void mac (rijndael_ctx *ctx, unsigned char *msg, size_t len, unsigned char B[DTLS_CCM_BLOCKSIZE], unsigned char X[DTLS_CCM_BLOCKSIZE])
 
long int dtls_ccm_encrypt_message (rijndael_ctx *ctx, size_t M, size_t L, unsigned char nonce[DTLS_CCM_BLOCKSIZE], unsigned char *msg, size_t lm, const unsigned char *aad, size_t la)
 
long int dtls_ccm_decrypt_message (rijndael_ctx *ctx, size_t M, size_t L, unsigned char nonce[DTLS_CCM_BLOCKSIZE], unsigned char *msg, size_t lm, const unsigned char *aad, size_t la)
 

Macro Definition Documentation

#define CCM_FLAGS (   A,
  M,
 
)    (((A > 0) << 6) | (((M - 2)/2) << 3) | (L - 1))

Definition at line 37 of file ccm.c.

#define MASK_L (   _L)    ((1 << 8 * _L) - 1)

Definition at line 39 of file ccm.c.

#define SET_COUNTER (   A,
  L,
  cnt,
 
)
Value:
{ \
int i; \
memset((A) + DTLS_CCM_BLOCKSIZE - (L), 0, (L)); \
(C) = (cnt) & MASK_L(L); \
for (i = DTLS_CCM_BLOCKSIZE - 1; (C) && (i > (L)); --i, (C) >>= 8) \
(A)[i] |= (C) & 0xFF; \
}
#define MASK_L(_L)
Definition: ccm.c:39
#define DTLS_CCM_BLOCKSIZE
Definition: ccm.h:33

Definition at line 41 of file ccm.c.

Function Documentation

static void add_auth_data ( rijndael_ctx *  ctx,
const unsigned char *  msg,
size_t  la,
unsigned char  B[DTLS_CCM_BLOCKSIZE],
unsigned char  X[DTLS_CCM_BLOCKSIZE] 
)
static

Creates the CBC-MAC for the additional authentication data that is sent in cleartext.

Parameters
ctxThe crypto context for the AES encryption.
msgThe message starting with the additional authentication data.
laThe number of additional authentication bytes in msg.
BThe input buffer for crypto operations. When this function is called, B must be initialized with B0 (the first authentication block.
XThe output buffer where the result of the CBC calculation is placed.
Returns
The result is written to X.

Definition at line 84 of file ccm.c.

static void block0 ( size_t  M,
size_t  L,
size_t  la,
size_t  lm,
unsigned char  nonce[DTLS_CCM_BLOCKSIZE],
unsigned char *  result 
)
inlinestatic

Definition at line 50 of file ccm.c.

long int dtls_ccm_decrypt_message ( rijndael_ctx *  ctx,
size_t  M,
size_t  L,
unsigned char  nonce[DTLS_CCM_BLOCKSIZE],
unsigned char *  msg,
size_t  lm,
const unsigned char *  aad,
size_t  la 
)

Definition at line 240 of file ccm.c.

long int dtls_ccm_encrypt_message ( rijndael_ctx *  ctx,
size_t  M,
size_t  L,
unsigned char  nonce[DTLS_CCM_BLOCKSIZE],
unsigned char *  msg,
size_t  lm,
const unsigned char *  aad,
size_t  la 
)

Authenticates and encrypts a message using AES in CCM mode. Please see also RFC 3610 for the meaning of M, L, lm and la.

Parameters
ctxThe initialized rijndael_ctx object to be used for AES operations.
MThe number of authentication octets.
LThe number of bytes used to encode the message length.
NThe nonce value to use. You must provide DTLS_CCM_BLOCKSIZE nonce octets, although only the first 16 - L are used.
msgThe message to encrypt. The first la octets are additional authentication data that will be cleartext. Note that the encryption operation modifies the contents of msg and adds M bytes MAC. Therefore, the buffer must be at least lm + M bytes large.
lmThe actual length of msg.
aadA pointer to the additional authentication data (can be NULL if la is zero).
laThe number of additional authentication octets (may be zero).
Returns
FIXME

Definition at line 176 of file ccm.c.

static void encrypt ( rijndael_ctx *  ctx,
size_t  L,
unsigned long  counter,
unsigned char *  msg,
size_t  len,
unsigned char  A[DTLS_CCM_BLOCKSIZE],
unsigned char  S[DTLS_CCM_BLOCKSIZE] 
)
inlinestatic

Definition at line 149 of file ccm.c.

static void mac ( rijndael_ctx *  ctx,
unsigned char *  msg,
size_t  len,
unsigned char  B[DTLS_CCM_BLOCKSIZE],
unsigned char  X[DTLS_CCM_BLOCKSIZE] 
)
inlinestatic

Definition at line 162 of file ccm.c.