pq_crypto 0.6.2 → 0.6.3

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.
Files changed (113) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -0
  3. data/ext/pqcrypto/pqcrypto_version.h +1 -1
  4. data/ext/pqcrypto/vendor/.vendored +4 -4
  5. data/ext/pqcrypto/vendor/mlkem-native/README.md +6 -3
  6. data/ext/pqcrypto/vendor/mlkem-native/RELEASE.md +22 -0
  7. data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native.c +77 -36
  8. data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native.h +135 -146
  9. data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native_asm.S +116 -72
  10. data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native_config.h +351 -415
  11. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/cbmc.h +43 -20
  12. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/common.h +16 -8
  13. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/compress.c +57 -31
  14. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/compress.h +260 -349
  15. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/debug.h +17 -24
  16. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/fips202.c +35 -37
  17. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/fips202.h +43 -57
  18. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/fips202x4.c +14 -15
  19. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/fips202x4.h +5 -4
  20. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/keccakf1600.c +42 -6
  21. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/fips202_native_aarch64.h +31 -20
  22. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/{keccak_f1600_x1_scalar_asm.S → keccak_f1600_x1_scalar_aarch64_asm.S} +10 -10
  23. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/{keccak_f1600_x1_v84a_asm.S → keccak_f1600_x1_v84a_aarch64_asm.S} +10 -10
  24. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/{keccak_f1600_x2_v84a_asm.S → keccak_f1600_x2_v84a_aarch64_asm.S} +10 -10
  25. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/{keccak_f1600_x4_v8a_scalar_hybrid_asm.S → keccak_f1600_x4_v8a_scalar_hybrid_aarch64_asm.S} +10 -10
  26. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/{keccak_f1600_x4_v8a_v84a_scalar_hybrid_asm.S → keccak_f1600_x4_v8a_v84a_scalar_hybrid_aarch64_asm.S} +10 -10
  27. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccakf1600_round_constants.c +10 -9
  28. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x1_scalar.h +2 -1
  29. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x1_v84a.h +1 -1
  30. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x2_v84a.h +4 -2
  31. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x4_v8a_scalar.h +2 -2
  32. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x4_v8a_v84a_scalar.h +1 -1
  33. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/fips202_native_armv81m.h +2 -1
  34. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.S +55 -9
  35. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/keccakf1600_round_constants.c +26 -25
  36. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/state_extract_bytes_x4_mve.S +58 -14
  37. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/state_xor_bytes_x4_mve.S +57 -16
  38. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/auto.h +2 -1
  39. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/keccak_f1600_x4_avx2.h +2 -2
  40. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/src/fips202_native_x86_64.h +10 -7
  41. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/src/{keccak_f1600_x4_avx2.S → keccak_f1600_x4_avx2_asm.S} +13 -11
  42. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/src/keccakf1600_constants.c +12 -11
  43. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/indcpa.c +167 -136
  44. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/indcpa.h +75 -68
  45. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/kem.h +135 -157
  46. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/meta.h +15 -13
  47. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/aarch64_zetas.c +143 -135
  48. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/arith_native_aarch64.h +52 -46
  49. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{intt.S → intt_aarch64_asm.S} +10 -10
  50. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{ntt.S → ntt_aarch64_asm.S} +10 -10
  51. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{poly_mulcache_compute_asm.S → poly_mulcache_compute_aarch64_asm.S} +10 -10
  52. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{poly_reduce_asm.S → poly_reduce_aarch64_asm.S} +10 -10
  53. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{poly_tobytes_asm.S → poly_tobytes_aarch64_asm.S} +10 -10
  54. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{poly_tomont_asm.S → poly_tomont_aarch64_asm.S} +10 -12
  55. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{polyvec_basemul_acc_montgomery_cached_asm_k2.S → polyvec_basemul_acc_montgomery_cached_k2_aarch64_asm.S} +10 -10
  56. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{polyvec_basemul_acc_montgomery_cached_asm_k3.S → polyvec_basemul_acc_montgomery_cached_k3_aarch64_asm.S} +10 -10
  57. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{polyvec_basemul_acc_montgomery_cached_asm_k4.S → polyvec_basemul_acc_montgomery_cached_k4_aarch64_asm.S} +10 -10
  58. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{rej_uniform_asm.S → rej_uniform_aarch64_asm.S} +12 -12
  59. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/rej_uniform_table.c +514 -513
  60. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/api.h +254 -253
  61. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/meta.h +6 -1
  62. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/README.md +6 -0
  63. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/meta.h +77 -0
  64. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/arith_native_ppc64le.h +24 -0
  65. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/consts.c +299 -0
  66. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/consts.h +34 -0
  67. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/intt_ppc_asm.S +3222 -0
  68. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/ntt_ppc_asm.S +1651 -0
  69. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/poly_tomont_ppc_asm.S +294 -0
  70. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/reduce_ppc_asm.S +710 -0
  71. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/meta.h +5 -0
  72. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/rv64v_debug.c +18 -16
  73. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/rv64v_debug.h +19 -24
  74. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/rv64v_poly.c +53 -65
  75. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/meta.h +20 -20
  76. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/arith_native_x86_64.h +106 -88
  77. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/compress_consts.c +45 -35
  78. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/compress_consts.h +8 -8
  79. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/consts.c +1 -1
  80. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/consts.h +1 -1
  81. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{intt.S → intt_avx2_asm.S} +8 -8
  82. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{ntt.S → ntt_avx2_asm.S} +8 -8
  83. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{nttfrombytes.S → nttfrombytes_avx2_asm.S} +8 -8
  84. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{ntttobytes.S → ntttobytes_avx2_asm.S} +8 -8
  85. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{nttunpack.S → nttunpack_avx2_asm.S} +8 -8
  86. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{poly_compress_d10.S → poly_compress_d10_avx2_asm.S} +9 -9
  87. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{poly_compress_d11.S → poly_compress_d11_avx2_asm.S} +9 -9
  88. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{poly_compress_d4.S → poly_compress_d4_avx2_asm.S} +9 -9
  89. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{poly_compress_d5.S → poly_compress_d5_avx2_asm.S} +9 -9
  90. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{poly_decompress_d10.S → poly_decompress_d10_avx2_asm.S} +9 -9
  91. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{poly_decompress_d11.S → poly_decompress_d11_avx2_asm.S} +9 -9
  92. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{poly_decompress_d4.S → poly_decompress_d4_avx2_asm.S} +9 -9
  93. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{poly_decompress_d5.S → poly_decompress_d5_avx2_asm.S} +9 -9
  94. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{mulcache_compute.S → poly_mulcache_compute_avx2_asm.S} +8 -8
  95. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{polyvec_basemul_acc_montgomery_cached_asm_k2.S → polyvec_basemul_acc_montgomery_cached_k2_avx2_asm.S} +8 -8
  96. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{polyvec_basemul_acc_montgomery_cached_asm_k3.S → polyvec_basemul_acc_montgomery_cached_k3_avx2_asm.S} +8 -8
  97. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{polyvec_basemul_acc_montgomery_cached_asm_k4.S → polyvec_basemul_acc_montgomery_cached_k4_avx2_asm.S} +8 -8
  98. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{reduce.S → reduce_avx2_asm.S} +8 -8
  99. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{rej_uniform_asm.S → rej_uniform_avx2_asm.S} +9 -9
  100. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/rej_uniform_table.c +514 -513
  101. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{tomont.S → tomont_avx2_asm.S} +8 -8
  102. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/poly.c +61 -57
  103. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/poly.h +89 -116
  104. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/poly_k.c +31 -32
  105. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/poly_k.h +226 -301
  106. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/randombytes.h +21 -29
  107. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/sampling.c +68 -63
  108. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/sampling.h +37 -48
  109. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/sys.h +44 -2
  110. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/verify.h +141 -159
  111. data/lib/pq_crypto/version.rb +1 -1
  112. data/script/vendor_libs.rb +3 -3
  113. metadata +47 -38
