pq_crypto 0.6.1 → 0.6.2

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 (141) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -0
  3. data/SECURITY.md +7 -0
  4. data/ext/pqcrypto/pqcrypto_version.h +1 -1
  5. data/ext/pqcrypto/vendor/.vendored +4 -4
  6. data/ext/pqcrypto/vendor/mldsa-native/README.md +23 -10
  7. data/ext/pqcrypto/vendor/mldsa-native/mldsa/README.md +23 -0
  8. data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native.c +114 -58
  9. data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native.h +498 -461
  10. data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native_asm.S +145 -85
  11. data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native_config.h +456 -422
  12. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/cbmc.h +47 -25
  13. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/common.h +26 -14
  14. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/ct.h +56 -81
  15. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/debug.h +17 -24
  16. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/fips202.c +33 -40
  17. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/fips202.h +67 -87
  18. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/fips202x4.c +19 -14
  19. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/fips202x4.h +13 -5
  20. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/keccakf1600.c +84 -10
  21. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/keccakf1600.h +10 -5
  22. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/auto.h +6 -0
  23. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/fips202_native_aarch64.h +22 -15
  24. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_scalar_aarch64_asm.S +376 -0
  25. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_v84a_aarch64_asm.S +204 -0
  26. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x2_v84a_aarch64_asm.S +259 -0
  27. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_scalar_hybrid_aarch64_asm.S +1077 -0
  28. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_v84a_scalar_hybrid_aarch64_asm.S +987 -0
  29. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccakf1600_round_constants.c +16 -10
  30. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x1_scalar.h +2 -1
  31. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x1_v84a.h +1 -1
  32. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x2_v84a.h +4 -2
  33. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x4_v8a_scalar.h +2 -2
  34. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x4_v8a_v84a_scalar.h +1 -1
  35. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/api.h +60 -0
  36. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/mve.h +48 -0
  37. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/fips202_native_armv81m.h +18 -1
  38. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.S +658 -582
  39. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.c +5 -100
  40. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccakf1600_round_constants.c +26 -25
  41. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/state_extract_bytes_x4_mve.S +334 -0
  42. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/state_xor_bytes_x4_mve.S +355 -0
  43. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/auto.h +8 -3
  44. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/{xkcp.h → keccak_f1600_x4_avx2.h} +11 -8
  45. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/fips202_native_x86_64.h +44 -0
  46. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/keccak_f1600_x4_avx2_asm.S +454 -0
  47. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/keccakf1600_constants.c +52 -0
  48. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/meta.h +37 -28
  49. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/aarch64_zetas.c +213 -196
  50. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/arith_native_aarch64.h +248 -64
  51. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/intt_aarch64_asm.S +753 -0
  52. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l4_aarch64_asm.S +129 -0
  53. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l5_aarch64_asm.S +145 -0
  54. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l7_aarch64_asm.S +177 -0
  55. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/ntt_aarch64_asm.S +653 -0
  56. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/pointwise_montgomery_aarch64_asm.S +84 -0
  57. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_caddq_aarch64_asm.S +53 -0
  58. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_chknorm_aarch64_asm.S +55 -0
  59. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_decompose_32_aarch64_asm.S +86 -0
  60. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_decompose_88_aarch64_asm.S +86 -0
  61. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_use_hint_32_aarch64_asm.S +103 -0
  62. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_use_hint_88_aarch64_asm.S +111 -0
  63. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/polyz_unpack_17_aarch64_asm.S +75 -0
  64. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/polyz_unpack_19_aarch64_asm.S +72 -0
  65. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/polyz_unpack_table.c +23 -11
  66. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_aarch64_asm.S +189 -0
  67. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_eta2_aarch64_asm.S +137 -0
  68. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_eta4_aarch64_asm.S +130 -0
  69. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_eta_table.c +520 -516
  70. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_table.c +34 -33
  71. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/api.h +202 -242
  72. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/meta.h +25 -17
  73. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/arith_native_x86_64.h +112 -28
  74. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/consts.c +1 -1
  75. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/consts.h +1 -1
  76. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/intt_avx2_asm.S +2311 -0
  77. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/ntt_avx2_asm.S +2383 -0
  78. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/nttunpack_avx2_asm.S +238 -0
  79. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l4_avx2_asm.S +139 -0
  80. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l5_avx2_asm.S +155 -0
  81. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l7_avx2_asm.S +187 -0
  82. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_avx2_asm.S +130 -0
  83. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_caddq_avx2_asm.S +190 -0
  84. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_decompose_32_avx2.c +6 -4
  85. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_decompose_88_avx2.c +6 -4
  86. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_use_hint_32_avx2.c +9 -8
  87. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_use_hint_88_avx2.c +10 -9
  88. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/polyz_unpack_17_avx2.c +8 -5
  89. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/polyz_unpack_19_avx2.c +8 -5
  90. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/rej_uniform_eta2_avx2.c +6 -4
  91. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/rej_uniform_eta4_avx2.c +6 -4
  92. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/rej_uniform_table.c +130 -129
  93. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/packing.c +109 -180
  94. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/packing.h +169 -150
  95. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly.c +56 -40
  96. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly.h +149 -164
  97. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly_kl.c +52 -57
  98. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly_kl.h +132 -167
  99. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec.c +57 -424
  100. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec.h +167 -474
  101. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec_lazy.c +308 -0
  102. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec_lazy.h +653 -0
  103. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/reduce.h +22 -29
  104. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/rounding.h +37 -43
  105. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/sign.c +511 -367
  106. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/sign.h +456 -417
  107. data/lib/pq_crypto/version.rb +1 -1
  108. data/script/vendor_libs.rb +3 -3
  109. metadata +41 -35
  110. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_scalar_asm.S +0 -376
  111. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_v84a_asm.S +0 -204
  112. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x2_v84a_asm.S +0 -259
  113. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_scalar_hybrid_asm.S +0 -1077
  114. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_v84a_scalar_hybrid_asm.S +0 -987
  115. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/KeccakP_1600_times4_SIMD256.c +0 -488
  116. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/KeccakP_1600_times4_SIMD256.h +0 -16
  117. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/intt.S +0 -753
  118. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l4.S +0 -129
  119. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l5.S +0 -145
  120. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l7.S +0 -177
  121. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/ntt.S +0 -653
  122. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/pointwise_montgomery.S +0 -79
  123. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_caddq_asm.S +0 -53
  124. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_chknorm_asm.S +0 -55
  125. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_decompose_32_asm.S +0 -85
  126. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_decompose_88_asm.S +0 -85
  127. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_use_hint_32_asm.S +0 -102
  128. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_use_hint_88_asm.S +0 -110
  129. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/polyz_unpack_17_asm.S +0 -72
  130. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/polyz_unpack_19_asm.S +0 -69
  131. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_asm.S +0 -189
  132. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_eta2_asm.S +0 -135
  133. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_eta4_asm.S +0 -128
  134. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/intt.S +0 -2311
  135. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/ntt.S +0 -2383
  136. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/nttunpack.S +0 -239
  137. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise.S +0 -131
  138. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l4.S +0 -139
  139. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l5.S +0 -155
  140. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l7.S +0 -187
  141. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_caddq_avx2.c +0 -61
