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
@@ -28,40 +28,37 @@
28
28
  #define mlk_polyvec_mulcache MLK_ADD_PARAM_SET(mlk_polyvec_mulcache)
29
29
  /* End of parameter set namespacing */
30
30
 
31
+ /** Vector of MLKEM_K polynomials. */
31
32
  typedef struct
32
33
  {
33
- mlk_poly vec[MLKEM_K];
34
+ mlk_poly vec[MLKEM_K]; /**< Component polynomials. */
34
35
  } MLK_ALIGN mlk_polyvec;
35
36
 
37
+ /** MLKEM_K x MLKEM_K matrix of polynomials. */
36
38
  typedef struct
37
39
  {
38
- mlk_polyvec vec[MLKEM_K];
40
+ mlk_polyvec vec[MLKEM_K]; /**< Rows of the matrix. */
39
41
  } MLK_ALIGN mlk_polymat;
40
42
 
43
+ /** Vector of MLKEM_K mlk_poly_mulcache entries. */
41
44
  typedef struct
42
45
  {
43
- mlk_poly_mulcache vec[MLKEM_K];
46
+ mlk_poly_mulcache vec[MLKEM_K]; /**< Per-component caches. */
44
47
  } MLK_ALIGN mlk_polyvec_mulcache;
45
48
 
46
49
  #define mlk_poly_compress_du MLK_NAMESPACE_K(poly_compress_du)
47
- /*************************************************
48
- * Name: mlk_poly_compress_du
50
+ /**
51
+ * Compression (du bits) and subsequent serialization of a polynomial.
49
52
  *
50
- * Description: Compression (du bits) and subsequent serialization of a
51
- * polynomial
53
+ * @spec{Implements `ByteEncode_{d_u} (Compress_{d_u} (u))` in @[FIPS203,
54
+ * Algorithm 14 (K-PKE.Encrypt), L22], with level-specific d_u defined in
55
+ * @[FIPS203, Table 2], and given by MLKEM_DU here.}
52
56
  *
53
- * Arguments: - uint8_t *r: pointer to output byte array
54
- * (of length MLKEM_POLYCOMPRESSEDBYTES_DU bytes)
55
- * - const mlk_poly *a: pointer to input polynomial
56
- * Coefficients must be unsigned canonical,
57
- * i.e. in [0,1,..,MLKEM_Q-1].
58
- *
59
- * Specification: Implements `ByteEncode_{d_u} (Compress_{d_u} (u))`
60
- * in @[FIPS203, Algorithm 14 (K-PKE.Encrypt), L22],
61
- * with level-specific d_u defined in @[FIPS203, Table 2],
62
- * and given by MLKEM_DU here.
63
- *
64
- **************************************************/
57
+ * @param[out] r Output byte array (of length MLKEM_POLYCOMPRESSEDBYTES_DU
58
+ * bytes).
59
+ * @param[in] a Input polynomial. Coefficients must be unsigned canonical,
60
+ * i.e. in [0,1,..,MLKEM_Q-1].
61
+ */
65
62
  static MLK_INLINE void mlk_poly_compress_du(
66
63
  uint8_t r[MLKEM_POLYCOMPRESSEDBYTES_DU], const mlk_poly *a)