@@ -21,137 +21,119 @@
21
21
  #ifndef MLK_CONFIG_H
22
22
  #define MLK_CONFIG_H
23
23
 
24
- /******************************************************************************
25
- * Name: MLK_CONFIG_PARAMETER_SET
26
- *
27
- * Description: Specifies the parameter set for ML-KEM
28
- * - MLK_CONFIG_PARAMETER_SET=512 corresponds to ML-KEM-512
29
- * - MLK_CONFIG_PARAMETER_SET=768 corresponds to ML-KEM-768
30
- * - MLK_CONFIG_PARAMETER_SET=1024 corresponds to ML-KEM-1024
31
- *
32
- * If you want to support multiple parameter sets, build the
33
- * library multiple times and set MLK_CONFIG_MULTILEVEL_BUILD.
34
- * See MLK_CONFIG_MULTILEVEL_BUILD for how to do this while
35
- * minimizing code duplication.
24
+ /**
25
+ * Specifies the parameter set for ML-KEM:
26
+ * - MLK_CONFIG_PARAMETER_SET=512 corresponds to ML-KEM-512
27
+ * - MLK_CONFIG_PARAMETER_SET=768 corresponds to ML-KEM-768
28
+ * - MLK_CONFIG_PARAMETER_SET=1024 corresponds to ML-KEM-1024
36
29
  *
37
- * This can also be set using CFLAGS.
30
+ * If you want to support multiple parameter sets, build the library multiple
31
+ * times and set MLK_CONFIG_MULTILEVEL_BUILD. See MLK_CONFIG_MULTILEVEL_BUILD
32
+ * for how to do this while minimizing code duplication.
38
33
  *
39
- *****************************************************************************/
34
+ * This can also be set using CFLAGS.
35
+ */
40
36
  #ifndef MLK_CONFIG_PARAMETER_SET
41
37
  #define MLK_CONFIG_PARAMETER_SET \
42
38
  768 /* Change this for different security strengths */
43
39
  #endif
44
40
 
45
- /******************************************************************************
46
- * Name: MLK_CONFIG_FILE
47
- *
48
- * Description: If defined, this is a header that will be included instead
49
- * of the default configuration file mlkem/mlkem_native_config.h.
41
+ /**
42
+ * MLK_CONFIG_FILE
50
43
  *
51
- * When you need to build mlkem-native in multiple configurations,
52
- * using varying MLK_CONFIG_FILE can be more convenient
53
- * then configuring everything through CFLAGS.
44
+ * If defined, this is a header that will be included instead of the default
45
+ * configuration file mlkem/mlkem_native_config.h.
54
46
  *
55
- * To use, MLK_CONFIG_FILE _must_ be defined prior
56
- * to the inclusion of any mlkem-native headers. For example,
57
- * it can be set by passing `-DMLK_CONFIG_FILE="..."`
58
- * on the command line.
47
+ * When you need to build mlkem-native in multiple configurations, using
48
+ * varying MLK_CONFIG_FILE can be more convenient than configuring everything
49
+ * through CFLAGS.
59
50
  *
60
- *****************************************************************************/
51
+ * To use, MLK_CONFIG_FILE _must_ be defined prior to the inclusion of any
52
+ * mlkem-native headers. For example, it can be set by passing
53
+ * `-DMLK_CONFIG_FILE="..."` on the command line.
54
+ */
61
55
  /* #define MLK_CONFIG_FILE "mlkem_native_config.h" */
62
56
 
63
- /******************************************************************************
64
- * Name: MLK_CONFIG_NAMESPACE_PREFIX
65
- *
66
- * Description: The prefix to use to namespace global symbols from mlkem/.
57
+ /**
58
+ * The prefix to use to namespace global symbols from mlkem/.
67
59
  *
68
- * In a multi-level build, level-dependent symbols will
69
- * additionally be prefixed with the parameter set (512/768/1024).
60
+ * In a multi-level build, level-dependent symbols will additionally be
61
+ * prefixed with the parameter set (512/768/1024).
70
62
  *
71
- * This can also be set using CFLAGS.
72
- *
73
- *****************************************************************************/
63
+ * This can also be set using CFLAGS.
64
+ */
74
65
  #if !defined(MLK_CONFIG_NAMESPACE_PREFIX)
75
66
  #define MLK_CONFIG_NAMESPACE_PREFIX MLK_DEFAULT_NAMESPACE_PREFIX
76
67
  #endif
77
68
 
78
- /******************************************************************************
79
- * Name: MLK_CONFIG_MULTILEVEL_BUILD
69
+ /**
70
+ * MLK_CONFIG_MULTILEVEL_BUILD
80
71
  *
81
- * Description: Set this if the build is part of a multi-level build supporting
82
- * multiple parameter sets.
72
+ * Set this if the build is part of a multi-level build supporting multiple
73
+ * parameter sets.
83
74
  *
84
- * If you need only a single parameter set, keep this unset.
75
+ * If you need only a single parameter set, keep this unset.
85
76
  *
86
- * To build mlkem-native with support for all parameter sets,
87
- * build it three times -- once per parameter set -- and set the
88
- * option MLK_CONFIG_MULTILEVEL_WITH_SHARED for exactly one of
89
- * them, and MLK_CONFIG_MULTILEVEL_NO_SHARED for the others.
90
- * MLK_CONFIG_MULTILEVEL_BUILD should be set for all of them.
77
+ * To build mlkem-native with support for all parameter sets, build it three
78
+ * times -- once per parameter set -- and set the option
79
+ * MLK_CONFIG_MULTILEVEL_WITH_SHARED for exactly one of them, and
80
+ * MLK_CONFIG_MULTILEVEL_NO_SHARED for the others.
81
+ * MLK_CONFIG_MULTILEVEL_BUILD should be set for all of them.
91
82
  *
92
- * See examples/multilevel_build for an example.
83
+ * See examples/multilevel_build for an example.
93
84
  *
94
- * This can also be set using CFLAGS.
95
- *
96
- *****************************************************************************/
85
+ * This can also be set using CFLAGS.
86
+ */
97
87
  /* #define MLK_CONFIG_MULTILEVEL_BUILD */
98
88
 