@@ -57,7 +57,7 @@
57
57
  #define MLD_REDUCE32_RANGE_MAX 6283009
58
58
  /*
59
59
  * This is the C<->native interface allowing for the drop-in of
60
- * native code for performance critical arithmetic components of ML-DSA.
60
+ * native code for performance-critical arithmetic components of ML-DSA.
61
61
  *
62
62
  * A _backend_ is a specific implementation of (part of) this interface.
63
63
  *
@@ -73,17 +73,15 @@
73
73
  */
74
74
 
75
75
  #if defined(MLD_USE_NATIVE_NTT)
76
- /*************************************************
77
- * Name: mld_ntt_native
76
+ /**
77
+ * Computes negacyclic number-theoretic transform (NTT) of a polynomial
78
+ * in place.
78
79
  *
79
- * Description: Computes negacyclic number-theoretic transform (NTT) of
80
- * a polynomial in place.
80
+ * The input polynomial is assumed to be in normal order. The output
81
+ * polynomial is in bitreversed order.
81
82
  *
82
- * The input polynomial is assumed to be in normal order.
83
- * The output polynomial is in bitreversed order.
84
- *
85
- * Arguments: - int32_t p[MLDSA_N]: pointer to in/output polynomial
86
- **************************************************/
83
+ * @param[in,out] p Pointer to in/output polynomial.
84
+ */
87
85
  MLD_MUST_CHECK_RETURN_VALUE
88
86
  static MLD_INLINE int mld_ntt_native(int32_t p[MLDSA_N])
