Skip to content

Commit 4702ea7

Browse files
committed
config.h: Align the divergence between mldsa-native and mlkem-native in config.h
Signed-off-by: willieyz <[email protected]>
1 parent 1e4c7d6 commit 4702ea7

File tree

1 file changed

+104
-103
lines changed

1 file changed

+104
-103
lines changed

mldsa/src/config.h

Lines changed: 104 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,24 @@
3737
44 /* Change this for different security strengths */
3838
#endif
3939

40+
/******************************************************************************
41+
* Name: MLD_CONFIG_FILE
42+
*
43+
* Description: If defined, this is a header that will be included instead
44+
* of the default configuration file mldsa/src/config.h.
45+
*
46+
* When you need to build mldsa-native in multiple configurations,
47+
* using varying MLD_CONFIG_FILE can be more convenient
48+
* then configuring everything through CFLAGS.
49+
*
50+
* To use, MLD_CONFIG_FILE _must_ be defined prior
51+
* to the inclusion of any mldsa-native headers. For example,
52+
* it can be set by passing `-DMLD_CONFIG_FILE="..."`
53+
* on the command line.
54+
*
55+
*****************************************************************************/
56+
/* #define MLD_CONFIG_FILE "config.h" */
57+
4058
/******************************************************************************
4159
* Name: MLD_CONFIG_NAMESPACE_PREFIX
4260
*
@@ -100,23 +118,6 @@
100118
*****************************************************************************/
101119
/* #define MLD_CONFIG_MULTILEVEL_NO_SHARED */
102120

103-
/******************************************************************************
104-
* Name: MLD_CONFIG_FILE
105-
*
106-
* Description: If defined, this is a header that will be included instead
107-
* of the default configuration file mldsa/src/config.h.
108-
*
109-
* When you need to build mldsa-native in multiple configurations,
110-
* using varying MLD_CONFIG_FILE can be more convenient
111-
* then configuring everything through CFLAGS.
112-
*
113-
* To use, MLD_CONFIG_FILE _must_ be defined prior
114-
* to the inclusion of any mldsa-native headers. For example,
115-
* it can be set by passing `-DMLD_CONFIG_FILE="..."`
116-
* on the command line.
117-
*
118-
*****************************************************************************/
119-
/* #define MLD_CONFIG_FILE "config.h" */
120121

121122
/******************************************************************************
122123
* Name: MLD_CONFIG_USE_NATIVE_BACKEND_ARITH
@@ -200,6 +201,7 @@
200201
!defined(MLD_CONFIG_FIPS202_BACKEND_FILE)
201202
#define MLD_CONFIG_FIPS202_BACKEND_FILE "fips202/native/auto.h"
202203
#endif
204+
203205
/******************************************************************************
204206
* Name: MLD_CONFIG_FIPS202_CUSTOM_HEADER
205207
*
@@ -273,52 +275,6 @@
273275
#endif
274276
*/
275277

276-
/******************************************************************************
277-
* Name: MLD_CONFIG_CUSTOM_MEMCPY
278-
*
279-
* Description: Set this option and define `mld_memcpy` if you want to
280-
* use a custom method to copy memory instead of the standard
281-
* library memcpy function.
282-
*
283-
* The custom implementation must have the same signature and
284-
* behavior as the standard memcpy function:
285-
* void *mld_memcpy(void *dest, const void *src, size_t n)
286-
*
287-
*****************************************************************************/
288-
/* #define MLD_CONFIG_CUSTOM_MEMCPY
289-
#if !defined(__ASSEMBLER__)
290-
#include <stdint.h>
291-
#include "sys.h"
292-
static MLD_INLINE void *mld_memcpy(void *dest, const void *src, size_t n)
293-
{
294-
... your implementation ...
295-
}
296-
#endif
297-
*/
298-
299-
/******************************************************************************
300-
* Name: MLD_CONFIG_CUSTOM_MEMSET
301-
*
302-
* Description: Set this option and define `mld_memset` if you want to
303-
* use a custom method to set memory instead of the standard
304-
* library memset function.
305-
*
306-
* The custom implementation must have the same signature and
307-
* behavior as the standard memset function:
308-
* void *mld_memset(void *s, int c, size_t n)
309-
*
310-
*****************************************************************************/
311-
/* #define MLD_CONFIG_CUSTOM_MEMSET
312-
#if !defined(__ASSEMBLER__)
313-
#include <stdint.h>
314-
#include "sys.h"
315-
static MLD_INLINE void *mld_memset(void *s, int c, size_t n)
316-
{
317-
... your implementation ...
318-
}
319-
#endif
320-
*/
321-
322278
/******************************************************************************
323279
* Name: MLD_CONFIG_CUSTOM_RANDOMBYTES
324280
*
@@ -345,7 +301,6 @@
345301
#endif
346302
*/
347303

