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
@@ -3,6 +3,15 @@
3
3
  * SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
4
4
  */
5
5
 
6
+ /* References
7
+ * ==========
8
+ *
9
+ * - [FIPS203]
10
+ * FIPS 203 Module-Lattice-Based Key-Encapsulation Mechanism Standard
11
+ * National Institute of Standards and Technology
12
+ * https://csrc.nist.gov/pubs/fips/203/final
13
+ */
14
+
6
15
  #ifndef MLK_NATIVE_API_H
7
16
  #define MLK_NATIVE_API_H
8
17
  /*
@@ -68,20 +77,20 @@
68
77
  */
69
78
 
70
79
  #if defined(MLK_USE_NATIVE_NTT)
71
- /*************************************************
72
- * Name: mlk_ntt_native
80
+ /**
81
+ * Compute the negacyclic number-theoretic transform (NTT) of a polynomial
82
+ * in place.
73
83
  *
74
- * Description: Computes negacyclic number-theoretic transform (NTT) of
75
- * a polynomial in place.
84
+ * The input polynomial is assumed to be in normal order. The output
85
+ * polynomial is in bitreversed order, or of a custom order if
86
+ * MLK_USE_NATIVE_NTT_CUSTOM_ORDER is set. See the documentation of
87
+ * MLK_USE_NATIVE_NTT_CUSTOM_ORDER for more information.
76
88
  *
77
- * The input polynomial is assumed to be in normal order.
78
- * The output polynomial is in bitreversed order, or of a
79
- * custom order if MLK_USE_NATIVE_NTT_CUSTOM_ORDER is set.
80
- * See the documentation of MLK_USE_NATIVE_NTT_CUSTOM_ORDER
81
- * for more information.
89
+ * @param[in,out] p Input/output polynomial.
82
90
  *
83
- * Arguments: - int16_t p[MLKEM_N]: pointer to in/output polynomial
84
- **************************************************/
91
+ * @retval MLK_NATIVE_FUNC_SUCCESS Operation succeeded.
92
+ * @retval MLK_NATIVE_FUNC_FALLBACK Backend declined; caller should fall back.
93
+ */
85
94
  MLK_MUST_CHECK_RETURN_VALUE
86
95
  static MLK_INLINE int mlk_ntt_native(int16_t p[MLKEM_N])
