mldsa_gh 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README.md +88 -0
- data/ext/mldsa_gh_native/extconf.rb +14 -0
- data/ext/mldsa_gh_native/mldsa_gh_native.c +222 -0
- data/ext/mldsa_gh_native/mldsa_gh_native_all.c +24 -0
- data/ext/mldsa_gh_native/mldsa_gh_native_all.h +26 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/BUILDING.md +108 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/LICENSE +305 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/README.md +247 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/README.md +23 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/mldsa_native.c +803 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/mldsa_native.h +956 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/mldsa_native_asm.S +830 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/mldsa_native_config.h +855 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/cbmc.h +233 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/common.h +301 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/context.h +152 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/ct.c +21 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/ct.h +373 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/debug.c +75 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/debug.h +125 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/fips202.c +270 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/fips202.h +224 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/fips202x4.c +187 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/fips202x4.h +125 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/keccakf1600.c +510 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/keccakf1600.h +110 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/auto.h +85 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/fips202_native_aarch64.h +69 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_scalar_aarch64_asm.S +378 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_v84a_aarch64_asm.S +207 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x2_v84a_aarch64_asm.S +262 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_scalar_hybrid_aarch64_asm.S +1080 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_v84a_scalar_hybrid_aarch64_asm.S +990 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccakf1600_round_constants.c +47 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x1_scalar.h +27 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x1_v84a.h +36 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x2_v84a.h +40 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x4_v8a_scalar.h +32 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x4_v8a_v84a_scalar.h +37 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/api.h +129 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/README.md +10 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/mve.h +67 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/fips202_native_armv81m.h +37 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.S +717 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.c +42 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccak_f1600_x4_state_extract_bytes_mve.S +334 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccak_f1600_x4_state_xor_bytes_mve.S +355 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccakf1600_round_constants.c +53 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/auto.h +35 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/keccak_f1600_x4_avx2.h +34 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/fips202_native_x86_64.h +45 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/keccak_f1600_x4_avx2_asm.S +488 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/keccakf1600_constants.c +52 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/meta.h +314 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/aarch64_zetas.c +248 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/arith_native_aarch64.h +367 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_intt_aarch64_asm.S +786 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_ntt_aarch64_asm.S +686 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_pointwise_montgomery_aarch64_asm.S +106 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_poly_caddq_aarch64_asm.S +69 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_poly_chknorm_aarch64_asm.S +76 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_poly_decompose_32_aarch64_asm.S +108 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_poly_decompose_88_aarch64_asm.S +108 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_poly_use_hint_32_aarch64_asm.S +125 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_poly_use_hint_88_aarch64_asm.S +133 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_polyvecl_pointwise_acc_montgomery_l4_aarch64_asm.S +157 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_polyvecl_pointwise_acc_montgomery_l5_aarch64_asm.S +173 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_polyvecl_pointwise_acc_montgomery_l7_aarch64_asm.S +205 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_polyz_unpack_17_aarch64_asm.S +103 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_polyz_unpack_19_aarch64_asm.S +100 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_rej_uniform_aarch64_asm.S +222 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_rej_uniform_eta2_aarch64_asm.S +170 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_rej_uniform_eta4_aarch64_asm.S +163 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/polyz_unpack_table.c +52 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_eta_table.c +547 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_table.c +63 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/api.h +617 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/meta.h +24 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/meta.h +323 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/arith_native_x86_64.h +330 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/consts.c +157 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/consts.h +27 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_intt_avx2_asm.S +2333 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_ntt_avx2_asm.S +2405 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_nttunpack_avx2_asm.S +254 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_pointwise_acc_l4_avx2_asm.S +173 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_pointwise_acc_l5_avx2_asm.S +189 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_pointwise_acc_l7_avx2_asm.S +221 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_pointwise_avx2_asm.S +158 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_poly_caddq_avx2_asm.S +199 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_poly_chknorm_avx2_asm.S +176 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_poly_decompose_32_avx2_asm.S +490 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_poly_decompose_88_avx2_asm.S +489 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_poly_use_hint_32_avx2_asm.S +123 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_poly_use_hint_88_avx2_asm.S +125 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_polyz_unpack_17_avx2_asm.S +355 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_polyz_unpack_19_avx2_asm.S +355 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_rej_uniform_avx2_asm.S +132 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_rej_uniform_eta2_avx2_asm.S +205 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_rej_uniform_eta4_avx2_asm.S +176 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/rej_uniform_table.c +161 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/packing.c +213 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/packing.h +277 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/params.h +153 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/poly.c +1066 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/poly.h +464 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/poly_kl.c +910 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/poly_kl.h +367 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/polyvec.c +509 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/polyvec.h +435 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/polyvec_lazy.c +311 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/polyvec_lazy.h +652 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/randombytes.h +26 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/reduce.h +144 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/rounding.h +265 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/sign.c +1720 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/sign.h +850 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/symmetric.h +68 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/sys.h +327 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/zetas.inc +55 -0
- data/lib/mldsa/parameter_set.rb +82 -0
- data/lib/mldsa/signing_key.rb +147 -0
- data/lib/mldsa/verify_key.rb +72 -0
- data/lib/mldsa/version.rb +7 -0
- data/lib/mldsa_gh.rb +93 -0
- metadata +225 -0
|
@@ -0,0 +1,855 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) The mldsa-native project authors
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/* References
|
|
7
|
+
* ==========
|
|
8
|
+
*
|
|
9
|
+
* - [FIPS140_3_IG]
|
|
10
|
+
* Implementation Guidance for FIPS 140-3 and the Cryptographic Module
|
|
11
|
+
* Validation Program
|
|
12
|
+
* National Institute of Standards and Technology
|
|
13
|
+
* https://csrc.nist.gov/projects/cryptographic-module-validation-program/fips-140-3-ig-announcements
|
|
14
|
+
*
|
|
15
|
+
* - [FIPS204]
|
|
16
|
+
* FIPS 204 Module-Lattice-Based Digital Signature Standard
|
|
17
|
+
* National Institute of Standards and Technology
|
|
18
|
+
* https://csrc.nist.gov/pubs/fips/204/final
|
|
19
|
+
*
|
|
20
|
+
* - [FIPS204_UPDATES]
|
|
21
|
+
* FIPS 204 Potential Updates (Errata)
|
|
22
|
+
* National Institute of Standards and Technology
|
|
23
|
+
* https://csrc.nist.gov/files/pubs/fips/204/final/docs/fips-204-potential-updates.xlsx
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
#ifndef MLD_CONFIG_H
|
|
27
|
+
#define MLD_CONFIG_H
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* MLD_CONFIG_PARAMETER_SET
|
|
31
|
+
*
|
|
32
|
+
* Specifies the parameter set for ML-DSA
|
|
33
|
+
* - MLD_CONFIG_PARAMETER_SET=44 corresponds to ML-DSA-44
|
|
34
|
+
* - MLD_CONFIG_PARAMETER_SET=65 corresponds to ML-DSA-65
|
|
35
|
+
* - MLD_CONFIG_PARAMETER_SET=87 corresponds to ML-DSA-87
|
|
36
|
+
*
|
|
37
|
+
* If you want to support multiple parameter sets, build the
|
|
38
|
+
* library multiple times and set MLD_CONFIG_MULTILEVEL_BUILD.
|
|
39
|
+
* See MLD_CONFIG_MULTILEVEL_BUILD for how to do this while
|
|
40
|
+
* minimizing code duplication.
|
|
41
|
+
*
|
|
42
|
+
* This can also be set using CFLAGS.
|
|
43
|
+
*/
|
|
44
|
+
#ifndef MLD_CONFIG_PARAMETER_SET
|
|
45
|
+
#define MLD_CONFIG_PARAMETER_SET \
|
|
46
|
+
44 /* Change this for different security strengths */
|
|
47
|
+
#endif
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* MLD_CONFIG_FILE
|
|
51
|
+
*
|
|
52
|
+
* If defined, this is a header that will be included instead
|
|
53
|
+
* of the default configuration file mldsa/mldsa_native_config.h.
|
|
54
|
+
*
|
|
55
|
+
* When you need to build mldsa-native in multiple configurations,
|
|
56
|
+
* using varying MLD_CONFIG_FILE can be more convenient
|
|
57
|
+
* than configuring everything through CFLAGS.
|
|
58
|
+
*
|
|
59
|
+
* To use, MLD_CONFIG_FILE _must_ be defined prior
|
|
60
|
+
* to the inclusion of any mldsa-native headers. For example,
|
|
61
|
+
* it can be set by passing `-DMLD_CONFIG_FILE="..."`
|
|
62
|
+
* on the command line.
|
|
63
|
+
*/
|
|
64
|
+
/* #define MLD_CONFIG_FILE "mldsa_native_config.h" */
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* MLD_CONFIG_NAMESPACE_PREFIX
|
|
68
|
+
*
|
|
69
|
+
* The prefix to use to namespace global symbols from mldsa/.
|
|
70
|
+
*
|
|
71
|
+
* In a multi-level build, level-dependent symbols will
|
|
72
|
+
* additionally be prefixed with the parameter set (44/65/87).
|
|
73
|
+
*
|
|
74
|
+
* This can also be set using CFLAGS.
|
|
75
|
+
*/
|
|
76
|
+
#if !defined(MLD_CONFIG_NAMESPACE_PREFIX)
|
|
77
|
+
#define MLD_CONFIG_NAMESPACE_PREFIX MLD_DEFAULT_NAMESPACE_PREFIX
|
|
78
|
+
#endif
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* MLD_CONFIG_MULTILEVEL_BUILD
|
|
82
|
+
*
|
|
83
|
+
* Set this if the build is part of a multi-level build supporting
|
|
84
|
+
* multiple parameter sets.
|
|
85
|
+
*
|
|
86
|
+
* If you need only a single parameter set, keep this unset.
|
|
87
|
+
*
|
|
88
|
+
* To build mldsa-native with support for all parameter sets,
|
|
89
|
+
* build it three times -- once per parameter set -- and set the
|
|
90
|
+
* option MLD_CONFIG_MULTILEVEL_WITH_SHARED for exactly one of
|
|
91
|
+
* them, and MLD_CONFIG_MULTILEVEL_NO_SHARED for the others.
|
|
92
|
+
* MLD_CONFIG_MULTILEVEL_BUILD should be set for all of them.
|
|
93
|
+
*
|
|
94
|
+
* See examples/multilevel_build for an example.
|
|
95
|
+
*
|
|
96
|
+
* This can also be set using CFLAGS.
|
|
97
|
+
*/
|
|
98
|
+
/* #define MLD_CONFIG_MULTILEVEL_BUILD */
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* MLD_CONFIG_EXTERNAL_API_QUALIFIER
|
|
102
|
+
*
|
|
103
|
+
* If set, this option provides an additional function
|
|
104
|
+
* qualifier to be added to declarations of mldsa-native's
|
|
105
|
+
* public API.
|
|
106
|
+
*
|
|
107
|
+
* The primary use case for this option are single-CU builds
|
|
108
|
+
* where the public API exposed by mldsa-native is wrapped by
|
|
109
|
+
* another API in the consuming application. In this case,
|
|
110
|
+
* even mldsa-native's public API can be marked `static`.
|
|
111
|
+
*/
|
|
112
|
+
/* #define MLD_CONFIG_EXTERNAL_API_QUALIFIER */
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* MLD_CONFIG_NO_KEYPAIR_API
|
|
116
|
+
*
|
|
117
|
+
* By default, mldsa-native includes support for generating key
|
|
118
|
+
* pairs. If you don't need this, set MLD_CONFIG_NO_KEYPAIR_API
|
|
119
|
+
* to exclude keypair, keypair_internal,
|
|
120
|
+
* pk_from_sk, and all internal APIs only needed by
|
|
121
|
+
* those functions.
|
|
122
|
+
*/
|
|
123
|
+
/* #define MLD_CONFIG_NO_KEYPAIR_API */
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* MLD_CONFIG_NO_SIGN_API
|
|
127
|
+
*
|
|
128
|
+
* By default, mldsa-native includes support for creating
|
|
129
|
+
* signatures. If you don't need this, set MLD_CONFIG_NO_SIGN_API
|
|
130
|
+
* to exclude signature,
|
|
131
|
+
* signature_extmu, signature_internal,
|
|
132
|
+
* signature_pre_hash_internal,
|
|
133
|
+
* signature_pre_hash_shake256, and all internal APIs
|
|
134
|
+
* only needed by those functions.
|
|
135
|
+
*/
|
|
136
|
+
/* #define MLD_CONFIG_NO_SIGN_API */
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* MLD_CONFIG_NO_VERIFY_API
|
|
140
|
+
*
|
|
141
|
+
* By default, mldsa-native includes support for verifying
|
|
142
|
+
* signatures. If you don't need this, set
|
|
143
|
+
* MLD_CONFIG_NO_VERIFY_API to exclude verify,
|
|
144
|
+
* verify_extmu, verify_internal,
|
|
145
|
+
* verify_pre_hash_internal,
|
|
146
|
+
* verify_pre_hash_shake256, and all internal APIs
|
|
147
|
+
* only needed by those functions.
|
|
148
|
+
*/
|
|
149
|
+
/* #define MLD_CONFIG_NO_VERIFY_API */
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* MLD_CONFIG_CORE_API_ONLY
|
|
153
|
+
*
|
|
154
|
+
* Set this to remove all public APIs except
|
|
155
|
+
* keypair_internal, signature_internal,
|
|
156
|
+
* and verify_internal.
|
|
157
|
+
*/
|
|
158
|
+
/* #define MLD_CONFIG_CORE_API_ONLY */
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* MLD_CONFIG_NO_RANDOMIZED_API
|
|
162
|
+
*
|
|
163
|
+
* If this option is set, mldsa-native will be built without the
|
|
164
|
+
* randomized API functions (keypair,
|
|
165
|
+
* signature, and signature_extmu).
|
|
166
|
+
* This allows users to build mldsa-native without providing a
|
|
167
|
+
* randombytes() implementation if they only need the
|
|
168
|
+
* internal deterministic API
|
|
169
|
+
* (keypair_internal, signature_internal).
|
|
170
|
+
*
|
|
171
|
+
* @note This option is incompatible with MLD_CONFIG_KEYGEN_PCT
|
|
172
|
+
* as the current PCT implementation requires
|
|
173
|
+
* signature().
|
|
174
|
+
*/
|
|
175
|
+
/* #define MLD_CONFIG_NO_RANDOMIZED_API */
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* MLD_CONFIG_CONSTANTS_ONLY
|
|
179
|
+
*
|
|
180
|
+
* If you only need the size constants (MLDSA_PUBLICKEYBYTES, etc.)
|
|
181
|
+
* but no function declarations, set MLD_CONFIG_CONSTANTS_ONLY.
|
|
182
|
+
*
|
|
183
|
+
* This only affects the public header mldsa_native.h, not
|
|
184
|
+
* the implementation.
|
|
185
|
+
*/
|
|
186
|
+
/* #define MLD_CONFIG_CONSTANTS_ONLY */
|
|
187
|
+
/******************************************************************************
|
|
188
|
+
*
|
|
189
|
+
* Build-only configuration options
|
|
190
|
+
*
|
|
191
|
+
* The remaining configurations are build-options only.
|
|
192
|
+
* They do not affect the API described in mldsa_native.h.
|
|
193
|
+
*
|
|
194
|
+
*****************************************************************************/
|
|
195
|
+
#if defined(MLD_BUILD_INTERNAL)
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* MLD_CONFIG_MULTILEVEL_WITH_SHARED
|
|
199
|
+
*
|
|
200
|
+
* This is for multi-level builds of mldsa-native only. If you
|
|
201
|
+
* need only a single parameter set, keep this unset.
|
|
202
|
+
*
|
|
203
|
+
* If this is set, all MLD_CONFIG_PARAMETER_SET-independent
|
|
204
|
+
* code will be included in the build, including code needed only
|
|
205
|
+
* for other parameter sets.
|
|
206
|
+
*
|
|
207
|
+
* Example: mld_polyw1_pack_88 is only needed for
|
|
208
|
+
* MLD_CONFIG_PARAMETER_SET == 44. Yet, if this option is set for a
|
|
209
|
+
* build with MLD_CONFIG_PARAMETER_SET == 65/87, it would be included.
|
|
210
|
+
*
|
|
211
|
+
* To build mldsa-native with support for all parameter sets,
|
|
212
|
+
* build it three times -- once per parameter set -- and set the
|
|
213
|
+
* option MLD_CONFIG_MULTILEVEL_WITH_SHARED for exactly one of
|
|
214
|
+
* them, and MLD_CONFIG_MULTILEVEL_NO_SHARED for the others.
|
|
215
|
+
* MLD_CONFIG_MULTILEVEL_BUILD should be set for all of them.
|
|
216
|
+
*
|
|
217
|
+
* See examples/multilevel_build for an example.
|
|
218
|
+
*
|
|
219
|
+
* This can also be set using CFLAGS.
|
|
220
|
+
*/
|
|
221
|
+
/* #define MLD_CONFIG_MULTILEVEL_WITH_SHARED */
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* MLD_CONFIG_MULTILEVEL_NO_SHARED
|
|
225
|
+
*
|
|
226
|
+
* This is for multi-level builds of mldsa-native only. If you
|
|
227
|
+
* need only a single parameter set, keep this unset.
|
|
228
|
+
*
|
|
229
|
+
* If this is set, no MLD_CONFIG_PARAMETER_SET-independent code
|
|
230
|
+
* will be included in the build.
|
|
231
|
+
*
|
|
232
|
+
* To build mldsa-native with support for all parameter sets,
|
|
233
|
+
* build it three times -- once per parameter set -- and set the
|
|
234
|
+
* option MLD_CONFIG_MULTILEVEL_WITH_SHARED for exactly one of
|
|
235
|
+
* them, and MLD_CONFIG_MULTILEVEL_NO_SHARED for the others.
|
|
236
|
+
* MLD_CONFIG_MULTILEVEL_BUILD should be set for all of them.
|
|
237
|
+
*
|
|
238
|
+
* See examples/multilevel_build for an example.
|
|
239
|
+
*
|
|
240
|
+
* This can also be set using CFLAGS.
|
|
241
|
+
*/
|
|
242
|
+
/* #define MLD_CONFIG_MULTILEVEL_NO_SHARED */
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* MLD_CONFIG_MONOBUILD_KEEP_SHARED_HEADERS
|
|
246
|
+
*
|
|
247
|
+
* This is only relevant for single compilation unit (SCU)
|
|
248
|
+
* builds of mldsa-native. In this case, it determines whether
|
|
249
|
+
* directives defined in parameter-set-independent headers should
|
|
250
|
+
* be #undef'ined or not at the end of the SCU file. This is
|
|
251
|
+
* needed in multilevel builds.
|
|
252
|
+
*
|
|
253
|
+
* See examples/multilevel_build_native for an example.
|
|
254
|
+
*
|
|
255
|
+
* This can also be set using CFLAGS.
|
|
256
|
+
*/
|
|
257
|
+
/* #define MLD_CONFIG_MONOBUILD_KEEP_SHARED_HEADERS */
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* MLD_CONFIG_USE_NATIVE_BACKEND_ARITH
|
|
261
|
+
*
|
|
262
|
+
* Determines whether a native arithmetic backend should be used.
|
|
263
|
+
*
|
|
264
|
+
* The arithmetic backend covers performance-critical functions
|
|
265
|
+
* such as the number-theoretic transform (NTT).
|
|
266
|
+
*
|
|
267
|
+
* If this option is unset, the C backend will be used.
|
|
268
|
+
*
|
|
269
|
+
* If this option is set, the arithmetic backend to be used is
|
|
270
|
+
* determined by MLD_CONFIG_ARITH_BACKEND_FILE: If the latter is
|
|
271
|
+
* unset, the default backend for your target architecture
|
|
272
|
+
* will be used. If set, it must be the name of a backend metadata
|
|
273
|
+
* file.
|
|
274
|
+
*
|
|
275
|
+
* This can also be set using CFLAGS.
|
|
276
|
+
*/
|
|
277
|
+
#if !defined(MLD_CONFIG_USE_NATIVE_BACKEND_ARITH)
|
|
278
|
+
/* #define MLD_CONFIG_USE_NATIVE_BACKEND_ARITH */
|
|
279
|
+
#endif
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* MLD_CONFIG_ARITH_BACKEND_FILE
|
|
283
|
+
*
|
|
284
|
+
* The arithmetic backend to use.
|
|
285
|
+
*
|
|
286
|
+
* If MLD_CONFIG_USE_NATIVE_BACKEND_ARITH is unset, this option
|
|
287
|
+
* is ignored.
|
|
288
|
+
*
|
|
289
|
+
* If MLD_CONFIG_USE_NATIVE_BACKEND_ARITH is set, this option must
|
|
290
|
+
* either be undefined or the filename of an arithmetic backend.
|
|
291
|
+
* If unset, the default backend will be used.
|
|
292
|
+
*
|
|
293
|
+
* This can be set using CFLAGS.
|
|
294
|
+
*/
|
|
295
|
+
#if defined(MLD_CONFIG_USE_NATIVE_BACKEND_ARITH) && \
|
|
296
|
+
!defined(MLD_CONFIG_ARITH_BACKEND_FILE)
|
|
297
|
+
#define MLD_CONFIG_ARITH_BACKEND_FILE "native/meta.h"
|
|
298
|
+
#endif
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* MLD_CONFIG_USE_NATIVE_BACKEND_FIPS202
|
|
302
|
+
*
|
|
303
|
+
* Determines whether a native FIPS202 backend should be used.
|
|
304
|
+
*
|
|
305
|
+
* The FIPS202 backend covers 1x/2x/4x-fold Keccak-f1600, which is
|
|
306
|
+
* the performance bottleneck of SHA3 and SHAKE.
|
|
307
|
+
*
|
|
308
|
+
* If this option is unset, the C backend will be used.
|
|
309
|
+
*
|
|
310
|
+
* If this option is set, the FIPS202 backend to be used is
|
|
311
|
+
* determined by MLD_CONFIG_FIPS202_BACKEND_FILE: If the latter is
|
|
312
|
+
* unset, the default backend for your target architecture
|
|
313
|
+
* will be used. If set, it must be the name of a backend metadata
|
|
314
|
+
* file.
|
|
315
|
+
*
|
|
316
|
+
* This can also be set using CFLAGS.
|
|
317
|
+
*/
|
|
318
|
+
#if !defined(MLD_CONFIG_USE_NATIVE_BACKEND_FIPS202)
|
|
319
|
+
/* #define MLD_CONFIG_USE_NATIVE_BACKEND_FIPS202 */
|
|
320
|
+
#endif
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* MLD_CONFIG_FIPS202_BACKEND_FILE
|
|
324
|
+
*
|
|
325
|
+
* The FIPS-202 backend to use.
|
|
326
|
+
*
|
|
327
|
+
* If MLD_CONFIG_USE_NATIVE_BACKEND_FIPS202 is set, this option
|
|
328
|
+
* must either be undefined or the filename of a FIPS202 backend.
|
|
329
|
+
* If unset, the default backend will be used.
|
|
330
|
+
*
|
|
331
|
+
* This can be set using CFLAGS.
|
|
332
|
+
*/
|
|
333
|
+
#if defined(MLD_CONFIG_USE_NATIVE_BACKEND_FIPS202) && \
|
|
334
|
+
!defined(MLD_CONFIG_FIPS202_BACKEND_FILE)
|
|
335
|
+
#define MLD_CONFIG_FIPS202_BACKEND_FILE "fips202/native/auto.h"
|
|
336
|
+
#endif
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* MLD_CONFIG_FIPS202_CUSTOM_HEADER
|
|
340
|
+
*
|
|
341
|
+
* Custom header to use for FIPS-202
|
|
342
|
+
*
|
|
343
|
+
* This should only be set if you intend to use a custom
|
|
344
|
+
* FIPS-202 implementation, different from the one shipped
|
|
345
|
+
* with mldsa-native.
|
|
346
|
+
*
|
|
347
|
+
* If set, it must be the name of a file serving as the
|
|
348
|
+
* replacement for mldsa/src/fips202/fips202.h, and exposing
|
|
349
|
+
* the same API (see FIPS202.md).
|
|
350
|
+
*/
|
|
351
|
+
/* #define MLD_CONFIG_FIPS202_CUSTOM_HEADER "SOME_FILE.h" */
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* MLD_CONFIG_FIPS202X4_CUSTOM_HEADER
|
|
355
|
+
*
|
|
356
|
+
* Custom header to use for FIPS-202-X4
|
|
357
|
+
*
|
|
358
|
+
* This should only be set if you intend to use a custom
|
|
359
|
+
* FIPS-202 implementation, different from the one shipped
|
|
360
|
+
* with mldsa-native.
|
|
361
|
+
*
|
|
362
|
+
* If set, it must be the name of a file serving as the
|
|
363
|
+
* replacement for mldsa/src/fips202/fips202x4.h, and exposing
|
|
364
|
+
* the same API (see FIPS202.md).
|
|
365
|
+
*/
|
|
366
|
+
/* #define MLD_CONFIG_FIPS202X4_CUSTOM_HEADER "SOME_FILE.h" */
|
|
367
|
+
|
|
368
|
+
/**
|
|
369
|
+
* MLD_CONFIG_CUSTOM_ZEROIZE
|
|
370
|
+
*
|
|
371
|
+
* In compliance with @[FIPS204, Section 3.6.3], mldsa-native zeroizes
|
|
372
|
+
* intermediate buffers before returning from function calls. By default,
|
|
373
|
+
* those buffers are allocated from the stack; if MLD_CONFIG_CUSTOM_ALLOC_FREE
|
|
374
|
+
* is set, they are (mostly -- few exceptions remain at present) allocated from
|
|
375
|
+
* the configured custom allocator.
|
|
376
|
+
*
|
|
377
|
+
* mldsa-native also zeroizes caller-owned output buffers as needed to uphold
|
|
378
|
+
* the API convention that outputs be either unmodified or zeroized upon
|
|
379
|
+
* failure.
|
|
380
|
+
*
|
|
381
|
+
* Set this option and define `mld_zeroize` if you want to use a custom
|
|
382
|
+
* method to zeroize intermediate and output buffers.
|
|
383
|
+
*
|
|
384
|
+
* The default implementation uses SecureZeroMemory on Windows and a
|
|
385
|
+
* memset + compiler barrier otherwise. If neither of those is available on
|
|
386
|
+
* the target platform, compilation will fail, and you will need to use
|
|
387
|
+
* MLD_CONFIG_CUSTOM_ZEROIZE to provide a custom implementation of
|
|
388
|
+
* `mld_zeroize()`.
|
|
389
|
+
*
|
|
390
|
+
* @warning
|
|
391
|
+
* The zeroization conducted by mldsa-native reduces the likelihood of data
|
|
392
|
+
* leaking on the stack or custom allocators, but it does not eliminate it.
|
|
393
|
+
* For example, the C standard makes no guarantee about where a compiler
|
|
394
|
+
* allocates local structures and whether/where it makes copies of them.
|
|
395
|
+
* Also, in addition to entire structures, there may also be potentially
|
|
396
|
+
* exploitable leakage of individual values on the stack. If you need
|
|
397
|
+
* bullet-proof zeroization of the stack, you need to consider additional
|
|
398
|
+
* measures instead of what this feature provides. In this case, you can
|
|
399
|
+
* set mld_zeroize to a no-op. Note that in this case you are also responsible
|
|
400
|
+
* for zeroizing output buffers upon failure.
|
|
401
|
+
*/
|
|
402
|
+
/* #define MLD_CONFIG_CUSTOM_ZEROIZE
|
|
403
|
+
#if !defined(__ASSEMBLER__)
|
|
404
|
+
#include <stdint.h>
|
|
405
|
+
#include "src/src.h"
|
|
406
|
+
static MLD_INLINE void mld_zeroize(void *ptr, size_t len)
|
|
407
|
+
{
|
|
408
|
+
... your implementation ...
|
|
409
|
+
}
|
|
410
|
+
#endif
|
|
411
|
+
*/
|
|
412
|
+
|
|
413
|
+
/**
|
|
414
|
+
* MLD_CONFIG_CUSTOM_RANDOMBYTES
|
|
415
|
+
*
|
|
416
|
+
* mldsa-native does not provide a secure randombytes
|
|
417
|
+
* implementation. Such an implementation has to be provided by
|
|
418
|
+
* the consumer.
|
|
419
|
+
*
|
|
420
|
+
* If this option is not set, mldsa-native expects a function
|
|
421
|
+
* int randombytes(uint8_t *out, size_t outlen).
|
|
422
|
+
*
|
|
423
|
+
* Set this option and define `mld_randombytes` if you want to
|
|
424
|
+
* use a custom method to sample randombytes with a different name
|
|
425
|
+
* or signature.
|
|
426
|
+
*/
|
|
427
|
+
/* #define MLD_CONFIG_CUSTOM_RANDOMBYTES
|
|
428
|
+
#if !defined(__ASSEMBLER__)
|
|
429
|
+
#include <stdint.h>
|
|
430
|
+
#include "src/src.h"
|
|
431
|
+
static MLD_INLINE int mld_randombytes(uint8_t *ptr, size_t len)
|
|
432
|
+
{
|
|
433
|
+
... your implementation ...
|
|
434
|
+
return 0;
|
|
435
|
+
}
|
|
436
|
+
#endif
|
|
437
|
+
*/
|
|
438
|
+
|
|
439
|
+
/**
|
|
440
|
+
* MLD_CONFIG_CUSTOM_CAPABILITY_FUNC
|
|
441
|
+
*
|
|
442
|
+
* mldsa-native backends may rely on specific hardware features.
|
|
443
|
+
* Those backends will only be included in an mldsa-native build
|
|
444
|
+
* if support for the respective features is enabled at
|
|
445
|
+
* compile-time. However, when building for a heterogeneous set
|
|
446
|
+
* of CPUs to run the resulting binary/library on, feature
|
|
447
|
+
* detection at _runtime_ is needed to decide whether a backend
|
|
448
|
+
* can be used or not.
|
|
449
|
+
*
|
|
450
|
+
* Set this option and define `mld_sys_check_capability` if you
|
|
451
|
+
* want to use a custom method to dispatch between implementations.
|
|
452
|
+
*
|
|
453
|
+
* Return value 1 indicates that a capability is supported.
|
|
454
|
+
* Return value 0 indicates that a capability is not supported.
|
|
455
|
+
*
|
|
456
|
+
* If this option is not set, mldsa-native uses compile-time
|
|
457
|
+
* feature detection only to decide which backend to use.
|
|
458
|
+
*
|
|
459
|
+
* If you compile mldsa-native on a system with different
|
|
460
|
+
* capabilities than the system that the resulting binary/library
|
|
461
|
+
* will be run on, you must use this option.
|
|
462
|
+
*/
|
|
463
|
+
/* #define MLD_CONFIG_CUSTOM_CAPABILITY_FUNC
|
|
464
|
+
static MLD_INLINE int mld_sys_check_capability(mld_sys_cap cap)
|
|
465
|
+
{
|
|
466
|
+
... your implementation ...
|
|
467
|
+
}
|
|
468
|
+
*/
|
|
469
|
+
|
|
470
|
+
/**
|
|
471
|
+
* MLD_CONFIG_CUSTOM_ALLOC_FREE
|
|
472
|
+
*
|
|
473
|
+
* Set this option and define `MLD_CUSTOM_ALLOC` and
|
|
474
|
+
* `MLD_CUSTOM_FREE` if you want to use custom allocation for
|
|
475
|
+
* large local structures or buffers.
|
|
476
|
+
*
|
|
477
|
+
* By default, all buffers/structures are allocated on the stack.
|
|
478
|
+
* If this option is set, most of them will be allocated via
|
|
479
|
+
* MLD_CUSTOM_ALLOC.
|
|
480
|
+
*
|
|
481
|
+
* Parameters to MLD_CUSTOM_ALLOC:
|
|
482
|
+
* - T* v: Target pointer to declare.
|
|
483
|
+
* - T: Type of structure to be allocated
|
|
484
|
+
* - N: Number of elements to be allocated.
|
|
485
|
+
*
|
|
486
|
+
* Parameters to MLD_CUSTOM_FREE:
|
|
487
|
+
* - T* v: Target pointer to free. May be NULL.
|
|
488
|
+
* - T: Type of structure to be freed.
|
|
489
|
+
* - N: Number of elements to be freed.
|
|
490
|
+
*
|
|
491
|
+
* @warning This option is experimental. Its scope, configuration and
|
|
492
|
+
* function/macro signatures may change at any time. We expect a
|
|
493
|
+
* stable API in a future version.
|
|
494
|
+
*
|
|
495
|
+
* @note Even if this option is set, some allocations further down
|
|
496
|
+
* the call stack will still be made from the stack. Those will
|
|
497
|
+
* likely be added to the scope of this option in the future.
|
|
498
|
+
*
|
|
499
|
+
* @note MLD_CUSTOM_ALLOC need not guarantee a successful
|
|
500
|
+
* allocation nor include error handling. Upon failure, the
|
|
501
|
+
* target pointer should simply be set to NULL. The calling
|
|
502
|
+
* code will handle this case and invoke MLD_CUSTOM_FREE.
|
|
503
|
+
*/
|
|
504
|
+
/* #define MLD_CONFIG_CUSTOM_ALLOC_FREE
|
|
505
|
+
#if !defined(__ASSEMBLER__)
|
|
506
|
+
#include <stdlib.h>
|
|
507
|
+
#define MLD_CUSTOM_ALLOC(v, T, N) \
|
|
508
|
+
T* (v) = (T *)aligned_alloc(MLD_DEFAULT_ALIGN, \
|
|
509
|
+
MLD_ALIGN_UP(sizeof(T) * (N)))
|
|
510
|
+
#define MLD_CUSTOM_FREE(v, T, N) free(v)
|
|
511
|
+
#endif
|
|
512
|
+
*/
|
|
513
|
+
|
|
514
|
+
/**
|
|
515
|
+
* MLD_CONFIG_CUSTOM_MEMCPY
|
|
516
|
+
*
|
|
517
|
+
* Set this option and define `mld_memcpy` if you want to
|
|
518
|
+
* use a custom method to copy memory instead of the standard
|
|
519
|
+
* library memcpy function.
|
|
520
|
+
*
|
|
521
|
+
* The custom implementation must have the same signature and
|
|
522
|
+
* behavior as the standard memcpy function:
|
|
523
|
+
* void *mld_memcpy(void *dest, const void *src, size_t n)
|
|
524
|
+
*/
|
|
525
|
+
/* #define MLD_CONFIG_CUSTOM_MEMCPY
|
|
526
|
+
#if !defined(__ASSEMBLER__)
|
|
527
|
+
#include <stdint.h>
|
|
528
|
+
#include "src/src.h"
|
|
529
|
+
static MLD_INLINE void *mld_memcpy(void *dest, const void *src, size_t n)
|
|
530
|
+
{
|
|
531
|
+
... your implementation ...
|
|
532
|
+
}
|
|
533
|
+
#endif
|
|
534
|
+
*/
|
|
535
|
+
|
|
536
|
+
/**
|
|
537
|
+
* MLD_CONFIG_CUSTOM_MEMSET
|
|
538
|
+
*
|
|
539
|
+
* Set this option and define `mld_memset` if you want to
|
|
540
|
+
* use a custom method to set memory instead of the standard
|
|
541
|
+
* library memset function.
|
|
542
|
+
*
|
|
543
|
+
* The custom implementation must have the same signature and
|
|
544
|
+
* behavior as the standard memset function:
|
|
545
|
+
* void *mld_memset(void *s, int c, size_t n)
|
|
546
|
+
*/
|
|
547
|
+
/* #define MLD_CONFIG_CUSTOM_MEMSET
|
|
548
|
+
#if !defined(__ASSEMBLER__)
|
|
549
|
+
#include <stdint.h>
|
|
550
|
+
#include "src/src.h"
|
|
551
|
+
static MLD_INLINE void *mld_memset(void *s, int c, size_t n)
|
|
552
|
+
{
|
|
553
|
+
... your implementation ...
|
|
554
|
+
}
|
|
555
|
+
#endif
|
|
556
|
+
*/
|
|
557
|
+
|
|
558
|
+
/**
|
|
559
|
+
* MLD_CONFIG_INTERNAL_API_QUALIFIER
|
|
560
|
+
*
|
|
561
|
+
* If set, this option provides an additional qualifier
|
|
562
|
+
* to be added to declarations of internal API functions and data.
|
|
563
|
+
*
|
|
564
|
+
* The primary use case for this option are single-CU builds,
|
|
565
|
+
* in which case this option can be set to `static`.
|
|
566
|
+
*/
|
|
567
|
+
/* #define MLD_CONFIG_INTERNAL_API_QUALIFIER */
|
|
568
|
+
|
|
569
|
+
/**
|
|
570
|
+
* MLD_CONFIG_CT_TESTING_ENABLED
|
|
571
|
+
*
|
|
572
|
+
* If set, mldsa-native annotates data as secret / public using
|
|
573
|
+
* valgrind's annotations VALGRIND_MAKE_MEM_UNDEFINED and
|
|
574
|
+
* VALGRIND_MAKE_MEM_DEFINED, enabling various checks for secret-
|
|
575
|
+
* dependent control flow of variable time execution (depending
|
|
576
|
+
* on the exact version of valgrind installed).
|
|
577
|
+
*/
|
|
578
|
+
/* #define MLD_CONFIG_CT_TESTING_ENABLED */
|
|
579
|
+
|
|
580
|
+
/**
|
|
581
|
+
* MLD_CONFIG_NO_ASM
|
|
582
|
+
*
|
|
583
|
+
* If this option is set, mldsa-native will be built without
|
|
584
|
+
* use of native code or inline assembly.
|
|
585
|
+
*
|
|
586
|
+
* By default, inline assembly is used to implement value barriers.
|
|
587
|
+
* Without inline assembly, mldsa-native will use a global volatile
|
|
588
|
+
* 'opt blocker' instead; see ct.h.
|
|
589
|
+
*
|
|
590
|
+
* Inline assembly is also used to implement a secure zeroization
|
|
591
|
+
* function on non-Windows platforms. If this option is set and
|
|
592
|
+
* the target platform is not Windows, you MUST set
|
|
593
|
+
* MLD_CONFIG_CUSTOM_ZEROIZE and provide a custom zeroization
|
|
594
|
+
* function.
|
|
595
|
+
*
|
|
596
|
+
* If this option is set, MLD_CONFIG_USE_NATIVE_BACKEND_FIPS202 and
|
|
597
|
+
* MLD_CONFIG_USE_NATIVE_BACKEND_ARITH will be ignored, and no
|
|
598
|
+
* native backends will be used.
|
|
599
|
+
*/
|
|
600
|
+
/* #define MLD_CONFIG_NO_ASM */
|
|
601
|
+
|
|
602
|
+
/**
|
|
603
|
+
* MLD_CONFIG_NO_ASM_VALUE_BARRIER
|
|
604
|
+
*
|
|
605
|
+
* If this option is set, mldsa-native will be built without
|
|
606
|
+
* use of native code or inline assembly for value barriers.
|
|
607
|
+
*
|
|
608
|
+
* By default, inline assembly (if available) is used to implement
|
|
609
|
+
* value barriers.
|
|
610
|
+
* Without inline assembly, mldsa-native will use a global volatile
|
|
611
|
+
* 'opt blocker' instead; see ct.h.
|
|
612
|
+
*/
|
|
613
|
+
/* #define MLD_CONFIG_NO_ASM_VALUE_BARRIER */
|
|
614
|
+
|
|
615
|
+
/**
|
|
616
|
+
* MLD_CONFIG_KEYGEN_PCT
|
|
617
|
+
*
|
|
618
|
+
* Compliance with @[FIPS140_3_IG, p.87] requires a
|
|
619
|
+
* Pairwise Consistency Test (PCT) to be carried out on a freshly
|
|
620
|
+
* generated keypair before it can be exported.
|
|
621
|
+
*
|
|
622
|
+
* Set this option if such a check should be implemented.
|
|
623
|
+
* In this case, keypair_internal and
|
|
624
|
+
* keypair will return MLD_ERR_PCT_FAIL if the
|
|
625
|
+
* PCT failed.
|
|
626
|
+
*
|
|
627
|
+
* @note This feature will drastically lower the performance of
|
|
628
|
+
* key generation.
|
|
629
|
+
*
|
|
630
|
+
* @note This option is incompatible with MLD_CONFIG_NO_SIGN_API
|
|
631
|
+
* and MLD_CONFIG_NO_VERIFY_API as the current PCT implementation
|
|
632
|
+
* requires signature() and verify().
|
|
633
|
+
*/
|
|
634
|
+
/* #define MLD_CONFIG_KEYGEN_PCT */
|
|
635
|
+
|
|
636
|
+
/**
|
|
637
|
+
* MLD_CONFIG_KEYGEN_PCT_BREAKAGE_TEST
|
|
638
|
+
*
|
|
639
|
+
* If this option is set, the user must provide a runtime
|
|
640
|
+
* function `static inline int mld_break_pct() { ... }` to
|
|
641
|
+
* indicate whether the PCT should be made fail.
|
|
642
|
+
*
|
|
643
|
+
* This option only has an effect if MLD_CONFIG_KEYGEN_PCT is set.
|
|
644
|
+
*/
|
|
645
|
+
/* #define MLD_CONFIG_KEYGEN_PCT_BREAKAGE_TEST
|
|
646
|
+
#if !defined(__ASSEMBLER__)
|
|
647
|
+
#include "src/src.h"
|
|
648
|
+
static MLD_INLINE int mld_break_pct(void)
|
|
649
|
+
{
|
|
650
|
+
... return 0/1 depending on whether PCT should be broken ...
|
|
651
|
+
}
|
|
652
|
+
#endif
|
|
653
|
+
*/
|
|
654
|
+
|
|
655
|
+
/**
|
|
656
|
+
* MLD_CONFIG_MAX_SIGNING_ATTEMPTS
|
|
657
|
+
*
|
|
658
|
+
* Upper bound on the number of rejection-sampling iterations
|
|
659
|
+
* performed by ML-DSA signing (@[FIPS204, Algorithm 7]).
|
|
660
|
+
*
|
|
661
|
+
* If a valid signature is not produced within this many
|
|
662
|
+
* attempts, signing returns MLD_ERR_SIGN_ATTEMPTS_EXHAUSTED.
|
|
663
|
+
* This is useful in timing-sensitive environments that
|
|
664
|
+
* require a deterministic worst-case bound on signing time.
|
|
665
|
+
*
|
|
666
|
+
* For FIPS 204 compliance, this value MUST be at least 821,
|
|
667
|
+
* cf. @[FIPS204, Appendix C] and @[FIPS204_UPDATES], which is
|
|
668
|
+
* chosen so that the signing failure rate is < 2^{-256}.
|
|
669
|
+
*
|
|
670
|
+
* Default: Largest possible value before internal counters
|
|
671
|
+
* would overflow. This is larger than the FIPS204 bound.
|
|
672
|
+
*
|
|
673
|
+
* In particular, in the default configuration, the signing
|
|
674
|
+
* failure rate is < 2^{-256}.
|
|
675
|
+
*/
|
|
676
|
+
/* #define MLD_CONFIG_MAX_SIGNING_ATTEMPTS 821 */
|
|
677
|
+
|
|
678
|
+
/**
|
|
679
|
+
* MLD_CONFIG_SERIAL_FIPS202_ONLY
|
|
680
|
+
*
|
|
681
|
+
* Set this to use a FIPS202 implementation with global state
|
|
682
|
+
* that supports only one active Keccak computation at a time
|
|
683
|
+
* (e.g. some hardware accelerators).
|
|
684
|
+
*
|
|
685
|
+
* If this option is set, ML-DSA will use FIPS202 operations
|
|
686
|
+
* serially, ensuring that only one SHAKE context is active
|
|
687
|
+
* at any given time.
|
|
688
|
+
*
|
|
689
|
+
* This allows offloading Keccak computations to a hardware
|
|
690
|
+
* accelerator that holds only a single Keccak state locally,
|
|
691
|
+
* rather than requiring support for multiple concurrent
|
|
692
|
+
* Keccak states.
|
|
693
|
+
*
|
|
694
|
+
* @note Depending on the target CPU, this may reduce
|
|
695
|
+
* performance when using software FIPS202 implementations.
|
|
696
|
+
* Only enable this when you have to.
|
|
697
|
+
*/
|
|
698
|
+
/* #define MLD_CONFIG_SERIAL_FIPS202_ONLY */
|
|
699
|
+
|
|
700
|
+
/**
|
|
701
|
+
* MLD_CONFIG_CONTEXT_PARAMETER
|
|
702
|
+
*
|
|
703
|
+
* Set this to add a caller-supplied context parameter to the public API
|
|
704
|
+
* functions, which is then forwarded unchanged to the custom callbacks
|
|
705
|
+
* (allocation, and signing hooks below).
|
|
706
|
+
*
|
|
707
|
+
* When this option is set, every public API function gains a trailing
|
|
708
|
+
* parameter
|
|
709
|
+
*
|
|
710
|
+
* MLD_CONFIG_CONTEXT_PARAMETER_TYPE context
|
|
711
|
+
*
|
|
712
|
+
* as its last argument; its type is configured via
|
|
713
|
+
* MLD_CONFIG_CONTEXT_PARAMETER_TYPE (see below). mldsa-native treats this
|
|
714
|
+
* value as opaque: it never dereferences it and only passes it on to the
|
|
715
|
+
* configurable hook macros. It is meant to carry per-caller state -- e.g. a
|
|
716
|
+
* pointer to a memory pool for the allocation hooks, or the resume state for
|
|
717
|
+
* the signing hooks -- into those hooks.
|
|
718
|
+
*
|
|
719
|
+
* When this option is unset (the default), no extra parameter is added and
|
|
720
|
+
* the hook macros never receive a context argument.
|
|
721
|
+
*
|
|
722
|
+
* The hooks that receive the context are the allocation hooks (see
|
|
723
|
+
* MLD_CONFIG_CUSTOM_ALLOC_FREE) and the signing hooks (see
|
|
724
|
+
* MLD_CONFIG_SIGN_HOOK_RESUME / _ATTEMPT / _FINISH); each is documented with
|
|
725
|
+
* its own option below.
|
|
726
|
+
*/
|
|
727
|
+
/* #define MLD_CONFIG_CONTEXT_PARAMETER */
|
|
728
|
+
|
|
729
|
+
/**
|
|
730
|
+
* MLD_CONFIG_CONTEXT_PARAMETER_TYPE
|
|
731
|
+
*
|
|
732
|
+
* Set this to define the type of the context parameter added by
|
|
733
|
+
* MLD_CONFIG_CONTEXT_PARAMETER. It can be any C type usable as a function
|
|
734
|
+
* parameter, e.g. `void *` or a pointer to a caller-defined struct such as
|
|
735
|
+
* `struct my_ctx *`.
|
|
736
|
+
*
|
|
737
|
+
* This option must be defined if and only if MLD_CONFIG_CONTEXT_PARAMETER is
|
|
738
|
+
* defined; defining one without the other is a compile-time error.
|
|
739
|
+
*/
|
|
740
|
+
/* #define MLD_CONFIG_CONTEXT_PARAMETER_TYPE void* */
|
|
741
|
+
|
|
742
|
+
/**
|
|
743
|
+
* Signing hooks: MLD_CONFIG_SIGN_HOOK_RESUME / _ATTEMPT / _FINISH
|
|
744
|
+
*
|
|
745
|
+
* Three optional, independent hooks into the ML-DSA signing rejection-sampling
|
|
746
|
+
* loop. Each is enabled by defining the matching option, in which case the
|
|
747
|
+
* integration must provide the corresponding function. If a hook needs
|
|
748
|
+
* per-operation state, enable MLD_CONFIG_CONTEXT_PARAMETER; the context is then
|
|
749
|
+
* appended as the last argument.
|
|
750
|
+
*
|
|
751
|
+
* @warning This feature is experimental. Its scope, configuration and
|
|
752
|
+
* function signatures may change at any time, including after v2.
|
|
753
|
+
*
|
|
754
|
+
* Enabling any of the hooks requires MLD_CONFIG_NO_RANDOMIZED_API (restricting
|
|
755
|
+
* the public API to deterministic operations). This is because the restartable
|
|
756
|
+
* signing as enabled by the signing hooks only produces the uninterrupted
|
|
757
|
+
* signature when the randomness is fixed across calls. A logging-only use
|
|
758
|
+
* (attempt always returns 0; resume/finish merely observe) would be safe with
|
|
759
|
+
* the randomized API too, but for now the requirement is imposed uniformly on
|
|
760
|
+
* all three hooks.
|
|
761
|
+
*
|
|
762
|
+
* Note: Randomized signing is a shim wrapper around deterministic signing, and
|
|
763
|
+
* all helper functions you need to build it are exposed publicly. Thus, if you
|
|
764
|
+
* need a restartable, randomized signing operation, you can build your own by
|
|
765
|
+
* replicating the logic and adding the RNG seed to the restart context. In this
|
|
766
|
+
* case, please also consider letting the mldsa-native maintainers know of your
|
|
767
|
+
* need for randomized, restartable signing, so the feature can be appropriately
|
|
768
|
+
* prioritized.
|
|
769
|
+
*
|
|
770
|
+
* - MLD_CONFIG_SIGN_HOOK_ATTEMPT: int mld_sign_hook_attempt(attempt[, ctxt])
|
|
771
|
+
* Called before each attempt. Returns 0 to proceed, or non-zero to pause:
|
|
772
|
+
* signing then returns MLD_ERR_SIGNING_PAUSED with `attempt` as the resume
|
|
773
|
+
* point (needs MLD_CONFIG_SIGN_HOOK_RESUME to resume; otherwise just aborts).
|
|
774
|
+
* Always returning 0 makes it a logging/benchmarking hook.
|
|
775
|
+
*
|
|
776
|
+
* - MLD_CONFIG_SIGN_HOOK_RESUME: uint16_t mld_sign_hook_resume([ctxt])
|
|
777
|
+
* Returns the attempt to resume from (0 for a fresh operation), i.e. the one
|
|
778
|
+
* recorded when a previous call paused.
|
|
779
|
+
*
|
|
780
|
+
* - MLD_CONFIG_SIGN_HOOK_FINISH: void mld_sign_hook_finish(attempt[, ctxt])
|
|
781
|
+
* Called on success with the succeeding attempt. Observe-only.
|
|
782
|
+
*
|
|
783
|
+
* When an option is unset, the hook is a no-op (resume to 0, attempt proceeds),
|
|
784
|
+
* i.e. ordinary one-shot signing.
|
|
785
|
+
*
|
|
786
|
+
* Independent of MLD_CONFIG_MAX_SIGNING_ATTEMPTS, which is a static upper bound
|
|
787
|
+
* on the number of signing attempts.
|
|
788
|
+
*
|
|
789
|
+
* See test/src/test_sign_hook.c for a worked example using all three.
|
|
790
|
+
*/
|
|
791
|
+
/* #define MLD_CONFIG_SIGN_HOOK_RESUME
|
|
792
|
+
#define MLD_CONFIG_SIGN_HOOK_ATTEMPT
|
|
793
|
+
#define MLD_CONFIG_SIGN_HOOK_FINISH
|
|
794
|
+
#if !defined(__ASSEMBLER__)
|
|
795
|
+
#include <stdint.h>
|
|
796
|
+
#include "src/sys.h"
|
|
797
|
+
static MLD_INLINE uint16_t mld_sign_hook_resume(void)
|
|
798
|
+
{
|
|
799
|
+
... return the attempt to resume from ...
|
|
800
|
+
}
|
|
801
|
+
static MLD_INLINE int mld_sign_hook_attempt(uint16_t attempt)
|
|
802
|
+
{
|
|
803
|
+
... return non-zero to pause here; for resume, store attempt ...
|
|
804
|
+
return 0;
|
|
805
|
+
}
|
|
806
|
+
static MLD_INLINE void mld_sign_hook_finish(uint16_t attempt)
|
|
807
|
+
{
|
|
808
|
+
... mark the operation complete (attempt = successful attempt) ...
|
|
809
|
+
}
|
|
810
|
+
#endif
|
|
811
|
+
*/
|
|
812
|
+
|
|
813
|
+
/**
|
|
814
|
+
* MLD_CONFIG_REDUCE_RAM
|
|
815
|
+
*
|
|
816
|
+
* Set this to reduce RAM usage. This trades memory for performance.
|
|
817
|
+
*
|
|
818
|
+
* For expected memory usage, see the MLD_TOTAL_ALLOC_* constants defined in
|
|
819
|
+
* mldsa_native.h.
|
|
820
|
+
*
|
|
821
|
+
* This option is useful for embedded systems with tight RAM constraints but
|
|
822
|
+
* relaxed performance requirements.
|
|
823
|
+
*
|
|
824
|
+
*/
|
|
825
|
+
/* #define MLD_CONFIG_REDUCE_RAM */
|
|
826
|
+
|
|
827
|
+
/************************* Config internals ********************************/
|
|
828
|
+
|
|
829
|
+
#endif /* MLD_BUILD_INTERNAL */
|
|
830
|
+
|
|
831
|
+
/* Default namespace
|
|
832
|
+
*
|
|
833
|
+
* Don't change this. If you need a different namespace, re-define
|
|
834
|
+
* MLD_CONFIG_NAMESPACE_PREFIX above instead, and remove the following.
|
|
835
|
+
*
|
|
836
|
+
* The default MLDSA namespace is
|
|
837
|
+
*
|
|
838
|
+
* PQCP_MLDSA_NATIVE_MLDSA<LEVEL>_
|
|
839
|
+
*
|
|
840
|
+
* e.g., PQCP_MLDSA_NATIVE_MLDSA44_
|
|
841
|
+
*/
|
|
842
|
+
|
|
843
|
+
#if defined(MLD_CONFIG_MULTILEVEL_BUILD)
|
|
844
|
+
/* In a multi-level build the parameter set is appended by the namespacing
|
|
845
|
+
* machinery, so the default prefix must not embed it. */
|
|
846
|
+
#define MLD_DEFAULT_NAMESPACE_PREFIX PQCP_MLDSA_NATIVE_MLDSA
|
|
847
|
+
#elif MLD_CONFIG_PARAMETER_SET == 44
|
|
848
|
+
#define MLD_DEFAULT_NAMESPACE_PREFIX PQCP_MLDSA_NATIVE_MLDSA44
|
|
849
|
+
#elif MLD_CONFIG_PARAMETER_SET == 65
|
|
850
|
+
#define MLD_DEFAULT_NAMESPACE_PREFIX PQCP_MLDSA_NATIVE_MLDSA65
|
|
851
|
+
#elif MLD_CONFIG_PARAMETER_SET == 87
|
|
852
|
+
#define MLD_DEFAULT_NAMESPACE_PREFIX PQCP_MLDSA_NATIVE_MLDSA87
|
|
853
|
+
#endif
|
|
854
|
+
|
|
855
|
+
#endif /* !MLD_CONFIG_H */
|