348-
349304
/******************************************************************************
350305
* Name: MLD_CONFIG_CUSTOM_CAPABILITY_FUNC
351306
*
@@ -376,58 +331,47 @@
376331
*/
377332

378333
/******************************************************************************
379-
* Name: MLD_CONFIG_NO_RANDOMIZED_API
380-
*
381-
* Description: If this option is set, mldsa-native will be built without the
382-
* randomized API functions (crypto_sign_keypair,
383-
* crypto_sign, crypto_sign_signature, and
384-
* crypto_sign_signature_extmu).
385-
* This allows users to build mldsa-native without providing a
386-
* randombytes() implementation if they only need the
387-
* internal deterministic API
388-
* (crypto_sign_keypair_internal, crypto_sign_signature_internal).
389-
*
390-
* NOTE: This option is incompatible with MLD_CONFIG_KEYGEN_PCT
391-
* as the current PCT implementation requires
392-
* crypto_sign_signature().
393-
*
394-
*****************************************************************************/
395-
/* #define MLD_CONFIG_NO_RANDOMIZED_API */
396-
397-
/******************************************************************************
398-
* Name: MLD_CONFIG_KEYGEN_PCT
399-
*
400-
* Description: Compliance with @[FIPS140_3_IG, p.87] requires a
401-
* Pairwise Consistency Test (PCT) to be carried out on a freshly
402-
* generated keypair before it can be exported.
334+
* Name: MLD_CONFIG_CUSTOM_MEMCPY
403335
*
404-
* Set this option if such a check should be implemented.
405-
* In this case, crypto_sign_keypair_internal and
406-
* crypto_sign_keypair will return a non-zero error code if the
407-
* PCT failed.
336+
* Description: Set this option and define `mld_memcpy` if you want to
337+
* use a custom method to copy memory instead of the standard
338+
* library memcpy function.
408339
*
409-
* NOTE: This feature will drastically lower the performance of
410-
* key generation.
340+
* The custom implementation must have the same signature and
341+
* behavior as the standard memcpy function:
342+
* void *mld_memcpy(void *dest, const void *src, size_t n)
411343
*
412344
*****************************************************************************/
413-
/* #define MLD_CONFIG_KEYGEN_PCT */
345+
/* #define MLD_CONFIG_CUSTOM_MEMCPY
346+
#if !defined(__ASSEMBLER__)
347+
#include <stdint.h>
348+
#include "sys.h"
349+
static MLD_INLINE void *mld_memcpy(void *dest, const void *src, size_t n)
350+
{
351+
... your implementation ...
352+
}
353+
#endif
354+
*/
414355

