Leancrypto 1.6.0
Post-Quantum Cryptographic Library
Loading...
Searching...
No Matches
lc_aead.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2022 - 2025, 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
26#ifdef __cplusplus
27extern "C" {
28#endif
29
31struct lc_aead {
32 int (*setkey)(void *state, const uint8_t *key, const size_t keylen,
33 const uint8_t *iv, size_t ivlen);
34 void (*encrypt)(void *state, const uint8_t *plaintext,
35 uint8_t *ciphertext, size_t datalen, const uint8_t *aad,
36 size_t aadlen, uint8_t *tag, size_t taglen);
37 void (*enc_init)(void *state, const uint8_t *aad, size_t aadlen);
38 void (*enc_update)(void *state, const uint8_t *plaintext,
39 uint8_t *ciphertext, size_t datalen);
40 void (*enc_final)(void *state, uint8_t *tag, size_t taglen);
41 int (*decrypt)(void *state, const uint8_t *ciphertext,
42 uint8_t *plaintext, size_t datalen, const uint8_t *aad,
43 size_t aadlen, const uint8_t *tag, size_t taglen);
44 void (*dec_init)(void *state, const uint8_t *aad, size_t aadlen);
45 void (*dec_update)(void *state, const uint8_t *ciphertext,
46 uint8_t *plaintext, size_t datalen);
47 int (*dec_final)(void *state, const uint8_t *tag, size_t taglen);
48 void (*zero)(void *state);
49 uint64_t algorithm_type;
50};
51
52struct lc_aead_ctx {
53 const struct lc_aead *aead;
54 void *aead_state;
55};
56
57#define LC_AEAD_CTX(name, cb) \
58 name->aead = cb; \
59 name->aead_state = (uint8_t *)(name) + sizeof(struct lc_aead_ctx)
60
61#define LC_AEAD_HASH_ALIGN_CTX(name, cb) \
62 name->aead = cb; \
63 name->aead_state = LC_ALIGN_HASH_MASK((uint8_t *)(name) + \
64 sizeof(struct lc_aead_ctx))
66
82
89void lc_aead_zero(struct lc_aead_ctx *ctx);
90
97void lc_aead_zero_free(struct lc_aead_ctx *ctx);
98
114int lc_aead_setkey(struct lc_aead_ctx *ctx, const uint8_t *key,
115 const size_t keylen, const uint8_t *iv, size_t ivlen);
116
138int lc_aead_encrypt(struct lc_aead_ctx *ctx, const uint8_t *plaintext,
139 uint8_t *ciphertext, size_t datalen, const uint8_t *aad,
140 size_t aadlen, uint8_t *tag, size_t taglen);
141
156int lc_aead_enc_init(struct lc_aead_ctx *ctx, const uint8_t *aad,
157 size_t aadlen);
158
175int lc_aead_enc_update(struct lc_aead_ctx *ctx, const uint8_t *plaintext,
176 uint8_t *ciphertext, size_t datalen);
177
191int lc_aead_enc_final(struct lc_aead_ctx *ctx, uint8_t *tag, size_t taglen);
192
214int lc_aead_decrypt(struct lc_aead_ctx *ctx, const uint8_t *ciphertext,
215 uint8_t *plaintext, size_t datalen, const uint8_t *aad,
216 size_t aadlen, const uint8_t *tag, size_t taglen);
217
232int lc_aead_dec_init(struct lc_aead_ctx *ctx, const uint8_t *aad,
233 size_t aadlen);
234
251int lc_aead_dec_update(struct lc_aead_ctx *ctx, const uint8_t *ciphertext,
252 uint8_t *plaintext, size_t datalen);
253
266int lc_aead_dec_final(struct lc_aead_ctx *ctx, const uint8_t *tag,
267 size_t taglen);
268
277uint64_t lc_aead_algorithm_type(const struct lc_aead *aead);
278
287uint64_t lc_aead_ctx_algorithm_type(const struct lc_aead_ctx *ctx);
288
289#ifdef __cplusplus
290}
291#endif
292
293#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.
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.
uint64_t lc_aead_ctx_algorithm_type(const struct lc_aead_ctx *ctx)
Obtain algorithm type usable with lc_alg_status.
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.
uint64_t lc_aead_algorithm_type(const struct lc_aead *aead)
Obtain algorithm type usable with lc_alg_status.