99
- /******************************************************************************
100
- * Name: MLK_CONFIG_EXTERNAL_API_QUALIFIER
89
+ /**
90
+ * MLK_CONFIG_EXTERNAL_API_QUALIFIER
101
91
  *
102
- * Description: If set, this option provides an additional function
103
- * qualifier to be added to declarations of mlkem-native's
104
- * public API.
92
+ * If set, this option provides an additional function qualifier to be added
93
+ * to declarations of mlkem-native's public API.
105
94
  *
106
- * The primary use case for this option are single-CU builds
107
- * where the public API exposed by mlkem-native is wrapped by
108
- * another API in the consuming application. In this case,
109
- * even mlkem-native's public API can be marked `static`.
110
- *
111
- *****************************************************************************/
95
+ * The primary use case for this option are single-CU builds where the public
96
+ * API exposed by mlkem-native is wrapped by another API in the consuming
97
+ * application. In this case, even mlkem-native's public API can be marked
98
+ * `static`.
99
+ */
112
100
  /* #define MLK_CONFIG_EXTERNAL_API_QUALIFIER */
113
101
 
114
- /******************************************************************************
115
- * Name: MLK_CONFIG_NO_RANDOMIZED_API
102
+ /**
103
+ * MLK_CONFIG_NO_RANDOMIZED_API
116
104
  *
117
- * Description: If this option is set, mlkem-native will be built without the
118
- * randomized API functions (crypto_kem_keypair and
119
- * crypto_kem_enc).
120
- * This allows users to build mlkem-native without providing a
121
- * randombytes() implementation if they only need the
122
- * deterministic API
123
- * (crypto_kem_keypair_derand, crypto_kem_enc_derand,
124
- * crypto_kem_dec).
105
+ * If this option is set, mlkem-native will be built without the randomized
106
+ * API functions (crypto_kem_keypair and crypto_kem_enc). This allows users
107
+ * to build mlkem-native without providing a randombytes() implementation
108
+ * if they only need the deterministic API (crypto_kem_keypair_derand,
109
+ * crypto_kem_enc_derand, crypto_kem_dec).
125
110
  *
126
- * NOTE: This option is incompatible with MLK_CONFIG_KEYGEN_PCT
127
- * as the current PCT implementation requires crypto_kem_enc().
128
- *
129
- *****************************************************************************/
111
+ * @note This option is incompatible with MLK_CONFIG_KEYGEN_PCT as the
112
+ * current PCT implementation requires crypto_kem_enc().
113
+ */
130
114
  /* #define MLK_CONFIG_NO_RANDOMIZED_API */
131
115
 
132
- /******************************************************************************
133
- * Name: MLK_CONFIG_NO_SUPERCOP
116
+ /**
117
+ * MLK_CONFIG_NO_SUPERCOP
134
118
  *
135
- * Description: By default, mlkem_native.h exposes the mlkem-native API in the
136
- * SUPERCOP naming convention (crypto_kem_xxx). If you don't need
137
- * this, set MLK_CONFIG_NO_SUPERCOP.
119
+ * By default, mlkem_native.h exposes the mlkem-native API in the SUPERCOP
120
+ * naming convention (crypto_kem_xxx). If you don't need this, set
121
+ * MLK_CONFIG_NO_SUPERCOP.
138
122
  *
139
- * NOTE: You must set this for a multi-level build as the SUPERCOP
140
- * naming does not disambiguate between the parameter sets.
141
- *
142
- *****************************************************************************/
123
+ * @note You must set this for a multi-level build as the SUPERCOP naming
124
+ * does not disambiguate between the parameter sets.
125
+ */
143
126
  /* #define MLK_CONFIG_NO_SUPERCOP */
144
127
 
145
- /******************************************************************************
146
- * Name: MLK_CONFIG_CONSTANTS_ONLY
128
+ /**
129
+ * MLK_CONFIG_CONSTANTS_ONLY
147
130
  *
148
- * Description: If you only need the size constants (MLKEM_PUBLICKEYBYTES, etc.)
149
- * but no function declarations, set MLK_CONFIG_CONSTANTS_ONLY.
131
+ * If you only need the size constants (MLKEM_PUBLICKEYBYTES, etc.) but no
132
+ * function declarations, set MLK_CONFIG_CONSTANTS_ONLY.
150
133
  *
151
- * This only affects the public header mlkem_native.h, not
152
- * the implementation.
153
- *
154
- *****************************************************************************/
134
+ * This only affects the public header mlkem_native.h, not the
135
+ * implementation.
136
+ */
155
137
  /* #define MLK_CONFIG_CONSTANTS_ONLY */
156
138
 
157
139
  /******************************************************************************
@@ -164,216 +146,193 @@
164
146
  *****************************************************************************/
165
147
 
166
148
  #if defined(MLK_BUILD_INTERNAL)
167
- /******************************************************************************
168
- * Name: MLK_CONFIG_MULTILEVEL_WITH_SHARED
149
+ /**
150
+ * MLK_CONFIG_MULTILEVEL_WITH_SHARED
169
151
  *
170
- * Description: This is for multi-level builds of mlkem-native only. If you
171
- * need only a single parameter set, keep this unset.
152
+ * This is for multi-level builds of mlkem-native only. If you need only a
153
+ * single parameter set, keep this unset.
172
154
  *
173
- * If this is set, all MLK_CONFIG_PARAMETER_SET-independent
174
- * code will be included in the build, including code needed only
175
- * for other parameter sets.
155
+ * If this is set, all MLK_CONFIG_PARAMETER_SET-independent code will be
156
+ * included in the build, including code needed only for other parameter
157
+ * sets.
176
158
  *
177
- * Example: mlk_poly_cbd3 is only needed for
178
- * MLK_CONFIG_PARAMETER_SET == 512. Yet, if this option is set
179
- * for a build with MLK_CONFIG_PARAMETER_SET == 768/1024, it
180
- * would be included.
159
+ * Example: mlk_poly_cbd3 is only needed for MLK_CONFIG_PARAMETER_SET == 512.
160
+ * Yet, if this option is set for a build with
161
+ * MLK_CONFIG_PARAMETER_SET == 768/1024, it would be included.
181
162
  *
182
- * To build mlkem-native with support for all parameter sets,
183
- * build it three times -- once per parameter set -- and set the
184
- * option MLK_CONFIG_MULTILEVEL_WITH_SHARED for exactly one of
185
- * them, and MLK_CONFIG_MULTILEVEL_NO_SHARED for the others.
186
- * MLK_CONFIG_MULTILEVEL_BUILD should be set for all of them.
163
+ * To build mlkem-native with support for all parameter sets, build it three
164
+ * times -- once per parameter set -- and set the option
165
+ * MLK_CONFIG_MULTILEVEL_WITH_SHARED for exactly one of them, and
166
+ * MLK_CONFIG_MULTILEVEL_NO_SHARED for the others.
167
+ * MLK_CONFIG_MULTILEVEL_BUILD should be set for all of them.
187
168
  *
188
- * See examples/multilevel_build for an example.
169
+ * See examples/multilevel_build for an example.
189
170
  *
190
- * This can also be set using CFLAGS.
191
- *
192
- *****************************************************************************/
171
+ * This can also be set using CFLAGS.
172
+ */
193
173
  /* #define MLK_CONFIG_MULTILEVEL_WITH_SHARED */
194
174
 
