Leancrypto 1.7.2
Post-Quantum Cryptographic Library
lc_aead.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2022 - 2026, Stephan Mueller <smueller@chronox.de>
3 *
4 * License: see LICENSE file in root directory
5 *
6 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
7 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
8 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
9 * WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
10 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
11 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
12 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
13 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
14 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
15 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
16 * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH
17 * DAMAGE.
18 */
19
20#ifndef LC_AEAD_H
21#define LC_AEAD_H
22
23#include "lc_aes.h"
24#include "lc_memory_support.h"
25#include "lc_status.h"
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
32struct lc_aead {
33 int (*setkey)(void *state, const uint8_t *key, const size_t keylen,
34 const uint8_t *iv, size_t ivlen);
35 void (*encrypt)(void *state, const uint8_t *plaintext,
36 uint8_t *ciphertext, size_t datalen, const uint8_t *aad,
37 size_t aadlen, uint8_t *tag, size_t taglen);
38 void (*enc_init)(void *state, const uint8_t *aad, size_t aadlen);
39 void (*enc_update)(void *state, const uint8_t *plaintext,
40 uint8_t *ciphertext, size_t datalen);
41 void (*enc_final)(void *state, uint8_t *tag, size_t taglen);
42 int (*decrypt)(void *state, const uint8_t *ciphertext,
43 uint8_t *plaintext, size_t datalen, const uint8_t *aad,
44 size_t aadlen, const uint8_t *tag, size_t taglen);
45 void (*dec_init)(void *state, const uint8_t *aad, size_t aadlen);
46 void (*dec_update)(void *state, const uint8_t *ciphertext,
47 uint8_t *plaintext, size_t datalen);
48 int (*dec_final)(void *state, const uint8_t *tag, size_t taglen);
49 void (*zero)(void *state);
50 uint64_t algorithm_type;
51};
52
53struct lc_aead_ctx {
54 const struct lc_aead *aead;
55 void *aead_state;
56};
57
58#define LC_AEAD_CTX(name, cb) \
59 name->aead = cb; \
60 name->aead_state = (uint8_t *)(name) + sizeof(struct lc_aead_ctx)
61
62#define LC_AEAD_HASH_ALIGN_CTX(name, cb) \
63 name->aead = cb; \
64 name->aead_state = LC_ALIGN_HASH_MASK((uint8_t *)(name) + \
65 sizeof(struct lc_aead_ctx))
67
90void lc_aead_zero(struct lc_aead_ctx *ctx);
91
98void lc_aead_zero_free(struct lc_aead_ctx *ctx);
99
115int lc_aead_setkey(struct lc_aead_ctx *ctx, const uint8_t *key,
116 const size_t keylen, const uint8_t *iv, size_t ivlen);
117
139int lc_aead_encrypt(struct lc_aead_ctx *ctx, const uint8_t *plaintext,
140 uint8_t *ciphertext, size_t datalen, const uint8_t *aad,
141 size_t aadlen, uint8_t *tag, size_t taglen);
142
157int lc_aead_enc_init(struct lc_aead_ctx *ctx, const uint8_t *aad,
158 size_t aadlen);
159
176int lc_aead_enc_update(struct lc_aead_ctx *ctx, const uint8_t *plaintext,
177 uint8_t *ciphertext, size_t datalen);
178
192int lc_aead_enc_final(struct lc_aead_ctx *ctx, uint8_t *tag, size_t taglen);
193
215int lc_aead_decrypt(struct lc_aead_ctx *ctx, const uint8_t *ciphertext,
216 uint8_t *plaintext, size_t datalen, const uint8_t *aad,
217 size_t aadlen, const uint8_t *tag, size_t taglen);
218
233int lc_aead_dec_init(struct lc_aead_ctx *ctx, const uint8_t *aad,
234 size_t aadlen);
235
252int lc_aead_dec_update(struct lc_aead_ctx *ctx, const uint8_t *ciphertext,
253 uint8_t *plaintext, size_t datalen);
254
267int lc_aead_dec_final(struct lc_aead_ctx *ctx, const uint8_t *tag,
268 size_t taglen);
269
278enum lc_alg_status_val lc_aead_alg_status(const struct lc_aead *aead);
279
288enum lc_alg_status_val lc_aead_ctx_alg_status(const struct lc_aead_ctx *ctx);
289
290#ifdef __cplusplus
291}
292#endif
293
294#endif /* LC_AEAD_H */
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.
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.
enum lc_alg_status_val lc_aead_ctx_alg_status(const struct lc_aead_ctx *ctx)
Obtain algorithm status.
enum lc_alg_status_val lc_aead_alg_status(const struct lc_aead *aead)
Obtain algorithm status.
int lc_aead_enc_init(struct lc_aead_ctx *ctx, const uint8_t *aad, size_t aadlen)
Initialize AEAD encryption.
int lc_aead_dec_init(struct lc_aead_ctx *ctx, const uint8_t *aad, size_t aadlen)
Initialize AEAD decryption.
int lc_aead_dec_final(struct lc_aead_ctx *ctx, const uint8_t *tag, size_t taglen)
AEAD-decrypt data - Perform authentication.
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.
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.
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.
void lc_aead_zero(struct lc_aead_ctx *ctx)
Zeroize AEAD context.
void lc_aead_zero_free(struct lc_aead_ctx *ctx)
Zeroize and free AEAD context.
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.
lc_alg_status_val
Definition: lc_status.h:63