Debian Codegraph @

others/mbedtls/tf-psa-crypto/drivers/pqcp/mldsa-native/integration/liboqs/config_x86_64.h

raw symbols SCIP
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
16 #ifndef MLD_INTEGRATION_LIBOQS_CONFIG_X86_64_H
17 #define MLD_INTEGRATION_LIBOQS_CONFIG_X86_64_H
18
19 /* Enable valgrind-based assertions in mldsa-native through macro
20 * from libOQS. */
21 #if !defined(__ASSEMBLER__)
22 #include <oqs/common.h>
23 #if defined(OQS_ENABLE_TEST_CONSTANT_TIME)
24 #define MLD_CONFIG_CT_TESTING_ENABLED
25 #endif
26 #endif /* !__ASSEMBLER__ */
27
28 /* Use OQS's FIPS202 via glue headers */
29 #define MLD_CONFIG_FIPS202_CUSTOM_HEADER \
30 "../../integration/liboqs/fips202_glue.h"
31 #define MLD_CONFIG_FIPS202X4_CUSTOM_HEADER \
32 "../../integration/liboqs/fips202x4_glue.h"
33
34 /******************************************************************************
35 * Name: MLD_CONFIG_PARAMETER_SET
36 *
37 * Description: Specifies the parameter set for ML-DSA
38 * - MLD_CONFIG_PARAMETER_SET=44 corresponds to ML-DSA-44
39 * - MLD_CONFIG_PARAMETER_SET=65 corresponds to ML-DSA-65
40 * - MLD_CONFIG_PARAMETER_SET=87 corresponds to ML-DSA-87
41 *
42 * This can also be set using CFLAGS.
43 *
44 *****************************************************************************/
45 #ifndef MLD_CONFIG_PARAMETER_SET
46 #define MLD_CONFIG_PARAMETER_SET \
47 44 /* Change this for different security strengths */
48 #endif
49
50 /******************************************************************************
51 * Name: MLD_CONFIG_NAMESPACE_PREFIX
52 *
53 * Description: The prefix to use to namespace global symbols from mldsa/.
54 * For integration builds, this adds an architecture-specific
55 * suffix to distinguish different builds.
56 *
57 * This can also be set using CFLAGS.
58 *
59 *****************************************************************************/
60 #if !defined(MLD_CONFIG_NAMESPACE_PREFIX)
61 #define MLD_CONFIG_NAMESPACE_PREFIX MLD_DEFAULT_NAMESPACE_PREFIX
62 #endif
63
64 /******************************************************************************
65 * Name: MLD_CONFIG_FILE
66 *
67 * Description: If defined, this is a header that will be included instead
68 * of this default configuration file mldsa/config.h.
69 *
70 * When you need to build mldsa-native in multiple configurations,
71 * using varying MLD_CONFIG_FILE can be more convenient
72 * then configuring everything through CFLAGS.
73 *
74 * To use, MLD_CONFIG_FILE _must_ be defined prior
75 * to the inclusion of any mldsa-native headers. For example,
76 * it can be set by passing `-DMLD_CONFIG_FILE="..."`
77 * on the command line.
78 *
79 *****************************************************************************/
80 /* #define MLD_CONFIG_FILE "config.h" */
81
82 /******************************************************************************
83 * Name: MLD_CONFIG_ARITH_BACKEND_FILE
84 *
85 * Description: The arithmetic backend to use.
86 *
87 * If MLD_CONFIG_USE_NATIVE_BACKEND_ARITH is unset, this option
88 * is ignored.
89 *
90 * If MLD_CONFIG_USE_NATIVE_BACKEND_ARITH is set, this option must
91 * either be undefined or the filename of an arithmetic backend.
92 * If unset, the default backend will be used.
93 *
94 * This can be set using CFLAGS.
95 *
96 *****************************************************************************/
97 #define MLD_CONFIG_USE_NATIVE_BACKEND_ARITH
98 #define MLD_CONFIG_ARITH_BACKEND_FILE "native/meta.h"
99
100 /******************************************************************************
101 * Name: MLD_CONFIG_FIPS202_BACKEND_FILE
102 *
103 * Description: The FIPS-202 backend to use.
104 *
105 * If MLD_CONFIG_USE_NATIVE_BACKEND_FIPS202 is set, this option
106 * must either be undefined or the filename of a FIPS202 backend.
107 * If unset, the default backend will be used.
108 *
109 * This can be set using CFLAGS.
110 *
111 *****************************************************************************/
112 /*
113 * #define MLD_CONFIG_USE_NATIVE_BACKEND_FIPS202
114 * #define MLD_CONFIG_FIPS202_BACKEND_FILE "fips202/native/auto.h"
115 */
116
117
118
119 /******************************************************************************
120 * Name: MLD_CONFIG_CUSTOM_ZEROIZE
121 *
122 * Description: In compliance with FIPS 204 Section 3.6.3, mldsa-native zeroizes
123 * intermediate stack buffers before returning from function calls.
124 *
125 * Set this option and define `mld_zeroize` if you want to
126 * use a custom method to zeroize intermediate stack buffers.
127 * The default implementation uses SecureZeroMemory on Windows
128 * and a memset + compiler barrier otherwise. If neither of those
129 * is available on the target platform, compilation will fail,
130 * and you will need to use MLD_CONFIG_CUSTOM_ZEROIZE to provide
131 * a custom implementation of `mld_zeroize()`.
132 *
133 * WARNING:
134 * The explicit stack zeroization conducted by mldsa-native
135 * reduces the likelihood of data leaking on the stack, but
136 * does not eliminate it! The C standard makes no guarantee about
137 * where a compiler allocates structures and whether/where it makes
138 * copies of them. Also, in addition to entire structures, there
139 * may also be potentially exploitable leakage of individual values
140 * on the stack.
141 *
142 * If you need bullet-proof zeroization of the stack, you need to
143 * consider additional measures instead of what this feature
144 * provides. In this case, you can set mld_zeroize to a
145 * no-op.
146 *
147 *****************************************************************************/
148 /* #define MLD_CONFIG_CUSTOM_ZEROIZE
149 #if !defined(__ASSEMBLER__)
150 #include <stdint.h>
151 #include "sys.h"
152 static MLD_INLINE void mld_zeroize(void *ptr, size_t len)
153 {
154 ... your implementation ...
155 }
156 #endif
157 */
158
159 /******************************************************************************
160 * Name: MLD_CONFIG_CUSTOM_RANDOMBYTES
161 *
162 * Description: mldsa-native does not provide a secure randombytes
163 * implementation. Such an implementation has to provided by the
164 * consumer.
165 *
166 * If this option is not set, mlkem-native expects a function
167 * int randombytes(uint8_t *out, size_t outlen).
168 *
169 * Set this option and define `mlk_randombytes` if you want to
170 * use a custom method to sample randombytes with a different name
171 * or signature.
172 *
173 *****************************************************************************/
174 #define MLD_CONFIG_CUSTOM_RANDOMBYTES
175 #if !defined(__ASSEMBLER__)
176 #include <oqs/rand.h>
177 #include <stdint.h>
178 #include "../../mldsa/src/sys.h"
179 static MLD_INLINE int mld_randombytes(uint8_t *ptr, size_t len)
180 {
181 OQS_randombytes(ptr, len);
182 return 0;
183 }
184 #endif /* !__ASSEMBLER__ */
185
186 /******************************************************************************
187 * Name: MLD_CONFIG_KEYGEN_PCT
188 *
189 * Description: Compliance with @[FIPS140_3_IG, p.87] requires a
190 * Pairwise Consistency Test (PCT) to be carried out on a freshly
191 * generated keypair before it can be exported.
192 *
193 * Set this option if such a check should be implemented.
194 * In this case, crypto_sign_keypair_internal and
195 * crypto_sign_keypair will return a non-zero error code if the
196 * PCT failed.
197 *
198 * NOTE: This feature will drastically lower the performance of
199 * key generation.
200 *
201 *****************************************************************************/
202 /* #define MLD_CONFIG_KEYGEN_PCT */
203
204 /******************************************************************************
205 * Name: MLD_CONFIG_KEYGEN_PCT_BREAKAGE_TEST
206 *
207 * Description: If this option is set, the user must provide a runtime
208 * function `static inline int mld_break_pct() { ... }` to
209 * indicate whether the PCT should be made fail.
210 *
211 * This option only has an effect if MLD_CONFIG_KEYGEN_PCT is set.
212 *
213 *****************************************************************************/
214 /* #define MLD_CONFIG_KEYGEN_PCT_BREAKAGE_TEST
215 #if !defined(__ASSEMBLER__)
216 #include "sys.h"
217 static MLD_INLINE int mld_break_pct(void)
218 {
219 ... return 0/1 depending on whether PCT should be broken ...
220 }
221 #endif
222 */
223
224 /******************************************************************************
225 * Name: MLD_CONFIG_NO_ASM
226 *
227 * Description: If this option is set, mldsa-native will be built without
228 * use of native code or inline assembly.
229 *
230 * By default, inline assembly is used to implement value barriers.
231 * Without inline assembly, mldsa-native will use a global volatile
232 * 'opt blocker' instead; see ct.h.
233 *
234 * Inline assembly is also used to implement a secure zeroization
235 * function on non-Windows platforms. If this option is set and
236 * the target platform is not Windows, you MUST set
237 * MLD_CONFIG_CUSTOM_ZEROIZE and provide a custom zeroization
238 * function.
239 *
240 * If this option is set, MLD_CONFIG_USE_NATIVE_BACKEND_FIPS202 and
241 * and MLD_CONFIG_USE_NATIVE_BACKEND_ARITH will be ignored, and no
242 * native backends will be used.
243 *
244 *****************************************************************************/
245 /* #define MLD_CONFIG_NO_ASM */
246
247 /******************************************************************************
248 * Name: MLD_CONFIG_EXTERNAL_API_QUALIFIER
249 *
250 * Description: If set, this option provides an additional function
251 * qualifier to be added to declarations of mldsa-native's
252 * public API.
253 *
254 * The primary use case for this option are single-CU builds
255 * where the public API exposed by mldsa-native is wrapped by
256 * another API in the consuming application. In this case,
257 * even mldsa-native's public API can be marked `static`.
258 *
259 *****************************************************************************/
260 #if !defined(__ASSEMBLER__)
261 #include <oqs/common.h>
262 #define MLD_CONFIG_EXTERNAL_API_QUALIFIER OQS_API
263 #endif
264
265 /******************************************************************************
266 * Name: MLD_CONFIG_NO_ASM_VALUE_BARRIER
267 *
268 * Description: If this option is set, mldsa-native will be built without
269 * use of native code or inline assembly for value barriers.
270 *
271 * By default, inline assembly (if available) is used to implement
272 * value barriers.
273 * Without inline assembly, mldsa-native will use a global volatile
274 * 'opt blocker' instead; see ct.h.
275 *
276 *****************************************************************************/
277 /* #define MLD_CONFIG_NO_ASM_VALUE_BARRIER */
278
279 /******************************************************************************
280 * Name: MLD_CONFIG_SERIAL_FIPS202_ONLY
281 *
282 * Description: Set this to use a FIPS202 implementation with global state
283 * that supports only one active Keccak computation at a time
284 * (e.g. some hardware accelerators).
285 *
286 * If this option is set, ML-DSA will use FIPS202 operations
287 * serially, ensuring that only one SHAKE context is active
288 * at any given time.
289 *
290 * This allows offloading Keccak computations to a hardware
291 * accelerator that holds only a single Keccak state locally,
292 * rather than requiring support for multiple concurrent
293 * Keccak states.
294 *
295 * NOTE: Depending on the target CPU, this may reduce
296 * performance when using software FIPS202 implementations.
297 * Only enable this when you have to.
298 *
299 *****************************************************************************/
300 /* #define MLD_CONFIG_SERIAL_FIPS202_ONLY */
301
302 /************************* Config internals ********************************/
303
304 /* Default namespace
305 *
306 * Don't change this. If you need a different namespace, re-define
307 * MLD_CONFIG_NAMESPACE_PREFIX above instead, and remove the following.
308 *
309 * The default MLDSA namespace for x86_64 integration is
310 *
311 * PQCP_MLDSA_NATIVE_MLDSA<LEVEL>_X86_64_
312 *
313 * e.g., PQCP_MLDSA_NATIVE_MLDSA44_X86_64_
314 */
315
316 #if MLD_CONFIG_PARAMETER_SET == 44
317 #define MLD_DEFAULT_NAMESPACE_PREFIX PQCP_MLDSA_NATIVE_MLDSA44_X86_64
318 #elif MLD_CONFIG_PARAMETER_SET == 65
319 #define MLD_DEFAULT_NAMESPACE_PREFIX PQCP_MLDSA_NATIVE_MLDSA65_X86_64
320 #elif MLD_CONFIG_PARAMETER_SET == 87
321 #define MLD_DEFAULT_NAMESPACE_PREFIX PQCP_MLDSA_NATIVE_MLDSA87_X86_64
322 #endif
323
324 #endif /* !MLD_INTEGRATION_LIBOQS_CONFIG_X86_64_H */