195
- /******************************************************************************
196
- * Name: MLK_CONFIG_MULTILEVEL_NO_SHARED
175
+ /**
176
+ * MLK_CONFIG_MULTILEVEL_NO_SHARED
197
177
  *
198
- * Description: This is for multi-level builds of mlkem-native only. If you
199
- * need only a single parameter set, keep this unset.
178
+ * This is for multi-level builds of mlkem-native only. If you need only a
179
+ * single parameter set, keep this unset.
200
180
  *
201
- * If this is set, no MLK_CONFIG_PARAMETER_SET-independent code
202
- * will be included in the build.
181
+ * If this is set, no MLK_CONFIG_PARAMETER_SET-independent code will be
182
+ * included in the build.
203
183
  *
204
- * To build mlkem-native with support for all parameter sets,
205
- * build it three times -- once per parameter set -- and set the
206
- * option MLK_CONFIG_MULTILEVEL_WITH_SHARED for exactly one of
207
- * them, and MLK_CONFIG_MULTILEVEL_NO_SHARED for the others.
208
- * MLK_CONFIG_MULTILEVEL_BUILD should be set for all of them.
184
+ * To build mlkem-native with support for all parameter sets, build it three
185
+ * times -- once per parameter set -- and set the option
186
+ * MLK_CONFIG_MULTILEVEL_WITH_SHARED for exactly one of them, and
187
+ * MLK_CONFIG_MULTILEVEL_NO_SHARED for the others.
188
+ * MLK_CONFIG_MULTILEVEL_BUILD should be set for all of them.
209
189
  *
210
- * See examples/multilevel_build for an example.
190
+ * See examples/multilevel_build for an example.
211
191
  *
212
- * This can also be set using CFLAGS.
213
- *
214
- *****************************************************************************/
192
+ * This can also be set using CFLAGS.
193
+ */
215
194
  /* #define MLK_CONFIG_MULTILEVEL_NO_SHARED */
216
195
 
217
- /******************************************************************************
218
- * Name: MLK_CONFIG_MONOBUILD_KEEP_SHARED_HEADERS
196
+ /**
197
+ * MLK_CONFIG_MONOBUILD_KEEP_SHARED_HEADERS
219
198
  *
220
- * Description: This is only relevant for single compilation unit (SCU)
221
- * builds of mlkem-native. In this case, it determines whether
222
- * directives defined in parameter-set-independent headers should
223
- * be #undef'ined or not at the of the SCU file. This is needed
224
- * in multilevel builds.
199
+ * This is only relevant for single compilation unit (SCU) builds of
200
+ * mlkem-native. In this case, it determines whether directives defined in
201
+ * parameter-set-independent headers should be #undef'ined or not at the
202
+ * end of the SCU file. This is needed in multilevel builds.
225
203
  *
226
- * See examples/multilevel_build_native for an example.
204
+ * See examples/multilevel_build_native for an example.
227
205
  *
228
- * This can also be set using CFLAGS.
229
- *
230
- *****************************************************************************/
206
+ * This can also be set using CFLAGS.
207
+ */
231
208
  /* #define MLK_CONFIG_MONOBUILD_KEEP_SHARED_HEADERS */
232
209
 
233
- /******************************************************************************
234
- * Name: MLK_CONFIG_USE_NATIVE_BACKEND_ARITH
210
+ /**
211
+ * MLK_CONFIG_USE_NATIVE_BACKEND_ARITH
235
212
  *
236
- * Description: Determines whether an native arithmetic backend should be used.
213
+ * Determines whether a native arithmetic backend should be used.
237
214
  *
238
- * The arithmetic backend covers performance critical functions
239
- * such as the number-theoretic transform (NTT).
215
+ * The arithmetic backend covers performance-critical functions such as the
216
+ * number-theoretic transform (NTT).
240
217
  *
241
- * If this option is unset, the C backend will be used.
218
+ * If this option is unset, the C backend will be used.
242
219
  *
243
- * If this option is set, the arithmetic backend to be use is
244
- * determined by MLK_CONFIG_ARITH_BACKEND_FILE: If the latter is
245
- * unset, the default backend for your the target architecture
246
- * will be used. If set, it must be the name of a backend metadata
247
- * file.
220
+ * If this option is set, the arithmetic backend to be used is determined
221
+ * by MLK_CONFIG_ARITH_BACKEND_FILE: if the latter is unset, the default
222
+ * backend for the target architecture will be used. If set, it must be the
223
+ * name of a backend metadata file.
248
224
  *
249
- * This can also be set using CFLAGS.
250
- *
251
- *****************************************************************************/
225
+ * This can also be set using CFLAGS.
226
+ */
252
227
  #if !defined(MLK_CONFIG_USE_NATIVE_BACKEND_ARITH)
253
228
  /* #define MLK_CONFIG_USE_NATIVE_BACKEND_ARITH */
254
229
  #endif
255
230
 
256
- /******************************************************************************
257
- * Name: MLK_CONFIG_ARITH_BACKEND_FILE
231
+ /**
232
+ * MLK_CONFIG_ARITH_BACKEND_FILE
258
233
  *
259
- * Description: The arithmetic backend to use.
234
+ * The arithmetic backend to use.
260
235
  *
261
- * If MLK_CONFIG_USE_NATIVE_BACKEND_ARITH is unset, this option
262
- * is ignored.
236
+ * If MLK_CONFIG_USE_NATIVE_BACKEND_ARITH is unset, this option is ignored.
263
237
  *
264
- * If MLK_CONFIG_USE_NATIVE_BACKEND_ARITH is set, this option must
265
- * either be undefined or the filename of an arithmetic backend.
266
- * If unset, the default backend will be used.
238
+ * If MLK_CONFIG_USE_NATIVE_BACKEND_ARITH is set, this option must either
239
+ * be undefined or the filename of an arithmetic backend. If unset, the
240
+ * default backend will be used.
267
241
  *
268
- * This can be set using CFLAGS.
269
- *
270
- *****************************************************************************/
242
+ * This can be set using CFLAGS.
243
+ */
271
244
  #if defined(MLK_CONFIG_USE_NATIVE_BACKEND_ARITH) && \
272
245
  !defined(MLK_CONFIG_ARITH_BACKEND_FILE)
273
246
  #define MLK_CONFIG_ARITH_BACKEND_FILE "native/meta.h"
274
247
  #endif
275
248
 
