Debian Codegraph @

others/mbedtls/tf-psa-crypto/drivers/pqcp/mldsa-native/test/configs/configs.yml

raw symbols SCIP
1 # Copyright (c) The mlkem-native project authors
2 # Copyright (c) The mldsa-native project authors
3 # SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
4
5 # Metadata for test configuration files
6 # Each entry describes how a test config differs from mldsa/mldsa_native_config.h
7
8 configs:
9 - path: test/configs/no_asm_config.h
10 description: "Test configuration with no assembly code"
11 defines:
12 MLD_CONFIG_NO_ASM: true
13 MLD_CONFIG_CUSTOM_ZEROIZE:
14 content: |
15 #define MLD_CONFIG_CUSTOM_ZEROIZE
16 #if !defined(__ASSEMBLER__)
17 #include <stdint.h>
18 #include <string.h>
19 #include "../mldsa/src/sys.h"
20 static MLD_INLINE void mld_zeroize(void *ptr, size_t len)
21 {
22 explicit_bzero(ptr, len);
23 }
24 #endif
25
26 - path: test/configs/serial_fips202_config.h
27 description: "Test configuration with serial FIPS202 only"
28 defines:
29 MLD_CONFIG_SERIAL_FIPS202_ONLY: true
30
31 - path: test/configs/custom_randombytes_config.h
32 description: "Test configuration with custom randombytes"
33 defines:
34 MLD_CONFIG_CUSTOM_RANDOMBYTES:
35 content: |
36 #define MLD_CONFIG_CUSTOM_RANDOMBYTES
37 #if !defined(__ASSEMBLER__)
38 #include <stdint.h>
39 #include "../mldsa/src/sys.h"
40 #include "notrandombytes/notrandombytes.h"
41 static MLD_INLINE int mld_randombytes(uint8_t *ptr, size_t len)
42 {
43 return randombytes(ptr, len);
44 }
45 #endif /* !__ASSEMBLER__ */
46
47 - path: test/configs/custom_zeroize_config.h
48 description: "Test configuration with custom zeroize"
49 defines:
50 MLD_CONFIG_CUSTOM_ZEROIZE:
51 content: |
52 #define MLD_CONFIG_CUSTOM_ZEROIZE
53 #if !defined(__ASSEMBLER__)
54 #include <stdint.h>
55 #include <string.h>
56 #include "../mldsa/src/sys.h"
57 static MLD_INLINE void mld_zeroize(void *ptr, size_t len)
58 {
59 explicit_bzero(ptr, len);
60 }
61 #endif
62
63 - path: test/configs/custom_memcpy_config.h
64 description: "Test configuration with custom memcpy"
65 defines:
66 MLD_CONFIG_CUSTOM_MEMCPY:
67 content: |
68 #define MLD_CONFIG_CUSTOM_MEMCPY
69 #if !defined(__ASSEMBLER__)
70 #include <stddef.h>
71 #include <stdint.h>
72 #include "../mldsa/src/sys.h"
73 static MLD_INLINE void *mld_memcpy(void *dest, const void *src, size_t n)
74 {
75 /* Simple byte-by-byte copy implementation for testing */
76 unsigned char *d = (unsigned char *)dest;
77 const unsigned char *s = (const unsigned char *)src;
78 for (size_t i = 0; i < n; i++)
79 {
80 d[i] = s[i];
81 }
82 return dest;
83 }
84 #endif /* !__ASSEMBLER__ */
85
86 - path: test/configs/custom_memset_config.h
87 description: "Test configuration with custom memset"
88 defines:
89 MLD_CONFIG_CUSTOM_MEMSET:
90 content: |
91 #define MLD_CONFIG_CUSTOM_MEMSET
92 #if !defined(__ASSEMBLER__)
93 #include <stddef.h>
94 #include <stdint.h>
95 #include "../mldsa/src/sys.h"
96 static MLD_INLINE void *mld_memset(void *s, int c, size_t n)
97 {
98 /* Simple byte-by-byte set implementation for testing */
99 unsigned char *ptr = (unsigned char *)s;
100 for (size_t i = 0; i < n; i++)
101 {
102 ptr[i] = (unsigned char)c;
103 }
104 return s;
105 }
106 #endif
107
108 - path: test/configs/custom_stdlib_config.h
109 description: "Test configuration with custom stdlib functions"
110 defines:
111 MLD_CONFIG_CUSTOM_MEMCPY:
112 content: |
113 #define MLD_CONFIG_CUSTOM_MEMCPY
114 #if !defined(__ASSEMBLER__)
115 #include <stddef.h>
116 #include <stdint.h>
117 #include "../mldsa/src/sys.h"
118 static MLD_INLINE void *mld_memcpy(void *dest, const void *src, size_t n)
119 {
120 /* Simple byte-by-byte copy implementation for testing */
121 unsigned char *d = (unsigned char *)dest;
122 const unsigned char *s = (const unsigned char *)src;
123 for (size_t i = 0; i < n; i++)
124 {
125 d[i] = s[i];
126 }
127 return dest;
128 }
129 #endif /* !__ASSEMBLER__ */
130 MLD_CONFIG_CUSTOM_MEMSET:
131 content: |
132 #define MLD_CONFIG_CUSTOM_MEMSET
133 #if !defined(__ASSEMBLER__)
134 #include <stddef.h>
135 #include <stdint.h>
136 #include "../mldsa/src/sys.h"
137 static MLD_INLINE void *mld_memset(void *s, int c, size_t n)
138 {
139 /* Simple byte-by-byte set implementation for testing */
140 unsigned char *ptr = (unsigned char *)s;
141 for (size_t i = 0; i < n; i++)
142 {
143 ptr[i] = (unsigned char)c;
144 }
145 return s;
146 }
147 #endif
148
149 - path: test/configs/break_pct_config.h
150 description: "Test configuration for PCT breakage testing"
151 defines:
152 MLD_CONFIG_KEYGEN_PCT: true
153 MLD_CONFIG_KEYGEN_PCT_BREAKAGE_TEST:
154 content: |
155 #define MLD_CONFIG_KEYGEN_PCT_BREAKAGE_TEST
156 #if !defined(__ASSEMBLER__)
157 #include <stdlib.h>
158 #include <string.h>
159 #include "../mldsa/src/sys.h"
160 static MLD_INLINE int mld_break_pct(void)
161 {
162 /* Break PCT if and only if MLD_BREAK_PCT is set to 1 */
163 const char *val = getenv("MLD_BREAK_PCT");
164 return val != NULL && strcmp(val, "1") == 0;
165 }
166 #endif
167
168 - path: test/configs/custom_native_capability_config_0.h
169 description: "Test configuration with custom capability function returning 0"
170 defines:
171 MLD_CONFIG_CUSTOM_CAPABILITY_FUNC:
172 content: |
173 #define MLD_CONFIG_CUSTOM_CAPABILITY_FUNC
174 #if !defined(__ASSEMBLER__)
175 #include "../mldsa/src/sys.h"
176 /* System capability enumeration */
177
178 static MLD_INLINE int mld_sys_check_capability(mld_sys_cap cap)
179 {
180 (void)cap; /* Ignore parameter */
181 return 0;
182 }
183 #endif /* !__ASSEMBLER__ */
184
185 - path: test/configs/custom_native_capability_config_1.h
186 description: "Test configuration with custom capability function returning 1"
187 defines:
188 MLD_CONFIG_CUSTOM_CAPABILITY_FUNC:
189 content: |
190 #define MLD_CONFIG_CUSTOM_CAPABILITY_FUNC
191 #if !defined(__ASSEMBLER__)
192 #include "../mldsa/src/sys.h"
193
194 static MLD_INLINE int mld_sys_check_capability(mld_sys_cap cap)
195 {
196 (void)cap; /* Ignore parameter */
197 return 1;
198 }
199 #endif /* !__ASSEMBLER__ */
200
201 - path: test/configs/custom_native_capability_config_CPUID_AVX2.h
202 description: "Test configuration with CPUID-based AVX2 capability detection"
203 defines:
204 MLD_CONFIG_CUSTOM_CAPABILITY_FUNC:
205 content: |
206 #define MLD_CONFIG_CUSTOM_CAPABILITY_FUNC
207 #if !defined(__ASSEMBLER__)
208 #include <stdint.h>
209 #include "../mldsa/src/sys.h"
210
211 /* Assert this config is only used on Linux/x86_64 systems */
212 #if !defined(MLD_SYS_X86_64) || !defined(MLD_SYS_LINUX)
213 #error "This configuration is only supported on Linux/x86_64 systems"
214 #endif
215
216 static MLD_INLINE int mld_sys_check_capability(mld_sys_cap cap)
217 {
218 if (cap == MLD_SYS_CAP_AVX2)
219 {
220 uint32_t eax, ebx, ecx, edx;
221
222 /* AVX2 support is queried using `cpuid` with EAX=7, ECX=0.
223 * Check first if `cpuid` supports EAX=7 by calling it with
224 * EAX=0, which gives the maximum supported value of EAX in
225 * EAX. */
226
227 __asm__ volatile("cpuid"
228 : "=a"(eax), "=b"(ebx), "=c"(ecx), "=d"(edx)
229 : "a"(0));
230
231 if (eax < 7)
232 {
233 return 0; /* Extended features not supported */
234 }
235
236 __asm__ volatile("cpuid"
237 : "=a"(eax), "=b"(ebx), "=c"(ecx), "=d"(edx)
238 : "a"(7), "c"(0));
239
240 /* AVX2 is bit 5 in EBX */
241 return (ebx & (1 << 5)) ? 1 : 0;
242 }
243
244 /* Default to 0 (conservative) for unknown capabilities */
245 return 0;
246 }
247 #endif /* !__ASSEMBLER__ */
248
249 - path: test/configs/custom_native_capability_config_ID_AA64PFR1_EL1.h
250 description: "Test configuration with ARM system register capability detection"
251 defines:
252 MLD_CONFIG_CUSTOM_CAPABILITY_FUNC:
253 content: |
254 #define MLD_CONFIG_CUSTOM_CAPABILITY_FUNC
255 #if !defined(__ASSEMBLER__)
256 #include <stdint.h>
257 #include "../mldsa/src/sys.h"
258
259 #if !defined(MLD_SYS_AARCH64) || !defined(MLD_SYS_LINUX)
260 #error This configuration is only suitable for Linux/AArch64 systems
261 #endif
262
263 static MLD_INLINE int mld_sys_check_capability(mld_sys_cap cap)
264 {
265 if (cap == MLD_SYS_CAP_SHA3)
266 {
267 uint64_t id_aa64pfr1_el1;
268
269 /* Read ID_AA64PFR1_EL1 system register */
270 __asm__ volatile("mrs %0, id_aa64pfr1_el1" : "=r"(id_aa64pfr1_el1));
271
272 /* Extract SHA3 field (bits 35:32) and check if SHA3 is supported */
273 /* SHA3 field: 0b0000 = not implemented, 0b0001 = SHA3 implemented */
274 uint64_t sha3_field = (id_aa64pfr1_el1 >> 32) & 0xF;
275
276 return (sha3_field == 1) ? 1 : 0;
277 }
278
279 /* Default to 0 (conservative) for unknown capabilities */
280 return 0;
281 }
282 #endif /* !__ASSEMBLER__ */
283
284
285 # Example configs
286 - path: examples/monolithic_build/mldsa_native/mldsa_native_config.h
287 description: "Monolithic build config"
288 defines:
289 MLD_CONFIG_NAMESPACE_PREFIX: mldsa
290 MLD_CONFIG_INTERNAL_API_QUALIFIER: static
291 MLD_CONFIG_FILE:
292 comment: "/* No need to set this -- we _are_ already in a custom config */"
293
294 - path: examples/monolithic_build_native/mldsa_native/mldsa_native_config.h
295 description: "Monolithic build config (native backends disabled)"
296 defines:
297 MLD_CONFIG_NAMESPACE_PREFIX: mldsa
298 MLD_CONFIG_INTERNAL_API_QUALIFIER: static
299 MLD_CONFIG_FILE:
300 comment: "/* No need to set this -- we _are_ already in a custom config */"
301
302 - path: examples/monolithic_build_multilevel/mldsa_native/mldsa_native_config.h
303 description: "Multilevel monolithic build config"
304 defines:
305 MLD_CONFIG_NO_SUPERCOP: true
306 MLD_CONFIG_MULTILEVEL_BUILD: true
307 MLD_CONFIG_NAMESPACE_PREFIX: mldsa
308 MLD_CONFIG_INTERNAL_API_QUALIFIER: static
309 MLD_CONFIG_FILE:
310 comment: "/* No need to set this -- we _are_ already in a custom config */"
311
312 - path: examples/multilevel_build/mldsa_native/mldsa_native_config.h
313 description: "Multilevel build config"
314 defines:
315 MLD_CONFIG_NO_SUPERCOP: true
316 MLD_CONFIG_MULTILEVEL_BUILD: true
317 MLD_CONFIG_NAMESPACE_PREFIX: mldsa
318 MLD_CONFIG_FILE:
319 comment: "/* No need to set this -- we _are_ already in a custom config */"
320
321 - path: examples/multilevel_build_native/mldsa_native/mldsa_native_config.h
322 description: "Multilevel build config"
323 defines:
324 MLD_CONFIG_NO_SUPERCOP: true
325 MLD_CONFIG_MULTILEVEL_BUILD: true
326 MLD_CONFIG_NAMESPACE_PREFIX: mldsa
327 MLD_CONFIG_USE_NATIVE_BACKEND_ARITH: true
328 MLD_CONFIG_USE_NATIVE_BACKEND_FIPS202: true
329 MLD_CONFIG_FILE:
330 comment: "/* No need to set this -- we _are_ already in a custom config */"
331
332 - path: examples/monolithic_build_multilevel_native/mldsa_native/mldsa_native_config.h
333 description: "Multilevel monolithic build config with native backends"
334 defines:
335 MLD_CONFIG_NO_SUPERCOP: true
336 MLD_CONFIG_MULTILEVEL_BUILD: true
337 MLD_CONFIG_NAMESPACE_PREFIX: mldsa
338 MLD_CONFIG_USE_NATIVE_BACKEND_ARITH: true
339 MLD_CONFIG_USE_NATIVE_BACKEND_FIPS202: true
340 MLD_CONFIG_INTERNAL_API_QUALIFIER: static
341 MLD_CONFIG_EXTERNAL_API_QUALIFIER: static
342 MLD_CONFIG_FILE:
343 comment: "/* No need to set this -- we _are_ already in a custom config */"
344 MLD_CONFIG_CUSTOM_RANDOMBYTES:
345 comment: |
346 /* Even though we use the default randombytes signature here, registering it
347 * as a custom implementation avoids double-declaration of randombytes via
348 * mldsa/src/randombytes.h and test_only_rng/notrandombytes.h: The former is by
349 * default included by mldsa-native, and the latter is needed for this example
350 * since we rely on the additional randombytes_reset() API. */
351 content: |
352 #define MLD_CONFIG_CUSTOM_RANDOMBYTES
353 #if !defined(__ASSEMBLER__)
354 #include <stdint.h>
355 #include "src/sys.h"
356 #include "test_only_rng/notrandombytes.h"
357 static MLD_INLINE int mld_randombytes(uint8_t *ptr, size_t len)
358 {
359 return randombytes(ptr, len);
360 }
361 #endif /* !__ASSEMBLER__ */
362
363 - path: examples/custom_backend/mldsa_native/mldsa_native_config.h
364 description: "Custom backend config with tiny SHA3"
365 defines:
366 MLD_CONFIG_PARAMETER_SET:
367 comment: "/* This is set on the command line */"
368 MLD_CONFIG_USE_NATIVE_BACKEND_ARITH:
369 comment: "/* No native arithmetic backend */"
370 value: false
371 MLD_CONFIG_NAMESPACE_PREFIX: CUSTOM_TINY_SHA3
372 MLD_CONFIG_USE_NATIVE_BACKEND_FIPS202: true
373 MLD_CONFIG_FIPS202_BACKEND_FILE: '"fips202/native/custom/custom.h"'
374 MLD_CONFIG_FILE:
375 comment: "/* No need to set this -- we _are_ already in a custom config */"
376
377 - path: examples/bring_your_own_fips202/mldsa_native/mldsa_native_config.h
378 description: "Configuration for custom FIPS202 implementation"
379 defines:
380 MLD_CONFIG_NAMESPACE_PREFIX: mldsa
381 MLD_CONFIG_FIPS202_CUSTOM_HEADER: "\"../custom_fips202/fips202.h\""
382 MLD_CONFIG_FIPS202X4_CUSTOM_HEADER: "\"../custom_fips202/fips202x4.h\""
383 MLD_CONFIG_FILE:
384 comment: "/* No need to set this -- we _are_ already in a custom config */"
385
386 - path: examples/bring_your_own_fips202_static/mldsa_native/mldsa_native_config.h
387 description: "Configuration for custom serial FIPS202 implementation"
388 defines:
389 MLD_CONFIG_NAMESPACE_PREFIX: mldsa
390 MLD_CONFIG_SERIAL_FIPS202_ONLY: true
391 MLD_CONFIG_FIPS202_CUSTOM_HEADER: "\"../custom_fips202/fips202.h\""
392 MLD_CONFIG_FIPS202X4_CUSTOM_HEADER: "\"../custom_fips202/fips202x4.h\""
393 MLD_CONFIG_FILE:
394 comment: "/* No need to set this -- we _are_ already in a custom config */"
395
396 - path: examples/basic_deterministic/mldsa_native/mldsa_native_config.h
397 description: "Configuration for deterministic-only build of mldsa-native"
398 defines:
399 MLD_CONFIG_NAMESPACE_PREFIX: mldsa
400 MLD_CONFIG_NO_RANDOMIZED_API: true
401 MLD_CONFIG_FILE:
402 comment: "/* No need to set this -- we _are_ already in a custom config */"
403
404 - path: examples/basic_lowram/mldsa_native/mldsa_native_config.h
405 description: "Configuration for low RAM build of mldsa-native"
406 defines:
407 MLD_CONFIG_NAMESPACE_PREFIX: mldsa
408 MLD_CONFIG_REDUCE_RAM:
409 content: |
410 #if !defined(MLD_CONFIG_REDUCE_RAM)
411 #define MLD_CONFIG_REDUCE_RAM
412 #endif
413 MLD_CONFIG_FILE:
414 comment: "/* No need to set this -- we _are_ already in a custom config */"
415
416 - path: test/configs/test_alloc_config.h
417 description: "Using custom allocation that can be made fail at specific invocation"
418 defines:
419 MLD_CONFIG_NAMESPACE_PREFIX: mld
420 MLD_CONFIG_CONTEXT_PARAMETER: true
421 MLD_CONFIG_CONTEXT_PARAMETER_TYPE: struct test_ctx_t *
422 MLD_CONFIG_CUSTOM_ALLOC_FREE:
423 content: |
424 #define MLD_CONFIG_CUSTOM_ALLOC_FREE
425 #if !defined(__ASSEMBLER__)
426 #include <stdlib.h>
427 struct test_ctx_t; /* Forward declaration */
428 void * custom_alloc(struct test_ctx_t *ctx, size_t sz, const char *file, int line, const char *var, const char *type);
429 void custom_free(struct test_ctx_t *ctx, void *p, size_t sz, const char *file, int line, const char *var, const char *type);
430 #define MLD_CUSTOM_ALLOC(v, T, N, ctx) T *v = custom_alloc(ctx, sizeof(T)*(N), __FILE__, __LINE__, #v, #T)
431 #define MLD_CUSTOM_FREE(v, T, N, ctx) custom_free(ctx, v, sizeof(T)*(N), __FILE__, __LINE__, #v, #T)
432 #endif /* !__ASSEMBLER__ */
433 MLD_CONFIG_FILE:
434 comment: "/* No need to set this -- we _are_ already in a custom config */"
435