Changeset View
Changeset View
Standalone View
Standalone View
sys/opencrypto/xform_aes_icm.c
Show First 20 Lines • Show All 138 Lines • ▼ Show 20 Lines | aes_gcm_reinit(void *key, const uint8_t *iv, size_t ivlen) | ||||
ctx->ac_block[AESICM_BLOCKSIZE - 1] = 2; | ctx->ac_block[AESICM_BLOCKSIZE - 1] = 2; | ||||
} | } | ||||
static void | static void | ||||
aes_ccm_reinit(void *key, const uint8_t *iv, size_t ivlen) | aes_ccm_reinit(void *key, const uint8_t *iv, size_t ivlen) | ||||
{ | { | ||||
struct aes_icm_ctx *ctx; | struct aes_icm_ctx *ctx; | ||||
KASSERT(ivlen == AES_CCM_IV_LEN, | KASSERT(ivlen >= 7 && ivlen <= 13, | ||||
("%s: invalid IV length", __func__)); | ("%s: invalid IV length", __func__)); | ||||
ctx = key; | ctx = key; | ||||
/* CCM has flags, then the IV, then the counter, which starts at 1 */ | /* CCM has flags, then the IV, then the counter, which starts at 1 */ | ||||
bzero(ctx->ac_block, sizeof(ctx->ac_block)); | bzero(ctx->ac_block, sizeof(ctx->ac_block)); | ||||
/* 3 bytes for length field; this gives a nonce of 12 bytes */ | ctx->ac_block[0] = (15 - ivlen) - 1; | ||||
ctx->ac_block[0] = (15 - AES_CCM_IV_LEN) - 1; | bcopy(iv, ctx->ac_block + 1, ivlen); | ||||
bcopy(iv, ctx->ac_block+1, AES_CCM_IV_LEN); | |||||
ctx->ac_block[AESICM_BLOCKSIZE - 1] = 1; | ctx->ac_block[AESICM_BLOCKSIZE - 1] = 1; | ||||
} | } | ||||
static void | static void | ||||
aes_icm_crypt(void *key, const uint8_t *in, uint8_t *out) | aes_icm_crypt(void *key, const uint8_t *in, uint8_t *out) | ||||
{ | { | ||||
struct aes_icm_ctx *ctx; | struct aes_icm_ctx *ctx; | ||||
int i; | int i; | ||||
Show All 37 Lines |