89
87
  __contract__(
@@ -109,19 +107,16 @@ __contract__(
109
107
  set if there are native implementations for NTT and INTT."
110
108
  #endif
111
109
 
112
- /*************************************************
113
- * Name: mlD_poly_permute_bitrev_to_custom
114
- *
115
- * Description: When MLD_USE_NATIVE_NTT_CUSTOM_ORDER is defined,
116
- * convert a polynomial in NTT domain from bitreversed
117
- * order to the custom order output by the native NTT.
110
+ /**
111
+ * When MLD_USE_NATIVE_NTT_CUSTOM_ORDER is defined, convert a polynomial in
112
+ * NTT domain from bitreversed order to the custom order output by the native
113
+ * NTT.
118
114
  *
119
- * This must only be defined if there is native code for
120
- * both the NTT and INTT.
115
+ * This must only be defined if there is native code for both the NTT and
116
+ * INTT.
121
117
  *
122
- * Arguments: - int32_t p[MLDSA_N]: pointer to in/output polynomial
123
- *
124
- **************************************************/
118
+ * @param[in,out] p Pointer to in/output polynomial.
119
+ */
125
120
  static MLD_INLINE void mld_poly_permute_bitrev_to_custom(int32_t p[MLDSA_N])
126
121
  __contract__(
127
122
  /* We don't specify that this should be a permutation, but only
@@ -136,17 +131,15 @@ __contract__(
136
131
 
137
132
 
138
133
  #if defined(MLD_USE_NATIVE_INTT)
139
- /*************************************************
140
- * Name: mld_intt_native
141
- *
142
- * Description: Computes inverse of negacyclic number-theoretic transform
143
- *(NTT) of a polynomial in place.
134
+ /**
135
+ * Computes inverse of negacyclic number-theoretic transform (NTT) of a
136
+ * polynomial in place.
144
137
  *
145
- * The input polynomial is in bitreversed order.
146
- * The output polynomial is assumed to be in normal order.
138
+ * The input polynomial is in bitreversed order. The output polynomial is
139
+ * assumed to be in normal order.
147
140
  *
148
- * Arguments: - uint32_t p[MLDSA_N]: pointer to in/output polynomial
149
- **************************************************/
141
+ * @param[in,out] p Pointer to in/output polynomial.
142
+ */
150
143
  MLD_MUST_CHECK_RETURN_VALUE
151
144
  static MLD_INLINE int mld_intt_native(int32_t p[MLDSA_N])
152
145
  __contract__(
@@ -161,23 +154,22 @@ __contract__(
161
154
  #endif /* MLD_USE_NATIVE_INTT */
162
155
 
163
156
  #if defined(MLD_USE_NATIVE_REJ_UNIFORM)
164
- /*************************************************
165
- * Name: mld_rej_uniform_native
166
- *
167
- * Description: Run rejection sampling on uniform random bytes to generate
168
- * uniform random integers in [0, MLDSA_Q-1]
169
- *
170
- * Arguments: - int32_t *r: pointer to output buffer
171
- * - unsigned len: requested number of 32-bit integers
172
- * (uniform mod q).
173
- * - const uint8_t *buf: pointer to input buffer
174
- * (assumed to be uniform random bytes)
175
- * - unsigned buflen: length of input buffer in bytes.
176
- *
177
- * Return -1 if the native implementation does not support the input
178
- * lengths. Otherwise, returns non-negative number of sampled 32-bit integers
179
- * (at most len).
180
- **************************************************/
157
+ /**
158
+ * Run rejection sampling on uniform random bytes to generate uniform random
159
+ * integers in [0, MLDSA_Q-1].
160
+ *
161
+ * @param[out] r Pointer to output buffer.
162
+ * @param len Requested number of 32-bit integers (uniform mod
163
+ * MLDSA_Q).
164
+ * @param[in] buf Pointer to input buffer (assumed to be uniform random
165
+ * bytes).
166
+ * @param buflen Length of input buffer in bytes.
167
+ *
168
+ * @return - MLD_NATIVE_FUNC_FALLBACK if the native implementation does not
169
+ * support the input lengths.
170
+ * - Otherwise, the non-negative number of sampled 32-bit integers
171
+ * (at most len).
172
+ */
181
173
  MLD_MUST_CHECK_RETURN_VALUE
182
174
  static MLD_INLINE int mld_rej_uniform_native(int32_t *r, unsigned len,
183
175
  const uint8_t *buf,
@@ -193,25 +185,25 @@ __contract__(
193
185
  );
194
186
  #endif /* MLD_USE_NATIVE_REJ_UNIFORM */
195
187
 
188
+ #if !defined(MLD_CONFIG_NO_KEYPAIR_API)
196
189
  #if defined(MLD_USE_NATIVE_REJ_UNIFORM_ETA2)
197
190
  #if defined(MLD_CONFIG_MULTILEVEL_WITH_SHARED) || MLDSA_ETA == 2
198
- /*************************************************
199
- * Name: mld_rej_uniform_eta2_native
200
- *
201
- * Description: Run rejection sampling on uniform random bytes to generate
202
- * uniform random integers in [-2,+2].
203
- *
204
- * Arguments: - int32_t *r: pointer to output buffer
205
- * - unsigned len: requested number of 32-bit integers
206
- * (uniform in [-2, +2]).
207
- * - const uint8_t *buf: pointer to input buffer
208
- * (assumed to be uniform random bytes)
209
- * - unsigned buflen: length of input buffer in bytes.
210
- *
211
- * Return -1 if the native implementation does not support the input
212
- *lengths. Otherwise, returns non-negative number of sampled 32-bit integers
213
- *(at most len).
214
- **************************************************/
191
+ /**
192
+ * Run rejection sampling on uniform random bytes to generate uniform random
193
+ * integers in [-2, +2].
194
+ *
195
+ * @param[out] r Pointer to output buffer.
196
+ * @param len Requested number of 32-bit integers (uniform in
197
+ * [-2, +2]).
198
+ * @param[in] buf Pointer to input buffer (assumed to be uniform random
199
+ * bytes).
200
+ * @param buflen Length of input buffer in bytes.
201
+ *
202
+ * @return - MLD_NATIVE_FUNC_FALLBACK if the native implementation does not
203
+ * support the input lengths.
204
+ * - Otherwise, the non-negative number of sampled 32-bit integers
205
+ * (at most len).
206
+ */
215
207
  MLD_MUST_CHECK_RETURN_VALUE
216
208
  static MLD_INLINE int mld_rej_uniform_eta2_native(int32_t *r, unsigned len,
217
209
  const uint8_t *buf,
@@ -230,23 +222,22 @@ __contract__(
230
222
 
231
223
  #if defined(MLD_USE_NATIVE_REJ_UNIFORM_ETA4)
232
224
  #if defined(MLD_CONFIG_MULTILEVEL_WITH_SHARED) || MLDSA_ETA == 4
233
- /*************************************************
234
- * Name: mld_rej_uniform_eta4_native
235
- *
236
- * Description: Run rejection sampling on uniform random bytes to generate
237
- * uniform random integers in [-4,+4].
238
- *
239
- * Arguments: - int32_t *r: pointer to output buffer
240
- * - unsigned len: requested number of 32-bit integers
241
- * (uniform in [-4, +4]).
242
- * - const uint8_t *buf: pointer to input buffer
243
- * (assumed to be uniform random bytes)
244
- * - unsigned buflen: length of input buffer in bytes.
245
- *
246
- * Return -1 if the native implementation does not support the input
247
- *lengths. Otherwise, returns non-negative number of sampled 32-bit integers
248
- *(at most len).
249
- **************************************************/
225
+ /**
226
+ * Run rejection sampling on uniform random bytes to generate uniform random
227
+ * integers in [-4, +4].
228
+ *
229
+ * @param[out] r Pointer to output buffer.
230
+ * @param len Requested number of 32-bit integers (uniform in
231
+ * [-4, +4]).
232
+ * @param[in] buf Pointer to input buffer (assumed to be uniform random
233
+ * bytes).
234
+ * @param buflen Length of input buffer in bytes.
235
+ *
236
+ * @return - MLD_NATIVE_FUNC_FALLBACK if the native implementation does not
237
+ * support the input lengths.
238
+ * - Otherwise, the non-negative number of sampled 32-bit integers
239
+ * (at most len).
240
+ */
250
241
  MLD_MUST_CHECK_RETURN_VALUE
251
242
  static MLD_INLINE int mld_rej_uniform_eta4_native(int32_t *r, unsigned len,
252
243
  const uint8_t *buf,
@@ -262,26 +253,24 @@ __contract__(
262
253
  );
263
254
  #endif /* MLD_CONFIG_MULTILEVEL_WITH_SHARED || MLDSA_ETA == 4 */
264
255
  #endif /* MLD_USE_NATIVE_REJ_UNIFORM_ETA4 */
256
+ #endif /* !MLD_CONFIG_NO_KEYPAIR_API */
265
257
 
258
+ #if !defined(MLD_CONFIG_NO_SIGN_API)
266
259
  #if defined(MLD_USE_NATIVE_POLY_DECOMPOSE_32)
267
260
  #if defined(MLD_CONFIG_MULTILEVEL_WITH_SHARED) || \
268
261
  (MLD_CONFIG_PARAMETER_SET == 65 || MLD_CONFIG_PARAMETER_SET == 87)
269
- /*************************************************
270
- * Name: mld_poly_decompose_32_native
271
- *
272
- * Description: Native implementation of poly_decompose for GAMMA2 = (Q-1)/32.
273
- * For all coefficients c of the input polynomial,
274
- * compute high and low bits c0, c1 such
275
- * c mod MLDSA_Q = c1*(2*GAMMA2) + c0
276
- * with -(2*GAMMA2)/2 < c0 <= (2*GAMMA2)/2 except
277
- * c1 = (MLDSA_Q-1)/(2*GAMMA2) where we set
278
- * c1 = 0 and -(2*GAMMA2)/2 <= c0 = c mod MLDSA_Q - MLDSA_Q < 0.
279
- * Assumes coefficients to be standard representatives.
280
- *
281
- * Arguments: - int32_t *a1: output polynomial with coefficients c1
282
- * - int32_t *a0: input/output polynomial.
283
- * Output has coefficients c0
284
- **************************************************/
262
+ /**
263
+ * Native implementation of poly_decompose for GAMMA2 = (MLDSA_Q-1)/32.
264
+ *
265
+ * For all coefficients c of the input polynomial, compute high and low bits
266
+ * c0, c1 such c mod MLDSA_Q = c1*(2*GAMMA2) + c0 with
267
+ * -(2*GAMMA2)/2 < c0 <= (2*GAMMA2)/2 except c1 = (MLDSA_Q-1)/(2*GAMMA2) where
268
+ * we set c1 = 0 and -(2*GAMMA2)/2 <= c0 = c mod MLDSA_Q - MLDSA_Q < 0.
269
+ * Assumes coefficients to be standard representatives.
270
+ *
271
+ * @param[out] a1 Output polynomial with coefficients c1.
272
+ * @param[in,out] a0 Input/output polynomial. Output has coefficients c0.
273
+ */
285
274
  MLD_MUST_CHECK_RETURN_VALUE
286
275
  static MLD_INLINE int mld_poly_decompose_32_native(int32_t *a1, int32_t *a0)
287
276
  __contract__(
@@ -302,22 +291,18 @@ __contract__(
302
291
 
303
292
  #if defined(MLD_USE_NATIVE_POLY_DECOMPOSE_88)
304
293
  #if defined(MLD_CONFIG_MULTILEVEL_WITH_SHARED) || MLD_CONFIG_PARAMETER_SET == 44
305
- /*************************************************
306
- * Name: mld_poly_decompose_88_native
307
- *
308
- * Description: Native implementation of poly_decompose for GAMMA2 = (Q-1)/88.
309
- * For all coefficients c of the input polynomial,
310
- * compute high and low bits c0, c1 such
311
- * c mod MLDSA_Q = c1*(2*GAMMA2) + c0
312
- * with -(2*GAMMA2)/2 < c0 <= (2*GAMMA2)/2 except
313
- * c1 = (MLDSA_Q-1)/(2*GAMMA2) where we set
314
- * c1 = 0 and -(2*GAMMA2)/2 <= c0 = c mod MLDSA_Q - MLDSA_Q < 0.
315
- * Assumes coefficients to be standard representatives.
316
- *
317
- * Arguments: - int32_t *a1: output polynomial with coefficients c1
318
- * - int32_t *a0: output polynomial with coefficients c0.
319
- * Output has coefficients c0
320
- **************************************************/
294
+ /**
295
+ * Native implementation of poly_decompose for GAMMA2 = (MLDSA_Q-1)/88.
296
+ *
297
+ * For all coefficients c of the input polynomial, compute high and low bits
298
+ * c0, c1 such c mod MLDSA_Q = c1*(2*GAMMA2) + c0 with
299
+ * -(2*GAMMA2)/2 < c0 <= (2*GAMMA2)/2 except c1 = (MLDSA_Q-1)/(2*GAMMA2) where
300
+ * we set c1 = 0 and -(2*GAMMA2)/2 <= c0 = c mod MLDSA_Q - MLDSA_Q < 0.
301
+ * Assumes coefficients to be standard representatives.
302
+ *
303
+ * @param[out] a1 Output polynomial with coefficients c1.
304
+ * @param[in,out] a0 Input/output polynomial. Output has coefficients c0.
305
+ */
321
306
  MLD_MUST_CHECK_RETURN_VALUE
322
307
  static MLD_INLINE int mld_poly_decompose_88_native(int32_t *a1, int32_t *a0)
323
308
  __contract__(
@@ -335,16 +320,14 @@ __contract__(
335
320
  #endif /* MLD_CONFIG_MULTILEVEL_WITH_SHARED || MLD_CONFIG_PARAMETER_SET == 44 \
336
321
  */
337
322
  #endif /* MLD_USE_NATIVE_POLY_DECOMPOSE_88 */
323
+ #endif /* !MLD_CONFIG_NO_SIGN_API */
338
324
 
339
325
  #if defined(MLD_USE_NATIVE_POLY_CADDQ)
340
- /*************************************************
341
- * Name: mld_poly_caddq_native
342
- *
343
- * Description: For all coefficients of in/out polynomial add Q if
344
- * coefficient is negative.
326
+ /**
327
+ * For all coefficients of in/out polynomial add Q if coefficient is negative.
345
328
  *
346
- * Arguments: - int32_t *a: pointer to input/output polynomial
347
- **************************************************/
329
+ * @param[in,out] a Pointer to input/output polynomial.
330
+ */
348
331
  MLD_MUST_CHECK_RETURN_VALUE
349
332
  static MLD_INLINE int mld_poly_caddq_native(int32_t a[MLDSA_N])
350
333
  __contract__(
@@ -358,33 +341,29 @@ __contract__(
358
341
  );
359
342
  #endif /* MLD_USE_NATIVE_POLY_CADDQ */
360
343
 
344
+ #if !defined(MLD_CONFIG_NO_VERIFY_API)
361
345
  #if defined(MLD_USE_NATIVE_POLY_USE_HINT_32)
362
346
  #if defined(MLD_CONFIG_MULTILEVEL_WITH_SHARED) || \
363
347
  (MLD_CONFIG_PARAMETER_SET == 65 || MLD_CONFIG_PARAMETER_SET == 87)
364
- /*************************************************
365
- * Name: mld_poly_use_hint_32_native
348
+ /**
349
+ * Native implementation of poly_use_hint for GAMMA2 = (MLDSA_Q-1)/32.
366
350
  *
367
- * Description: Native implementation of poly_use_hint for GAMMA2 = (Q-1)/32.
368
- * Use hint polynomial to correct the high bits of a polynomial.
351
+ * Use hint h to correct the high bits of a in-place.
369
352
  *
370
- * Arguments: - int32_t *b: pointer to output polynomial with corrected high
371
- * bits
372
- * - const int32_t *a: pointer to input polynomial
373
- * - const int32_t *h: pointer to input hint polynomial
374
- **************************************************/
353
+ * @param[in,out] a Input/output polynomial.
354
+ * @param[in] h Hint polynomial.
355
+ */
375
356
  MLD_MUST_CHECK_RETURN_VALUE
376
- static MLD_INLINE int mld_poly_use_hint_32_native(int32_t *b, const int32_t *a,
377
- const int32_t *h)
357
+ static MLD_INLINE int mld_poly_use_hint_32_native(int32_t *a, const int32_t *h)
378
358
  __contract__(
379
359
  requires(memory_no_alias(a, sizeof(int32_t) * MLDSA_N))
380
- requires(memory_no_alias(b, sizeof(int32_t) * MLDSA_N))
381
360
  requires(memory_no_alias(h, sizeof(int32_t) * MLDSA_N))
382
361
  requires(array_bound(a, 0, MLDSA_N, 0, MLDSA_Q))
383
362
  requires(array_bound(h, 0, MLDSA_N, 0, 2))
384
- assigns(memory_slice(b, sizeof(int32_t) * MLDSA_N))
363
+ assigns(memory_slice(a, sizeof(int32_t) * MLDSA_N))
385
364
  ensures(return_value == MLD_NATIVE_FUNC_FALLBACK || return_value == MLD_NATIVE_FUNC_SUCCESS)
386
- ensures((return_value == MLD_NATIVE_FUNC_SUCCESS) ==> array_bound(b, 0, MLDSA_N, 0, (MLDSA_Q-1)/(2*MLDSA_GAMMA2)))
387
- ensures((return_value == MLD_NATIVE_FUNC_FALLBACK) ==> array_unchanged(b, MLDSA_N))
365
+ ensures((return_value == MLD_NATIVE_FUNC_SUCCESS) ==> array_bound(a, 0, MLDSA_N, 0, (MLDSA_Q-1)/(2*MLDSA_GAMMA2)))
366
+ ensures((return_value == MLD_NATIVE_FUNC_FALLBACK) ==> array_unchanged(a, MLDSA_N))
388
367
  );
389
368
  #endif /* MLD_CONFIG_MULTILEVEL_WITH_SHARED || MLD_CONFIG_PARAMETER_SET == 65 \
390
369
  || MLD_CONFIG_PARAMETER_SET == 87 */
@@ -392,54 +371,46 @@ __contract__(
392
371
 
393
372
  #if defined(MLD_USE_NATIVE_POLY_USE_HINT_88)
394
373
  #if defined(MLD_CONFIG_MULTILEVEL_WITH_SHARED) || MLD_CONFIG_PARAMETER_SET == 44
395
- /*************************************************
396
- * Name: mld_poly_use_hint_88_native
374
+ /**
375
+ * Native implementation of poly_use_hint for GAMMA2 = (MLDSA_Q-1)/88.
397
376
  *
398
- * Description: Native implementation of poly_use_hint for GAMMA2 = (Q-1)/88.
399
- * Use hint polynomial to correct the high bits of a polynomial.
377
+ * Use hint h to correct the high bits of a in-place.
400
378
  *
401
- * Arguments: - int32_t *b: pointer to output polynomial with corrected high
402
- * bits
403
- * - const int32_t *a: pointer to input polynomial
404
- * - const int32_t *h: pointer to input hint polynomial
405
- **************************************************/
379
+ * @param[in,out] a Input/output polynomial.
380
+ * @param[in] h Hint polynomial.
381
+ */
406
382
  MLD_MUST_CHECK_RETURN_VALUE
407
- static MLD_INLINE int mld_poly_use_hint_88_native(int32_t *b, const int32_t *a,
408
- const int32_t *h)
383
+ static MLD_INLINE int mld_poly_use_hint_88_native(int32_t *a, const int32_t *h)
409
384
  __contract__(
410
385
  requires(memory_no_alias(a, sizeof(int32_t) * MLDSA_N))
411
- requires(memory_no_alias(b, sizeof(int32_t) * MLDSA_N))
412
386
  requires(memory_no_alias(h, sizeof(int32_t) * MLDSA_N))
413
387
  requires(array_bound(a, 0, MLDSA_N, 0, MLDSA_Q))
414
388
  requires(array_bound(h, 0, MLDSA_N, 0, 2))
415
- assigns(memory_slice(b, sizeof(int32_t) * MLDSA_N))
389
+ assigns(memory_slice(a, sizeof(int32_t) * MLDSA_N))
416
390
  ensures(return_value == MLD_NATIVE_FUNC_FALLBACK || return_value == MLD_NATIVE_FUNC_SUCCESS)
417
- ensures((return_value == MLD_NATIVE_FUNC_SUCCESS) ==> array_bound(b, 0, MLDSA_N, 0, (MLDSA_Q-1)/(2*MLDSA_GAMMA2)))
418
- ensures((return_value == MLD_NATIVE_FUNC_FALLBACK) ==> array_unchanged(b, MLDSA_N))
391
+ ensures((return_value == MLD_NATIVE_FUNC_SUCCESS) ==> array_bound(a, 0, MLDSA_N, 0, (MLDSA_Q-1)/(2*MLDSA_GAMMA2)))
392
+ ensures((return_value == MLD_NATIVE_FUNC_FALLBACK) ==> array_unchanged(a, MLDSA_N))
419
393
  );
420
394
  #endif /* MLD_CONFIG_MULTILEVEL_WITH_SHARED || MLD_CONFIG_PARAMETER_SET == 44 \
421
395
  */
422
396
  #endif /* MLD_USE_NATIVE_POLY_USE_HINT_88 */
397
+ #endif /* !MLD_CONFIG_NO_VERIFY_API */
423
398
 
424
399
  #if defined(MLD_USE_NATIVE_POLY_CHKNORM)
425
- /*************************************************
426
- * Name: mld_poly_chknorm_native
427
- *
428
- * Description: Check infinity norm of polynomial against given bound.
429
- * Assumes input coefficients were reduced by mld_reduce32().
430
- *
431
- * Arguments: - const int32_t *a: pointer to polynomial
432
- * - int32_t B: norm bound, which must be in the range
433
- * 0 .. MLDSA_Q - MLD_REDUCE32_RANGE_MAX inclusive.
434
- *
435
- * Returns MLD_NATIVE_FUNC_FALLBACK (-1) if the target CPU cannot
436
- * support a native implementation of this function.
437
- *
438
- * If the target CPU can support this function, then
439
- * Returns MLD_NATIVE_FUNC_SUCCESS (0) if the infinity norm is strictly
440
- * smaller than B
441
- * Returns 1 otherwise
442
- **************************************************/
400
+ /**
401
+ * Check infinity norm of polynomial against given bound. Assumes input
402
+ * coefficients were reduced by mld_reduce32().
403
+ *
404
+ * @param[in] a Pointer to polynomial.
405
+ * @param B Norm bound, which must be in the range
406
+ * 0 .. MLDSA_Q - MLD_REDUCE32_RANGE_MAX inclusive.
407
+ *
408
+ * @return - MLD_NATIVE_FUNC_FALLBACK if the target CPU cannot support a
409
+ * native implementation of this function.
410
+ * - MLD_NATIVE_FUNC_SUCCESS if the infinity norm is strictly smaller
411
+ * than B.
412
+ * - 1 otherwise.
413
+ */
443
414
  MLD_MUST_CHECK_RETURN_VALUE
444
415
  static MLD_INLINE int mld_poly_chknorm_native(const int32_t *a, int32_t B)
445
416
  __contract__(
@@ -453,18 +424,18 @@ __contract__(
453
424
  );
454
425
  #endif /* MLD_USE_NATIVE_POLY_CHKNORM */
455
426
 
427
+ #if !defined(MLD_CONFIG_NO_SIGN_API) || !defined(MLD_CONFIG_NO_VERIFY_API)
456
428
  #if defined(MLD_USE_NATIVE_POLYZ_UNPACK_17)
457
429
  #if defined(MLD_CONFIG_MULTILEVEL_WITH_SHARED) || MLD_CONFIG_PARAMETER_SET == 44
458
- /*************************************************
459
- * Name: mld_polyz_unpack_17_native
430
+ /**
431
+ * Native implementation of polyz_unpack for GAMMA1 = 2^17.
460
432
  *
461
- * Description: Native implementation of polyz_unpack for GAMMA1 = 2^17.
462
- * Unpack polynomial z with coefficients
463
- * in [-(MLDSA_GAMMA1 - 1), MLDSA_GAMMA1].
433
+ * Unpack polynomial z with coefficients in
434
+ * [-(MLDSA_GAMMA1 - 1), MLDSA_GAMMA1].
464
435
  *
465
- * Arguments: - int32_t *r: pointer to output polynomial
466
- * - const uint8_t *a: byte array with bit-packed polynomial
467
- **************************************************/
436
+ * @param[out] r Pointer to output polynomial.
437
+ * @param[in] a Byte array with bit-packed polynomial.
438
+ */
468
439
  MLD_MUST_CHECK_RETURN_VALUE
469
440
  static MLD_INLINE int mld_polyz_unpack_17_native(int32_t *r, const uint8_t *a)
470
441
  __contract__(
@@ -482,16 +453,15 @@ __contract__(
482
453
  #if defined(MLD_USE_NATIVE_POLYZ_UNPACK_19)
483
454
  #if defined(MLD_CONFIG_MULTILEVEL_WITH_SHARED) || \
484
455
  (MLD_CONFIG_PARAMETER_SET == 65 || MLD_CONFIG_PARAMETER_SET == 87)
485
- /*************************************************
486
- * Name: mld_polyz_unpack_19_native
456
+ /**
457
+ * Native implementation of polyz_unpack for GAMMA1 = 2^19.
487
458
  *
488
- * Description: Native implementation of polyz_unpack for GAMMA1 = 2^19.
489
- * Unpack polynomial z with coefficients
490
- * in [-(MLDSA_GAMMA1 - 1), MLDSA_GAMMA1].
459
+ * Unpack polynomial z with coefficients in
460
+ * [-(MLDSA_GAMMA1 - 1), MLDSA_GAMMA1].
491
461
  *
492
- * Arguments: - int32_t *r: pointer to output polynomial
493
- * - const uint8_t *a: byte array with bit-packed polynomial
494
- **************************************************/
462
+ * @param[out] r Pointer to output polynomial.
463
+ * @param[in] a Byte array with bit-packed polynomial.
464
+ */
495
465
  MLD_MUST_CHECK_RETURN_VALUE
496
466
  static MLD_INLINE int mld_polyz_unpack_19_native(int32_t *r, const uint8_t *a)
497
467
  __contract__(
@@ -505,55 +475,51 @@ __contract__(
505
475
  #endif /* MLD_CONFIG_MULTILEVEL_WITH_SHARED || MLD_CONFIG_PARAMETER_SET == 65 \
506
476
  || MLD_CONFIG_PARAMETER_SET == 87 */
507
477
  #endif /* MLD_USE_NATIVE_POLYZ_UNPACK_19 */
478
+ #endif /* !MLD_CONFIG_NO_SIGN_API || !MLD_CONFIG_NO_VERIFY_API */
508
479
 
480
+ #if !defined(MLD_CONFIG_NO_SIGN_API) || !defined(MLD_CONFIG_NO_VERIFY_API) || \
481
+ defined(MLD_CONFIG_REDUCE_RAM) || defined(MLD_UNIT_TEST)
509
482
  #if defined(MLD_USE_NATIVE_POINTWISE_MONTGOMERY)
510
- /*************************************************
511
- * Name: mld_poly_pointwise_montgomery_native
512
- *
513
- * Description: Pointwise multiplication of polynomials in NTT domain
514
- * with Montgomery reduction.
483
+ /**
484
+ * Pointwise multiplication of polynomials in NTT domain with Montgomery
485
+ * reduction. Destructive in the first argument.
515
486
  *
516
- * Computes c[i] = a[i] * b[i] * R^(-1) mod q for all i,
517
- * where R = 2^32.
487
+ * Computes a[i] = a[i] * b[i] * R^(-1) mod MLDSA_Q for all i, where R = 2^32.
518
488
  *
519
- * Arguments: - int32_t c[MLDSA_N]: output polynomial
520
- * - const int32_t a[MLDSA_N]: first input polynomial
521
- * - const int32_t b[MLDSA_N]: second input polynomial
522
- **************************************************/
489
+ * @param[in,out] a First input/output polynomial.
490
+ * @param[in] b Second input polynomial.
491
+ */
523
492
  MLD_MUST_CHECK_RETURN_VALUE
524
493
  static MLD_INLINE int mld_poly_pointwise_montgomery_native(
525
- int32_t c[MLDSA_N], const int32_t a[MLDSA_N], const int32_t b[MLDSA_N])
494
+ int32_t a[MLDSA_N], const int32_t b[MLDSA_N])
526
495
  __contract__(
527
496
  requires(memory_no_alias(a, sizeof(int32_t) * MLDSA_N))
528
497
  requires(memory_no_alias(b, sizeof(int32_t) * MLDSA_N))
529
- requires(memory_no_alias(c, sizeof(int32_t) * MLDSA_N))
530
498
  requires(array_abs_bound(a, 0, MLDSA_N, MLD_NTT_BOUND))
531
499
  requires(array_abs_bound(b, 0, MLDSA_N, MLD_NTT_BOUND))
532
- assigns(memory_slice(c, sizeof(int32_t) * MLDSA_N))
500
+ assigns(memory_slice(a, sizeof(int32_t) * MLDSA_N))
533
501
  ensures(return_value == MLD_NATIVE_FUNC_FALLBACK || return_value == MLD_NATIVE_FUNC_SUCCESS)
534
- ensures((return_value == MLD_NATIVE_FUNC_SUCCESS) ==> array_abs_bound(c, 0, MLDSA_N, MLDSA_Q))
502
+ ensures((return_value == MLD_NATIVE_FUNC_SUCCESS) ==> array_abs_bound(a, 0, MLDSA_N, MLDSA_Q))
535
503
  ensures((return_value == MLD_NATIVE_FUNC_FALLBACK) ==> array_abs_bound(a, 0, MLDSA_N, MLD_NTT_BOUND))
536
504
  ensures((return_value == MLD_NATIVE_FUNC_FALLBACK) ==> array_abs_bound(b, 0, MLDSA_N, MLD_NTT_BOUND))
537
- ensures((return_value == MLD_NATIVE_FUNC_FALLBACK) ==> array_unchanged(c, MLDSA_N))
538
505
  );
539
506
  #endif /* MLD_USE_NATIVE_POINTWISE_MONTGOMERY */
507
+ #endif /* !MLD_CONFIG_NO_SIGN_API || !MLD_CONFIG_NO_VERIFY_API || \
508
+ MLD_CONFIG_REDUCE_RAM || MLD_UNIT_TEST */
540
509
 
541
510
  #if defined(MLD_USE_NATIVE_POLYVECL_POINTWISE_ACC_MONTGOMERY_L4)
542
511
  #if defined(MLD_CONFIG_MULTILEVEL_WITH_SHARED) || MLDSA_L == 4
543
- /*************************************************
544
- * Name: mld_polyvecl_pointwise_acc_montgomery_l4_native
545
- *
546
- * Description: Native implementation of polyvecl_pointwise_acc_montgomery for
547
- * MLDSA_L = 4.
548
- * Pointwise multiply vectors of polynomials of length MLDSA_L,
549
- * multiply resulting vector by 2^{-32} and add (accumulate)
550
- * polynomials in it.
551
- * Input/output vectors are in NTT domain representation.
552
- *
553
- * Arguments: - int32_t w[MLDSA_N]: output polynomial
554
- * - const int32_t u[MLDSA_L][MLDSA_N]: first input vector
555
- * - const int32_t v[MLDSA_L][MLDSA_N]: second input vector
556
- **************************************************/
512
+ /**
513
+ * Native implementation of polyvecl_pointwise_acc_montgomery for MLDSA_L = 4.
514
+ *
515
+ * Pointwise multiply vectors of polynomials of length MLDSA_L, multiply
516
+ * resulting vector by 2^{-32} and add (accumulate) polynomials in it.
517
+ * Input/output vectors are in NTT domain representation.
518
+ *
519
+ * @param[out] w Output polynomial.
520
+ * @param[in] u First input vector.
521
+ * @param[in] v Second input vector.
522
+ */
557
523
  MLD_MUST_CHECK_RETURN_VALUE
558
524
  static MLD_INLINE int mld_polyvecl_pointwise_acc_montgomery_l4_native(
559
525
  int32_t w[MLDSA_N], const int32_t u[4][MLDSA_N],
@@ -576,20 +542,17 @@ __contract__(
576
542
 
577
543
  #if defined(MLD_USE_NATIVE_POLYVECL_POINTWISE_ACC_MONTGOMERY_L5)
578
544
  #if defined(MLD_CONFIG_MULTILEVEL_WITH_SHARED) || MLDSA_L == 5
579
- /*************************************************
580
- * Name: mld_polyvecl_pointwise_acc_montgomery_l5_native
581
- *
582
- * Description: Native implementation of polyvecl_pointwise_acc_montgomery for
583
- * MLDSA_L = 5.
584
- * Pointwise multiply vectors of polynomials of length MLDSA_L,
585
- * multiply resulting vector by 2^{-32} and add (accumulate)
586
- * polynomials in it.
587
- * Input/output vectors are in NTT domain representation.
588
- *
589
- * Arguments: - int32_t w[MLDSA_N]: output polynomial
590
- * - const int32_t u[MLDSA_L][MLDSA_N]: first input vector
591
- * - const int32_t v[MLDSA_L][MLDSA_N]: second input vector
592
- **************************************************/
545
+ /**
546
+ * Native implementation of polyvecl_pointwise_acc_montgomery for MLDSA_L = 5.
547
+ *
548
+ * Pointwise multiply vectors of polynomials of length MLDSA_L, multiply
549
+ * resulting vector by 2^{-32} and add (accumulate) polynomials in it.
550
+ * Input/output vectors are in NTT domain representation.
551
+ *
552
+ * @param[out] w Output polynomial.
553
+ * @param[in] u First input vector.
554
+ * @param[in] v Second input vector.
555
+ */
593
556
  MLD_MUST_CHECK_RETURN_VALUE
594
557
  static MLD_INLINE int mld_polyvecl_pointwise_acc_montgomery_l5_native(
595
558
  int32_t w[MLDSA_N], const int32_t u[5][MLDSA_N],
@@ -612,20 +575,17 @@ __contract__(
612
575
 
613
576
  #if defined(MLD_USE_NATIVE_POLYVECL_POINTWISE_ACC_MONTGOMERY_L7)
614
577
  #if defined(MLD_CONFIG_MULTILEVEL_WITH_SHARED) || MLDSA_L == 7
615
- /*************************************************
616
- * Name: mld_polyvecl_pointwise_acc_montgomery_l7_native
617
- *
618
- * Description: Native implementation of polyvecl_pointwise_acc_montgomery for
619
- * MLDSA_L = 7.
620
- * Pointwise multiply vectors of polynomials of length MLDSA_L,
621
- * multiply resulting vector by 2^{-32} and add (accumulate)
622
- * polynomials in it.
623
- * Input/output vectors are in NTT domain representation.
624
- *
625
- * Arguments: - int32_t w[MLDSA_N]: output polynomial
626
- * - const int32_t u[MLDSA_L][MLDSA_N]: first input vector
627
- * - const int32_t v[MLDSA_L][MLDSA_N]: second input vector
628
- **************************************************/
578
+ /**
579
+ * Native implementation of polyvecl_pointwise_acc_montgomery for MLDSA_L = 7.
580
+ *
581
+ * Pointwise multiply vectors of polynomials of length MLDSA_L, multiply
582
+ * resulting vector by 2^{-32} and add (accumulate) polynomials in it.
583
+ * Input/output vectors are in NTT domain representation.
584
+ *
585
+ * @param[out] w Output polynomial.
586
+ * @param[in] u First input vector.
587
+ * @param[in] v Second input vector.
588
+ */
629
589
  MLD_MUST_CHECK_RETURN_VALUE
630
590
  static MLD_INLINE int mld_polyvecl_pointwise_acc_montgomery_l7_native(
631
591
  int32_t w[MLDSA_N], const int32_t u[7][MLDSA_N],