31 int (*setkey)(
void *state,
const uint8_t *key,
const size_t keylen,
32 const uint8_t *iv,
size_t ivlen);
33 void (*encrypt)(
void *state,
const uint8_t *plaintext,
34 uint8_t *ciphertext,
size_t datalen,
const uint8_t *aad,
35 size_t aadlen, uint8_t *tag,
size_t taglen);
36 void (*enc_init)(
void *state,
const uint8_t *aad,
size_t aadlen);
37 void (*enc_update)(
void *state,
const uint8_t *plaintext,
38 uint8_t *ciphertext,
size_t datalen);
39 void (*enc_final)(
void *state, uint8_t *tag,
size_t taglen);
40 int (*decrypt)(
void *state,
const uint8_t *ciphertext,
41 uint8_t *plaintext,
size_t datalen,
const uint8_t *aad,
42 size_t aadlen,
const uint8_t *tag,
size_t taglen);
43 void (*dec_init)(
void *state,
const uint8_t *aad,
size_t aadlen);
44 void (*dec_update)(
void *state,
const uint8_t *ciphertext,
45 uint8_t *plaintext,
size_t datalen);
46 int (*dec_final)(
void *state,
const uint8_t *tag,
size_t taglen);
47 void (*zero)(
void *state);
51 const struct lc_aead *aead;
55#define LC_AEAD_CTX(name, cb) \
57 name->aead_state = (uint8_t *)(name) + sizeof(struct lc_aead_ctx)
59#define LC_AEAD_HASH_ALIGN_CTX(name, cb) \
61 name->aead_state = LC_ALIGN_HASH_MASK((uint8_t *)(name) + \
62 sizeof(struct lc_aead_ctx))
88 const struct lc_aead *aead;
95 aead_state = ctx->aead_state;
97 if (!aead || !aead_state)
100 aead->zero(aead_state);
134 const size_t keylen,
const uint8_t *iv,
137 const struct lc_aead *aead;
144 aead_state = ctx->aead_state;
146 if (!aead || !aead_state)
149 return aead->setkey(aead_state, key, keylen, iv, ivlen);
174 const uint8_t *plaintext, uint8_t *ciphertext,
175 size_t datalen,
const uint8_t *aad,
176 size_t aadlen, uint8_t *tag,
size_t taglen)
178 const struct lc_aead *aead;
185 aead_state = ctx->aead_state;
187 if (!aead || !aead_state || !aead->encrypt)
190 aead->encrypt(aead_state, plaintext, ciphertext, datalen, aad, aadlen,
213 const struct lc_aead *aead;
220 aead_state = ctx->aead_state;
222 if (!aead || !aead_state || !aead->enc_init)
225 aead->enc_init(aead_state, aad, aadlen);
247 const uint8_t *plaintext,
248 uint8_t *ciphertext,
size_t datalen)
250 const struct lc_aead *aead;
257 aead_state = ctx->aead_state;
259 if (!aead || !aead_state || !aead->enc_update)
262 aead->enc_update(aead_state, plaintext, ciphertext, datalen);
283 const struct lc_aead *aead;
290 aead_state = ctx->aead_state;
292 if (!aead || !aead_state || !aead->enc_final)
295 aead->enc_final(aead_state, tag, taglen);
322 const uint8_t *ciphertext, uint8_t *plaintext,
323 size_t datalen,
const uint8_t *aad,
324 size_t aadlen,
const uint8_t *tag,
327 const struct lc_aead *aead;
334 aead_state = ctx->aead_state;
336 if (!aead || !aead_state || !aead->decrypt)
339 return aead->decrypt(aead_state, ciphertext, plaintext, datalen, aad,
340 aadlen, tag, taglen);
360 const struct lc_aead *aead;
367 aead_state = ctx->aead_state;
369 if (!aead || !aead_state || !aead->dec_init)
372 aead->dec_init(aead_state, aad, aadlen);
394 const uint8_t *ciphertext,
395 uint8_t *plaintext,
size_t datalen)
397 const struct lc_aead *aead;
404 aead_state = ctx->aead_state;
406 if (!aead || !aead_state || !aead->dec_update)
409 aead->dec_update(aead_state, ciphertext, plaintext, datalen);
429 const struct lc_aead *aead;
436 aead_state = ctx->aead_state;
438 if (!aead || !aead_state || !aead->dec_final)
441 return aead->dec_final(aead_state, tag, taglen);
static int lc_aead_setkey(struct lc_aead_ctx *ctx, const uint8_t *key, const size_t keylen, const uint8_t *iv, size_t ivlen)
Set the key for the AEAD encyption or decryption operation.
static int lc_aead_dec_update(struct lc_aead_ctx *ctx, const uint8_t *ciphertext, uint8_t *plaintext, size_t datalen)
AEAD-decrypt data - send partial data.
static int lc_aead_dec_final(struct lc_aead_ctx *ctx, const uint8_t *tag, size_t taglen)
AEAD-decrypt data - Perform authentication.
static int lc_aead_enc_init(struct lc_aead_ctx *ctx, const uint8_t *aad, size_t aadlen)
Initialize AEAD encryption.
static int lc_aead_encrypt(struct lc_aead_ctx *ctx, const uint8_t *plaintext, uint8_t *ciphertext, size_t datalen, const uint8_t *aad, size_t aadlen, uint8_t *tag, size_t taglen)
AEAD-encrypt data in one call.
static int lc_aead_enc_update(struct lc_aead_ctx *ctx, const uint8_t *plaintext, uint8_t *ciphertext, size_t datalen)
AEAD-encrypt data - send partial data.
static int lc_aead_enc_final(struct lc_aead_ctx *ctx, uint8_t *tag, size_t taglen)
Complete AEAD encryption - Obtain the authentication tag from the encryption operation.
static void lc_aead_zero_free(struct lc_aead_ctx *ctx)
Zeroize and free AEAD context.
static void lc_aead_zero(struct lc_aead_ctx *ctx)
Zeroize AEAD context.
static int lc_aead_decrypt(struct lc_aead_ctx *ctx, const uint8_t *ciphertext, uint8_t *plaintext, size_t datalen, const uint8_t *aad, size_t aadlen, const uint8_t *tag, size_t taglen)
AEAD-decrypt data in one call.
static int lc_aead_dec_init(struct lc_aead_ctx *ctx, const uint8_t *aad, size_t aadlen)
Initialize AEAD decryption.
void lc_free(void *ptr)
free the memory allocated with lc_alloc_aligned