276
- /******************************************************************************
277
- * Name: MLK_CONFIG_USE_NATIVE_BACKEND_FIPS202
249
+ /**
250
+ * MLK_CONFIG_USE_NATIVE_BACKEND_FIPS202
278
251
  *
279
- * Description: Determines whether an native FIPS202 backend should be used.
252
+ * Determines whether a native FIPS202 backend should be used.
280
253
  *
281
- * The FIPS202 backend covers 1x/2x/4x-fold Keccak-f1600, which is
282
- * the performance bottleneck of SHA3 and SHAKE.
254
+ * The FIPS202 backend covers 1x/2x/4x-fold Keccak-f1600, which is the
255
+ * performance bottleneck of SHA3 and SHAKE.
283
256
  *
284
- * If this option is unset, the C backend will be used.
257
+ * If this option is unset, the C backend will be used.
285
258
  *
286
- * If this option is set, the FIPS202 backend to be use is
287
- * determined by MLK_CONFIG_FIPS202_BACKEND_FILE: If the latter is
288
- * unset, the default backend for your the target architecture
289
- * will be used. If set, it must be the name of a backend metadata
290
- * file.
259
+ * If this option is set, the FIPS202 backend to be used is determined by
260
+ * MLK_CONFIG_FIPS202_BACKEND_FILE: if the latter is unset, the default
261
+ * backend for the target architecture will be used. If set, it must be
262
+ * the name of a backend metadata file.
291
263
  *
292
- * This can also be set using CFLAGS.
293
- *
294
- *****************************************************************************/
264
+ * This can also be set using CFLAGS.
265
+ */
295
266
  #if !defined(MLK_CONFIG_USE_NATIVE_BACKEND_FIPS202)
296
267
  /* #define MLK_CONFIG_USE_NATIVE_BACKEND_FIPS202 */
297
268
  #endif
298
269
 
299
- /******************************************************************************
300
- * Name: MLK_CONFIG_FIPS202_BACKEND_FILE
270
+ /**
271
+ * MLK_CONFIG_FIPS202_BACKEND_FILE
301
272
  *
302
- * Description: The FIPS-202 backend to use.
273
+ * The FIPS-202 backend to use.
303
274
  *
304
- * If MLK_CONFIG_USE_NATIVE_BACKEND_FIPS202 is set, this option
305
- * must either be undefined or the filename of a FIPS202 backend.
306
- * If unset, the default backend will be used.
275
+ * If MLK_CONFIG_USE_NATIVE_BACKEND_FIPS202 is set, this option must either
276
+ * be undefined or the filename of a FIPS202 backend. If unset, the default
277
+ * backend will be used.
307
278
  *
308
- * This can be set using CFLAGS.
309
- *
310
- *****************************************************************************/
279
+ * This can be set using CFLAGS.
280
+ */
311
281
  #if defined(MLK_CONFIG_USE_NATIVE_BACKEND_FIPS202) && \
312
282
  !defined(MLK_CONFIG_FIPS202_BACKEND_FILE)
313
283
  #define MLK_CONFIG_FIPS202_BACKEND_FILE "fips202/native/auto.h"
314
284
  #endif
315
285
 
316
- /******************************************************************************
317
- * Name: MLK_CONFIG_FIPS202_CUSTOM_HEADER
286
+ /**
287
+ * MLK_CONFIG_FIPS202_CUSTOM_HEADER
318
288
  *
319
- * Description: Custom header to use for FIPS-202
289
+ * Custom header to use for FIPS-202.
320
290
  *
321
- * This should only be set if you intend to use a custom
322
- * FIPS-202 implementation, different from the one shipped
323
- * with mlkem-native.
291
+ * This should only be set if you intend to use a custom FIPS-202
292
+ * implementation, different from the one shipped with mlkem-native.
324
293
  *
325
- * If set, it must be the name of a file serving as the
326
- * replacement for mlkem/fips202/fips202.h, and exposing
327
- * the same API (see FIPS202.md).
328
- *
329
- *****************************************************************************/
294
+ * If set, it must be the name of a file serving as the replacement for
295
+ * mlkem/fips202/fips202.h, and exposing the same API (see FIPS202.md).
296
+ */
330
297
  /* #define MLK_CONFIG_FIPS202_CUSTOM_HEADER "SOME_FILE.h" */
331
298
 
332
- /******************************************************************************
333
- * Name: MLK_CONFIG_FIPS202X4_CUSTOM_HEADER
334
- *
335
- * Description: Custom header to use for FIPS-202-X4
299
+ /**
300
+ * MLK_CONFIG_FIPS202X4_CUSTOM_HEADER
336
301
  *
337
- * This should only be set if you intend to use a custom
338
- * FIPS-202 implementation, different from the one shipped
339
- * with mlkem-native.
302
+ * Custom header to use for FIPS-202-X4.
340
303
  *
341
- * If set, it must be the name of a file serving as the
342
- * replacement for mlkem/fips202/fips202x4.h, and exposing
343
- * the same API (see FIPS202.md).
304
+ * This should only be set if you intend to use a custom FIPS-202
305
+ * implementation, different from the one shipped with mlkem-native.
344
306
  *
345
- *****************************************************************************/
307
+ * If set, it must be the name of a file serving as the replacement for
308
+ * mlkem/fips202/fips202x4.h, and exposing the same API (see FIPS202.md).
309
+ */
346
310
  /* #define MLK_CONFIG_FIPS202X4_CUSTOM_HEADER "SOME_FILE.h" */
347
311
 
348
- /******************************************************************************
349
- * Name: MLK_CONFIG_CUSTOM_ZEROIZE
350
- *
351
- * Description: In compliance with @[FIPS203, Section 3.3], mlkem-native
352
- * zeroizes intermediate stack buffers before returning from
353
- * function calls.
354
- *
355
- * Set this option and define `mlk_zeroize` if you want to
356
- * use a custom method to zeroize intermediate stack buffers.
357
- * The default implementation uses SecureZeroMemory on Windows
358
- * and a memset + compiler barrier otherwise. If neither of those
359
- * is available on the target platform, compilation will fail,
360
- * and you will need to use MLK_CONFIG_CUSTOM_ZEROIZE to provide
361
- * a custom implementation of `mlk_zeroize()`.
362
- *
363
- * WARNING:
364
- * The explicit stack zeroization conducted by mlkem-native
365
- * reduces the likelihood of data leaking on the stack, but
366
- * does not eliminate it! The C standard makes no guarantee about
367
- * where a compiler allocates structures and whether/where it makes
368
- * copies of them. Also, in addition to entire structures, there
369
- * may also be potentially exploitable leakage of individual values
370
- * on the stack.
371
- *
372
- * If you need bullet-proof zeroization of the stack, you need to
373
- * consider additional measures instead of of what this feature
374
- * provides. In this case, you can set mlk_zeroize to a no-op.
375
- *
376
- *****************************************************************************/
312
+ /**
313
+ * MLK_CONFIG_CUSTOM_ZEROIZE
314
+ *
315
+ * In compliance with @[FIPS203, Section 3.3], mlkem-native zeroizes
316
+ * intermediate stack buffers before returning from function calls.
317
+ *
318
+ * Set this option and define `mlk_zeroize` if you want to use a custom
319
+ * method to zeroize intermediate stack buffers. The default implementation
320
+ * uses SecureZeroMemory on Windows and a memset + compiler barrier
321
+ * otherwise. If neither of those is available on the target platform,
322
+ * compilation will fail, and you will need to use MLK_CONFIG_CUSTOM_ZEROIZE
323
+ * to provide a custom implementation of `mlk_zeroize()`.
324
+ *
325
+ * @warning The explicit stack zeroization conducted by mlkem-native reduces
326
+ * the likelihood of data leaking on the stack, but does not
327
+ * eliminate it. The C standard makes no guarantee about where a
328
+ * compiler allocates structures and whether/where it makes copies
329
+ * of them. Also, in addition to entire structures, there may also
330
+ * be potentially exploitable leakage of individual values on the
331
+ * stack. If you need bullet-proof zeroization of the stack, you
332
+ * need to consider additional measures instead of what this
333
+ * feature provides. In this case, you can set mlk_zeroize to a
334
+ * no-op.
335
+ */
377
336
  /* #define MLK_CONFIG_CUSTOM_ZEROIZE
378
337
  #if !defined(__ASSEMBLER__)
379
338
  #include <stdint.h>
@@ -385,24 +344,21 @@
385
344
  #endif
386
345
  */
