#include <openssl/aead.h>
#include <assert.h>
#include <openssl/cipher.h>
#include <openssl/err.h>
#include <openssl/mem.h>
#include "../delocate.h"
#include "../modes/internal.h"
#include "../service_indicator/internal.h"
#include "internal.h"
#define EVP_AEAD_AES_CCM_MIN_TAG_LEN 4
#define EVP_AEAD_AES_CCM_MAX_TAG_LEN 16
#define CCM_MAX_NONCE_LEN 13
typedef struct ccm128_context {
block128_f block;
ctr128_f ctr;
uint32_t M, L;
} CCM128_CTX;
typedef struct ccm128_state {
alignas(16) uint8_t nonce[16];
alignas(16) uint8_t cmac[16];
} CCM128_STATE;
typedef struct cipher_aes_ccm_ctx {
union {
uint64_t align;
AES_KEY ks;
} ks;
CCM128_CTX ccm;
CCM128_STATE ccm_state;
uint8_t key_set;
uint8_t iv_set;
uint8_t tag_set;
uint8_t len_set;
uint8_t ccm_set;
uint32_t L; uint32_t M;
size_t message_len;
uint8_t tag[EVP_AEAD_AES_CCM_MAX_TAG_LEN];
uint8_t nonce[CCM_MAX_NONCE_LEN];
} CIPHER_AES_CCM_CTX;
#define CCM_INNER_CTX(ccm_ctx) (&ccm_ctx->ccm)
#define CCM_INNER_STATE(ccm_ctx) (&ccm_ctx->ccm_state)
#define CCM_L_TO_NONCE_LEN(L) (15 - L)
static int CRYPTO_ccm128_init(struct ccm128_context *ctx, block128_f block,
ctr128_f ctr, unsigned M, unsigned L) {
if (M < EVP_AEAD_AES_CCM_MIN_TAG_LEN || M > EVP_AEAD_AES_CCM_MAX_TAG_LEN
|| (M & 1) != 0 || L < 2 || L > 8) {
return 0;
}
if (block) {
ctx->block = block;
}
if (ctr) {
ctx->ctr = ctr;
}
ctx->M = M;
ctx->L = L;
return 1;
}
static size_t CRYPTO_ccm128_max_input(const struct ccm128_context *ctx) {
return ctx->L >= sizeof(size_t) ? SIZE_MAX
: (((size_t)1) << (ctx->L * 8)) - 1;
}
static int ccm128_init_state(const struct ccm128_context *ctx,
struct ccm128_state *state, const AES_KEY *key,
const uint8_t *nonce, size_t nonce_len,
const uint8_t *aad, size_t aad_len,
size_t plaintext_len) {
const block128_f block = ctx->block;
const uint32_t M = ctx->M;
const uint32_t L = ctx->L;
if (plaintext_len > CRYPTO_ccm128_max_input(ctx) ||
nonce_len != CCM_L_TO_NONCE_LEN(L)) {
return 0;
}
OPENSSL_memset(state, 0, sizeof(*state));
state->nonce[0] = (uint8_t)((L - 1) | ((M - 2) / 2) << 3);
if (aad_len != 0) {
state->nonce[0] |= 0x40; }
OPENSSL_memcpy(&state->nonce[1], nonce, nonce_len);
uint64_t plaintext_len_64 = plaintext_len;
for (uint32_t i = 0; i < L; i++) {
state->nonce[15 - i] = (uint8_t)(plaintext_len_64 >> (8 * i));
}
(*block)(state->nonce, state->cmac, key);
size_t blocks = 1;
if (aad_len != 0) {
unsigned i;
uint64_t aad_len_u64 = aad_len;
if (aad_len_u64 < 0x10000 - 0x100) {
state->cmac[0] ^= (uint8_t)(aad_len_u64 >> 8);
state->cmac[1] ^= (uint8_t)aad_len_u64;
i = 2;
} else if (aad_len_u64 <= 0xffffffff) {
state->cmac[0] ^= 0xff;
state->cmac[1] ^= 0xfe;
state->cmac[2] ^= (uint8_t)(aad_len_u64 >> 24);
state->cmac[3] ^= (uint8_t)(aad_len_u64 >> 16);
state->cmac[4] ^= (uint8_t)(aad_len_u64 >> 8);
state->cmac[5] ^= (uint8_t)aad_len_u64;
i = 6;
} else {
state->cmac[0] ^= 0xff;
state->cmac[1] ^= 0xff;
state->cmac[2] ^= (uint8_t)(aad_len_u64 >> 56);
state->cmac[3] ^= (uint8_t)(aad_len_u64 >> 48);
state->cmac[4] ^= (uint8_t)(aad_len_u64 >> 40);
state->cmac[5] ^= (uint8_t)(aad_len_u64 >> 32);
state->cmac[6] ^= (uint8_t)(aad_len_u64 >> 24);
state->cmac[7] ^= (uint8_t)(aad_len_u64 >> 16);
state->cmac[8] ^= (uint8_t)(aad_len_u64 >> 8);
state->cmac[9] ^= (uint8_t)aad_len_u64;
i = 10;
}
do {
for (; i < 16 && aad_len != 0; i++) {
state->cmac[i] ^= *aad;
aad++;
aad_len--;
}
(*block)(state->cmac, state->cmac, key);
blocks++;
i = 0;
} while (aad_len != 0);
}
size_t remaining_blocks = 2 * ((plaintext_len + 15) / 16) + 1;
if (plaintext_len + 15 < plaintext_len ||
remaining_blocks + blocks < blocks ||
(uint64_t) remaining_blocks + blocks > UINT64_C(1) << 61) {
return 0;
}
state->nonce[0] &= 7;
return 1;
}
static int ccm128_encrypt(const struct ccm128_context *ctx,
struct ccm128_state *state, const AES_KEY *key,
uint8_t *out, const uint8_t *in, size_t len) {
for (unsigned i = 0; i < ctx->L; i++) {
state->nonce[15 - i] = 0;
}
state->nonce[15] = 1;
uint8_t partial_buf[16];
unsigned num = 0;
if (ctx->ctr != NULL) {
CRYPTO_ctr128_encrypt_ctr32(in, out, len, key, state->nonce, partial_buf,
&num, ctx->ctr);
} else {
CRYPTO_ctr128_encrypt(in, out, len, key, state->nonce, partial_buf, &num,
ctx->block);
}
return 1;
}
static int ccm128_compute_mac(const struct ccm128_context *ctx,
struct ccm128_state *state, const AES_KEY *key,
uint8_t *out_tag, size_t tag_len,
const uint8_t *in, size_t len) {
block128_f block = ctx->block;
if (tag_len != ctx->M) {
return 0;
}
while (len >= 16) {
CRYPTO_xor16(state->cmac, state->cmac, in);
(*block)(state->cmac, state->cmac, key);
in += 16;
len -= 16;
}
if (len > 0) {
for (size_t i = 0; i < len; i++) {
state->cmac[i] ^= in[i];
}
(*block)(state->cmac, state->cmac, key);
}
for (unsigned i = 0; i < ctx->L; i++) {
state->nonce[15 - i] = 0;
}
alignas(16) uint8_t tmp[16];
(*block)(state->nonce, tmp, key);
CRYPTO_xor16(state->cmac, state->cmac, tmp);
OPENSSL_memcpy(out_tag, state->cmac, tag_len);
return 1;
}
static int CRYPTO_ccm128_encrypt(const struct ccm128_context *ctx,
const AES_KEY *key, uint8_t *out,
uint8_t *out_tag, size_t tag_len,
const uint8_t *nonce, size_t nonce_len,
const uint8_t *in, size_t len,
const uint8_t *aad, size_t aad_len) {
struct ccm128_state state;
return ccm128_init_state(ctx, &state, key, nonce, nonce_len, aad, aad_len,
len) &&
ccm128_compute_mac(ctx, &state, key, out_tag, tag_len, in, len) &&
ccm128_encrypt(ctx, &state, key, out, in, len);
}
static int CRYPTO_ccm128_decrypt(const struct ccm128_context *ctx,
const AES_KEY *key, uint8_t *out,
uint8_t *out_tag, size_t tag_len,
const uint8_t *nonce, size_t nonce_len,
const uint8_t *in, size_t len,
const uint8_t *aad, size_t aad_len) {
struct ccm128_state state;
return ccm128_init_state(ctx, &state, key, nonce, nonce_len, aad, aad_len,
len) &&
ccm128_encrypt(ctx, &state, key, out, in, len) &&
ccm128_compute_mac(ctx, &state, key, out_tag, tag_len, out, len);
}
struct aead_aes_ccm_ctx {
union {
double align;
AES_KEY ks;
} ks;
struct ccm128_context ccm;
};
OPENSSL_STATIC_ASSERT(sizeof(((EVP_AEAD_CTX *)NULL)->state) >=
sizeof(struct aead_aes_ccm_ctx),
AEAD_state_is_too_small)
OPENSSL_STATIC_ASSERT(alignof(union evp_aead_ctx_st_state) >=
alignof(struct aead_aes_ccm_ctx),
AEAD_state_has_insufficient_alignment)
static int aead_aes_ccm_init(EVP_AEAD_CTX *ctx, const uint8_t *key,
size_t key_len, size_t tag_len, unsigned M,
unsigned L) {
assert(M == EVP_AEAD_max_overhead(ctx->aead));
assert(M == EVP_AEAD_max_tag_len(ctx->aead));
assert(CCM_L_TO_NONCE_LEN(L) == EVP_AEAD_nonce_length(ctx->aead));
if (key_len != EVP_AEAD_key_length(ctx->aead)) {
OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_BAD_KEY_LENGTH);
return 0; }
if (tag_len == EVP_AEAD_DEFAULT_TAG_LENGTH) {
tag_len = M;
}
if (tag_len != M) {
OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_TAG_TOO_LARGE);
return 0;
}
struct aead_aes_ccm_ctx *ccm_ctx = (struct aead_aes_ccm_ctx *)&ctx->state;
block128_f block;
ctr128_f ctr = aes_ctr_set_key(&ccm_ctx->ks.ks, NULL, &block, key, key_len);
ctx->tag_len = tag_len;
if (!CRYPTO_ccm128_init(&ccm_ctx->ccm, block, ctr, M, L)) {
OPENSSL_PUT_ERROR(CIPHER, ERR_R_INTERNAL_ERROR);
return 0;
}
return 1;
}
static void aead_aes_ccm_cleanup(EVP_AEAD_CTX *ctx) {}
static int aead_aes_ccm_seal_scatter(
const EVP_AEAD_CTX *ctx, uint8_t *out, uint8_t *out_tag,
size_t *out_tag_len, size_t max_out_tag_len, const uint8_t *nonce,
size_t nonce_len, const uint8_t *in, size_t in_len, const uint8_t *extra_in,
size_t extra_in_len, const uint8_t *ad, size_t ad_len) {
const struct aead_aes_ccm_ctx *ccm_ctx =
(struct aead_aes_ccm_ctx *)&ctx->state;
if (in_len > CRYPTO_ccm128_max_input(&ccm_ctx->ccm)) {
OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_TOO_LARGE);
return 0;
}
if (max_out_tag_len < ctx->tag_len) {
OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_BUFFER_TOO_SMALL);
return 0;
}
if (nonce_len != EVP_AEAD_nonce_length(ctx->aead)) {
OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_INVALID_NONCE_SIZE);
return 0;
}
if (!CRYPTO_ccm128_encrypt(&ccm_ctx->ccm, &ccm_ctx->ks.ks, out, out_tag,
ctx->tag_len, nonce, nonce_len, in, in_len, ad,
ad_len)) {
OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_TOO_LARGE);
return 0;
}
*out_tag_len = ctx->tag_len;
AEAD_CCM_verify_service_indicator(ctx);
return 1;
}
static int aead_aes_ccm_open_gather(const EVP_AEAD_CTX *ctx, uint8_t *out,
const uint8_t *nonce, size_t nonce_len,
const uint8_t *in, size_t in_len,
const uint8_t *in_tag, size_t in_tag_len,
const uint8_t *ad, size_t ad_len) {
const struct aead_aes_ccm_ctx *ccm_ctx =
(struct aead_aes_ccm_ctx *)&ctx->state;
if (in_len > CRYPTO_ccm128_max_input(&ccm_ctx->ccm)) {
OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_TOO_LARGE);
return 0;
}
if (nonce_len != EVP_AEAD_nonce_length(ctx->aead)) {
OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_INVALID_NONCE_SIZE);
return 0;
}
if (in_tag_len != ctx->tag_len) {
OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_BAD_DECRYPT);
return 0;
}
uint8_t tag[EVP_AEAD_AES_CCM_MAX_TAG_LEN];
assert(ctx->tag_len <= EVP_AEAD_AES_CCM_MAX_TAG_LEN);
if (!CRYPTO_ccm128_decrypt(&ccm_ctx->ccm, &ccm_ctx->ks.ks, out, tag,
ctx->tag_len, nonce, nonce_len, in, in_len, ad,
ad_len)) {
OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_TOO_LARGE);
return 0;
}
if (CRYPTO_memcmp(tag, in_tag, ctx->tag_len) != 0) {
OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_BAD_DECRYPT);
return 0;
}
AEAD_CCM_verify_service_indicator(ctx);
return 1;
}
static int aead_aes_ccm_bluetooth_init(EVP_AEAD_CTX *ctx, const uint8_t *key,
size_t key_len, size_t tag_len) {
return aead_aes_ccm_init(ctx, key, key_len, tag_len, 4, 2);
}
DEFINE_METHOD_FUNCTION(EVP_AEAD, EVP_aead_aes_128_ccm_bluetooth) {
memset(out, 0, sizeof(EVP_AEAD));
out->key_len = 16;
out->nonce_len = 13;
out->overhead = 4;
out->max_tag_len = 4;
out->aead_id = AEAD_AES_128_CCM_BLUETOOTH_ID;
out->seal_scatter_supports_extra_in = 0;
out->init = aead_aes_ccm_bluetooth_init;
out->cleanup = aead_aes_ccm_cleanup;
out->seal_scatter = aead_aes_ccm_seal_scatter;
out->open_gather = aead_aes_ccm_open_gather;
}
static int aead_aes_ccm_bluetooth_8_init(EVP_AEAD_CTX *ctx, const uint8_t *key,
size_t key_len, size_t tag_len) {
return aead_aes_ccm_init(ctx, key, key_len, tag_len, 8, 2);
}
DEFINE_METHOD_FUNCTION(EVP_AEAD, EVP_aead_aes_128_ccm_bluetooth_8) {
memset(out, 0, sizeof(EVP_AEAD));
out->key_len = 16;
out->nonce_len = 13;
out->overhead = 8;
out->max_tag_len = 8;
out->aead_id = AEAD_AES_128_CCM_BLUETOOTH_8_ID;
out->seal_scatter_supports_extra_in = 0;
out->init = aead_aes_ccm_bluetooth_8_init;
out->cleanup = aead_aes_ccm_cleanup;
out->seal_scatter = aead_aes_ccm_seal_scatter;
out->open_gather = aead_aes_ccm_open_gather;
}
static int aead_aes_ccm_matter_init(EVP_AEAD_CTX *ctx, const uint8_t *key,
size_t key_len, size_t tag_len) {
return aead_aes_ccm_init(ctx, key, key_len, tag_len, 16, 2);
}
DEFINE_METHOD_FUNCTION(EVP_AEAD, EVP_aead_aes_128_ccm_matter) {
memset(out, 0, sizeof(EVP_AEAD));
out->key_len = 16;
out->nonce_len = 13;
out->overhead = 16;
out->aead_id = AEAD_AES_128_CCM_MATTER_ID;
out->max_tag_len = 16;
out->init = aead_aes_ccm_matter_init;
out->cleanup = aead_aes_ccm_cleanup;
out->seal_scatter = aead_aes_ccm_seal_scatter;
out->open_gather = aead_aes_ccm_open_gather;
}
#if defined(OPENSSL_32_BIT)
#define CIPHER_AES_CCM_CTX_PADDING (4 + 8)
#else
#define CIPHER_AES_CCM_CTX_PADDING 8
#endif
static CIPHER_AES_CCM_CTX *aes_ccm_from_cipher_ctx(EVP_CIPHER_CTX *ctx) {
OPENSSL_STATIC_ASSERT(
alignof(CIPHER_AES_CCM_CTX) <= 16,
EVP_AES_CCM_CTX_needs_more_alignment_than_this_function_provides)
assert(ctx->cipher->ctx_size ==
sizeof(CIPHER_AES_CCM_CTX) + CIPHER_AES_CCM_CTX_PADDING);
char *ptr = ctx->cipher_data;
#if defined(OPENSSL_32_BIT)
assert((uintptr_t)ptr % 4 == 0);
ptr += (uintptr_t)ptr & 4;
#endif
assert((uintptr_t)ptr % 8 == 0);
ptr += (uintptr_t)ptr & 8;
return (CIPHER_AES_CCM_CTX *)ptr;
}
static int cipher_aes_ccm_init(EVP_CIPHER_CTX *ctx, const uint8_t *key,
const uint8_t *iv, int enc) {
CIPHER_AES_CCM_CTX *cipher_ctx = aes_ccm_from_cipher_ctx(ctx);
if (!iv && !key) {
return 1;
}
if (key) {
block128_f block;
ctr128_f ctr = aes_ctr_set_key(&cipher_ctx->ks.ks, NULL, &block, key,
ctx->key_len);
if (!CRYPTO_ccm128_init(&cipher_ctx->ccm, block, ctr, cipher_ctx->M,
cipher_ctx->L)) {
return 0;
}
cipher_ctx->key_set = 1;
}
if (iv) {
if (!CRYPTO_ccm128_init(&cipher_ctx->ccm, NULL, NULL, cipher_ctx->M,
cipher_ctx->L)) {
return 0;
}
OPENSSL_memcpy(cipher_ctx->nonce, iv, CCM_L_TO_NONCE_LEN(cipher_ctx->L));
cipher_ctx->iv_set = 1;
}
return 1;
}
static int cipher_aes_ccm_cipher(EVP_CIPHER_CTX *ctx, uint8_t *out,
const uint8_t *in, size_t len) {
CIPHER_AES_CCM_CTX *cipher_ctx = aes_ccm_from_cipher_ctx(ctx);
CCM128_CTX *ccm_ctx = CCM_INNER_CTX(cipher_ctx);
CCM128_STATE *ccm_state = CCM_INNER_STATE(cipher_ctx);
if (in == NULL && out != NULL) {
return 0;
}
if (!cipher_ctx->iv_set || !cipher_ctx->key_set) {
return -1;
}
if (!out) {
if (!in) {
cipher_ctx->message_len = len;
cipher_ctx->len_set = 1;
return len;
} else {
if (!cipher_ctx->len_set && len) {
return -1;
}
if (ccm128_init_state(ccm_ctx, ccm_state,
&cipher_ctx->ks.ks, cipher_ctx->nonce,
CCM_L_TO_NONCE_LEN(cipher_ctx->L), in, len,
cipher_ctx->message_len)) {
cipher_ctx->ccm_set = 1;
return len;
} else {
return -1;
}
}
}
if (!EVP_CIPHER_CTX_encrypting(ctx) && !cipher_ctx->tag_set) {
return -1;
}
if (!cipher_ctx->len_set) {
return -1;
}
if (!cipher_ctx->ccm_set) {
if (!ccm128_init_state(ccm_ctx, ccm_state, &cipher_ctx->ks.ks,
cipher_ctx->nonce, CCM_L_TO_NONCE_LEN(cipher_ctx->L),
NULL, 0, cipher_ctx->message_len)) {
return -1;
}
cipher_ctx->ccm_set = 1;
}
if (EVP_CIPHER_CTX_encrypting(ctx)) {
if (!ccm128_compute_mac(ccm_ctx, ccm_state, &cipher_ctx->ks.ks,
cipher_ctx->tag, cipher_ctx->M, in, len)) {
return -1;
}
if (!ccm128_encrypt(ccm_ctx, ccm_state, &cipher_ctx->ks.ks, out, in, len)) {
return -1;
}
cipher_ctx->tag_set = 1;
} else {
if (!ccm128_encrypt(ccm_ctx, ccm_state, &cipher_ctx->ks.ks, out, in, len)) {
return -1;
}
uint8_t computed_tag[EVP_AEAD_AES_CCM_MAX_TAG_LEN] = {0};
if (!ccm128_compute_mac(ccm_ctx, ccm_state, &cipher_ctx->ks.ks,
computed_tag, cipher_ctx->M, out, len)) {
OPENSSL_cleanse(out, len);
return -1;
}
if (OPENSSL_memcmp(cipher_ctx->tag, computed_tag, cipher_ctx->M)) {
OPENSSL_cleanse(out, len);
return -1;
}
cipher_ctx->iv_set = 0;
cipher_ctx->tag_set = 0;
cipher_ctx->len_set = 0;
cipher_ctx->ccm_set = 0;
}
return (int) len;
}
static int cipher_aes_ccm_ctrl_set_L(CIPHER_AES_CCM_CTX *ctx, int L) {
if (L < 2 || L > 8) {
return 0;
}
ctx->L = L;
return 1;
}
static int cipher_aes_ccm_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg,
void *ptr) {
CIPHER_AES_CCM_CTX *cipher_ctx = aes_ccm_from_cipher_ctx(ctx);
switch (type) {
case EVP_CTRL_INIT:
OPENSSL_cleanse(cipher_ctx, sizeof(CIPHER_AES_CCM_CTX));
cipher_ctx->key_set = 0;
cipher_ctx->iv_set = 0;
cipher_ctx->tag_set = 0;
cipher_ctx->len_set = 0;
cipher_ctx->ccm_set = 0;
cipher_ctx->L = 8;
cipher_ctx->M = 14;
cipher_ctx->message_len = 0;
return 1;
case EVP_CTRL_GET_IVLEN:
*(uint32_t *)ptr = CCM_L_TO_NONCE_LEN(cipher_ctx->L);
return 1;
case EVP_CTRL_AEAD_SET_IVLEN:
return cipher_aes_ccm_ctrl_set_L(cipher_ctx, 15 - arg);
case EVP_CTRL_CCM_SET_L:
return cipher_aes_ccm_ctrl_set_L(cipher_ctx, arg);
case EVP_CTRL_AEAD_SET_TAG:
if ((arg & 1) || arg < EVP_AEAD_AES_CCM_MIN_TAG_LEN
|| arg > EVP_AEAD_AES_CCM_MAX_TAG_LEN) {
return 0;
}
if (ctx->encrypt && ptr) {
return 0;
}
if (ptr) {
OPENSSL_memcpy(cipher_ctx->tag, ptr, arg);
cipher_ctx->tag_set = 1;
}
cipher_ctx->M = arg;
return 1;
case EVP_CTRL_AEAD_GET_TAG:
if (!ctx->encrypt || !cipher_ctx->tag_set) {
return 0;
}
if ((size_t) arg != cipher_ctx->M) {
return 0;
}
OPENSSL_memcpy(ptr, cipher_ctx->tag, cipher_ctx->M);
cipher_ctx->tag_set = 0;
cipher_ctx->iv_set = 0;
cipher_ctx->len_set = 0;
cipher_ctx->ccm_set = 0;
return 1;
case EVP_CTRL_COPY: {
EVP_CIPHER_CTX *out = ptr;
CIPHER_AES_CCM_CTX *cipher_ctx_out = aes_ccm_from_cipher_ctx(out);
OPENSSL_memcpy(cipher_ctx_out, cipher_ctx, sizeof(CIPHER_AES_CCM_CTX));
return 1;
}
default:
return -1;
}
}
DEFINE_METHOD_FUNCTION(EVP_CIPHER, EVP_aes_128_ccm) {
memset(out, 0, sizeof(EVP_CIPHER));
out->nid = NID_aes_128_ccm;
out->block_size = 1; out->key_len = 16;
out->iv_len = 13;
out->ctx_size = sizeof(CIPHER_AES_CCM_CTX) + CIPHER_AES_CCM_CTX_PADDING;
out->flags = EVP_CIPH_CCM_MODE | EVP_CIPH_CUSTOM_IV | EVP_CIPH_CUSTOM_COPY |
EVP_CIPH_FLAG_CUSTOM_CIPHER | EVP_CIPH_ALWAYS_CALL_INIT |
EVP_CIPH_CTRL_INIT | EVP_CIPH_FLAG_AEAD_CIPHER;
out->init = cipher_aes_ccm_init;
out->cipher = cipher_aes_ccm_cipher;
out->cleanup = NULL;
out->ctrl = cipher_aes_ccm_ctrl;
}
DEFINE_METHOD_FUNCTION(EVP_CIPHER, EVP_aes_192_ccm) {
memset(out, 0, sizeof(EVP_CIPHER));
out->nid = NID_aes_128_ccm;
out->block_size = 1; out->key_len = 24;
out->iv_len = 13;
out->ctx_size = sizeof(CIPHER_AES_CCM_CTX) + CIPHER_AES_CCM_CTX_PADDING;
out->flags = EVP_CIPH_CCM_MODE | EVP_CIPH_CUSTOM_IV | EVP_CIPH_CUSTOM_COPY |
EVP_CIPH_FLAG_CUSTOM_CIPHER | EVP_CIPH_ALWAYS_CALL_INIT |
EVP_CIPH_CTRL_INIT | EVP_CIPH_FLAG_AEAD_CIPHER;
out->init = cipher_aes_ccm_init;
out->cipher = cipher_aes_ccm_cipher;
out->cleanup = NULL;
out->ctrl = cipher_aes_ccm_ctrl;
}
DEFINE_METHOD_FUNCTION(EVP_CIPHER, EVP_aes_256_ccm) {
memset(out, 0, sizeof(EVP_CIPHER));
out->nid = NID_aes_128_ccm;
out->block_size = 1; out->key_len = 32;
out->iv_len = 13;
out->ctx_size = sizeof(CIPHER_AES_CCM_CTX) + CIPHER_AES_CCM_CTX_PADDING;
out->flags = EVP_CIPH_CCM_MODE | EVP_CIPH_CUSTOM_IV | EVP_CIPH_CUSTOM_COPY |
EVP_CIPH_FLAG_CUSTOM_CIPHER | EVP_CIPH_ALWAYS_CALL_INIT |
EVP_CIPH_CTRL_INIT | EVP_CIPH_FLAG_AEAD_CIPHER;
out->init = cipher_aes_ccm_init;
out->cipher = cipher_aes_ccm_cipher;
out->cleanup = NULL;
out->ctrl = cipher_aes_ccm_ctrl;
}