415356
/******************************************************************************
416-
* Name: MLD_CONFIG_KEYGEN_PCT_BREAKAGE_TEST
357+
* Name: MLD_CONFIG_CUSTOM_MEMSET
417358
*
418-
* Description: If this option is set, the user must provide a runtime
419-
* function `static inline int mld_break_pct() { ... }` to
420-
* indicate whether the PCT should be made fail.
359+
* Description: Set this option and define `mld_memset` if you want to
360+
* use a custom method to set memory instead of the standard
361+
* library memset function.
421362
*
422-
* This option only has an effect if MLD_CONFIG_KEYGEN_PCT is set.
363+
* The custom implementation must have the same signature and
364+
* behavior as the standard memset function:
365+
* void *mld_memset(void *s, int c, size_t n)
423366
*
424367
*****************************************************************************/
425-
/* #define MLD_CONFIG_KEYGEN_PCT_BREAKAGE_TEST
368+
/* #define MLD_CONFIG_CUSTOM_MEMSET
426369
#if !defined(__ASSEMBLER__)
370+
#include <stdint.h>
427371
#include "sys.h"
428-
static MLD_INLINE int mld_break_pct(void)
372+
static MLD_INLINE void *mld_memset(void *s, int c, size_t n)
429373
{
430-
... return 0/1 depending on whether PCT should be broken ...
374+
... your implementation ...
431375
}
432376
#endif
433377
*/
@@ -508,6 +452,63 @@
508452
*****************************************************************************/
509453
/* #define MLD_CONFIG_NO_ASM_VALUE_BARRIER */
510454

455+
/******************************************************************************
456+
* Name: MLD_CONFIG_NO_RANDOMIZED_API
457+
*
458+
* Description: If this option is set, mldsa-native will be built without the
459+
* randomized API functions (crypto_sign_keypair,
460+
* crypto_sign, crypto_sign_signature, and
461+
* crypto_sign_signature_extmu).
462+
* This allows users to build mldsa-native without providing a
463+
* randombytes() implementation if they only need the
464+
* internal deterministic API
465+
* (crypto_sign_keypair_internal, crypto_sign_signature_internal).
466+
*
467+
* NOTE: This option is incompatible with MLD_CONFIG_KEYGEN_PCT
468+
* as the current PCT implementation requires
469+
* crypto_sign_signature().
470+
*
471+
*****************************************************************************/
472+
/* #define MLD_CONFIG_NO_RANDOMIZED_API */
473+
474+
/******************************************************************************
475+
* Name: MLD_CONFIG_KEYGEN_PCT
476+
*
477+
* Description: Compliance with @[FIPS140_3_IG, p.87] requires a
478+
* Pairwise Consistency Test (PCT) to be carried out on a freshly
479+
* generated keypair before it can be exported.
480+
*
481+
* Set this option if such a check should be implemented.
482+
* In this case, crypto_sign_keypair_internal and
483+
* crypto_sign_keypair will return a non-zero error code if the
484+
* PCT failed.
485+
*
486+
* NOTE: This feature will drastically lower the performance of
487+
* key generation.
488+
*
489+
*****************************************************************************/
490+
/* #define MLD_CONFIG_KEYGEN_PCT */
491+
492+
/******************************************************************************
493+
* Name: MLD_CONFIG_KEYGEN_PCT_BREAKAGE_TEST
494+
*
495+
* Description: If this option is set, the user must provide a runtime
496+
* function `static inline int mld_break_pct() { ... }` to
497+
* indicate whether the PCT should be made fail.
498+
*
499+
* This option only has an effect if MLD_CONFIG_KEYGEN_PCT is set.
500+
*
501+
*****************************************************************************/
502+
/* #define MLD_CONFIG_KEYGEN_PCT_BREAKAGE_TEST
503+
#if !defined(__ASSEMBLER__)
504+
#include "sys.h"
505+
static MLD_INLINE int mld_break_pct(void)
506+
{
507+
... return 0/1 depending on whether PCT should be broken ...
508+
}
509+
#endif
510+
*/
511+
511512
/******************************************************************************
512513
* Name: MLD_CONFIG_SERIAL_FIPS202_ONLY
513514
*

0 commit comments

Comments
 (0)