67
64
  __contract__(
@@ -80,25 +77,21 @@ __contract__(
80
77
  }
81
78
 
82
79
  #define mlk_poly_decompress_du MLK_NAMESPACE_K(poly_decompress_du)
83
- /*************************************************
84
- * Name: mlk_poly_decompress_du
85
- *
86
- * Description: De-serialization and subsequent decompression (du bits) of a
87
- * polynomial; approximate inverse of mlk_poly_compress_du
80
+ /**
81
+ * De-serialization and subsequent decompression (du bits) of a polynomial;
82
+ * approximate inverse of mlk_poly_compress_du.
88
83
  *
89
- * Arguments: - mlk_poly *r: pointer to output polynomial
90
- * - const uint8_t *a: pointer to input byte array
91
- * (of length MLKEM_POLYCOMPRESSEDBYTES_DU bytes)
84
+ * Upon return, the coefficients of the output polynomial are
85
+ * unsigned-canonical (non-negative and smaller than MLKEM_Q).
92
86
  *
93
- * Upon return, the coefficients of the output polynomial are unsigned-canonical
94
- * (non-negative and smaller than MLKEM_Q).
87
+ * @spec{Implements `Decompress_{d_u} (ByteDecode_{d_u} (u))` in @[FIPS203,
88
+ * Algorithm 15 (K-PKE.Decrypt), L3], with level-specific d_u defined in
89
+ * @[FIPS203, Table 2], and given by MLKEM_DU here.}
95
90
  *
96
- * Specification: Implements `Decompress_{d_u} (ByteDecode_{d_u} (u))`
97
- * in @[FIPS203, Algorithm 15 (K-PKE.Decrypt), L3].
98
- * with level-specific d_u defined in @[FIPS203, Table 2],
99
- * and given by MLKEM_DU here.
100
- *
101
- **************************************************/
91
+ * @param[out] r Output polynomial.
92
+ * @param[in] a Input byte array (of length MLKEM_POLYCOMPRESSEDBYTES_DU
93
+ * bytes).
94
+ */
102
95
  static MLK_INLINE void mlk_poly_decompress_du(
103
96
  mlk_poly *r, const uint8_t a[MLKEM_POLYCOMPRESSEDBYTES_DU])
104
97
  __contract__(
@@ -117,24 +110,18 @@ __contract__(
117
110
  }
118
111
 
119
112
  #define mlk_poly_compress_dv MLK_NAMESPACE_K(poly_compress_dv)
120
- /*************************************************
121
- * Name: mlk_poly_compress_dv
122
- *
123
- * Description: Compression (dv bits) and subsequent serialization of a
124
- * polynomial
113
+ /**
114
+ * Compression (dv bits) and subsequent serialization of a polynomial.
125
115
  *
126
- * Arguments: - uint8_t *r: pointer to output byte array
127
- * (of length MLKEM_POLYCOMPRESSEDBYTES_DV bytes)
128
- * - const mlk_poly *a: pointer to input polynomial
129
- * Coefficients must be unsigned canonical,
130
- * i.e. in [0,1,..,MLKEM_Q-1].
116
+ * @spec{Implements `ByteEncode_{d_v} (Compress_{d_v} (v))` in @[FIPS203,
117
+ * Algorithm 14 (K-PKE.Encrypt), L23], with level-specific d_v defined in
118
+ * @[FIPS203, Table 2], and given by MLKEM_DV here.}
131
119
  *
132
- * Specification: Implements `ByteEncode_{d_v} (Compress_{d_v} (v))`
133
- * in @[FIPS203, Algorithm 14 (K-PKE.Encrypt), L23].
134
- * with level-specific d_v defined in @[FIPS203, Table 2],
135
- * and given by MLKEM_DV here.
136
- *
137
- **************************************************/
120
+ * @param[out] r Output byte array (of length MLKEM_POLYCOMPRESSEDBYTES_DV
121
+ * bytes).
122
+ * @param[in] a Input polynomial. Coefficients must be unsigned canonical,
123
+ * i.e. in [0,1,..,MLKEM_Q-1].
124
+ */
138
125
  static MLK_INLINE void mlk_poly_compress_dv(
139
126
  uint8_t r[MLKEM_POLYCOMPRESSEDBYTES_DV], const mlk_poly *a)
140
127
  __contract__(
@@ -154,25 +141,21 @@ __contract__(
154
141
 
155
142
 
156
143
  #define mlk_poly_decompress_dv MLK_NAMESPACE_K(poly_decompress_dv)
157
- /*************************************************
158
- * Name: mlk_poly_decompress_dv
159
- *
160
- * Description: De-serialization and subsequent decompression (dv bits) of a
161
- * polynomial; approximate inverse of poly_compress
144
+ /**
145
+ * De-serialization and subsequent decompression (dv bits) of a polynomial;
146
+ * approximate inverse of mlk_poly_compress_dv.
162
147
  *
163
- * Arguments: - mlk_poly *r: pointer to output polynomial
164
- * - const uint8_t *a: pointer to input byte array
165
- * (of length MLKEM_POLYCOMPRESSEDBYTES_DV bytes)
148
+ * Upon return, the coefficients of the output polynomial are
149
+ * unsigned-canonical (non-negative and smaller than MLKEM_Q).
166
150
  *
167
- * Upon return, the coefficients of the output polynomial are unsigned-canonical
168
- * (non-negative and smaller than MLKEM_Q).
151
+ * @spec{Implements `Decompress_{d_v} (ByteDecode_{d_v} (v))` in @[FIPS203,
152
+ * Algorithm 15 (K-PKE.Decrypt), L4], with level-specific d_v defined in
153
+ * @[FIPS203, Table 2], and given by MLKEM_DV here.}
169
154
  *
170
- * Specification: Implements `Decompress_{d_v} (ByteDecode_{d_v} (v))`
171
- * in @[FIPS203, Algorithm 15 (K-PKE.Decrypt), L4].
172
- * with level-specific d_v defined in @[FIPS203, Table 2],
173
- * and given by MLKEM_DV here.
174
- *
175
- **************************************************/
155
+ * @param[out] r Output polynomial.
156
+ * @param[in] a Input byte array (of length MLKEM_POLYCOMPRESSEDBYTES_DV
157
+ * bytes).
158
+ */
176
159
  static MLK_INLINE void mlk_poly_decompress_dv(
177
160
  mlk_poly *r, const uint8_t a[MLKEM_POLYCOMPRESSEDBYTES_DV])
178
161
  __contract__(
@@ -191,23 +174,18 @@ __contract__(
191
174
  }
192
175
 
193
176
  #define mlk_polyvec_compress_du MLK_NAMESPACE_K(polyvec_compress_du)
194
- /*************************************************
195
- * Name: mlk_polyvec_compress_du
196
- *
197
- * Description: Compress and serialize vector of polynomials
177
+ /**
178
+ * Compress and serialize a vector of polynomials.
198
179
  *
199
- * Arguments: - uint8_t *r: pointer to output byte array
200
- * (needs space for MLKEM_POLYVECCOMPRESSEDBYTES_DU)
201
- * - const mlk_polyvec a: pointer to input vector of polynomials.
202
- * Coefficients must be unsigned canonical,
203
- * i.e. in [0,1,..,MLKEM_Q-1].
180
+ * @spec{Implements `ByteEncode_{d_u} (Compress_{d_u} (u))` in @[FIPS203,
181
+ * Algorithm 14 (K-PKE.Encrypt), L22], with level-specific d_u defined in
182
+ * @[FIPS203, Table 2], and given by MLKEM_DU here.}
204
183
  *
205
- * Specification: Implements `ByteEncode_{d_u} (Compress_{d_u} (u))`
206
- * in @[FIPS203, Algorithm 14 (K-PKE.Encrypt), L22].
207
- * with level-specific d_u defined in @[FIPS203, Table 2],
208
- * and given by MLKEM_DU here.
209
- *
210
- **************************************************/
184
+ * @param[out] r Output byte array (needs space for
185
+ * MLKEM_POLYVECCOMPRESSEDBYTES_DU bytes).
186
+ * @param[in] a Input vector of polynomials. Coefficients must be unsigned
187
+ * canonical, i.e. in [0,1,..,MLKEM_Q-1].
188
+ */
211
189
  MLK_INTERNAL_API
212
190
  void mlk_polyvec_compress_du(uint8_t r[MLKEM_POLYVECCOMPRESSEDBYTES_DU],
213
191
  const mlk_polyvec *a)
@@ -220,23 +198,19 @@ __contract__(
220
198
  );
221
199
 
222
200
  #define mlk_polyvec_decompress_du MLK_NAMESPACE_K(polyvec_decompress_du)
223
- /*************************************************
224
- * Name: mlk_polyvec_decompress_du
225
- *
226
- * Description: De-serialize and decompress vector of polynomials;
227
- * approximate inverse of mlk_polyvec_compress_du
228
- *
229
- * Arguments: - mlk_polyvec r: pointer to output vector of polynomials.
230
- * Output will have coefficients normalized to [0,..,q-1].
231
- * - const uint8_t *a: pointer to input byte array
232
- * (of length MLKEM_POLYVECCOMPRESSEDBYTES_DU)
233
- *
234
- * Specification: Implements `Decompress_{d_u} (ByteDecode_{d_u} (u))`
235
- * in @[FIPS203, Algorithm 15 (K-PKE.Decrypt), L3].
236
- * with level-specific d_u defined in @[FIPS203, Table 2],
237
- * and given by MLKEM_DU here.
238
- *
239
- **************************************************/
201
+ /**
202
+ * De-serialize and decompress a vector of polynomials; approximate inverse
203
+ * of mlk_polyvec_compress_du.
204
+ *
205
+ * @spec{Implements `Decompress_{d_u} (ByteDecode_{d_u} (u))` in @[FIPS203,
206
+ * Algorithm 15 (K-PKE.Decrypt), L3], with level-specific d_u defined in
207
+ * @[FIPS203, Table 2], and given by MLKEM_DU here.}
208
+ *
209
+ * @param[out] r Output vector of polynomials. Coefficients are normalized
210
+ * to [0,1,..,MLKEM_Q-1].
211
+ * @param[in] a Input byte array (of length MLKEM_POLYVECCOMPRESSEDBYTES_DU
212
+ * bytes).
213
+ */
240
214
  MLK_INTERNAL_API
241
215
  void mlk_polyvec_decompress_du(mlk_polyvec *r,
242
216
  const uint8_t a[MLKEM_POLYVECCOMPRESSEDBYTES_DU])
@@ -249,22 +223,17 @@ __contract__(
249
223
  );
250
224
 
251
225
  #define mlk_polyvec_tobytes MLK_NAMESPACE_K(polyvec_tobytes)
252
- /*************************************************
253
- * Name: mlk_polyvec_tobytes
226
+ /**
227
+ * Serialize a vector of polynomials.
254
228
  *
255
- * Description: Serialize vector of polynomials
229
+ * @spec{Implements ByteEncode_12 @[FIPS203, Algorithm 5]. Extended to
230
+ * vectors as per @[FIPS203, 2.4.8 Applying Algorithms to Arrays] and
231
+ * @[FIPS203, 2.4.6, Matrices and Vectors].}
256
232
  *
257
- * Arguments: - uint8_t *r: pointer to output byte array
258
- * (needs space for MLKEM_POLYVECBYTES)
259
- * - const mlk_polyvec a: pointer to input vector of polynomials
260
- * Each polynomial must have coefficients in [0,..,q-1].
261
- *
262
- * Specification: Implements ByteEncode_12 @[FIPS203, Algorithm 5].
263
- * Extended to vectors as per
264
- * @[FIPS203, 2.4.8 Applying Algorithms to Arrays]
265
- * and @[FIPS203, 2.4.6, Matrices and Vectors]
266
- *
267
- **************************************************/
233
+ * @param[out] r Output byte array (needs space for MLKEM_POLYVECBYTES bytes).
234
+ * @param[in] a Input vector of polynomials. Each polynomial must have
235
+ * coefficients in [0,1,..,MLKEM_Q-1].
236
+ */
268
237
  MLK_INTERNAL_API
269
238
  void mlk_polyvec_tobytes(uint8_t r[MLKEM_POLYVECBYTES], const mlk_polyvec *a)
270
239
  __contract__(
@@ -276,23 +245,17 @@ __contract__(
276
245
  );
277
246
 
278
247
  #define mlk_polyvec_frombytes MLK_NAMESPACE_K(polyvec_frombytes)
279
- /*************************************************
280
- * Name: mlk_polyvec_frombytes
248
+ /**
249
+ * De-serialize a vector of polynomials; inverse of mlk_polyvec_tobytes.
281
250
  *
282
- * Description: De-serialize vector of polynomials;
283
- * inverse of mlk_polyvec_tobytes
251
+ * @spec{Implements ByteDecode_12 @[FIPS203, Algorithm 6]. Extended to
252
+ * vectors as per @[FIPS203, 2.4.8 Applying Algorithms to Arrays] and
253
+ * @[FIPS203, 2.4.6, Matrices and Vectors].}
284
254
  *
285
- * Arguments: - const mlk_polyvec a: pointer to output vector of polynomials
286
- * (of length MLKEM_POLYVECBYTES). Output will have coefficients
287
- * normalized in [0..4095].
288
- * - uint8_t *r: pointer to input byte array
289
- *
290
- * Specification: Implements ByteDecode_12 @[FIPS203, Algorithm 6].
291
- * Extended to vectors as per
292
- * @[FIPS203, 2.4.8 Applying Algorithms to Arrays]
293
- * and @[FIPS203, 2.4.6, Matrices and Vectors]
294
- *
295
- **************************************************/
255
+ * @param[out] r Output vector of polynomials. Coefficients will be
256
+ * normalized in [0,1,..,4095].
257
+ * @param[in] a Input byte array (of length MLKEM_POLYVECBYTES bytes).
258
+ */
296
259
  MLK_INTERNAL_API
297
260
  void mlk_polyvec_frombytes(mlk_polyvec *r, const uint8_t a[MLKEM_POLYVECBYTES])
298
261
  __contract__(
@@ -304,24 +267,20 @@ __contract__(
304
267
  );
305
268
 
306
269
  #define mlk_polyvec_ntt MLK_NAMESPACE_K(polyvec_ntt)
307
- /*************************************************
308
- * Name: mlk_polyvec_ntt
270
+ /**
271
+ * Apply forward NTT to all elements of a vector of polynomials.
309
272
  *
310
- * Description: Apply forward NTT to all elements of a vector of polynomials.
273
+ * The input is assumed to be in normal order and coefficient-wise bound by
274
+ * MLKEM_Q in absolute value.
311
275
  *
312
- * The input is assumed to be in normal order and
313
- * coefficient-wise bound by MLKEM_Q in absolute value.
276
+ * The output polynomial is in bitreversed order, and coefficient-wise bound
277
+ * by MLK_NTT_BOUND in absolute value.
314
278
  *
315
- * The output polynomial is in bitreversed order, and
316
- * coefficient-wise bound by MLK_NTT_BOUND in absolute value.
279
+ * @spec{Implements @[FIPS203, Algorithm 9, NTT]. Extended to vectors as per
280
+ * @[FIPS203, 2.4.6, Matrices and Vectors].}
317
281
  *
318
- * Arguments: - mlk_polyvec r: pointer to in/output vector of polynomials
319
- *
320
- * Specification:
321
- * - Implements @[FIPS203, Algorithm 9, NTT]
322
- * - Extended to vectors as per @[FIPS203, 2.4.6, Matrices and Vectors]
323
- *
324
- **************************************************/
282
+ * @param[in,out] r Input/output vector of polynomials.
283
+ */
325
284
  MLK_INTERNAL_API
326
285
  void mlk_polyvec_ntt(mlk_polyvec *r)
327
286
  __contract__(
@@ -334,25 +293,21 @@ __contract__(
334
293
  );
335
294
 
336
295
  #define mlk_polyvec_invntt_tomont MLK_NAMESPACE_K(polyvec_invntt_tomont)
337
- /*************************************************
338
- * Name: mlk_polyvec_invntt_tomont
339
- *
340
- * Description: Apply inverse NTT to all elements of a vector of polynomials
341
- * and multiply by Montgomery factor 2^16
296
+ /**
297
+ * Apply inverse NTT to all elements of a vector of polynomials and multiply
298
+ * by Montgomery factor 2^16.
342
299
  *
343
- * The input is assumed to be in bitreversed order, and can
344
- * have arbitrary coefficients in int16_t.
300
+ * The input is assumed to be in bitreversed order, and can have arbitrary
301
+ * coefficients in int16_t.
345
302
  *
346
- * The output polynomial is in normal order, and
347
- * coefficient-wise bound by MLK_INVNTT_BOUND in absolute value.
303
+ * The output polynomial is in normal order, and coefficient-wise bound by
304
+ * MLK_INVNTT_BOUND in absolute value.
348
305
  *
349
- * Arguments: - mlk_polyvec r: pointer to in/output vector of polynomials
306
+ * @spec{Implements @[FIPS203, Algorithm 10, NTT^{-1}]. Extended to vectors
307
+ * as per @[FIPS203, 2.4.6, Matrices and Vectors].}
350
308
  *
351
- * Specification:
352
- * - Implements @[FIPS203, Algorithm 10, NTT^{-1}]
353
- * - Extended to vectors as per @[FIPS203, 2.4.6, Matrices and Vectors]
354
- *
355
- **************************************************/
309
+ * @param[in,out] r Input/output vector of polynomials.
310
+ */
356
311
  MLK_INTERNAL_API
357
312
  void mlk_polyvec_invntt_tomont(mlk_polyvec *r)
358
313
  __contract__(
@@ -364,30 +319,23 @@ __contract__(
364
319
 
365
320
  #define mlk_polyvec_basemul_acc_montgomery_cached \
366
321
  MLK_NAMESPACE_K(polyvec_basemul_acc_montgomery_cached)
367
- /*************************************************
368
- * Name: mlk_polyvec_basemul_acc_montgomery_cached
369
- *
370
- * Description: Scalar product of two vectors of polynomials in NTT domain,
371
- * using mulcache for second operand.
372
- *
373
- * Bounds:
374
- * - Every coefficient of a is assumed to be in [0..4095]
375
- * - No bounds guarantees for the coefficients in the result.
376
- *
377
- * Arguments: - mlk_poly *r: pointer to output polynomial
378
- * - const mlk_polyvec a: pointer to first input polynomial vector
379
- * - const mlk_polyvec b: pointer to second input polynomial
380
- * vector
381
- * - const mlk_polyvec_mulcache b_cache: pointer to mulcache
382
- * for second input polynomial vector. Can be computed
383
- * via mlk_polyvec_mulcache_compute().
384
- *
385
- * Specification: Implements
386
- * - @[FIPS203, Section 2.4.7, Eq (2.14)]
387
- * - @[FIPS203, Algorithm 11, MultiplyNTTs]
388
- * - @[FIPS203, Algorithm 12, BaseCaseMultiply]
389
- *
390
- **************************************************/
322
+ /**
323
+ * Scalar product of two vectors of polynomials in NTT domain, using
324
+ * mulcache for the second operand.
325
+ *
326
+ * Bounds: every coefficient of @p a is assumed to be in [0,1,..,4095]. No
327
+ * bounds guarantees for the coefficients in the result.
328
+ *
329
+ * @spec{Implements @[FIPS203, Section 2.4.7, Eq (2.14)], @[FIPS203,
330
+ * Algorithm 11, MultiplyNTTs], and @[FIPS203, Algorithm 12,
331
+ * BaseCaseMultiply].}
332
+ *
333
+ * @param[out] r Output polynomial.
334
+ * @param[in] a First input polynomial vector.
335
+ * @param[in] b Second input polynomial vector.
336
+ * @param[in] b_cache Mulcache for the second input polynomial vector. Can
337
+ * be computed via mlk_polyvec_mulcache_compute().
338
+ */
391
339
  MLK_INTERNAL_API
392
340
  void mlk_polyvec_basemul_acc_montgomery_cached(
393
341
  mlk_poly *r, const mlk_polyvec *a, const mlk_polyvec *b,
@@ -403,30 +351,26 @@ __contract__(
403
351
  );
404
352
 
405
353
  #define mlk_polyvec_mulcache_compute MLK_NAMESPACE_K(polyvec_mulcache_compute)
406
- /************************************************************
407
- * Name: mlk_polyvec_mulcache_compute
354
+ /**
355
+ * Compute the mulcache for a vector of polynomials in NTT domain.
408
356
  *
409
- * Description: Computes the mulcache for a vector of polynomials in NTT domain
357
+ * The mulcache of a degree-2 polynomial b := b0 + b1*X in Fq[X]/(X^2-zeta)
358
+ * is the value b1*zeta, needed when computing products of b in
359
+ * Fq[X]/(X^2-zeta).
410
360
  *
411
- * The mulcache of a degree-2 polynomial b := b0 + b1*X
412
- * in Fq[X]/(X^2-zeta) is the value b1*zeta, needed when
413
- * computing products of b in Fq[X]/(X^2-zeta).
361
+ * The mulcache of a polynomial in NTT domain -- which is a 128-tuple of
362
+ * degree-2 polynomials in Fq[X]/(X^2-zeta), for varying zeta, is the
363
+ * 128-tuple of mulcaches of those polynomials.
414
364
  *
415
- * The mulcache of a polynomial in NTT domain -- which is
416
- * a 128-tuple of degree-2 polynomials in Fq[X]/(X^2-zeta),
417
- * for varying zeta, is the 128-tuple of mulcaches of those
418
- * polynomials.
365
+ * The mulcache of a vector of polynomials is the vector of mulcaches of
366
+ * its entries.
419
367
  *
420
- * The mulcache of a vector of polynomials is the vector
421
- * of mulcaches of its entries.
368
+ * @spec{Caches `b_1 * \gamma` in @[FIPS203, Algorithm 12, BaseCaseMultiply,
369
+ * L1].}
422
370
  *
423
- * Arguments: - x: Pointer to mulcache to be populated
424
- * - a: Pointer to input polynomial vector
425
- *
426
- * Specification:
427
- * - Caches `b_1 * \gamma` in @[FIPS203, Algorithm 12, BaseCaseMultiply, L1]
428
- *
429
- ************************************************************/
371
+ * @param[out] x Mulcache to be populated.
372
+ * @param[in] a Input polynomial vector.
373
+ */
430
374
  /*
431
375
  * NOTE: The default C implementation of this function populates
432
376
  * the mulcache with values in (-q,q), but this is not needed for the
@@ -441,20 +385,16 @@ __contract__(
441
385
  );
442
386
 
443
387
  #define mlk_polyvec_reduce MLK_NAMESPACE_K(polyvec_reduce)
444
- /*************************************************
445
- * Name: mlk_polyvec_reduce
388
+ /**
389
+ * Apply Barrett reduction to each coefficient of each element of a vector
390
+ * of polynomials. For details of the Barrett reduction see comments in
391
+ * poly.c.
446
392
  *
447
- * Description: Applies Barrett reduction to each coefficient
448
- * of each element of a vector of polynomials;
449
- * for details of the Barrett reduction see comments in poly.c
393
+ * @spec{Normalizes on unsigned canonical representatives ahead of calling
394
+ * @[FIPS203, Compress_d, Eq (4.7)]. This is not made explicit in FIPS 203.}
450
395
  *
451
- * Arguments: - mlk_polyvec r: pointer to input/output polynomial
452
- *
453
- * Specification: Normalizes on unsigned canoncial representatives
454
- * ahead of calling @[FIPS203, Compress_d, Eq (4.7)].
455
- * This is not made explicit in FIPS 203.
456
- *
457
- **************************************************/
396
+ * @param[in,out] r Input/output polynomial vector.
397
+ */
458
398
  /*
459
399
  * NOTE: The semantics of mlk_polyvec_reduce() is different in
460
400
  * the reference implementation, which requires
@@ -472,28 +412,22 @@ __contract__(
472
412
  );
473
413
 
474
414
  #define mlk_polyvec_add MLK_NAMESPACE_K(polyvec_add)
475
- /*************************************************
476
- * Name: mlk_polyvec_add
415
+ /**
416
+ * Add vectors of polynomials.
477
417
  *
478
- * Description: Add vectors of polynomials
479
- *
480
- * Arguments: - mlk_polyvec r: pointer to input-output vector of polynomials to
481
- * be added to
482
- * - const mlk_polyvec b: pointer to second input vector of
483
- * polynomials
484
- *
485
- * The coefficients of r and b must be so that the addition does
418
+ * The coefficients of @p r and @p b must be such that the addition does
486
419
  * not overflow. Otherwise, the behaviour of this function is undefined.
487
420
  *
488
- * The coefficients returned in *r are in int16_t which is sufficient
489
- * to prove type-safety of calling units. Therefore, no stronger
490
- * ensures clause is required on this function.
421
+ * The coefficients returned in @p *r are in int16_t which is sufficient to
422
+ * prove type-safety of calling units. Therefore, no stronger ensures clause
423
+ * is required on this function.
491
424
  *
492
- * Specification:
493
- * - @[FIPS203, 2.4.5, Arithmetic With Polynomials and NTT Representations]
494
- * - Used in @[FIPS203, Algorithm 14 (K-PKE.Encrypt), L19]
425
+ * @spec{@[FIPS203, 2.4.5, Arithmetic With Polynomials and NTT
426
+ * Representations]. Used in @[FIPS203, Algorithm 14 (K-PKE.Encrypt), L19].}
495
427
  *
496
- **************************************************/
428
+ * @param[in,out] r Input-output vector of polynomials to be added to.
429
+ * @param[in] b Second input vector of polynomials.
430
+ */
497
431
  MLK_INTERNAL_API
498
432
  void mlk_polyvec_add(mlk_polyvec *r, const mlk_polyvec *b)
499
433
  __contract__(
@@ -509,20 +443,18 @@ __contract__(
509
443
  );
510
444
 
511
445
  #define mlk_polyvec_tomont MLK_NAMESPACE_K(polyvec_tomont)
512
- /*************************************************
513
- * Name: mlk_polyvec_tomont
446
+ /**
447
+ * In-place conversion of all coefficients of a polynomial vector from the
448
+ * normal domain to the Montgomery domain.
514
449
  *
515
- * Description: Inplace conversion of all coefficients of a polynomial
516
- * vector from normal domain to Montgomery domain
450
+ * Bounds: output < MLKEM_Q in absolute value.
517
451
  *
518
- * Bounds: Output < q in absolute value.
452
+ * @spec{Internal normalization required in `mlk_indcpa_keypair_derand` as
453
+ * part of matrix-vector multiplication @[FIPS203, Algorithm 13, K-PKE.KeyGen,
454
+ * L18].}
519
455
  *
520
- *
521
- * Specification: Internal normalization required in `mlk_indcpa_keypair_derand`
522
- * as part of matrix-vector multiplication
523
- * @[FIPS203, Algorithm 13, K-PKE.KeyGen, L18].
524
- *
525
- **************************************************/
456
+ * @param[in,out] r Input/output polynomial vector.
457
+ */
526
458
  MLK_INTERNAL_API
527
459
  void mlk_polyvec_tomont(mlk_polyvec *r)
528
460
  __contract__(
@@ -533,28 +465,27 @@ __contract__(
533
465
  );
534
466
 
535
467
  #define mlk_poly_getnoise_eta1_4x MLK_NAMESPACE_K(poly_getnoise_eta1_4x)
536
- /*************************************************
537
- * Name: mlk_poly_getnoise_eta1_4x
538
- *
539
- * Description: Batch sample four polynomials deterministically from a seed
540
- * and nonces, with output polynomials close to centered binomial
541
- * distribution with parameter MLKEM_ETA1.
542
- *
543
- * Arguments: - mlk_poly *r{0,1,2,3}: pointer to output polynomial. The last
544
- * polynomial pointer may be NULL.
545
- * - const uint8_t *seed: pointer to input seed
546
- * (of length MLKEM_SYMBYTES bytes)
547
- * - uint8_t nonce{0,1,2,3}: one-byte input nonce
548
- *
549
- * Specification:
550
- * Implements 4x `SamplePolyCBD_{eta1} (PRF_{eta1} (sigma, N))`:
551
- * - @[FIPS203, Algorithm 8, SamplePolyCBD_eta]
552
- * - @[FIPS203, Eq (4.3), PRF_eta]
553
- * - `SamplePolyCBD_{eta1} (PRF_{eta1} (sigma, N))` appears in
554
- * @[FIPS203, Algorithm 13, K-PKE.KeyGen, L{9, 13}]
555
- * @[FIPS203, Algorithm 14, K-PKE.Encrypt, L10]
556
- *
557
- **************************************************/
468
+ /**
469
+ * Batch sample four polynomials deterministically from a seed and nonces,
470
+ * with output polynomials close to centered binomial distribution with
471
+ * parameter MLKEM_ETA1.
472
+ *
473
+ * @spec{Implements 4x `SamplePolyCBD_{eta1} (PRF_{eta1} (sigma, N))`:
474
+ * @[FIPS203, Algorithm 8, SamplePolyCBD_eta] and @[FIPS203, Eq (4.3),
475
+ * PRF_eta]. `SamplePolyCBD_{eta1} (PRF_{eta1} (sigma, N))` appears in
476
+ * @[FIPS203, Algorithm 13, K-PKE.KeyGen, L{9, 13}] and @[FIPS203,
477
+ * Algorithm 14, K-PKE.Encrypt, L10].}
478
+ *
479
+ * @param[out] r0 Output polynomial.
480
+ * @param[out] r1 Output polynomial.
481
+ * @param[out] r2 Output polynomial.
482
+ * @param[out] r3 Output polynomial. May be NULL.
483
+ * @param[in] seed Input seed (of length MLKEM_SYMBYTES bytes).
484
+ * @param nonce0 One-byte input nonce.
485
+ * @param nonce1 One-byte input nonce.
486
+ * @param nonce2 One-byte input nonce.
487
+ * @param nonce3 One-byte input nonce.
488
+ */
558
489
  MLK_INTERNAL_API
559
490
  void mlk_poly_getnoise_eta1_4x(mlk_poly *r0, mlk_poly *r1, mlk_poly *r2,
560
491
  mlk_poly *r3, const uint8_t seed[MLKEM_SYMBYTES],
@@ -587,26 +518,20 @@ __contract__(
587
518
 
588
519
  #if MLKEM_K == 2 || MLKEM_K == 4
589
520
  #define mlk_poly_getnoise_eta2 MLK_NAMESPACE_K(poly_getnoise_eta2)
590
- /*************************************************
591
- * Name: mlk_poly_getnoise_eta2
592
- *
593
- * Description: Sample a polynomial deterministically from a seed and a nonce,
594
- * with output polynomial close to centered binomial distribution
595
- * with parameter MLKEM_ETA2
596
- *
597
- * Arguments: - mlk_poly *r: pointer to output polynomial
598
- * - const uint8_t *seed: pointer to input seed
599
- * (of length MLKEM_SYMBYTES bytes)
600
- * - uint8_t nonce: one-byte input nonce
601
- *
602
- * Specification:
603
- * Implements `SamplePolyCBD_{eta2} (PRF_{eta2} (sigma, N))`:
604
- * - @[FIPS203, Algorithm 8, SamplePolyCBD_eta]
605
- * - @[FIPS203, Eq (4.3), PRF_eta]
606
- * - `SamplePolyCBD_{eta2} (PRF_{eta2} (sigma, N))` appears in
607
- * @[FIPS203, Algorithm 14, K-PKE.Encrypt, L14]
608
- *
609
- **************************************************/
521
+ /**
522
+ * Sample a polynomial deterministically from a seed and a nonce, with
523
+ * output polynomial close to centered binomial distribution with parameter
524
+ * MLKEM_ETA2.
525
+ *
526
+ * @spec{Implements `SamplePolyCBD_{eta2} (PRF_{eta2} (sigma, N))`:
527
+ * @[FIPS203, Algorithm 8, SamplePolyCBD_eta] and @[FIPS203, Eq (4.3),
528
+ * PRF_eta]. `SamplePolyCBD_{eta2} (PRF_{eta2} (sigma, N))` appears in
529
+ * @[FIPS203, Algorithm 14, K-PKE.Encrypt, L14].}
530
+ *
531
+ * @param[out] r Output polynomial.
532
+ * @param[in] seed Input seed (of length MLKEM_SYMBYTES bytes).
533
+ * @param nonce One-byte input nonce.
534
+ */
610
535
  MLK_INTERNAL_API
611
536
  void mlk_poly_getnoise_eta2(mlk_poly *r, const uint8_t seed[MLKEM_SYMBYTES],
612
537
  uint8_t nonce)
@@ -620,28 +545,28 @@ __contract__(
620
545
 
621
546
  #if MLKEM_K == 2
622
547
  #define mlk_poly_getnoise_eta1122_4x MLK_NAMESPACE_K(poly_getnoise_eta1122_4x)
623
- /*************************************************
624
- * Name: mlk_poly_getnoise_eta1122_4x
625
- *
626
- * Description: Batch sample four polynomials deterministically from a seed
627
- * and a nonces, with output polynomials close to centered binomial
628
- * distribution with parameter MLKEM_ETA1 and MLKEM_ETA2
548
+ /**
549
+ * Batch sample four polynomials deterministically from a seed and nonces,
550
+ * with output polynomials close to centered binomial distribution with
551
+ * parameter MLKEM_ETA1 and MLKEM_ETA2.
629
552
  *
630
- * Arguments: - mlk_poly *r{0,1,2,3}: pointer to output polynomial
631
- * - const uint8_t *seed: pointer to input seed
632
- * (of length MLKEM_SYMBYTES bytes)
633
- * - uint8_t nonce{0,1,2,3}: one-byte input nonce
634
- *
635
- * Specification:
636
- * Implements two instances each of
553
+ * @spec{Implements two instances each of
637
554
  * `SamplePolyCBD_{eta1} (PRF_{eta1} (sigma, N))` and
638
555
  * `SamplePolyCBD_{eta2} (PRF_{eta2} (sigma, N))`:
639
- * - @[FIPS203, Algorithm 8, SamplePolyCBD_eta]
640
- * - @[FIPS203, Eq (4.3), PRF_eta]
641
- * - `SamplePolyCBD_{eta2} (PRF_{eta2} (sigma, N))` appears in
642
- * @[FIPS203, Algorithm 14, K-PKE.Encrypt, L14]
643
- *
644
- **************************************************/
556
+ * @[FIPS203, Algorithm 8, SamplePolyCBD_eta] and @[FIPS203, Eq (4.3),
557
+ * PRF_eta]. `SamplePolyCBD_{eta2} (PRF_{eta2} (sigma, N))` appears in
558
+ * @[FIPS203, Algorithm 14, K-PKE.Encrypt, L14].}
559
+ *
560
+ * @param[out] r0 Output polynomial.
561
+ * @param[out] r1 Output polynomial.
562
+ * @param[out] r2 Output polynomial.
563
+ * @param[out] r3 Output polynomial.
564
+ * @param[in] seed Input seed (of length MLKEM_SYMBYTES bytes).
565
+ * @param nonce0 One-byte input nonce.
566
+ * @param nonce1 One-byte input nonce.
567
+ * @param nonce2 One-byte input nonce.
568
+ * @param nonce3 One-byte input nonce.
569
+ */
645
570
  MLK_INTERNAL_API
646
571
  void mlk_poly_getnoise_eta1122_4x(mlk_poly *r0, mlk_poly *r1, mlk_poly *r2,
647
572
  mlk_poly *r3,