Leancrypto 1.7.2
Post-Quantum Cryptographic Library
lc_dilithium_87.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 * This code is derived in parts from the code distribution provided with
21 * https://github.com/pq-crystals/dilithium
22 *
23 * That code is released under Public Domain
24 * (https://creativecommons.org/share-your-work/public-domain/cc0/);
25 * or Apache 2.0 License (https://www.apache.org/licenses/LICENSE-2.0.html).
26 */
27
28#ifndef LC_DILITHIUM_87_H
29#define LC_DILITHIUM_87_H
30
31#ifndef __ASSEMBLER__
32
33#include "ext_headers.h"
34#include "lc_hash.h"
35#include "lc_rng.h"
36#include "lc_sha3.h"
37
38#endif /* __ASSEMBLER__ */
39
40#ifdef __cplusplus
41extern "C" {
42#endif
43
45
46/*
47 * Dilithium Security Levels
48 * 2 -> 192 bits of security strength
49 * 3 -> 225 bits of security strength
50 * 5 -> 257 bits of security strength
51 */
52#define LC_DILITHIUM_MODE 5
53
54#define LC_DILITHIUM_SEEDBYTES 32
55#define LC_DILITHIUM_CRHBYTES 64
56#define LC_DILITHIUM_TRBYTES 64
57#define LC_DILITHIUM_RNDBYTES 32
58#define LC_DILITHIUM_N 256
59#define LC_DILITHIUM_Q 8380417
60#define LC_DILITHIUM_D 13
61#define LC_DILITHIUM_ROOT_OF_UNITY 1753
62
63#if LC_DILITHIUM_MODE == 2
64#define LC_DILITHIUM_NIST_CATEGORY 1
65#define LC_DILITHIUM_LAMBDA 128
66#define LC_DILITHIUM_K 4
67#define LC_DILITHIUM_L 4
68#define LC_DILITHIUM_ETA 2
69#define LC_DILITHIUM_TAU 39
70#define LC_DILITHIUM_BETA 78
71#define LC_DILITHIUM_GAMMA1 (1 << 17)
72#define LC_DILITHIUM_GAMMA2 ((LC_DILITHIUM_Q - 1) / 88)
73#define LC_DILITHIUM_OMEGA 80
74
75#elif LC_DILITHIUM_MODE == 3
76#define LC_DILITHIUM_NIST_CATEGORY 3
77#define LC_DILITHIUM_LAMBDA 192
78#define LC_DILITHIUM_K 6
79#define LC_DILITHIUM_L 5
80#define LC_DILITHIUM_ETA 4
81#define LC_DILITHIUM_TAU 49
82#define LC_DILITHIUM_BETA 196
83#define LC_DILITHIUM_GAMMA1 (1 << 19)
84#define LC_DILITHIUM_GAMMA2 ((LC_DILITHIUM_Q - 1) / 32)
85#define LC_DILITHIUM_OMEGA 55
86
87#elif LC_DILITHIUM_MODE == 5
88#define LC_DILITHIUM_NIST_CATEGORY 5
89#define LC_DILITHIUM_LAMBDA 256
90#define LC_DILITHIUM_K 8
91#define LC_DILITHIUM_L 7
92#define LC_DILITHIUM_ETA 2
93#define LC_DILITHIUM_TAU 60
94#define LC_DILITHIUM_BETA 120
95#define LC_DILITHIUM_GAMMA1 (1 << 19)
96#define LC_DILITHIUM_GAMMA2 ((LC_DILITHIUM_Q - 1) / 32)
97#define LC_DILITHIUM_OMEGA 75
98
99#endif
100
101#define LC_DILITHIUM_CTILDE_BYTES (LC_DILITHIUM_LAMBDA * 2 / 8)
102#define LC_DILITHIUM_POLYT1_PACKEDBYTES 320
103#define LC_DILITHIUM_POLYT0_PACKEDBYTES 416
104#define LC_DILITHIUM_POLYVECH_PACKEDBYTES (LC_DILITHIUM_OMEGA + LC_DILITHIUM_K)
105
106#if LC_DILITHIUM_GAMMA1 == (1 << 17)
107#define LC_DILITHIUM_POLYZ_PACKEDBYTES 576
108#elif LC_DILITHIUM_GAMMA1 == (1 << 19)
109#define LC_DILITHIUM_POLYZ_PACKEDBYTES 640
110#endif
111
112#if LC_DILITHIUM_GAMMA2 == (LC_DILITHIUM_Q - 1) / 88
113#define LC_DILITHIUM_POLYW1_PACKEDBYTES 192
114#elif LC_DILITHIUM_GAMMA2 == (LC_DILITHIUM_Q - 1) / 32
115#define LC_DILITHIUM_POLYW1_PACKEDBYTES 128
116#endif
117
118#if LC_DILITHIUM_ETA == 2
119#define LC_DILITHIUM_POLYETA_PACKEDBYTES 96
120#elif LC_DILITHIUM_ETA == 4
121#define LC_DILITHIUM_POLYETA_PACKEDBYTES 128
122#endif
123
124/*
125 * Sizes of the different Dilithium buffer types.
126 *
127 * WARNING: Do not use these defines in your code. If you need the sizes of
128 * the different variable sizes, use sizeof of the different variable structs or
129 * use the different *_size functions documented below to retrieve the data size
130 * of a particular Dilithium component.
131 */
132#define LC_DILITHIUM_PUBLICKEYBYTES \
133 (LC_DILITHIUM_SEEDBYTES + \
134 LC_DILITHIUM_K * LC_DILITHIUM_POLYT1_PACKEDBYTES)
135#define LC_DILITHIUM_SECRETKEYBYTES \
136 (2 * LC_DILITHIUM_SEEDBYTES + LC_DILITHIUM_TRBYTES + \
137 LC_DILITHIUM_L * LC_DILITHIUM_POLYETA_PACKEDBYTES + \
138 LC_DILITHIUM_K * LC_DILITHIUM_POLYETA_PACKEDBYTES + \
139 LC_DILITHIUM_K * LC_DILITHIUM_POLYT0_PACKEDBYTES)
140
141#define LC_DILITHIUM_CRYPTO_BYTES \
142 (LC_DILITHIUM_CTILDE_BYTES + \
143 LC_DILITHIUM_L * LC_DILITHIUM_POLYZ_PACKEDBYTES + \
144 LC_DILITHIUM_POLYVECH_PACKEDBYTES)
146
147#ifndef __ASSEMBLER__
152 uint8_t sk[LC_DILITHIUM_SECRETKEYBYTES];
153};
154
159 uint8_t pk[LC_DILITHIUM_PUBLICKEYBYTES];
160};
161
166 uint8_t sig[LC_DILITHIUM_CRYPTO_BYTES];
167};
168
169#ifndef LC_DILITHIUM_CTX_ON_STACK
170struct lc_dilithium_ctx {
175 struct lc_hash_ctx dilithium_hash_ctx;
176
181 uint8_t shake_state[LC_HASH_STATE_SIZE_ALIGN(LC_SHA3_256_STATE_SIZE)];
182
194 const struct lc_hash *dilithium_prehash_type;
195
203 size_t userctxlen;
204
211 const uint8_t *userctx;
212
220 const uint8_t *external_mu;
221 size_t external_mu_len;
222
231 void *ahat;
232 unsigned short ahat_size;
233
240 uint8_t nist_category;
241
246 unsigned int composite_algorithm:1;
247
260 unsigned int ml_dsa_internal:1;
261
265 unsigned int ahat_expanded:1;
266};
267#endif
268
270
271/*
272 * The alignment is based on largest alignment of a polyvecl typedef - this is
273 * the AVX2 definition.
274 */
275#define LC_DILITHIUM_AHAT_ALIGNMENT (32)
276
277/*
278 * Padding between struct lc_dilithium_ctx and AHat buffer to ensure AHat buffer
279 * is aligned to LC_DILITHIUM_AHAT_ALIGNMENT
280 */
281#define LC_DILITHIUM_87_AHAT_PAD \
282 (LC_DILITHIUM_AHAT_ALIGNMENT - \
283 (sizeof(struct lc_dilithium_ctx) % LC_DILITHIUM_AHAT_ALIGNMENT))
284
285/* Size of the AHat matrix for ML-DSA 87 */
286#define LC_DILITHIUM_87_AHAT_SIZE \
287 (256 * sizeof(int32_t) * LC_DILITHIUM_K * LC_DILITHIUM_L)
288
289#ifndef LC_DILITHIUM_CTX_ON_STACK
290#define LC_DILITHIUM_CTX_SIZE \
291 sizeof(struct lc_dilithium_ctx)
292
293#define LC_DILITHIUM_CTX_INIT_HASH(name) \
294 LC_SHAKE_256_CTX((&(name)->dilithium_hash_ctx))
295
296#define LC_DILITHIUM_SET_CTX_COMMON(name) \
297 (name)->dilithium_prehash_type = NULL; \
298 (name)->ml_dsa_internal = 0; \
299 (name)->userctxlen = 0; \
300 (name)->userctx = NULL; \
301 (name)->ahat = NULL; \
302 (name)->ahat_size = 0; \
303 (name)->external_mu = NULL; \
304 (name)->external_mu_len = 0; \
305 (name)->nist_category = 0; \
306 (name)->composite_algorithm = 0;
307
308#define LC_DILITHIUM_SET_CTX(name) \
309 LC_DILITHIUM_CTX_INIT_HASH(name); \
310 LC_DILITHIUM_SET_CTX_COMMON(name)
311#endif
313
321#ifndef LC_DILITHIUM_CTX_ON_STACK
322#define LC_DILITHIUM_CTX_ON_STACK(name) \
323 _Pragma("GCC diagnostic push") _Pragma( \
324 "GCC diagnostic ignored \"-Wdeclaration-after-statement\"") \
325 LC_ALIGNED_BUFFER( \
326 name##_ctx_buf, LC_DILITHIUM_CTX_SIZE, \
327 LC_HASH_COMMON_ALIGNMENT); \
328 struct lc_dilithium_ctx *name = \
329 (struct lc_dilithium_ctx *)name##_ctx_buf; \
330 LC_DILITHIUM_SET_CTX(name); \
331 _Pragma("GCC diagnostic pop")
332#endif
333
374#define LC_DILITHIUM_87_CTX_ON_STACK_AHAT(name) \
375 _Pragma("GCC diagnostic push") _Pragma( \
376 "GCC diagnostic ignored \"-Wdeclaration-after-statement\"") \
377 LC_ALIGNED_BUFFER( \
378 name##_ctx_buf, LC_DILITHIUM_CTX_SIZE + \
379 LC_DILITHIUM_87_AHAT_PAD + LC_DILITHIUM_87_AHAT_SIZE, \
380 LC_HASH_COMMON_ALIGNMENT); \
381 struct lc_dilithium_ctx *name = \
382 (struct lc_dilithium_ctx *)name##_ctx_buf; \
383 LC_DILITHIUM_SET_CTX(name); \
384 name->ahat = (uint8_t *)name + LC_DILITHIUM_CTX_SIZE + \
385 LC_DILITHIUM_87_AHAT_PAD; \
386 name->ahat_expanded = 0; \
387 name->ahat_size = LC_DILITHIUM_87_AHAT_SIZE; \
388 _Pragma("GCC diagnostic pop")
389
396static inline void lc_dilithium_87_ctx_zero(struct lc_dilithium_ctx *ctx)
397{
398 if (!ctx)
399 return;
401 if (ctx->ahat) {
402 lc_memset_secure(ctx->ahat, 0, ctx->ahat_size);
403 ctx->ahat_expanded = 0;
404 }
405}
406
415
427
434
438LC_PURE
439static inline unsigned int lc_dilithium_87_sk_size(void)
440{
441 return lc_member_size(struct lc_dilithium_87_sk, sk);
442}
443
447LC_PURE
448static inline unsigned int lc_dilithium_87_pk_size(void)
449{
450 return lc_member_size(struct lc_dilithium_87_pk, pk);
451}
452
456LC_PURE
457static inline unsigned int lc_dilithium_87_sig_size(void)
458{
459 return lc_member_size(struct lc_dilithium_87_sig, sig);
460}
461
472 struct lc_rng_ctx *rng_ctx);
473
483 const struct lc_dilithium_87_sk *sk);
484
505 struct lc_dilithium_87_sk *sk,
506 const uint8_t *seed, size_t seedlen);
507
521int lc_dilithium_87_sign(struct lc_dilithium_87_sig *sig, const uint8_t *m,
522 size_t mlen, const struct lc_dilithium_87_sk *sk,
523 struct lc_rng_ctx *rng_ctx);
524
543 struct lc_dilithium_ctx *ctx,
544 const uint8_t *m, size_t mlen,
545 const struct lc_dilithium_87_sk *sk,
546 struct lc_rng_ctx *rng_ctx);
547
562 const struct lc_dilithium_87_sk *sk);
563
578int lc_dilithium_87_sign_update(struct lc_dilithium_ctx *ctx, const uint8_t *m,
579 size_t mlen);
580
596 struct lc_dilithium_ctx *ctx,
597 const struct lc_dilithium_87_sk *sk,
598 struct lc_rng_ctx *rng_ctx);
599
611int lc_dilithium_87_verify(const struct lc_dilithium_87_sig *sig, const uint8_t *m,
612 size_t mlen, const struct lc_dilithium_87_pk *pk);
613
630 struct lc_dilithium_ctx *ctx,
631 const uint8_t *m, size_t mlen,
632 const struct lc_dilithium_87_pk *pk);
633
649 const struct lc_dilithium_87_pk *pk);
650
666int lc_dilithium_87_verify_update(struct lc_dilithium_ctx *ctx, const uint8_t *m,
667 size_t mlen);
668
682 struct lc_dilithium_ctx *ctx,
683 const struct lc_dilithium_87_pk *pk);
684
685/****************************** Dilithium ED25510 *****************************/
686/* Macro set during leancrypto compile time for target platform */
687#define LC_DILITHIUM_ED25519_SIG
688#ifdef LC_DILITHIUM_ED25519_SIG
689
690#include "lc_ed25519.h"
691#include "lc_sha512.h"
692
698 struct lc_ed25519_sk sk_ed25519;
699};
700
706 struct lc_ed25519_pk pk_ed25519;
707};
708
714 struct lc_ed25519_sig sig_ed25519;
715};
716
723#ifndef LC_DILITHIUM_ED25519_CTX_ON_STACK
726};
727#endif
728
730#ifndef LC_DILITHIUM_ED25519_CTX_ON_STACK
731#define LC_DILITHIUM_ED25519_CTX_SIZE \
732 sizeof(struct lc_dilithium_ed25519_ctx)
733
734#ifdef LC_SHA2_512
735#define LC_DILITHIUM_ED25519_CTX_INIT_HASH(name) \
736 LC_SHA512_CTX((&(name)->dilithium_ctx.dilithium_hash_ctx))
737#else
738#define LC_DILITHIUM_ED25519_CTX_INIT_HASH(name) \
739 LC_SHAKE_256_CTX(((&(name)->dilithium_ctx.dilithium_hash_ctx))
740#endif
741#define LC_DILITHIUM_ED25519_SET_CTX(name) \
742 LC_DILITHIUM_SET_CTX_COMMON(&(name)->dilithium_ctx); \
743 LC_DILITHIUM_ED25519_CTX_INIT_HASH(name); \
744 (name)->dilithium_ctx.composite_algorithm = 1
745#endif
747
753#ifndef LC_DILITHIUM_ED25519_CTX_ON_STACK
754#define LC_DILITHIUM_ED25519_CTX_ON_STACK(name) \
755 _Pragma("GCC diagnostic push") _Pragma( \
756 "GCC diagnostic ignored \"-Wdeclaration-after-statement\"") \
757 LC_ALIGNED_BUFFER( \
758 name##_ctx_buf, LC_DILITHIUM_ED25519_CTX_SIZE, \
759 LC_HASH_COMMON_ALIGNMENT); \
760 struct lc_dilithium_ed25519_ctx *name = \
761 (struct lc_dilithium_ed25519_ctx *)name##_ctx_buf; \
762 LC_DILITHIUM_ED25519_SET_CTX(name); \
763 _Pragma("GCC diagnostic pop")
764#endif
765
773 struct lc_dilithium_ed25519_ctx *ctx)
774{
775 if (!ctx)
776 return;
778}
779
788 struct lc_dilithium_ed25519_ctx **ctx);
789
796 struct lc_dilithium_ed25519_ctx *ctx);
797
809 struct lc_rng_ctx *rng_ctx);
810
821 const struct lc_dilithium_87_ed25519_sk *sk);
822
837 const uint8_t *m, size_t mlen,
838 const struct lc_dilithium_87_ed25519_sk *sk,
839 struct lc_rng_ctx *rng_ctx);
840
859 struct lc_dilithium_ed25519_ctx *ctx,
860 const uint8_t *m, size_t mlen,
861 const struct lc_dilithium_87_ed25519_sk *sk,
862 struct lc_rng_ctx *rng_ctx);
863
879 struct lc_dilithium_ed25519_ctx *ctx,
880 const struct lc_dilithium_87_ed25519_sk *sk);
881
898 struct lc_dilithium_ed25519_ctx *ctx, const uint8_t *m,
899 size_t mlen);
900
920 struct lc_dilithium_87_ed25519_sig *sig,
921 struct lc_dilithium_ed25519_ctx *ctx,
922 const struct lc_dilithium_87_ed25519_sk *sk,
923 struct lc_rng_ctx *rng_ctx);
924
937 const uint8_t *m, size_t mlen,
938 const struct lc_dilithium_87_ed25519_pk *pk);
939
956 struct lc_dilithium_ed25519_ctx *ctx,
957 const uint8_t *m, size_t mlen,
958 const struct lc_dilithium_87_ed25519_pk *pk);
959
975 struct lc_dilithium_ed25519_ctx *ctx,
976 const struct lc_dilithium_87_ed25519_pk *pk);
977
994 struct lc_dilithium_ed25519_ctx *ctx, const uint8_t *m,
995 size_t mlen);
996
1013 const struct lc_dilithium_87_ed25519_sig *sig,
1014 struct lc_dilithium_ed25519_ctx *ctx,
1015 const struct lc_dilithium_87_ed25519_pk *pk);
1016
1017#endif /* LC_DILITHIUM_ED25519_SIG */
1018
1019/****************************** Dilithium ED25510 *****************************/
1020/* Macro set during leancrypto compile time for target platform */
1021#define LC_DILITHIUM_ED448_SIG
1022#ifdef LC_DILITHIUM_ED448_SIG
1023
1024#include "lc_ed448.h"
1025
1031 struct lc_ed448_sk sk_ed448;
1032};
1033
1039 struct lc_ed448_pk pk_ed448;
1040};
1041
1047 struct lc_ed448_sig sig_ed448;
1048};
1049
1056#ifndef LC_DILITHIUM_ED448_CTX_ON_STACK
1059};
1060#endif
1061
1063#ifndef LC_DILITHIUM_ED448_CTX_ON_STACK
1064#define LC_DILITHIUM_ED448_CTX_SIZE \
1065 sizeof(struct lc_dilithium_ed448_ctx)
1066#define LC_DILITHIUM_ED448_SET_CTX(name) \
1067 LC_DILITHIUM_SET_CTX(&(name)->dilithium_ctx); \
1068 (name)->dilithium_ctx.composite_algorithm = 1;
1069#endif
1071
1077#ifndef LC_DILITHIUM_ED448_CTX_ON_STACK
1078#define LC_DILITHIUM_ED448_CTX_ON_STACK(name) \
1079 _Pragma("GCC diagnostic push") _Pragma( \
1080 "GCC diagnostic ignored \"-Wdeclaration-after-statement\"") \
1081 LC_ALIGNED_BUFFER( \
1082 name##_ctx_buf, LC_DILITHIUM_ED448_CTX_SIZE, \
1083 LC_HASH_COMMON_ALIGNMENT); \
1084 struct lc_dilithium_ed448_ctx *name = \
1085 (struct lc_dilithium_ed448_ctx *)name##_ctx_buf; \
1086 LC_DILITHIUM_ED448_SET_CTX(name); \
1087 _Pragma("GCC diagnostic pop")
1088#endif
1089
1097 struct lc_dilithium_ed448_ctx *ctx)
1098{
1099 if (!ctx)
1100 return;
1102}
1103
1112 struct lc_dilithium_ed448_ctx **ctx);
1113
1120 struct lc_dilithium_ed448_ctx *ctx);
1121
1132 struct lc_dilithium_87_ed448_sk *sk,
1133 struct lc_rng_ctx *rng_ctx);
1134
1144 struct lc_dilithium_87_ed448_pk *pk,
1145 const struct lc_dilithium_87_ed448_sk *sk);
1146
1161 const uint8_t *m, size_t mlen,
1162 const struct lc_dilithium_87_ed448_sk *sk,
1163 struct lc_rng_ctx *rng_ctx);
1164
1183 struct lc_dilithium_ed448_ctx *ctx,
1184 const uint8_t *m, size_t mlen,
1185 const struct lc_dilithium_87_ed448_sk *sk,
1186 struct lc_rng_ctx *rng_ctx);
1187
1203 struct lc_dilithium_ed448_ctx *ctx,
1204 const struct lc_dilithium_87_ed448_sk *sk);
1205
1222 struct lc_dilithium_ed448_ctx *ctx, const uint8_t *m,
1223 size_t mlen);
1224
1244 struct lc_dilithium_87_ed448_sig *sig,
1245 struct lc_dilithium_ed448_ctx *ctx,
1246 const struct lc_dilithium_87_ed448_sk *sk,
1247 struct lc_rng_ctx *rng_ctx);
1248
1261 const uint8_t *m, size_t mlen,
1262 const struct lc_dilithium_87_ed448_pk *pk);
1263
1280 struct lc_dilithium_ed448_ctx *ctx,
1281 const uint8_t *m, size_t mlen,
1282 const struct lc_dilithium_87_ed448_pk *pk);
1283
1299 struct lc_dilithium_ed448_ctx *ctx,
1300 const struct lc_dilithium_87_ed448_pk *pk);
1301
1318 struct lc_dilithium_ed448_ctx *ctx, const uint8_t *m,
1319 size_t mlen);
1320
1337 const struct lc_dilithium_87_ed448_sig *sig,
1338 struct lc_dilithium_ed448_ctx *ctx,
1339 const struct lc_dilithium_87_ed448_pk *pk);
1340
1341#endif /* LC_DILITHIUM_ED448_SIG */
1342
1343#endif /* __ASSEMBLER__ */
1344
1345/*
1346 * To allow including the different lc_dilithium_*.h files, these macros need to
1347 * be undefined. Only during compilation of leancrypto, these macros remain
1348 * defined as this header file is not included multiple times.
1349 */
1350#ifndef LC_DILITHIUM_INTERNAL
1351#undef LC_DILITHIUM_MODE
1352#undef LC_DILITHIUM_NIST_CATEGORY
1353#undef LC_DILITHIUM_SEEDBYTES
1354#undef LC_DILITHIUM_CRHBYTES
1355#undef LC_DILITHIUM_TRBYTES
1356#undef LC_DILITHIUM_RNDBYTES
1357#undef LC_DILITHIUM_N
1358#undef LC_DILITHIUM_Q
1359#undef LC_DILITHIUM_D
1360#undef LC_DILITHIUM_ROOT_OF_UNITY
1361#undef LC_DILITHIUM_LAMBDA
1362#undef LC_DILITHIUM_K
1363#undef LC_DILITHIUM_L
1364#undef LC_DILITHIUM_ETA
1365#undef LC_DILITHIUM_TAU
1366#undef LC_DILITHIUM_BETA
1367#undef LC_DILITHIUM_GAMMA1
1368#undef LC_DILITHIUM_GAMMA2
1369#undef LC_DILITHIUM_OMEGA
1370#undef LC_DILITHIUM_CTILDE_BYTES
1371#undef LC_DILITHIUM_POLYT1_PACKEDBYTES
1372#undef LC_DILITHIUM_POLYT0_PACKEDBYTES
1373#undef LC_DILITHIUM_POLYVECH_PACKEDBYTES
1374#undef LC_DILITHIUM_POLYZ_PACKEDBYTES
1375#undef LC_DILITHIUM_POLYW1_PACKEDBYTES
1376#undef LC_DILITHIUM_POLYETA_PACKEDBYTES
1377#undef LC_DILITHIUM_PUBLICKEYBYTES
1378#undef LC_DILITHIUM_SECRETKEYBYTES
1379#undef LC_DILITHIUM_CRYPTO_BYTES
1380#endif /* LC_DILITHIUM_INTERNAL */
1381
1382#ifdef __cplusplus
1383}
1384#endif
1385
1386#endif /* LC_DILITHIUM_87_H */
void lc_hash_zero(struct lc_hash_ctx *hash_ctx)
Zeroize Hash context allocated with either LC_HASH_CTX_ON_STACK or lc_hmac_alloc.
int lc_hash(const struct lc_hash *hash, const uint8_t *in, size_t inlen, uint8_t *digest)
Calculate message digest - one-shot.
int lc_dilithium_87_sign_ctx(struct lc_dilithium_87_sig *sig, struct lc_dilithium_ctx *ctx, const uint8_t *m, size_t mlen, const struct lc_dilithium_87_sk *sk, struct lc_rng_ctx *rng_ctx)
Computes signature with Dilithium context in one shot.
struct lc_dilithium_87_sk sk
struct lc_dilithium_87_sig sig
void lc_dilithium_87_ctx_zero_free(struct lc_dilithium_ctx *ctx)
Zeroize and free Dilithium stream context.
unsigned int composite_algorithm
Indicator whether it is a composite algorithm usage. This is used and set internally.
int lc_dilithium_87_verify(const struct lc_dilithium_87_sig *sig, const uint8_t *m, size_t mlen, const struct lc_dilithium_87_pk *pk)
Verifies ML-DSA signature in one shot.
int lc_dilithium_87_ctx_alloc(struct lc_dilithium_ctx **ctx)
Allocate Dilithium stream context on heap.
int lc_dilithium_87_ed25519_sign(struct lc_dilithium_87_ed25519_sig *sig, const uint8_t *m, size_t mlen, const struct lc_dilithium_87_ed25519_sk *sk, struct lc_rng_ctx *rng_ctx)
Computes signature in one shot.
int lc_dilithium_87_ed448_sign(struct lc_dilithium_87_ed448_sig *sig, const uint8_t *m, size_t mlen, const struct lc_dilithium_87_ed448_sk *sk, struct lc_rng_ctx *rng_ctx)
Computes signature in one shot.
int lc_dilithium_87_ed448_verify_update(struct lc_dilithium_ed448_ctx *ctx, const uint8_t *m, size_t mlen)
Updates signature verification with Dilithium context in stream operation.
struct lc_ed448_sk sk_ed448
static LC_PURE unsigned int lc_dilithium_87_sig_size(void)
Return the size of the Dilithium signature.
uint8_t shake_state[LC_HASH_STATE_SIZE_ALIGN(LC_SHA3_256_STATE_SIZE)]
State memory of the hash context used internally to the library - it should not be touched by the use...
int lc_dilithium_87_keypair(struct lc_dilithium_87_pk *pk, struct lc_dilithium_87_sk *sk, struct lc_rng_ctx *rng_ctx)
Generates Dilithium public and private key.
void lc_dilithium_87_ed25519_ctx_zero_free(struct lc_dilithium_ed25519_ctx *ctx)
Zeroize and free Dilithium-ED25519 stream context.
struct lc_dilithium_87_pk pk
int lc_dilithium_87_ed25519_sign_update(struct lc_dilithium_ed25519_ctx *ctx, const uint8_t *m, size_t mlen)
Updates signature generation with Dilithium context in stream operation.
struct lc_ed25519_sig sig_ed25519
unsigned int ahat_expanded
Was aHat already filled? This is used and set internally.
const uint8_t * external_mu
Pointer to the external mu.
int lc_dilithium_87_ed448_verify_init(struct lc_dilithium_ed448_ctx *ctx, const struct lc_dilithium_87_ed448_pk *pk)
Initiates signature verification with Dilithium context in stream operation.
int lc_dilithium_87_sign_final(struct lc_dilithium_87_sig *sig, struct lc_dilithium_ctx *ctx, const struct lc_dilithium_87_sk *sk, struct lc_rng_ctx *rng_ctx)
Computes signature.
static LC_PURE unsigned int lc_dilithium_87_pk_size(void)
Return the size of the Dilithium public key.
int lc_dilithium_87_ed448_verify_ctx(const struct lc_dilithium_87_ed448_sig *sig, struct lc_dilithium_ed448_ctx *ctx, const uint8_t *m, size_t mlen, const struct lc_dilithium_87_ed448_pk *pk)
Verifies signature in one shot with Dilithium context.
static void lc_dilithium_87_ctx_zero(struct lc_dilithium_ctx *ctx)
Zeroize Dilithium context allocated with LC_DILITHIUM_CTX_ON_STACK lc_dilithium_ed25519_alloc.
struct lc_ed448_pk pk_ed448
static void lc_dilithium_87_ed25519_ctx_zero(struct lc_dilithium_ed25519_ctx *ctx)
Zeroize Dilithium-ED25519 context allocated with LC_DILITHIUM_ED25519_CTX_ON_STACK lc_dilithium_ed255...
int lc_dilithium_87_pk_from_sk(struct lc_dilithium_87_pk *pk, const struct lc_dilithium_87_sk *sk)
Generates Dilithium public from private key.
int lc_dilithium_87_sign_init(struct lc_dilithium_ctx *ctx, const struct lc_dilithium_87_sk *sk)
Initializes a signature operation.
int lc_dilithium_87_ed448_keypair(struct lc_dilithium_87_ed448_pk *pk, struct lc_dilithium_87_ed448_sk *sk, struct lc_rng_ctx *rng_ctx)
Generates Dilithium public and private key.
struct lc_hash_ctx dilithium_hash_ctx
Hash context used internally to the library - it should not be touched by the user.
int lc_dilithium_87_verify_ctx(const struct lc_dilithium_87_sig *sig, struct lc_dilithium_ctx *ctx, const uint8_t *m, size_t mlen, const struct lc_dilithium_87_pk *pk)
Verifies signature with Dilithium context in one shot.
int lc_dilithium_87_ed25519_sign_init(struct lc_dilithium_ed25519_ctx *ctx, const struct lc_dilithium_87_ed25519_sk *sk)
Initiates signature generation with Dilithium context in stream operation.
unsigned int ml_dsa_internal
When set to true, only the ML-DSA.Sign_internal or ML-DSA.Verify_internal are performed (see FIPS 204...
struct lc_ed448_sig sig_ed448
int lc_dilithium_87_ed448_sign_init(struct lc_dilithium_ed448_ctx *ctx, const struct lc_dilithium_87_ed448_sk *sk)
Initiates signature generation with Dilithium context in stream operation.
int lc_dilithium_87_ed448_sign_update(struct lc_dilithium_ed448_ctx *ctx, const uint8_t *m, size_t mlen)
Updates signature generation with Dilithium context in stream operation.
struct lc_dilithium_ctx dilithium_ctx
int lc_dilithium_87_ed25519_verify(const struct lc_dilithium_87_ed25519_sig *sig, const uint8_t *m, size_t mlen, const struct lc_dilithium_87_ed25519_pk *pk)
Verifies signature in one shot.
void lc_dilithium_87_ed448_ctx_zero_free(struct lc_dilithium_ed448_ctx *ctx)
Zeroize and free Dilithium-ED448 stream context.
static void lc_dilithium_87_ed448_ctx_zero(struct lc_dilithium_ed448_ctx *ctx)
Zeroize Dilithium-ED448 context allocated with LC_DILITHIUM_ED448_CTX_ON_STACK lc_dilithium_ed448_all...
struct lc_ed25519_pk pk_ed25519
int lc_dilithium_87_ed448_sign_final(struct lc_dilithium_87_ed448_sig *sig, struct lc_dilithium_ed448_ctx *ctx, const struct lc_dilithium_87_ed448_sk *sk, struct lc_rng_ctx *rng_ctx)
Perform signature generation with Dilithium context in stream operation.
int lc_dilithium_87_ed448_sign_ctx(struct lc_dilithium_87_ed448_sig *sig, struct lc_dilithium_ed448_ctx *ctx, const uint8_t *m, size_t mlen, const struct lc_dilithium_87_ed448_sk *sk, struct lc_rng_ctx *rng_ctx)
Computes signature with Dilithium context in one shot.
int lc_dilithium_87_verify_update(struct lc_dilithium_ctx *ctx, const uint8_t *m, size_t mlen)
Add more data to an already initialized signature state.
unsigned short ahat_size
size_t userctxlen
length of the user context (allowed range between 0 and 255 bytes)
int lc_dilithium_87_ed25519_verify_ctx(const struct lc_dilithium_87_ed25519_sig *sig, struct lc_dilithium_ed25519_ctx *ctx, const uint8_t *m, size_t mlen, const struct lc_dilithium_87_ed25519_pk *pk)
Verifies signature in one shot with Dilithium context.
struct lc_dilithium_87_sk sk
int lc_dilithium_87_ed448_verify(const struct lc_dilithium_87_ed448_sig *sig, const uint8_t *m, size_t mlen, const struct lc_dilithium_87_ed448_pk *pk)
Verifies signature in one shot.
int lc_dilithium_87_sign_update(struct lc_dilithium_ctx *ctx, const uint8_t *m, size_t mlen)
Add more data to an already initialized signature state.
int lc_dilithium_87_ed25519_verify_init(struct lc_dilithium_ed25519_ctx *ctx, const struct lc_dilithium_87_ed25519_pk *pk)
Initiates signature verification with Dilithium context in stream operation.
int lc_dilithium_87_keypair_from_seed(struct lc_dilithium_87_pk *pk, struct lc_dilithium_87_sk *sk, const uint8_t *seed, size_t seedlen)
Generates Dilithium public and private key from a given seed.
int lc_dilithium_87_ed448_ctx_alloc(struct lc_dilithium_ed448_ctx **ctx)
Allocate Dilithium-ED448 stream context on heap.
void * ahat
Pointer to the AHat buffer. This can be provided by the caller or it must be NULL otherwise.
int lc_dilithium_87_ed448_pk_from_sk(struct lc_dilithium_87_ed448_pk *pk, const struct lc_dilithium_87_ed448_sk *sk)
Generates Dilithium public from private key.
uint8_t sig[LC_DILITHIUM_CRYPTO_BYTES]
int lc_dilithium_87_ctx_alloc_ahat(struct lc_dilithium_ctx **ctx)
Allocate Dilithium stream context on heap including additional parameter relevant for the signature o...
struct lc_ed25519_sk sk_ed25519
struct lc_dilithium_ctx dilithium_ctx
int lc_dilithium_87_ed25519_verify_final(const struct lc_dilithium_87_ed25519_sig *sig, struct lc_dilithium_ed25519_ctx *ctx, const struct lc_dilithium_87_ed25519_pk *pk)
Perform signature verification with Dilithium context in stream operation.
int lc_dilithium_87_ed25519_keypair(struct lc_dilithium_87_ed25519_pk *pk, struct lc_dilithium_87_ed25519_sk *sk, struct lc_rng_ctx *rng_ctx)
Generates Dilithium public and private key.
int lc_dilithium_87_sign(struct lc_dilithium_87_sig *sig, const uint8_t *m, size_t mlen, const struct lc_dilithium_87_sk *sk, struct lc_rng_ctx *rng_ctx)
Computes ML-DSA signature in one shot.
int lc_dilithium_87_ed25519_pk_from_sk(struct lc_dilithium_87_ed25519_pk *pk, const struct lc_dilithium_87_ed25519_sk *sk)
Generates Dilithium public from private key.
const uint8_t * userctx
buffer with a caller-specified context string
int lc_dilithium_87_ed25519_sign_final(struct lc_dilithium_87_ed25519_sig *sig, struct lc_dilithium_ed25519_ctx *ctx, const struct lc_dilithium_87_ed25519_sk *sk, struct lc_rng_ctx *rng_ctx)
Perform signature generation with Dilithium context in stream operation.
int lc_dilithium_87_ed448_verify_final(const struct lc_dilithium_87_ed448_sig *sig, struct lc_dilithium_ed448_ctx *ctx, const struct lc_dilithium_87_ed448_pk *pk)
Perform signature verification with Dilithium context in stream operation.
uint8_t nist_category
NIST category required for composite signatures.
struct lc_dilithium_87_sig sig
int lc_dilithium_87_ed25519_ctx_alloc(struct lc_dilithium_ed25519_ctx **ctx)
Allocate Dilithium-ED25519 stream context on heap.
struct lc_dilithium_87_pk pk
int lc_dilithium_87_verify_init(struct lc_dilithium_ctx *ctx, const struct lc_dilithium_87_pk *pk)
Initializes a signature verification operation.
uint8_t pk[LC_DILITHIUM_PUBLICKEYBYTES]
static LC_PURE unsigned int lc_dilithium_87_sk_size(void)
Return the size of the Dilithium secret key.
int lc_dilithium_87_verify_final(const struct lc_dilithium_87_sig *sig, struct lc_dilithium_ctx *ctx, const struct lc_dilithium_87_pk *pk)
Verifies signature.
uint8_t sk[LC_DILITHIUM_SECRETKEYBYTES]
int lc_dilithium_87_ed25519_verify_update(struct lc_dilithium_ed25519_ctx *ctx, const uint8_t *m, size_t mlen)
Updates signature verification with Dilithium context in stream operation.
int lc_dilithium_87_ed25519_sign_ctx(struct lc_dilithium_87_ed25519_sig *sig, struct lc_dilithium_ed25519_ctx *ctx, const uint8_t *m, size_t mlen, const struct lc_dilithium_87_ed25519_sk *sk, struct lc_rng_ctx *rng_ctx)
Computes signature with Dilithium context in one shot.
const struct lc_hash * dilithium_prehash_type
When using HashML-DSA, set the hash reference used for the hash operation. Allowed values are lc_sha2...
Dilithium public key.
Dilithium signature.
Dilithium secret key.
Dilithium public key.
Dilithium signature.
Dilithium secret key.
Dilithium public key.
Dilithium signature.
Dilithium secret key.
Dilithium stream context.
Dilithium stream context.
static void lc_memset_secure(void *s, int c, size_t n)