387
346
 
388
- /******************************************************************************
389
- * Name: MLK_CONFIG_CUSTOM_RANDOMBYTES
390
- *
391
- * Description: mlkem-native does not provide a secure randombytes
392
- * implementation. Such an implementation has to be provided by the
393
- * consumer.
347
+ /**
348
+ * MLK_CONFIG_CUSTOM_RANDOMBYTES
394
349
  *
395
- * If this option is not set, mlkem-native expects a function
396
- * int randombytes(uint8_t *out, size_t outlen).
397
- * It is expected to return zero on success, and non-zero on
398
- * failure. In case of failure, the top level APIs will return a
399
- * MLK_ERR_RNG_FAIL error code.
350
+ * mlkem-native does not provide a secure randombytes implementation. Such
351
+ * an implementation has to be provided by the consumer.
400
352
  *
401
- * Set this option and define `mlk_randombytes` (with the same
402
- * signature and behaviour) if you want to use a custom method to
403
- * sample randombytes with a different name or signature.
353
+ * If this option is not set, mlkem-native expects a function
354
+ * int randombytes(uint8_t *out, size_t outlen). It is expected to return
355
+ * zero on success, and non-zero on failure. In case of failure, the
356
+ * top-level APIs will return an MLK_ERR_RNG_FAIL error code.
404
357
  *
405
- *****************************************************************************/
358
+ * Set this option and define `mlk_randombytes` (with the same signature
359
+ * and behaviour) if you want to use a custom method to sample randombytes
360
+ * with a different name or signature.
361
+ */
406
362
  /* #define MLK_CONFIG_CUSTOM_RANDOMBYTES
407
363
  #if !defined(__ASSEMBLER__)
408
364
  #include <stdint.h>
@@ -415,28 +371,26 @@
415
371
  #endif
416
372
  */
417
373
 
418
- /******************************************************************************
419
- * Name: MLK_CONFIG_CUSTOM_CAPABILITY_FUNC
420
- *
421
- * Description: mlkem-native backends may rely on specific hardware features.
422
- * Those backends will only be included in an mlkem-native build
423
- * if support for the respective features is enabled at
424
- * compile-time. However, when building for a heteroneous set
425
- * of CPUs to run the resulting binary/library on, feature
426
- * detection at _runtime_ is needed to decided whether a backend
427
- * can be used or not.
374
+ /**
375
+ * MLK_CONFIG_CUSTOM_CAPABILITY_FUNC
428
376
  *
429
- * Set this option and define `mlk_sys_check_capability` if you
430
- * want to use a custom method to dispatch between implementations.
377
+ * mlkem-native backends may rely on specific hardware features. Those
378
+ * backends will only be included in an mlkem-native build if support for
379
+ * the respective features is enabled at compile-time. However, when
380
+ * building for a heterogeneous set of CPUs to run the resulting
381
+ * binary/library on, feature detection at _runtime_ is needed to decide
382
+ * whether a backend can be used or not.
431
383
  *
432
- * If this option is not set, mlkem-native uses compile-time
433
- * feature detection only to decide which backend to use.
384
+ * Set this option and define `mlk_sys_check_capability` if you want to
385
+ * use a custom method to dispatch between implementations.
434
386
  *
435
- * If you compile mlkem-native on a system with different
436
- * capabilities than the system that the resulting binary/library
437
- * will be run on, you must use this option.
387
+ * If this option is not set, mlkem-native uses compile-time feature
388
+ * detection only to decide which backend to use.
438
389
  *
439
- *****************************************************************************/
390
+ * If you compile mlkem-native on a system with different capabilities
391
+ * than the system that the resulting binary/library will be run on, you
392
+ * must use this option.
393
+ */
440
394
  /* #define MLK_CONFIG_CUSTOM_CAPABILITY_FUNC
441
395
  static MLK_INLINE int mlk_sys_check_capability(mlk_sys_cap cap)
442
396
  __contract__(
@@ -447,42 +401,39 @@
447
401
  }
448
402
  */
449
403
 
450
- /******************************************************************************
451
- * Name: MLK_CONFIG_CUSTOM_ALLOC_FREE [EXPERIMENTAL]
452
- *
453
- * Description: Set this option and define `MLK_CUSTOM_ALLOC` and
454
- * `MLK_CUSTOM_FREE` if you want to use custom allocation for
455
- * large local structures or buffers.
404
+ /**
405
+ * MLK_CONFIG_CUSTOM_ALLOC_FREE [EXPERIMENTAL]
456
406
  *
457
- * By default, all buffers/structures are allocated on the stack.
458
- * If this option is set, most of them will be allocated via
459
- * MLK_CUSTOM_ALLOC.
407
+ * Set this option and define `MLK_CUSTOM_ALLOC` and `MLK_CUSTOM_FREE` if
408
+ * you want to use custom allocation for large local structures or buffers.
460
409
  *
461
- * Parameters to MLK_CUSTOM_ALLOC:
462
- * - T* v: Target pointer to declare.
463
- * - T: Type of structure to be allocated
464
- * - N: Number of elements to be allocated.
410
+ * By default, all buffers/structures are allocated on the stack. If this
411
+ * option is set, most of them will be allocated via MLK_CUSTOM_ALLOC.
465
412
  *
466
- * Parameters to MLK_CUSTOM_FREE:
467
- * - T* v: Target pointer to free. May be NULL.
468
- * - T: Type of structure to be freed.
469
- * - N: Number of elements to be freed.
413
+ * Parameters to MLK_CUSTOM_ALLOC:
414
+ * - T* v: Target pointer to declare.
415
+ * - T: Type of structure to be allocated.
416
+ * - N: Number of elements to be allocated.
470
417
  *
471
- * WARNING: This option is experimental!
472
- * Its scope, configuration and function/macro signatures may
473
- * change at any time. We expect a stable API for v2.
418
+ * Parameters to MLK_CUSTOM_FREE:
419
+ * - T* v: Target pointer to free. May be NULL.
420
+ * - T: Type of structure to be freed.
421
+ * - N: Number of elements to be freed.
474
422
  *
475
- * NOTE: Even if this option is set, some allocations further down
476
- * the call stack will still be made from the stack, consuming up
477
- * to 3KB of stack space. Those will likely be added to the scope
478
- * of this option in the future.
423
+ * @warning This option is experimental. Its scope, configuration and
424
+ * function/macro signatures may change at any time. We expect a
425
+ * stable API for v2.
479
426
  *
480
- * NOTE: MLK_CUSTOM_ALLOC need not guarantee a successful
481
- * allocation nor include error handling. Upon failure, the
482
- * target pointer should simply be set to NULL. The calling
483
- * code will handle this case and invoke MLK_CUSTOM_FREE.
427
+ * @note Even if this option is set, some allocations further down the call
428
+ * stack will still be made from the stack, consuming up to 3KB of
429
+ * stack space. Those will likely be added to the scope of this
430
+ * option in the future.
484
431
  *
485
- *****************************************************************************/
432
+ * @note MLK_CUSTOM_ALLOC need not guarantee a successful allocation nor
433
+ * include error handling. Upon failure, the target pointer should
434
+ * simply be set to NULL. The calling code will handle this case and
435
+ * invoke MLK_CUSTOM_FREE.
436
+ */
486
437
  /* #define MLK_CONFIG_CUSTOM_ALLOC_FREE
487
438
  #if !defined(__ASSEMBLER__)
488
439
  #include <stdlib.h>
@@ -493,18 +444,16 @@
493
444
  #endif
494
445
  */