87
96
  __contract__(
@@ -115,18 +124,16 @@ and to/from bytes conversions."
115
124
  !MLK_USE_NATIVE_POLYVEC_BASEMUL_ACC_MONTGOMERY_CACHED || \
116
125
  !MLK_USE_NATIVE_POLY_TOBYTES || !MLK_USE_NATIVE_POLY_FROMBYTES */
117
126
 
118
- /*************************************************
119
- * Name: mlk_poly_permute_bitrev_to_custom
120
- *
121
- * Description: When MLK_USE_NATIVE_NTT_CUSTOM_ORDER is defined,
122
- * convert a polynomial in NTT domain from bitreversed
123
- * order to the custom order output by the native NTT.
127
+ /**
128
+ * When MLK_USE_NATIVE_NTT_CUSTOM_ORDER is defined, convert a polynomial in
129
+ * NTT domain from bitreversed order to the custom order output by the
130
+ * native NTT.
124
131
  *
125
- * This must only be defined if there is native code for
126
- * all of (a) NTT, (b) invNTT, (c) basemul, (d) mulcache.
127
- * Arguments: - int16_t p[MLKEM_N]: pointer to in/output polynomial
132
+ * This must only be defined if there is native code for all of (a) NTT,
133
+ * (b) invNTT, (c) basemul, (d) mulcache.
128
134
  *
129
- **************************************************/
135
+ * @param[in,out] p Input/output polynomial.
136
+ */
130
137
  static MLK_INLINE void mlk_poly_permute_bitrev_to_custom(int16_t p[MLKEM_N])
131
138
  __contract__(
132
139
  /* We don't specify that this should be a permutation, but only
@@ -138,20 +145,20 @@ __contract__(
138
145
  #endif /* MLK_USE_NATIVE_NTT_CUSTOM_ORDER */
139
146
 
140
147
  #if defined(MLK_USE_NATIVE_INTT)
141
- /*************************************************
142
- * Name: mlk_intt_native
148
+ /**
149
+ * Compute the inverse negacyclic number-theoretic transform (NTT) of a
150
+ * polynomial in place.
143
151
  *
144
- * Description: Computes inverse of negacyclic number-theoretic transform (NTT)
145
- * of a polynomial in place.
152
+ * The input polynomial is in bitreversed order, or of a custom order if
153
+ * MLK_USE_NATIVE_NTT_CUSTOM_ORDER is set. See the documentation of
154
+ * MLK_USE_NATIVE_NTT_CUSTOM_ORDER for more information. The output
155
+ * polynomial is assumed to be in normal order.
146
156
  *
147
- * The input polynomial is in bitreversed order, or of a
148
- * custom order if MLK_USE_NATIVE_NTT_CUSTOM_ORDER is set.
149
- * See the documentation of MLK_USE_NATIVE_NTT_CUSTOM_ORDER
150
- * for more information.
151
- * The output polynomial is assumed to be in normal order.
157
+ * @param[in,out] p Input/output polynomial.
152
158
  *
153
- * Arguments: - uint16_t *a: pointer to in/output polynomial
154
- **************************************************/
159
+ * @retval MLK_NATIVE_FUNC_SUCCESS Operation succeeded.
160
+ * @retval MLK_NATIVE_FUNC_FALLBACK Backend declined; caller should fall back.
161
+ */
155
162
  MLK_MUST_CHECK_RETURN_VALUE
156
163
  static MLK_INLINE int mlk_intt_native(int16_t p[MLKEM_N])
157
164
  __contract__(
@@ -164,13 +171,15 @@ __contract__(
164
171
  #endif /* MLK_USE_NATIVE_INTT */
165
172
 
166
173
  #if defined(MLK_USE_NATIVE_POLY_REDUCE)
167
- /*************************************************
168
- * Name: mlk_poly_reduce_native
174
+ /**
175
+ * Apply modular reduction to all coefficients of a polynomial, mapping them
176
+ * to unsigned canonical representatives in [0,..,MLKEM_Q-1].
169
177
  *
170
- * Description: Applies modular reduction to all coefficients of a polynomial.
178
+ * @param[in,out] p Input/output polynomial.
171
179
  *
172
- * Arguments: - int16_t r[MLKEM_N]: pointer to input/output polynomial
173
- **************************************************/
180
+ * @retval MLK_NATIVE_FUNC_SUCCESS Operation succeeded.
181
+ * @retval MLK_NATIVE_FUNC_FALLBACK Backend declined; caller should fall back.
182
+ */
174
183
  MLK_MUST_CHECK_RETURN_VALUE
175
184
  static MLK_INLINE int mlk_poly_reduce_native(int16_t p[MLKEM_N])
176
185
  __contract__(
@@ -183,14 +192,15 @@ __contract__(
183
192
  #endif /* MLK_USE_NATIVE_POLY_REDUCE */
184
193
 
185
194
  #if defined(MLK_USE_NATIVE_POLY_TOMONT)
186
- /*************************************************
187
- * Name: mlk_poly_tomont_native
195
+ /**
196
+ * In-place conversion of all coefficients of a polynomial from the normal
197
+ * domain to the Montgomery domain.
188
198
  *
189
- * Description: Inplace conversion of all coefficients of a polynomial
190
- * from normal domain to Montgomery domain
199
+ * @param[in,out] p Input/output polynomial.
191
200
  *
192
- * Arguments: - int16_t r[MLKEM_N]: pointer to input/output polynomial
193
- **************************************************/
201
+ * @retval MLK_NATIVE_FUNC_SUCCESS Operation succeeded.
202
+ * @retval MLK_NATIVE_FUNC_FALLBACK Backend declined; caller should fall back.
203
+ */
194
204
  MLK_MUST_CHECK_RETURN_VALUE
195
205
  static MLK_INLINE int mlk_poly_tomont_native(int16_t p[MLKEM_N])
196
206
  __contract__(
@@ -203,27 +213,23 @@ __contract__(
203
213
  #endif /* MLK_USE_NATIVE_POLY_TOMONT */
204
214
 
205
215
  #if defined(MLK_USE_NATIVE_POLY_MULCACHE_COMPUTE)
206
- /*************************************************
207
- * Name: mlk_poly_mulcache_compute_native
208
- *
209
- * Description: Compute multiplication cache for a polynomial
210
- * in NTT domain.
211
- *
212
- * The purpose of the multiplication cache is to
213
- * cache repeated computations required during a
214
- * base multiplication of polynomials in NTT domain.
215
- * The structure of the multiplication-cache is
216
- * implementation defined.
217
- *
218
- * Arguments: INPUT:
219
- * - mlk_poly: const pointer to input polynomial.
220
- * This must be in NTT domain and inin bitreversed order, or of
221
- * a custom order if MLK_USE_NATIVE_NTT_CUSTOM_ORDER is set.
222
- * See the documentation of MLK_USE_NATIVE_NTT_CUSTOM_ORDER
223
- * for more information.
224
- * OUTPUT
225
- * - cache: pointer to multiplication cache
226
- **************************************************/
216
+ /**
217
+ * Compute multiplication cache for a polynomial in NTT domain.
218
+ *
219
+ * The purpose of the multiplication cache is to cache repeated computations
220
+ * required during a base multiplication of polynomials in NTT domain. The
221
+ * structure of the multiplication-cache is implementation defined.
222
+ *
223
+ * @param[out] cache Multiplication cache.
224
+ * @param[in] mlk_poly Input polynomial. Must be in NTT domain and in
225
+ * bitreversed order, or of a custom order if
226
+ * MLK_USE_NATIVE_NTT_CUSTOM_ORDER is set. See the
227
+ * documentation of MLK_USE_NATIVE_NTT_CUSTOM_ORDER for
228
+ * more information.
229
+ *
230
+ * @retval MLK_NATIVE_FUNC_SUCCESS Operation succeeded.
231
+ * @retval MLK_NATIVE_FUNC_FALLBACK Backend declined; caller should fall back.
232
+ */
227
233
  MLK_MUST_CHECK_RETURN_VALUE
228
234
  static MLK_INLINE int mlk_poly_mulcache_compute_native(
229
235
  int16_t cache[MLKEM_N / 2], const int16_t mlk_poly[MLKEM_N])
@@ -238,25 +244,22 @@ __contract__(
238
244
 
239
245
  #if defined(MLK_USE_NATIVE_POLYVEC_BASEMUL_ACC_MONTGOMERY_CACHED)
240
246
  #if defined(MLK_CONFIG_MULTILEVEL_WITH_SHARED) || MLKEM_K == 2
241
- /*************************************************
242
- * Name: poly_mulcache_compute_k2_native
243
- *
244
- * Description: Compute scalar product of length-2 polynomial vectors in NTT
245
- * domain.
246
- *
247
- * Arguments: INPUT:
248
- * - a: First polynomial vector operand.
249
- * This must be in NTT domain and in bitreversed order, or of
250
- * a custom order if MLK_USE_NATIVE_NTT_CUSTOM_ORDER is set.
251
- * See the documentation of MLK_USE_NATIVE_NTT_CUSTOM_ORDER
252
- * for more information.
253
- * - b: Second polynomial vector operand.
254
- * As for a.
255
- * - b_cache: Multiplication-cache for b.
256
- * OUTPUT
257
- * - r: The result of the scalar product. This is again
258
- * in NTT domain, and of the same ordering as a and b.
259
- **************************************************/
247
+ /**
248
+ * Compute scalar product of length-2 polynomial vectors in NTT domain.
249
+ *
250
+ * @param[out] r Result of the scalar product. Again in NTT domain, of
251
+ * the same ordering as @p a and @p b.
252
+ * @param[in] a First polynomial vector operand. Must be in NTT
253
+ * domain and in bitreversed order, or of a custom order
254
+ * if MLK_USE_NATIVE_NTT_CUSTOM_ORDER is set. See the
255
+ * documentation of MLK_USE_NATIVE_NTT_CUSTOM_ORDER for
256
+ * more information.
257
+ * @param[in] b Second polynomial vector operand. As for @p a.
258
+ * @param[in] b_cache Multiplication-cache for @p b.
259
+ *
260
+ * @retval MLK_NATIVE_FUNC_SUCCESS Operation succeeded.
261
+ * @retval MLK_NATIVE_FUNC_FALLBACK Backend declined; caller should fall back.
262
+ */
260
263
  MLK_MUST_CHECK_RETURN_VALUE
261
264
  static MLK_INLINE int mlk_polyvec_basemul_acc_montgomery_cached_k2_native(
262
265
  int16_t r[MLKEM_N], const int16_t a[2 * MLKEM_N],
@@ -273,25 +276,22 @@ __contract__(
273
276
  #endif /* MLK_CONFIG_MULTILEVEL_WITH_SHARED || MLKEM_K == 2 */
274
277
 
275
278
  #if defined(MLK_CONFIG_MULTILEVEL_WITH_SHARED) || MLKEM_K == 3
276
- /*************************************************
277
- * Name: poly_mulcache_compute_k3_native
278
- *
279
- * Description: Compute scalar product of length-3 polynomial vectors in NTT
280
- * domain.
281
- *
282
- * Arguments: INPUT:
283
- * - a: First polynomial vector operand.
284
- * This must be in NTT domain and in bitreversed order, or of
285
- * a custom order if MLK_USE_NATIVE_NTT_CUSTOM_ORDER is set.
286
- * See the documentation of MLK_USE_NATIVE_NTT_CUSTOM_ORDER
287
- * for more information.
288
- * - b: Second polynomial vector operand.
289
- * As for a.
290
- * - b_cache: Multiplication-cache for b.
291
- * OUTPUT
292
- * - r: The result of the scalar product. This is again
293
- * in NTT domain, and of the same ordering as a and b.
294
- **************************************************/
279
+ /**
280
+ * Compute scalar product of length-3 polynomial vectors in NTT domain.
281
+ *
282
+ * @param[out] r Result of the scalar product. Again in NTT domain, of
283
+ * the same ordering as @p a and @p b.
284
+ * @param[in] a First polynomial vector operand. Must be in NTT
285
+ * domain and in bitreversed order, or of a custom order
286
+ * if MLK_USE_NATIVE_NTT_CUSTOM_ORDER is set. See the
287
+ * documentation of MLK_USE_NATIVE_NTT_CUSTOM_ORDER for
288
+ * more information.
289
+ * @param[in] b Second polynomial vector operand. As for @p a.
290
+ * @param[in] b_cache Multiplication-cache for @p b.
291
+ *
292
+ * @retval MLK_NATIVE_FUNC_SUCCESS Operation succeeded.
293
+ * @retval MLK_NATIVE_FUNC_FALLBACK Backend declined; caller should fall back.
294
+ */
295
295
  MLK_MUST_CHECK_RETURN_VALUE
296
296
  static MLK_INLINE int mlk_polyvec_basemul_acc_montgomery_cached_k3_native(
297
297
  int16_t r[MLKEM_N], const int16_t a[3 * MLKEM_N],
@@ -308,25 +308,22 @@ __contract__(
308
308
  #endif /* MLK_CONFIG_MULTILEVEL_WITH_SHARED || MLKEM_K == 3 */
309
309
 
310
310
  #if defined(MLK_CONFIG_MULTILEVEL_WITH_SHARED) || MLKEM_K == 4
311
- /*************************************************
312
- * Name: poly_mulcache_compute_k4_native
313
- *
314
- * Description: Compute scalar product of length-4 polynomial vectors in NTT
315
- * domain.
316
- *
317
- * Arguments: INPUT:
318
- * - a: First polynomial vector operand.
319
- * This must be in NTT domain and in bitreversed order, or of
320
- * a custom order if MLK_USE_NATIVE_NTT_CUSTOM_ORDER is set.
321
- * See the documentation of MLK_USE_NATIVE_NTT_CUSTOM_ORDER
322
- * for more information.
323
- * - b: Second polynomial vector operand.
324
- * As for a.
325
- * - b_cache: Multiplication-cache for b.
326
- * OUTPUT
327
- * - r: The result of the scalar product. This is again
328
- * in NTT domain, and of the same ordering as a and b.
329
- **************************************************/
311
+ /**
312
+ * Compute scalar product of length-4 polynomial vectors in NTT domain.
313
+ *
314
+ * @param[out] r Result of the scalar product. Again in NTT domain, of
315
+ * the same ordering as @p a and @p b.
316
+ * @param[in] a First polynomial vector operand. Must be in NTT
317
+ * domain and in bitreversed order, or of a custom order
318
+ * if MLK_USE_NATIVE_NTT_CUSTOM_ORDER is set. See the
319
+ * documentation of MLK_USE_NATIVE_NTT_CUSTOM_ORDER for
320
+ * more information.
321
+ * @param[in] b Second polynomial vector operand. As for @p a.
322
+ * @param[in] b_cache Multiplication-cache for @p b.
323
+ *
324
+ * @retval MLK_NATIVE_FUNC_SUCCESS Operation succeeded.
325
+ * @retval MLK_NATIVE_FUNC_FALLBACK Backend declined; caller should fall back.
326
+ */
330
327
  MLK_MUST_CHECK_RETURN_VALUE
331
328
  static MLK_INLINE int mlk_polyvec_basemul_acc_montgomery_cached_k4_native(
332
329
  int16_t r[MLKEM_N], const int16_t a[4 * MLKEM_N],
@@ -344,20 +341,17 @@ __contract__(
344
341
  #endif /* MLK_USE_NATIVE_POLYVEC_BASEMUL_ACC_MONTGOMERY_CACHED */
345
342
 
346
343
  #if defined(MLK_USE_NATIVE_POLY_TOBYTES)
347
- /*************************************************
348
- * Name: mlk_poly_tobytes_native
349
- *
350
- * Description: Serialization of a polynomial.
351
- * Signed coefficients are converted to
352
- * unsigned form before serialization.
353
- *
354
- * Arguments: INPUT:
355
- * - a: const pointer to input polynomial,
356
- * with each coefficient in the range 0 .. Q-1
357
- * OUTPUT
358
- * - r: pointer to output byte array
359
- * (of MLKEM_POLYBYTES bytes)
360
- **************************************************/
344
+ /**
345
+ * Serialization of a polynomial with unsigned canonical coefficients.
346
+ *
347
+ * @spec{Implements ByteEncode_12 from @[FIPS203, Algorithm 5].}
348
+ *
349
+ * @param[out] r Output byte array (of MLKEM_POLYBYTES bytes).
350
+ * @param[in] a Input polynomial, with each coefficient in [0,..,MLKEM_Q-1].
351
+ *
352
+ * @retval MLK_NATIVE_FUNC_SUCCESS Operation succeeded.
353
+ * @retval MLK_NATIVE_FUNC_FALLBACK Backend declined; caller should fall back.
354
+ */
361
355
  MLK_MUST_CHECK_RETURN_VALUE
362
356
  static MLK_INLINE int mlk_poly_tobytes_native(uint8_t r[MLKEM_POLYBYTES],
363
357
  const int16_t a[MLKEM_N])
@@ -371,19 +365,17 @@ __contract__(
371
365
  #endif /* MLK_USE_NATIVE_POLY_TOBYTES */
372
366
 
373
367
  #if defined(MLK_USE_NATIVE_POLY_FROMBYTES)
374
- /*************************************************
375
- * Name: mlk_poly_frombytes_native
376
- *
377
- * Description: Serialization of a polynomial.
378
- * Signed coefficients are converted to
379
- * unsigned form before serialization.
380
- *
381
- * Arguments: INPUT:
382
- * - r: pointer to output polynomial in NTT domain
383
- * OUTPUT
384
- * - a: const pointer to input byte array
385
- * (of MLKEM_POLYBYTES bytes)
386
- **************************************************/
368
+ /**
369
+ * Deserialization of a polynomial.
370
+ *
371
+ * @spec{Implements ByteDecode_12 from @[FIPS203, Algorithm 6].}
372
+ *
373
+ * @param[out] a Output polynomial in NTT domain.
374
+ * @param[in] r Input byte array (of MLKEM_POLYBYTES bytes).
375
+ *
376
+ * @retval MLK_NATIVE_FUNC_SUCCESS Operation succeeded.
377
+ * @retval MLK_NATIVE_FUNC_FALLBACK Backend declined; caller should fall back.
378
+ */
387
379
  MLK_MUST_CHECK_RETURN_VALUE
388
380
  static MLK_INLINE int mlk_poly_frombytes_native(
389
381
  int16_t a[MLKEM_N], const uint8_t r[MLKEM_POLYBYTES])
@@ -397,23 +389,20 @@ __contract__(
397
389
  #endif /* MLK_USE_NATIVE_POLY_FROMBYTES */
398
390
 
399
391
  #if defined(MLK_USE_NATIVE_REJ_UNIFORM)
400
- /*************************************************
401
- * Name: mlk_rej_uniform_native
402
- *
403
- * Description: Run rejection sampling on uniform random bytes to generate
404
- * uniform random integers mod q
405
- *
406
- * Arguments: - int16_t *r: pointer to output buffer
407
- * - unsigned len: requested number of 16-bit integers
408
- * (uniform mod q).
409
- * - const uint8_t *buf: pointer to input buffer
410
- * (assumed to be uniform random bytes)
411
- * - unsigned buflen: length of input buffer in bytes.
412
- *
413
- * Return -1 if the native implementation does not support the input lengths.
414
- * Otherwise, returns non-negative number of sampled 16-bit integers (at most
415
- * len).
416
- **************************************************/
392
+ /**
393
+ * Run rejection sampling on uniformly random bytes to generate uniformly random
394
+ * integers mod MLKEM_Q, represented in [0,..,MLKEM_Q-1].
395
+ *
396
+ * @param[out] r Output buffer.
397
+ * @param len Requested number of 16-bit integers (uniform mod MLKEM_Q).
398
+ * @param[in] buf Input buffer (assumed to be uniform random bytes).
399
+ * @param buflen Length of input buffer in bytes.
400
+ *
401
+ * @retval MLK_NATIVE_FUNC_FALLBACK Native implementation does not support
402
+ * the input lengths.
403
+ * @retval other Non-negative number of sampled 16-bit
404
+ * integers (at most @p len).
405
+ */
417
406
  MLK_MUST_CHECK_RETURN_VALUE
418
407
  static MLK_INLINE int mlk_rej_uniform_native(int16_t *r, unsigned len,
419
408
  const uint8_t *buf,
@@ -432,18 +421,19 @@ __contract__(
432
421
 
433
422
  #if defined(MLK_CONFIG_MULTILEVEL_WITH_SHARED) || (MLKEM_K == 2 || MLKEM_K == 3)
434
423
  #if defined(MLK_USE_NATIVE_POLY_COMPRESS_D4)
435
- /*************************************************
436
- * Name: mlk_poly_compress_d4_native
437
- *
438
- * Description: Compression (4 bits) and subsequent serialization of a
439
- * polynomial
440
- *
441
- * Arguments: - uint8_t *r: pointer to output byte array
442
- * (of length MLKEM_POLYCOMPRESSEDBYTES_D4 bytes)
443
- * - const int16_t a[MLKEM_N]: pointer to input polynomial
444
- * Coefficients must be unsigned canonical,
445
- * i.e. in [0,1,..,MLKEM_Q-1].
446
- **************************************************/
424
+ /**
425
+ * Compression (4 bits) and subsequent serialization of a polynomial.
426
+ *
427
+ * @spec{Compress_4 from @[FIPS203, Eq (4.7)].}
428
+ *
429
+ * @param[out] r Output byte array (of length MLKEM_POLYCOMPRESSEDBYTES_D4
430
+ * bytes).
431
+ * @param[in] a Input polynomial. Coefficients must be unsigned canonical,
432
+ * i.e. in [0,1,..,MLKEM_Q-1].
433
+ *
434
+ * @retval MLK_NATIVE_FUNC_SUCCESS Operation succeeded.
435
+ * @retval MLK_NATIVE_FUNC_FALLBACK Backend declined; caller should fall back.
436
+ */
447
437
  MLK_MUST_CHECK_RETURN_VALUE
448
438
  static MLK_INLINE int mlk_poly_compress_d4_native(
449
439
  uint8_t r[MLKEM_POLYCOMPRESSEDBYTES_D4], const int16_t a[MLKEM_N])
@@ -456,18 +446,19 @@ __contract__(
456
446
  #endif /* MLK_USE_NATIVE_POLY_COMPRESS_D4 */
457
447
 
458
448
  #if defined(MLK_USE_NATIVE_POLY_COMPRESS_D10)
459
- /*************************************************
460
- * Name: mlk_poly_compress_d10_native
461
- *
462
- * Description: Compression (10 bits) and subsequent serialization of a
463
- * polynomial
464
- *
465
- * Arguments: - uint8_t *r: pointer to output byte array
466
- * (of length MLKEM_POLYCOMPRESSEDBYTES_D10 bytes)
467
- * - const int16_t a[MLKEM_N]: pointer to input polynomial
468
- * Coefficients must be unsigned canonical,
469
- * i.e. in [0,1,..,MLKEM_Q-1].
470
- **************************************************/
449
+ /**
450
+ * Compression (10 bits) and subsequent serialization of a polynomial.
451
+ *
452
+ * @spec{Compress_10 from @[FIPS203, Eq (4.7)].}
453
+ *
454
+ * @param[out] r Output byte array (of length MLKEM_POLYCOMPRESSEDBYTES_D10
455
+ * bytes).
456
+ * @param[in] a Input polynomial. Coefficients must be unsigned canonical,
457
+ * i.e. in [0,1,..,MLKEM_Q-1].
458
+ *
459
+ * @retval MLK_NATIVE_FUNC_SUCCESS Operation succeeded.
460
+ * @retval MLK_NATIVE_FUNC_FALLBACK Backend declined; caller should fall back.
461
+ */
471
462
  MLK_MUST_CHECK_RETURN_VALUE
472
463
  static MLK_INLINE int mlk_poly_compress_d10_native(
473
464
  uint8_t r[MLKEM_POLYCOMPRESSEDBYTES_D10], const int16_t a[MLKEM_N])
@@ -480,20 +471,22 @@ __contract__(
480
471
  #endif /* MLK_USE_NATIVE_POLY_COMPRESS_D10 */
481
472
 
482
473
  #if defined(MLK_USE_NATIVE_POLY_DECOMPRESS_D4)
483
- /*************************************************
484
- * Name: mlk_poly_decompress_d4
474
+ /**
475
+ * De-serialization and subsequent decompression (4 bits) of a polynomial;
476
+ * approximate inverse of mlk_poly_compress_d4.
485
477
  *
486
- * Description: De-serialization and subsequent decompression (dv bits) of a
487
- * polynomial; approximate inverse of poly_compress
478
+ * @spec{Decompress_4 from @[FIPS203, Eq (4.8)].}
488
479
  *
489
- * Arguments: - int16_t r[MLKEM_N]: pointer to output polynomial
490
- * - const uint8_t *a: pointer to input byte array
491
- * (of length MLKEM_POLYCOMPRESSEDBYTES_D4 bytes)
480
+ * Upon return, the coefficients of the output polynomial are
481
+ * unsigned-canonical (non-negative and smaller than MLKEM_Q).
492
482
  *
493
- * Upon return, the coefficients of the output polynomial are unsigned-canonical
494
- * (non-negative and smaller than MLKEM_Q).
483
+ * @param[out] r Output polynomial.
484
+ * @param[in] a Input byte array (of length MLKEM_POLYCOMPRESSEDBYTES_D4
485
+ * bytes).
495
486
  *
496
- **************************************************/
487
+ * @retval MLK_NATIVE_FUNC_SUCCESS Operation succeeded.
488
+ * @retval MLK_NATIVE_FUNC_FALLBACK Backend declined; caller should fall back.
489
+ */
497
490
  MLK_MUST_CHECK_RETURN_VALUE
498
491
  static MLK_INLINE int mlk_poly_decompress_d4_native(
499
492
  int16_t r[MLKEM_N], const uint8_t a[MLKEM_POLYCOMPRESSEDBYTES_D4])
@@ -506,20 +499,22 @@ __contract__(
506
499
  #endif /* MLK_USE_NATIVE_POLY_DECOMPRESS_D4 */
507
500
 
508
501
  #if defined(MLK_USE_NATIVE_POLY_DECOMPRESS_D10)
509
- /*************************************************
510
- * Name: mlk_poly_decompress_d10_native
502
+ /**
503
+ * De-serialization and subsequent decompression (10 bits) of a polynomial;
504
+ * approximate inverse of mlk_poly_compress_d10.
511
505
  *
512
- * Description: De-serialization and subsequent decompression (10 bits) of a
513
- * polynomial; approximate inverse of mlk_poly_compress_d10
506
+ * @spec{Decompress_10 from @[FIPS203, Eq (4.8)].}
514
507
  *
515
- * Arguments: - int16_t r[MLKEM_N]: pointer to output polynomial
516
- * - const uint8_t *a: pointer to input byte array
517
- * (of length MLKEM_POLYCOMPRESSEDBYTES_D10 bytes)
508
+ * Upon return, the coefficients of the output polynomial are
509
+ * unsigned-canonical (non-negative and smaller than MLKEM_Q).
518
510
  *
519
- * Upon return, the coefficients of the output polynomial are unsigned-canonical
520
- * (non-negative and smaller than MLKEM_Q).
511
+ * @param[out] r Output polynomial.
512
+ * @param[in] a Input byte array (of length MLKEM_POLYCOMPRESSEDBYTES_D10
513
+ * bytes).
521
514
  *
522
- **************************************************/
515
+ * @retval MLK_NATIVE_FUNC_SUCCESS Operation succeeded.
516
+ * @retval MLK_NATIVE_FUNC_FALLBACK Backend declined; caller should fall back.
517
+ */
523
518
  MLK_MUST_CHECK_RETURN_VALUE
524
519
  static MLK_INLINE int mlk_poly_decompress_d10_native(
525
520
  int16_t r[MLKEM_N], const uint8_t a[MLKEM_POLYCOMPRESSEDBYTES_D10])
@@ -534,18 +529,19 @@ __contract__(
534
529
 
535
530
  #if defined(MLK_CONFIG_MULTILEVEL_WITH_SHARED) || MLKEM_K == 4
536
531
  #if defined(MLK_USE_NATIVE_POLY_COMPRESS_D5)
537
- /*************************************************
538
- * Name: mlk_poly_compress_d5_native
539
- *
540
- * Description: Compression (5 bits) and subsequent serialization of a
541
- * polynomial
542
- *
543
- * Arguments: - uint8_t *r: pointer to output byte array
544
- * (of length MLKEM_POLYCOMPRESSEDBYTES_D5 bytes)
545
- * - const int16_t a[MLKEM_N]: pointer to input polynomial
546
- * Coefficients must be unsigned canonical,
547
- * i.e. in [0,1,..,MLKEM_Q-1].
548
- **************************************************/
532
+ /**
533
+ * Compression (5 bits) and subsequent serialization of a polynomial.
534
+ *
535
+ * @spec{Compress_5 from @[FIPS203, Eq (4.7)].}
536
+ *
537
+ * @param[out] r Output byte array (of length MLKEM_POLYCOMPRESSEDBYTES_D5
538
+ * bytes).
539
+ * @param[in] a Input polynomial. Coefficients must be unsigned canonical,
540
+ * i.e. in [0,1,..,MLKEM_Q-1].
541
+ *
542
+ * @retval MLK_NATIVE_FUNC_SUCCESS Operation succeeded.
543
+ * @retval MLK_NATIVE_FUNC_FALLBACK Backend declined; caller should fall back.
544
+ */
549
545
  MLK_MUST_CHECK_RETURN_VALUE
550
546
  static MLK_INLINE int mlk_poly_compress_d5_native(
551
547
  uint8_t r[MLKEM_POLYCOMPRESSEDBYTES_D5], const int16_t a[MLKEM_N])
@@ -558,18 +554,19 @@ __contract__(
558
554
  #endif /* MLK_USE_NATIVE_POLY_COMPRESS_D5 */
559
555
 
560
556
  #if defined(MLK_USE_NATIVE_POLY_COMPRESS_D11)
561
- /*************************************************
562
- * Name: mlk_poly_compress_d11_native
563
- *
564
- * Description: Compression (11 bits) and subsequent serialization of a
565
- * polynomial
566
- *
567
- * Arguments: - uint8_t *r: pointer to output byte array
568
- * (of length MLKEM_POLYCOMPRESSEDBYTES_D11 bytes)
569
- * - const int16_t a[MLKEM_N]: pointer to input polynomial
570
- * Coefficients must be unsigned canonical,
571
- * i.e. in [0,1,..,MLKEM_Q-1].
572
- **************************************************/
557
+ /**
558
+ * Compression (11 bits) and subsequent serialization of a polynomial.
559
+ *
560
+ * @spec{Compress_11 from @[FIPS203, Eq (4.7)].}
561
+ *
562
+ * @param[out] r Output byte array (of length MLKEM_POLYCOMPRESSEDBYTES_D11
563
+ * bytes).
564
+ * @param[in] a Input polynomial. Coefficients must be unsigned canonical,
565
+ * i.e. in [0,1,..,MLKEM_Q-1].
566
+ *
567
+ * @retval MLK_NATIVE_FUNC_SUCCESS Operation succeeded.
568
+ * @retval MLK_NATIVE_FUNC_FALLBACK Backend declined; caller should fall back.
569
+ */
573
570
  MLK_MUST_CHECK_RETURN_VALUE
574
571
  static MLK_INLINE int mlk_poly_compress_d11_native(
575
572
  uint8_t r[MLKEM_POLYCOMPRESSEDBYTES_D11], const int16_t a[MLKEM_N])
@@ -582,20 +579,22 @@ __contract__(
582
579
  #endif /* MLK_USE_NATIVE_POLY_COMPRESS_D11 */
583
580
 
584
581
  #if defined(MLK_USE_NATIVE_POLY_DECOMPRESS_D5)
585
- /*************************************************
586
- * Name: mlk_poly_decompress_d5_native
582
+ /**
583
+ * De-serialization and subsequent decompression (5 bits) of a polynomial;
584
+ * approximate inverse of mlk_poly_compress_d5.
587
585
  *
588
- * Description: De-serialization and subsequent decompression (dv bits) of a
589
- * polynomial; approximate inverse of poly_compress
586
+ * @spec{Decompress_5 from @[FIPS203, Eq (4.8)].}
590
587
  *
591
- * Arguments: - int16_t r[MLKEM_N]: pointer to output polynomial
592
- * - const uint8_t *a: pointer to input byte array
593
- * (of length MLKEM_POLYCOMPRESSEDBYTES_D5 bytes)
588
+ * Upon return, the coefficients of the output polynomial are
589
+ * unsigned-canonical (non-negative and smaller than MLKEM_Q).
594
590
  *
595
- * Upon return, the coefficients of the output polynomial are unsigned-canonical
596
- * (non-negative and smaller than MLKEM_Q).
591
+ * @param[out] r Output polynomial.
592
+ * @param[in] a Input byte array (of length MLKEM_POLYCOMPRESSEDBYTES_D5
593
+ * bytes).
597
594
  *
598
- **************************************************/
595
+ * @retval MLK_NATIVE_FUNC_SUCCESS Operation succeeded.
596
+ * @retval MLK_NATIVE_FUNC_FALLBACK Backend declined; caller should fall back.
597
+ */
599
598
  MLK_MUST_CHECK_RETURN_VALUE
600
599
  static MLK_INLINE int mlk_poly_decompress_d5_native(
601
600
  int16_t r[MLKEM_N], const uint8_t a[MLKEM_POLYCOMPRESSEDBYTES_D5])
@@ -608,20 +607,22 @@ __contract__(
608
607
  #endif /* MLK_USE_NATIVE_POLY_DECOMPRESS_D5 */
609
608
 
610
609
  #if defined(MLK_USE_NATIVE_POLY_DECOMPRESS_D11)
611
- /*************************************************
612
- * Name: mlk_poly_decompress_d11_native
610
+ /**
611
+ * De-serialization and subsequent decompression (11 bits) of a polynomial;
612
+ * approximate inverse of mlk_poly_compress_d11.
613
613
  *
614
- * Description: De-serialization and subsequent decompression (11 bits) of a
615
- * polynomial; approximate inverse of mlk_poly_compress_d11
614
+ * @spec{Decompress_11 from @[FIPS203, Eq (4.8)].}
616
615
  *
617
- * Arguments: - int16_t r[MLKEM_N]: pointer to output polynomial
618
- * - const uint8_t *a: pointer to input byte array
619
- * (of length MLKEM_POLYCOMPRESSEDBYTES_D11 bytes)
616
+ * Upon return, the coefficients of the output polynomial are
617
+ * unsigned-canonical (non-negative and smaller than MLKEM_Q).
620
618
  *
621
- * Upon return, the coefficients of the output polynomial are unsigned-canonical
622
- * (non-negative and smaller than MLKEM_Q).
619
+ * @param[out] r Output polynomial.
620
+ * @param[in] a Input byte array (of length MLKEM_POLYCOMPRESSEDBYTES_D11
621
+ * bytes).
623
622
  *
624
- **************************************************/
623
+ * @retval MLK_NATIVE_FUNC_SUCCESS Operation succeeded.
624
+ * @retval MLK_NATIVE_FUNC_FALLBACK Backend declined; caller should fall back.
625
+ */
625
626
  MLK_MUST_CHECK_RETURN_VALUE
626
627
  static MLK_INLINE int mlk_poly_decompress_d11_native(
627
628
  int16_t r[MLKEM_N], const uint8_t a[MLKEM_POLYCOMPRESSEDBYTES_D11])