#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.
|
#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) |
|
|
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) |
|
#define CCM_FLAGS |
( |
|
A, |
|
|
|
M, |
|
|
|
L |
|
) |
| (((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, |
|
|
|
C |
|
) |
| |
Value:{ \
int i; \
(A)[i] |= (C) & 0xFF; \
}
#define DTLS_CCM_BLOCKSIZE
Definition at line 41 of file ccm.c.
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
-
ctx | The crypto context for the AES encryption. |
msg | The message starting with the additional authentication data. |
la | The number of additional authentication bytes in msg . |
B | The input buffer for crypto operations. When this function is called, B must be initialized with B0 (the first authentication block. |
X | The 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 |
|
) |
| |
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
-
ctx | The initialized rijndael_ctx object to be used for AES operations. |
M | The number of authentication octets. |
L | The number of bytes used to encode the message length. |
N | The nonce value to use. You must provide DTLS_CCM_BLOCKSIZE nonce octets, although only the first 16 - L are used. |
msg | The 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. |
lm | The actual length of msg . |
aad | A pointer to the additional authentication data (can be NULL if la is zero). |
la | The 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 |
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 |