495
446
 
496
- /******************************************************************************
497
- * Name: MLK_CONFIG_CUSTOM_MEMCPY
498
- *
499
- * Description: Set this option and define `mlk_memcpy` if you want to
500
- * use a custom method to copy memory instead of the standard
501
- * library memcpy function.
447
+ /**
448
+ * MLK_CONFIG_CUSTOM_MEMCPY
502
449
  *
503
- * The custom implementation must have the same signature and
504
- * behavior as the standard memcpy function:
505
- * void *mlk_memcpy(void *dest, const void *src, size_t n)
450
+ * Set this option and define `mlk_memcpy` if you want to use a custom
451
+ * method to copy memory instead of the standard library memcpy function.
506
452
  *
507
- *****************************************************************************/
453
+ * The custom implementation must have the same signature and behavior as
454
+ * the standard memcpy function:
455
+ * void *mlk_memcpy(void *dest, const void *src, size_t n)
456
+ */
508
457
  /* #define MLK_CONFIG_CUSTOM_MEMCPY
509
458
  #if !defined(__ASSEMBLER__)
510
459
  #include <stdint.h>
@@ -516,18 +465,16 @@
516
465
  #endif
517
466
  */
518
467
 
519
- /******************************************************************************
520
- * Name: MLK_CONFIG_CUSTOM_MEMSET
521
- *
522
- * Description: Set this option and define `mlk_memset` if you want to
523
- * use a custom method to set memory instead of the standard
524
- * library memset function.
468
+ /**
469
+ * MLK_CONFIG_CUSTOM_MEMSET
525
470
  *
526
- * The custom implementation must have the same signature and
527
- * behavior as the standard memset function:
528
- * void *mlk_memset(void *s, int c, size_t n)
471
+ * Set this option and define `mlk_memset` if you want to use a custom
472
+ * method to set memory instead of the standard library memset function.
529
473
  *
530
- *****************************************************************************/
474
+ * The custom implementation must have the same signature and behavior as
475
+ * the standard memset function:
476
+ * void *mlk_memset(void *s, int c, size_t n)
477
+ */
531
478
  /* #define MLK_CONFIG_CUSTOM_MEMSET
532
479
  #if !defined(__ASSEMBLER__)
533
480
  #include <stdint.h>
@@ -539,94 +486,86 @@
539
486
  #endif
540
487
  */
541
488
 
542
- /******************************************************************************
543
- * Name: MLK_CONFIG_INTERNAL_API_QUALIFIER
544
- *
545
- * Description: If set, this option provides an additional function
546
- * qualifier to be added to declarations of internal API.
489
+ /**
490
+ * MLK_CONFIG_INTERNAL_API_QUALIFIER
547
491
  *
548
- * The primary use case for this option are single-CU builds,
549
- * in which case this option can be set to `static`.
492
+ * If set, this option provides an additional qualifier to be added to
493
+ * declarations of internal API functions and data.
550
494
  *
551
- *****************************************************************************/
495
+ * The primary use case for this option are single-CU builds, in which case
496
+ * this option can be set to `static`.
497
+ */
552
498
  /* #define MLK_CONFIG_INTERNAL_API_QUALIFIER */
553
499
 
554
- /******************************************************************************
555
- * Name: MLK_CONFIG_CT_TESTING_ENABLED
556
- *
557
- * Description: If set, mlkem-native annotates data as secret / public using
558
- * valgrind's annotations VALGRIND_MAKE_MEM_UNDEFINED and
559
- * VALGRIND_MAKE_MEM_DEFINED, enabling various checks for secret-
560
- * dependent control flow of variable time execution (depending
561
- * on the exact version of valgrind installed).
500
+ /**
501
+ * MLK_CONFIG_CT_TESTING_ENABLED
562
502
  *
563
- *****************************************************************************/
503
+ * If set, mlkem-native annotates data as secret/public using valgrind's
504
+ * annotations VALGRIND_MAKE_MEM_UNDEFINED and VALGRIND_MAKE_MEM_DEFINED,
505
+ * enabling various checks for secret-dependent control flow or
506
+ * variable-time execution (depending on the exact version of valgrind
507
+ * installed).
508
+ */
564
509
  /* #define MLK_CONFIG_CT_TESTING_ENABLED */
565
510
 
566
- /******************************************************************************
567
- * Name: MLK_CONFIG_NO_ASM
568
- *
569
- * Description: If this option is set, mlkem-native will be built without
570
- * use of native code or inline assembly.
511
+ /**
512
+ * MLK_CONFIG_NO_ASM
571
513
  *
572
- * By default, inline assembly is used to implement value barriers.
573
- * Without inline assembly, mlkem-native will use a global volatile
574
- * 'opt blocker' instead; see verify.h.
514
+ * If this option is set, mlkem-native will be built without use of native
515
+ * code or inline assembly.
575
516
  *
576
- * Inline assembly is also used to implement a secure zeroization
577
- * function on non-Windows platforms. If this option is set and
578
- * the target platform is not Windows, you MUST set
579
- * MLK_CONFIG_CUSTOM_ZEROIZE and provide a custom zeroization
580
- * function.
517
+ * By default, inline assembly is used to implement value barriers. Without
518
+ * inline assembly, mlkem-native will use a global volatile 'opt blocker'
519
+ * instead; see verify.h.
581
520
  *
582
- * If this option is set, MLK_CONFIG_USE_NATIVE_BACKEND_FIPS202 and
583
- * and MLK_CONFIG_USE_NATIVE_BACKEND_ARITH will be ignored, and no
584
- * native backends will be used.
521
+ * Inline assembly is also used to implement a secure zeroization function
522
+ * on non-Windows platforms. If this option is set and the target platform
523
+ * is not Windows, you MUST set MLK_CONFIG_CUSTOM_ZEROIZE and provide a
524
+ * custom zeroization function.
585
525
  *
586
- *****************************************************************************/
526
+ * If this option is set, MLK_CONFIG_USE_NATIVE_BACKEND_FIPS202 and
527
+ * MLK_CONFIG_USE_NATIVE_BACKEND_ARITH will be ignored, and no native
528
+ * backends will be used.
529
+ */
587
530
  /* #define MLK_CONFIG_NO_ASM */
588
531
 
589
- /******************************************************************************
590
- * Name: MLK_CONFIG_NO_ASM_VALUE_BARRIER
591
- *
592
- * Description: If this option is set, mlkem-native will be built without
593
- * use of native code or inline assembly for value barriers.
532
+ /**
533
+ * MLK_CONFIG_NO_ASM_VALUE_BARRIER
594
534
  *
595
- * By default, inline assembly (if available) is used to implement
596
- * value barriers.
597
- * Without inline assembly, mlkem-native will use a global volatile
598
- * 'opt blocker' instead; see verify.h.
535
+ * If this option is set, mlkem-native will be built without use of native
536
+ * code or inline assembly for value barriers.
599
537
  *
600
- *****************************************************************************/
601
- /* #define MLk_CONFIG_NO_ASM_VALUE_BARRIER */
538
+ * By default, inline assembly (if available) is used to implement value
539
+ * barriers. Without inline assembly, mlkem-native will use a global
540
+ * volatile 'opt blocker' instead; see verify.h.
541
+ */
542
+ /* #define MLK_CONFIG_NO_ASM_VALUE_BARRIER */
602
543
 
603
- /******************************************************************************
604
- * Name: MLK_CONFIG_KEYGEN_PCT
605
- *
606
- * Description: Compliance with @[FIPS140_3_IG, p.87] requires a
607
- * Pairwise Consistency Test (PCT) to be carried out on a freshly
608
- * generated keypair before it can be exported.
544
+ /**
545
+ * MLK_CONFIG_KEYGEN_PCT
609
546
  *
610
- * Set this option if such a check should be implemented.
611
- * In this case, crypto_kem_keypair_derand and crypto_kem_keypair
612
- * will return a non-zero error code if the PCT failed.
547
+ * Compliance with @[FIPS140_3_IG, p.87] requires a Pairwise Consistency
548
+ * Test (PCT) to be carried out on a freshly generated keypair before it
549
+ * can be exported.
613
550
  *
614
- * NOTE: This feature will drastically lower the performance of
615
- * key generation.
551
+ * Set this option if such a check should be implemented. In this case,
552
+ * crypto_kem_keypair_derand and crypto_kem_keypair will return a non-zero
553
+ * error code if the PCT failed.
616
554
  *
617
- *****************************************************************************/
555
+ * @note This feature will drastically lower the performance of key
556
+ * generation.
557
+ */
618
558
  /* #define MLK_CONFIG_KEYGEN_PCT */
619
559
 
620
- /******************************************************************************
621
- * Name: MLK_CONFIG_KEYGEN_PCT_BREAKAGE_TEST
622
- *
623
- * Description: If this option is set, the user must provide a runtime
624
- * function `static inline int mlk_break_pct() { ... }` to
625
- * indicate whether the PCT should be made fail.
560
+ /**
561
+ * MLK_CONFIG_KEYGEN_PCT_BREAKAGE_TEST
626
562
  *
627
- * This option only has an effect if MLK_CONFIG_KEYGEN_PCT is set.
563
+ * If this option is set, the user must provide a runtime function
564
+ * `static inline int mlk_break_pct() { ... }` to indicate whether the PCT
565
+ * should be made to fail.
628
566
  *
629
- *****************************************************************************/
567
+ * This option only has an effect if MLK_CONFIG_KEYGEN_PCT is set.
568
+ */
630
569
  /* #define MLK_CONFIG_KEYGEN_PCT_BREAKAGE_TEST
631
570
  #if !defined(__ASSEMBLER__)
632
571
  #include "src/sys.h"
@@ -637,49 +576,46 @@
637
576
  #endif
638
577
  */
639
578
 
640
- /******************************************************************************
641
- * Name: MLK_CONFIG_SERIAL_FIPS202_ONLY
642
- *
643
- * Description: Set this to use a FIPS202 implementation with global state
644
- * that supports only one active Keccak computation at a time
645
- * (e.g. some hardware accelerators).
579
+ /**
580
+ * MLK_CONFIG_SERIAL_FIPS202_ONLY
646
581
  *
647
- * If this option is set, batched Keccak operations are
648
- * disabled for rejection sampling during matrix generation.
649
- * Instead, matrix entries will be generated one at a time.
582
+ * Set this to use a FIPS202 implementation with global state that supports
583
+ * only one active Keccak computation at a time (e.g. some hardware
584
+ * accelerators).
650
585
  *
651
- * This allows offloading Keccak computations to a hardware
652
- * accelerator that holds only a single Keccak state locally,
653
- * rather than requiring support for batched (4x) Keccak states.
586
+ * If this option is set, batched Keccak operations are disabled for
587
+ * rejection sampling during matrix generation. Instead, matrix entries
588
+ * will be generated one at a time.
654
589
  *
655
- * NOTE: Depending on the target CPU, disabling batched Keccak
656
- * may reduce performance when using software FIPS202
657
- * implementations. Only enable this when you have to.
590
+ * This allows offloading Keccak computations to a hardware accelerator
591
+ * that holds only a single Keccak state locally, rather than requiring
592
+ * support for batched (4x) Keccak states.
658
593
  *
659
- *****************************************************************************/
594
+ * @note Depending on the target CPU, disabling batched Keccak may reduce
595
+ * performance when using software FIPS202 implementations. Only
596
+ * enable this when you have to.
597
+ */
660
598
  /* #define MLK_CONFIG_SERIAL_FIPS202_ONLY */
661
599
 
662
- /******************************************************************************
663
- * Name: MLK_CONFIG_CONTEXT_PARAMETER
664
- *
665
- * Description: Set this to add a context parameter that is provided to public
666
- * API functions and is then available in custom callbacks.
600
+ /**
601
+ * MLK_CONFIG_CONTEXT_PARAMETER
667
602
  *
668
- * The type of the context parameter is configured via
669
- * MLK_CONFIG_CONTEXT_PARAMETER_TYPE.
603
+ * Set this to add a context parameter that is provided to public API
604
+ * functions and is then available in custom callbacks.
670
605
  *
671
- *****************************************************************************/
606
+ * The type of the context parameter is configured via
607
+ * MLK_CONFIG_CONTEXT_PARAMETER_TYPE.
608
+ */
672
609
  /* #define MLK_CONFIG_CONTEXT_PARAMETER */
673
610
 
674
- /******************************************************************************
675
- * Name: MLK_CONFIG_CONTEXT_PARAMETER_TYPE
676
- *
677
- * Description: Set this to define the type for the context parameter used by
678
- * MLK_CONFIG_CONTEXT_PARAMETER.
611
+ /**
612
+ * MLK_CONFIG_CONTEXT_PARAMETER_TYPE
679
613
  *
680
- * This is only relevant if MLK_CONFIG_CONTEXT_PARAMETER is set.
614
+ * Set this to define the type for the context parameter used by
615
+ * MLK_CONFIG_CONTEXT_PARAMETER.
681
616
  *
682
- *****************************************************************************/
617
+ * This is only relevant if MLK_CONFIG_CONTEXT_PARAMETER is set.
618
+ */
683
619
  /* #define MLK_CONFIG_CONTEXT_PARAMETER_TYPE void* */
684
620
 
685
621
  /************************* Config internals ********************************/