pq_crypto 0.6.1 → 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 (247) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +10 -0
  3. data/SECURITY.md +7 -0
  4. data/ext/pqcrypto/pqcrypto_version.h +1 -1
  5. data/ext/pqcrypto/vendor/.vendored +7 -7
  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/ext/pqcrypto/vendor/mlkem-native/README.md +6 -3
  108. data/ext/pqcrypto/vendor/mlkem-native/RELEASE.md +22 -0
  109. data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native.c +77 -36
  110. data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native.h +135 -146
  111. data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native_asm.S +116 -72
  112. data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native_config.h +351 -415
  113. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/cbmc.h +43 -20
  114. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/common.h +16 -8
  115. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/compress.c +57 -31
  116. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/compress.h +260 -349
  117. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/debug.h +17 -24
  118. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/fips202.c +35 -37
  119. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/fips202.h +43 -57
  120. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/fips202x4.c +14 -15
  121. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/fips202x4.h +5 -4
  122. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/keccakf1600.c +42 -6
  123. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/fips202_native_aarch64.h +31 -20
  124. 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
  125. 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
  126. 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
  127. 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
  128. 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
  129. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccakf1600_round_constants.c +10 -9
  130. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x1_scalar.h +2 -1
  131. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x1_v84a.h +1 -1
  132. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x2_v84a.h +4 -2
  133. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x4_v8a_scalar.h +2 -2
  134. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x4_v8a_v84a_scalar.h +1 -1
  135. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/fips202_native_armv81m.h +2 -1
  136. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.S +55 -9
  137. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/keccakf1600_round_constants.c +26 -25
  138. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/state_extract_bytes_x4_mve.S +58 -14
  139. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/state_xor_bytes_x4_mve.S +57 -16
  140. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/auto.h +2 -1
  141. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/keccak_f1600_x4_avx2.h +2 -2
  142. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/src/fips202_native_x86_64.h +10 -7
  143. 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
  144. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/src/keccakf1600_constants.c +12 -11
  145. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/indcpa.c +167 -136
  146. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/indcpa.h +75 -68
  147. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/kem.h +135 -157
  148. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/meta.h +15 -13
  149. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/aarch64_zetas.c +143 -135
  150. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/arith_native_aarch64.h +52 -46
  151. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{intt.S → intt_aarch64_asm.S} +10 -10
  152. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{ntt.S → ntt_aarch64_asm.S} +10 -10
  153. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{poly_mulcache_compute_asm.S → poly_mulcache_compute_aarch64_asm.S} +10 -10
  154. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{poly_reduce_asm.S → poly_reduce_aarch64_asm.S} +10 -10
  155. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{poly_tobytes_asm.S → poly_tobytes_aarch64_asm.S} +10 -10
  156. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{poly_tomont_asm.S → poly_tomont_aarch64_asm.S} +10 -12
  157. 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
  158. 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
  159. 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
  160. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{rej_uniform_asm.S → rej_uniform_aarch64_asm.S} +12 -12
  161. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/rej_uniform_table.c +514 -513
  162. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/api.h +254 -253
  163. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/meta.h +6 -1
  164. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/README.md +6 -0
  165. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/meta.h +77 -0
  166. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/arith_native_ppc64le.h +24 -0
  167. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/consts.c +299 -0
  168. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/consts.h +34 -0
  169. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/intt_ppc_asm.S +3222 -0
  170. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/ntt_ppc_asm.S +1651 -0
  171. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/poly_tomont_ppc_asm.S +294 -0
  172. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/reduce_ppc_asm.S +710 -0
  173. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/meta.h +5 -0
  174. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/rv64v_debug.c +18 -16
  175. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/rv64v_debug.h +19 -24
  176. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/rv64v_poly.c +53 -65
  177. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/meta.h +20 -20
  178. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/arith_native_x86_64.h +106 -88
  179. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/compress_consts.c +45 -35
  180. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/compress_consts.h +8 -8
  181. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/consts.c +1 -1
  182. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/consts.h +1 -1
  183. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{intt.S → intt_avx2_asm.S} +8 -8
  184. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{ntt.S → ntt_avx2_asm.S} +8 -8
  185. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{nttfrombytes.S → nttfrombytes_avx2_asm.S} +8 -8
  186. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{ntttobytes.S → ntttobytes_avx2_asm.S} +8 -8
  187. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{nttunpack.S → nttunpack_avx2_asm.S} +8 -8
  188. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{poly_compress_d10.S → poly_compress_d10_avx2_asm.S} +9 -9
  189. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{poly_compress_d11.S → poly_compress_d11_avx2_asm.S} +9 -9
  190. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{poly_compress_d4.S → poly_compress_d4_avx2_asm.S} +9 -9
  191. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{poly_compress_d5.S → poly_compress_d5_avx2_asm.S} +9 -9
  192. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{poly_decompress_d10.S → poly_decompress_d10_avx2_asm.S} +9 -9
  193. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{poly_decompress_d11.S → poly_decompress_d11_avx2_asm.S} +9 -9
  194. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{poly_decompress_d4.S → poly_decompress_d4_avx2_asm.S} +9 -9
  195. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{poly_decompress_d5.S → poly_decompress_d5_avx2_asm.S} +9 -9
  196. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{mulcache_compute.S → poly_mulcache_compute_avx2_asm.S} +8 -8
  197. 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
  198. 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
  199. 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
  200. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{reduce.S → reduce_avx2_asm.S} +8 -8
  201. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{rej_uniform_asm.S → rej_uniform_avx2_asm.S} +9 -9
  202. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/rej_uniform_table.c +514 -513
  203. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{tomont.S → tomont_avx2_asm.S} +8 -8
  204. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/poly.c +61 -57
  205. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/poly.h +89 -116
  206. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/poly_k.c +31 -32
  207. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/poly_k.h +226 -301
  208. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/randombytes.h +21 -29
  209. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/sampling.c +68 -63
  210. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/sampling.h +37 -48
  211. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/sys.h +44 -2
  212. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/verify.h +141 -159
  213. data/lib/pq_crypto/version.rb +1 -1
  214. data/script/vendor_libs.rb +6 -6
  215. metadata +86 -71
  216. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_scalar_asm.S +0 -376
  217. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_v84a_asm.S +0 -204
  218. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x2_v84a_asm.S +0 -259
  219. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_scalar_hybrid_asm.S +0 -1077
  220. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_v84a_scalar_hybrid_asm.S +0 -987
  221. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/KeccakP_1600_times4_SIMD256.c +0 -488
  222. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/KeccakP_1600_times4_SIMD256.h +0 -16
  223. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/intt.S +0 -753
  224. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l4.S +0 -129
  225. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l5.S +0 -145
  226. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l7.S +0 -177
  227. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/ntt.S +0 -653
  228. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/pointwise_montgomery.S +0 -79
  229. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_caddq_asm.S +0 -53
  230. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_chknorm_asm.S +0 -55
  231. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_decompose_32_asm.S +0 -85
  232. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_decompose_88_asm.S +0 -85
  233. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_use_hint_32_asm.S +0 -102
  234. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_use_hint_88_asm.S +0 -110
  235. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/polyz_unpack_17_asm.S +0 -72
  236. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/polyz_unpack_19_asm.S +0 -69
  237. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_asm.S +0 -189
  238. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_eta2_asm.S +0 -135
  239. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_eta4_asm.S +0 -128
  240. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/intt.S +0 -2311
  241. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/ntt.S +0 -2383
  242. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/nttunpack.S +0 -239
  243. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise.S +0 -131
  244. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l4.S +0 -139
  245. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l5.S +0 -155
  246. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l7.S +0 -187
  247. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_caddq_avx2.c +0 -61
@@ -28,17 +28,13 @@
28
28
 
29
29
  /*
30
30
  * WARNING: This file is auto-derived from the mlkem-native source file
31
- * dev/x86_64/src/tomont.S using scripts/simpasm. Do not modify it directly.
31
+ * dev/x86_64/src/tomont_avx2_asm.S using scripts/simpasm. Do not modify it directly.
32
32
  */
33
33
 
34
- #if defined(__ELF__)
35
- .section .note.GNU-stack,"",@progbits
36
- #endif
37
-
38
34
  .text
39
35
  .balign 4
40
- .global MLK_ASM_NAMESPACE(tomont_avx2)
41
- MLK_ASM_FN_SYMBOL(tomont_avx2)
36
+ .global MLK_ASM_NAMESPACE(tomont_avx2_asm)
37
+ MLK_ASM_FN_SYMBOL(tomont_avx2_asm)
42
38
 
43
39
  .cfi_startproc
44
40
  movl $0xd010d01, %eax # imm = 0xD010D01
@@ -149,7 +145,11 @@ MLK_ASM_FN_SYMBOL(tomont_avx2)
149
145
  retq
150
146
  .cfi_endproc
151
147
 
152
- MLK_ASM_FN_SIZE(tomont_avx2)
148
+ MLK_ASM_FN_SIZE(tomont_avx2_asm)
153
149
 
154
150
  #endif /* MLK_ARITH_BACKEND_X86_64_DEFAULT && !MLK_CONFIG_MULTILEVEL_NO_SHARED \
155
151
  */
152
+
153
+ #if defined(__ELF__)
154
+ .section .note.GNU-stack,"",%progbits
155
+ #endif
@@ -28,22 +28,18 @@
28
28
  #include "symmetric.h"
29
29
  #include "verify.h"
30
30
 
31
- /*************************************************
32
- * Name: mlk_fqmul
31
+ /**
32
+ * Montgomery multiplication modulo MLKEM_Q.
33
33
  *
34
- * Description: Montgomery multiplication modulo MLKEM_Q
34
+ * @reference{`fqmul()` in the reference implementation @[REF].}
35
35
  *
36
- * Arguments: - int16_t a: first factor
37
- * Can be any int16_t.
38
- * - int16_t b: second factor.
39
- * Must be signed canonical (abs value <(MLKEM_Q+1)/2)
36
+ * @param a First factor. Can be any int16_t.
37
+ * @param b Second factor. Must be signed canonical
38
+ * (abs value < (MLKEM_Q+1)/2).
40
39
  *
41
- * Returns 16-bit integer congruent to a*b*R^{-1} mod MLKEM_Q, and
42
- * smaller than MLKEM_Q in absolute value.
43
- *
44
- **************************************************/
45
-
46
- /* Reference: `fqmul()` in the reference implementation @[REF]. */
40
+ * @return 16-bit integer congruent to a*b*R^{-1} mod MLKEM_Q, and
41
+ * smaller than MLKEM_Q in absolute value.
42
+ */
47
43
  static MLK_INLINE int16_t mlk_fqmul(int16_t a, int16_t b)
48
44
  __contract__(
49
45
  requires(b > -MLKEM_Q_HALF && b < MLKEM_Q_HALF)
@@ -65,20 +61,17 @@ __contract__(
65
61
  return res;
66
62
  }
67
63
 
68
- /*************************************************
69
- * Name: mlk_barrett_reduce
64
+ /**
65
+ * Barrett reduction; given a 16-bit integer a, computes the centered
66
+ * representative congruent to a mod MLKEM_Q in [-(MLKEM_Q-1)/2, (MLKEM_Q-1)/2].
70
67
  *
71
- * Description: Barrett reduction; given a 16-bit integer a, computes
72
- * centered representative congruent to a mod q in
73
- * {-(q-1)/2,...,(q-1)/2}
68
+ * @reference{`barrett_reduce()` in the reference implementation @[REF].}
74
69
  *
75
- * Arguments: - int16_t a: input integer to be reduced
70
+ * @param a Input integer to be reduced.
76
71
  *
77
- * Returns: integer in {-(q-1)/2,...,(q-1)/2} congruent to a modulo q.
78
- *
79
- **************************************************/
80
-
81
- /* Reference: `barrett_reduce()` in the reference implementation @[REF]. */
72
+ * @return Integer in [-(MLKEM_Q-1)/2, (MLKEM_Q-1)/2] congruent to @p a modulo
73
+ * MLKEM_Q.
74
+ */
82
75
  static MLK_INLINE int16_t mlk_barrett_reduce(int16_t a)
83
76
  __contract__(
84
77
  ensures(return_value > -MLKEM_Q_HALF && return_value < MLKEM_Q_HALF)
@@ -125,7 +118,8 @@ __contract__(
125
118
  for (i = 0; i < MLKEM_N; i++)
126
119
  __loop__(
127
120
  invariant(i <= MLKEM_N)
128
- invariant(array_abs_bound(r->coeffs, 0, i, MLKEM_Q)))
121
+ invariant(array_abs_bound(r->coeffs, 0, i, MLKEM_Q))
122
+ decreases(MLKEM_N - i))
129
123
  {
130
124
  r->coeffs[i] = mlk_fqmul(r->coeffs[i], f);
131
125
  }
@@ -149,21 +143,20 @@ void mlk_poly_tomont(mlk_poly *r)
149
143
  mlk_poly_tomont_c(r);
150
144
  }
151
145
 
152
- /************************************************************
153
- * Name: mlk_scalar_signed_to_unsigned_q
146
+ /**
147
+ * Constant-time conversion of signed representatives modulo MLKEM_Q within
148
+ * range [-(MLKEM_Q-1), MLKEM_Q-1] into unsigned representatives within
149
+ * range [0, MLKEM_Q-1].
154
150
  *
155
- * Description: Constant-time conversion of signed representatives
156
- * modulo MLKEM_Q within range (-(MLKEM_Q-1) .. (MLKEM_Q-1))
157
- * into unsigned representatives within range (0..(MLKEM_Q-1)).
151
+ * @reference{Not present in the reference implementation @[REF]. Used here
152
+ * to implement different semantics of `poly_reduce()`; see below. In the
153
+ * reference implementation @[REF] this logic is part of all compression
154
+ * functions (see `compress.c`).}
158
155
  *
159
- * Arguments: c: signed coefficient to be converted
156
+ * @param c Signed coefficient to be converted.
160
157
  *
161
- ************************************************************/
162
-
163
- /* Reference: Not present in the reference implementation @[REF].
164
- * - Used here to implement different semantics of `poly_reduce()`;
165
- * see below. in the reference implementation @[REF], this logic is
166
- * part of all compression functions (see `compress.c`). */
158
+ * @return Unsigned representative in [0, MLKEM_Q).
159
+ */
167
160
  static MLK_INLINE int16_t mlk_scalar_signed_to_unsigned_q(int16_t c)
168
161
  __contract__(
169
162
  requires(c > -MLKEM_Q && c < MLKEM_Q)
@@ -201,7 +194,8 @@ __contract__(
201
194
  for (i = 0; i < MLKEM_N; i++)
202
195
  __loop__(
203
196
  invariant(i <= MLKEM_N)
204
- invariant(array_bound(r->coeffs, 0, i, 0, MLKEM_Q)))
197
+ invariant(array_bound(r->coeffs, 0, i, 0, MLKEM_Q))
198
+ decreases(MLKEM_N - i))
205
199
  {
206
200
  /* Barrett reduction, giving signed canonical representative */
207
201
  int16_t t = mlk_barrett_reduce(r->coeffs[i]);
@@ -239,7 +233,8 @@ void mlk_poly_add(mlk_poly *r, const mlk_poly *b)
239
233
  __loop__(
240
234
  invariant(i <= MLKEM_N)
241
235
  invariant(forall(k0, i, MLKEM_N, r->coeffs[k0] == loop_entry(*r).coeffs[k0]))
242
- invariant(forall(k1, 0, i, r->coeffs[k1] == loop_entry(*r).coeffs[k1] + b->coeffs[k1])))
236
+ invariant(forall(k1, 0, i, r->coeffs[k1] == loop_entry(*r).coeffs[k1] + b->coeffs[k1]))
237
+ decreases(MLKEM_N - i))
243
238
  {
244
239
  /* The preconditions imply that the addition stays within int16_t. */
245
240
  r->coeffs[i] = (int16_t)(r->coeffs[i] + b->coeffs[i]);
@@ -257,7 +252,8 @@ void mlk_poly_sub(mlk_poly *r, const mlk_poly *b)
257
252
  __loop__(
258
253
  invariant(i <= MLKEM_N)
259
254
  invariant(forall(k0, i, MLKEM_N, r->coeffs[k0] == loop_entry(*r).coeffs[k0]))
260
- invariant(forall(k1, 0, i, r->coeffs[k1] == loop_entry(*r).coeffs[k1] - b->coeffs[k1])))
255
+ invariant(forall(k1, 0, i, r->coeffs[k1] == loop_entry(*r).coeffs[k1] - b->coeffs[k1]))
256
+ decreases(MLKEM_N - i))
261
257
  {
262
258
  /* The preconditions imply that the subtraction stays within int16_t. */
263
259
  r->coeffs[i] = (int16_t)(r->coeffs[i] - b->coeffs[i]);
@@ -282,7 +278,8 @@ __contract__(
282
278
  for (i = 0; i < MLKEM_N / 4; i++)
283
279
  __loop__(
284
280
  invariant(i <= MLKEM_N / 4)
285
- invariant(array_abs_bound(x->coeffs, 0, 2 * i, MLKEM_Q)))
281
+ invariant(array_abs_bound(x->coeffs, 0, 2 * i, MLKEM_Q))
282
+ decreases(MLKEM_N / 4 - i))
286
283
  {
287
284
  x->coeffs[2 * i + 0] = mlk_fqmul(a->coeffs[4 * i + 1], mlk_zetas[64 + i]);
288
285
  /* The values in zeta table are <= MLKEM_Q in absolute value,
@@ -371,7 +368,8 @@ __contract__(
371
368
  invariant(array_abs_bound(r, 0, j, bound + MLKEM_Q))
372
369
  invariant(array_abs_bound(r, j, start + len, bound))
373
370
  invariant(array_abs_bound(r, start + len, j + len, bound + MLKEM_Q))
374
- invariant(array_abs_bound(r, j + len, MLKEM_N, bound)))
371
+ invariant(array_abs_bound(r, j + len, MLKEM_N, bound))
372
+ decreases(start + len - j))
375
373
  {
376
374
  int16_t t;
377
375
  t = mlk_fqmul(r[j + len], zeta);
@@ -406,7 +404,8 @@ __contract__(
406
404
  invariant(start < MLKEM_N + 2 * len)
407
405
  invariant(k <= MLKEM_N / 2 && 2 * len * k == start + MLKEM_N)
408
406
  invariant(array_abs_bound(r, 0, start, layer * MLKEM_Q + MLKEM_Q))
409
- invariant(array_abs_bound(r, start, MLKEM_N, layer * MLKEM_Q)))
407
+ invariant(array_abs_bound(r, start, MLKEM_N, layer * MLKEM_Q))
408
+ decreases(MLKEM_N - start))
410
409
  {
411
410
  int16_t zeta = mlk_zetas[k++];
412
411
  mlk_ntt_butterfly_block(r, zeta, start, len, layer * MLKEM_Q);
@@ -443,7 +442,8 @@ __contract__(
443
442
  for (layer = 1; layer <= 7; layer++)
444
443
  __loop__(
445
444
  invariant(1 <= layer && layer <= 8)
446
- invariant(array_abs_bound(r, 0, MLKEM_N, layer * MLKEM_Q)))
445
+ invariant(array_abs_bound(r, 0, MLKEM_N, layer * MLKEM_Q))
446
+ decreases(8 - layer))
447
447
  {
448
448
  mlk_ntt_layer(r, layer);
449
449
  }
@@ -453,20 +453,20 @@ __contract__(
453
453
  }
454
454
 
455
455
  MLK_INTERNAL_API
456
- void mlk_poly_ntt(mlk_poly *p)
456
+ void mlk_poly_ntt(mlk_poly *r)
457
457
  {
458
458
  #if defined(MLK_USE_NATIVE_NTT)
459
459
  int ret;
460
- mlk_assert_abs_bound(p, MLKEM_N, MLKEM_Q);
461
- ret = mlk_ntt_native(p->coeffs);
460
+ mlk_assert_abs_bound(r, MLKEM_N, MLKEM_Q);
461
+ ret = mlk_ntt_native(r->coeffs);
462
462
  if (ret == MLK_NATIVE_FUNC_SUCCESS)
463
463
  {
464
- mlk_assert_abs_bound(p, MLKEM_N, MLK_NTT_BOUND);
464
+ mlk_assert_abs_bound(r, MLKEM_N, MLK_NTT_BOUND);
465
465
  return;
466
466
  }
467
467
  #endif /* MLK_USE_NATIVE_NTT */
468
468
 
469
- mlk_poly_ntt_c(p);
469
+ mlk_poly_ntt_c(r);
470
470
  }
471
471
 
472
472
 
@@ -489,7 +489,8 @@ __contract__(
489
489
  invariant(array_abs_bound(r, 0, MLKEM_N, MLKEM_Q))
490
490
  invariant(start <= MLKEM_N && k <= 127)
491
491
  /* Normalised form of k == MLKEM_N / len - 1 - start / (2 * len) */
492
- invariant(2 * len * k + start == 2 * MLKEM_N - 2 * len))
492
+ invariant(2 * len * k + start == 2 * MLKEM_N - 2 * len)
493
+ decreases(MLKEM_N - start))
493
494
  {
494
495
  unsigned j;
495
496
  int16_t zeta = mlk_zetas[k--];
@@ -497,7 +498,8 @@ __contract__(
497
498
  __loop__(
498
499
  invariant(start <= j && j <= start + len)
499
500
  invariant(start <= MLKEM_N && k <= 127)
500
- invariant(array_abs_bound(r, 0, MLKEM_N, MLKEM_Q)))
501
+ invariant(array_abs_bound(r, 0, MLKEM_N, MLKEM_Q))
502
+ decreases(start + len - j))
501
503
  {
502
504
  int16_t t = r[j];
503
505
  /* The preconditions imply that the arithmetic does not overflow. */
@@ -532,7 +534,8 @@ __contract__(
532
534
  for (j = 0; j < MLKEM_N; j++)
533
535
  __loop__(
534
536
  invariant(j <= MLKEM_N)
535
- invariant(array_abs_bound(r, 0, j, MLKEM_Q)))
537
+ invariant(array_abs_bound(r, 0, j, MLKEM_Q))
538
+ decreases(MLKEM_N - j))
536
539
  {
537
540
  r[j] = mlk_fqmul(r[j], f);
538
541
  }
@@ -541,7 +544,8 @@ __contract__(
541
544
  for (layer = 7; layer > 0; layer--)
542
545
  __loop__(
543
546
  invariant(0 <= layer && layer < 8)
544
- invariant(array_abs_bound(r, 0, MLKEM_N, MLKEM_Q)))
547
+ invariant(array_abs_bound(r, 0, MLKEM_N, MLKEM_Q))
548
+ decreases(layer))
545
549
  {
546
550
  mlk_invntt_layer(r, layer);
547
551
  }
@@ -550,19 +554,19 @@ __contract__(
550
554
  }
551
555
 
552
556
  MLK_INTERNAL_API
553
- void mlk_poly_invntt_tomont(mlk_poly *p)
557
+ void mlk_poly_invntt_tomont(mlk_poly *r)
554
558
  {
555
559
  #if defined(MLK_USE_NATIVE_INTT)
556
560
  int ret;
557
- ret = mlk_intt_native(p->coeffs);
561
+ ret = mlk_intt_native(r->coeffs);
558
562
  if (ret == MLK_NATIVE_FUNC_SUCCESS)
559
563
  {
560
- mlk_assert_abs_bound(p, MLKEM_N, MLK_INVNTT_BOUND);
564
+ mlk_assert_abs_bound(r, MLKEM_N, MLK_INVNTT_BOUND);
561
565
  return;
562
566
  }
563
567
  #endif /* MLK_USE_NATIVE_INTT */
564
568
 
565
- mlk_poly_invntt_tomont_c(p);
569
+ mlk_poly_invntt_tomont_c(r);
566
570
  }
567
571
 
568
572
  #else /* !MLK_CONFIG_MULTILEVEL_NO_SHARED */
@@ -27,37 +27,34 @@
27
27
  /* Absolute exclusive upper bound for the output of the forward NTT */
28
28
  #define MLK_NTT_BOUND (8 * MLKEM_Q)
29
29
 
30
- /*
31
- * Elements of R_q = Z_q[X]/(X^n + 1). Represents polynomial
32
- * coeffs[0] + X*coeffs[1] + X^2*coeffs[2] + ... + X^{n-1}*coeffs[n-1]
30
+ /**
31
+ * Element of R_q = Z_q[X]/(X^n + 1). Represents polynomial
32
+ * coeffs[0] + X*coeffs[1] + X^2*coeffs[2] + ... + X^{n-1}*coeffs[n-1].
33
33
  */
34
34
  typedef struct
35
35
  {
36
- int16_t coeffs[MLKEM_N];
36
+ int16_t coeffs[MLKEM_N]; /**< Polynomial coefficients. */
37
37
  } MLK_ALIGN mlk_poly;
38
38
 
39
- /*
40
- * INTERNAL presentation of precomputed data speeding up
39
+ /**
40
+ * INTERNAL representation of precomputed data speeding up
41
41
  * the base multiplication of two polynomials in NTT domain.
42
42
  */
43
43
  typedef struct
44
44
  {
45
- int16_t coeffs[MLKEM_N >> 1];
45
+ int16_t coeffs[MLKEM_N >> 1]; /**< Cached coefficients. */
46
46
  } MLK_ALIGN mlk_poly_mulcache;
47
47
 
48
- /*************************************************
49
- * Name: mlk_montgomery_reduce
50
- *
51
- * Description: Generic Montgomery reduction; given a 32-bit integer a, computes
52
- * 16-bit integer congruent to a * R^-1 mod q, where R=2^16
53
- *
54
- * Arguments: - int32_t a: input integer to be reduced, of absolute value
55
- * smaller or equal to INT32_MAX - 2^15 * MLKEM_Q.
48
+ /**
49
+ * Generic Montgomery reduction; given a 32-bit integer a, computes a 16-bit
50
+ * integer congruent to a * R^-1 mod MLKEM_Q, where R=2^16.
56
51
  *
57
- * Returns: integer congruent to a * R^-1 modulo q, with absolute value
58
- * <= ceil(|a| / 2^16) + (MLKEM_Q + 1)/2
52
+ * @param a Input integer to be reduced, of absolute value smaller or equal
53
+ * to INT32_MAX - 2^15 * MLKEM_Q.
59
54
  *
60
- **************************************************/
55
+ * @return Integer congruent to a * R^-1 modulo MLKEM_Q, with absolute value
56
+ * <= ceil(|a| / 2^16) + (MLKEM_Q + 1)/2.
57
+ */
61
58
  static MLK_ALWAYS_INLINE int16_t mlk_montgomery_reduce(int32_t a)
62
59
  __contract__(
63
60
  requires(a < +(INT32_MAX - (((int32_t)1 << 15) * MLKEM_Q)) &&
@@ -103,21 +100,18 @@ __contract__(
103
100
  }
104
101
 
105
102
  #define mlk_poly_tomont MLK_NAMESPACE(poly_tomont)
106
- /*************************************************
107
- * Name: mlk_poly_tomont
108
- *
109
- * Description: Inplace conversion of all coefficients of a polynomial
110
- * from normal domain to Montgomery domain
111
- *
112
- * Bounds: Output < q in absolute value.
103
+ /**
104
+ * In-place conversion of all coefficients of a polynomial from the normal
105
+ * domain to the Montgomery domain.
113
106
  *
114
- * Arguments: - mlk_poly *r: pointer to input/output polynomial
107
+ * Bounds: output < MLKEM_Q in absolute value.
115
108
  *
116
- * Specification: Internal normalization required in `mlk_indcpa_keypair_derand`
117
- * as part of matrix-vector multiplication
118
- * @[FIPS203, Algorithm 13, K-PKE.KeyGen, L18].
109
+ * @spec{Internal normalization required in `mlk_indcpa_keypair_derand` as
110
+ * part of matrix-vector multiplication @[FIPS203, Algorithm 13, K-PKE.KeyGen,
111
+ * L18].}
119
112
  *
120
- **************************************************/
113
+ * @param[in,out] r Input/output polynomial.
114
+ */
121
115
  MLK_INTERNAL_API
122
116
  void mlk_poly_tomont(mlk_poly *r)
123
117
  __contract__(
@@ -127,27 +121,23 @@ __contract__(
127
121
  );
128
122
 
129
123
  #define mlk_poly_mulcache_compute MLK_NAMESPACE(poly_mulcache_compute)
130
- /************************************************************
131
- * Name: mlk_poly_mulcache_compute
132
- *
133
- * Description: Computes the mulcache for a polynomial in NTT domain
134
- *
135
- * The mulcache of a degree-2 polynomial b := b0 + b1*X
136
- * in Fq[X]/(X^2-zeta) is the value b1*zeta, needed when
137
- * computing products of b in Fq[X]/(X^2-zeta).
124
+ /**
125
+ * Compute the mulcache for a polynomial in NTT domain.
138
126
  *
139
- * The mulcache of a polynomial in NTT domain -- which is
140
- * a 128-tuple of degree-2 polynomials in Fq[X]/(X^2-zeta),
141
- * for varying zeta, is the 128-tuple of mulcaches of those
142
- * polynomials.
127
+ * The mulcache of a degree-2 polynomial b := b0 + b1*X in Fq[X]/(X^2-zeta)
128
+ * is the value b1*zeta, needed when computing products of b in
129
+ * Fq[X]/(X^2-zeta).
143
130
  *
144
- * Arguments: - x: Pointer to mulcache to be populated
145
- * - a: Pointer to input polynomial
131
+ * The mulcache of a polynomial in NTT domain -- which is a 128-tuple of
132
+ * degree-2 polynomials in Fq[X]/(X^2-zeta), for varying zeta, is the
133
+ * 128-tuple of mulcaches of those polynomials.
146
134
  *
147
- * Specification:
148
- * - Caches `b_1 * \gamma` in @[FIPS203, Algorithm 12, BaseCaseMultiply, L1]
135
+ * @spec{Caches `b_1 * \gamma` in @[FIPS203, Algorithm 12, BaseCaseMultiply,
136
+ * L1].}
149
137
  *
150
- ************************************************************/
138
+ * @param[out] x Mulcache to be populated.
139
+ * @param[in] a Input polynomial.
140
+ */
151
141
  /*
152
142
  * NOTE: The default C implementation of this function populates
153
143
  * the mulcache with values in (-q,q), but this is not needed for the
@@ -162,21 +152,17 @@ __contract__(
162
152
  );
163
153
 
164
154
  #define mlk_poly_reduce MLK_NAMESPACE(poly_reduce)
165
- /*************************************************
166
- * Name: mlk_poly_reduce
167
- *
168
- * Description: Converts polynomial to _unsigned canonical_ representatives.
169
- *
170
- * The input coefficients can be arbitrary integers in int16_t.
171
- * The output coefficients are in [0,1,...,MLKEM_Q-1].
155
+ /**
156
+ * Convert a polynomial to unsigned canonical representatives.
172
157
  *
173
- * Arguments: - mlk_poly *r: pointer to input/output polynomial
158
+ * The input coefficients can be arbitrary integers in int16_t. The output
159
+ * coefficients are in [0,1,..,MLKEM_Q-1].
174
160
  *
175
- * Specification: Normalizes on unsigned canoncial representatives
176
- * ahead of calling @[FIPS203, Compress_d, Eq (4.7)].
177
- * This is not made explicit in FIPS 203.
161
+ * @spec{Normalizes on unsigned canonical representatives ahead of calling
162
+ * @[FIPS203, Compress_d, Eq (4.7)]. This is not made explicit in FIPS 203.}
178
163
  *
179
- **************************************************/
164
+ * @param[in,out] r Input/output polynomial.
165
+ */
180
166
  /*
181
167
  * NOTE: The semantics of mlk_poly_reduce() is different in
182
168
  * the reference implementation, which requires
@@ -193,23 +179,19 @@ __contract__(
193
179
  );
194
180
 
195
181
  #define mlk_poly_add MLK_NAMESPACE(poly_add)
196
- /************************************************************
197
- * Name: mlk_poly_add
198
- *
199
- * Description: Adds two polynomials in place
182
+ /**
183
+ * Add two polynomials in place.
200
184
  *
201
- * Arguments: - r: Pointer to input-output polynomial to be added to.
202
- * - b: Pointer to input polynomial that should be added
203
- * to r. Must be disjoint from r.
185
+ * The coefficients of @p r and @p b must be such that the addition does not
186
+ * overflow. Otherwise, the behaviour of this function is undefined.
204
187
  *
205
- * The coefficients of r and b must be so that the addition does
206
- * not overflow. Otherwise, the behaviour of this function is undefined.
188
+ * @spec{@[FIPS203, 2.4.5, Arithmetic With Polynomials and NTT
189
+ * Representations]. Used in @[FIPS203, Algorithm 14 (K-PKE.Encrypt), L21].}
207
190
  *
208
- * Specification:
209
- * - @[FIPS203, 2.4.5, Arithmetic With Polynomials and NTT Representations]
210
- * - Used in @[FIPS203, Algorithm 14 (K-PKE.Encrypt), L21]
211
- *
212
- ************************************************************/
191
+ * @param[in,out] r Input-output polynomial to be added to.
192
+ * @param[in] b Input polynomial that should be added to @p r. Must be
193
+ * disjoint from @p r.
194
+ */
213
195
  /*
214
196
  * NOTE: The reference implementation uses a 3-argument mlk_poly_add.
215
197
  * We specialize to the accumulator form to avoid reasoning about aliasing.
@@ -226,19 +208,15 @@ __contract__(
226
208
  );
227
209
 
228
210
  #define mlk_poly_sub MLK_NAMESPACE(poly_sub)
229
- /*************************************************
230
- * Name: mlk_poly_sub
211
+ /**
212
+ * Subtract two polynomials; no modular reduction is performed.
231
213
  *
232
- * Description: Subtract two polynomials; no modular reduction is performed
214
+ * @spec{@[FIPS203, 2.4.5, Arithmetic With Polynomials and NTT
215
+ * Representations]. Used in @[FIPS203, Algorithm 15, K-PKE.Decrypt, L6].}
233
216
  *
234
- * Arguments: - mlk_poly *r: Pointer to input-output polynomial to be added to.
235
- * - const mlk_poly *b: Pointer to second input polynomial
236
- *
237
- * Specification:
238
- * - @[FIPS203, 2.4.5, Arithmetic With Polynomials and NTT Representations]
239
- * - Used in @[FIPS203, Algorithm 15, K-PKE.Decrypt, L6]
240
- *
241
- **************************************************/
217
+ * @param[in,out] r Input-output polynomial to be subtracted from.
218
+ * @param[in] b Second input polynomial.
219
+ */
242
220
  /*
243
221
  * NOTE: The reference implementation uses a 3-argument mlk_poly_sub.
244
222
  * We specialize to the accumulator form to avoid reasoning about aliasing.
@@ -255,26 +233,24 @@ __contract__(
255
233
  );
256
234
 
257
235
  #define mlk_poly_ntt MLK_NAMESPACE(poly_ntt)
258
- /*************************************************
259
- * Name: mlk_poly_ntt
236
+ /**
237
+ * Compute the negacyclic number-theoretic transform (NTT) of a polynomial
238
+ * in place.
260
239
  *
261
- * Description: Computes negacyclic number-theoretic transform (NTT) of
262
- * a polynomial in place.
240
+ * The input is assumed to be in normal order and coefficient-wise bound by
241
+ * MLKEM_Q in absolute value.
263
242
  *
264
- * The input is assumed to be in normal order and
265
- * coefficient-wise bound by MLKEM_Q in absolute value.
243
+ * The output polynomial is in bitreversed order, or of a custom order if
244
+ * MLK_USE_NATIVE_NTT_CUSTOM_ORDER is set, and coefficient-wise bound
245
+ * by MLK_NTT_BOUND in absolute value.
266
246
  *
267
- * The output polynomial is in bitreversed order, and
268
- * coefficient-wise bound by MLK_NTT_BOUND in absolute value.
247
+ * (NOTE: Sometimes the input to the NTT is actually smaller, which gives
248
+ * better bounds.)
269
249
  *
270
- * (NOTE: Sometimes the input to the NTT is actually smaller,
271
- * which gives better bounds.)
250
+ * @spec{Implements @[FIPS203, Algorithm 9, NTT].}
272
251
  *
273
- * Arguments: - mlk_poly *p: pointer to in/output polynomial
274
- *
275
- * Specification: Implements @[FIPS203, Algorithm 9, NTT]
276
- *
277
- **************************************************/
252
+ * @param[in,out] r Input/output polynomial.
253
+ */
278
254
  MLK_INTERNAL_API
279
255
  void mlk_poly_ntt(mlk_poly *r)
280
256
  __contract__(
@@ -285,27 +261,24 @@ __contract__(
285
261
  );
286
262
 
287
263
  #define mlk_poly_invntt_tomont MLK_NAMESPACE(poly_invntt_tomont)
288
- /*************************************************
289
- * Name: mlk_poly_invntt_tomont
264
+ /**
265
+ * Compute the inverse negacyclic number-theoretic transform (NTT) of a
266
+ * polynomial in place; input assumed to be in bitreversed order, output in
267
+ * normal order.
290
268
  *
291
- * Description: Computes inverse of negacyclic number-theoretic transform (NTT)
292
- * of a polynomial in place;
293
- * inputs assumed to be in bitreversed order, output in normal
294
- * order
269
+ * The input is assumed to be in bitreversed order, or of a custom order if
270
+ * MLK_USE_NATIVE_NTT_CUSTOM_ORDER is set, and can have arbitrary
271
+ * coefficients in int16_t.
295
272
  *
296
- * The input is assumed to be in bitreversed order, and can
297
- * have arbitrary coefficients in int16_t.
273
+ * The output polynomial is in normal order, and coefficient-wise bound by
274
+ * MLK_INVNTT_BOUND in absolute value.
298
275
  *
299
- * The output polynomial is in normal order, and
300
- * coefficient-wise bound by MLK_INVNTT_BOUND in absolute value.
276
+ * @spec{Implements composition of @[FIPS203, Algorithm 10, NTT^{-1}] and
277
+ * elementwise modular multiplication with a suitable Montgomery factor
278
+ * introduced during the base multiplication.}
301
279
  *
302
- * Arguments: - uint16_t *a: pointer to in/output polynomial
303
- *
304
- * Specification: Implements composition of @[FIPS203, Algorithm 10, NTT^{-1}]
305
- * and elementwise modular multiplication with a suitable
306
- * Montgomery factor introduced during the base multiplication.
307
- *
308
- **************************************************/
280
+ * @param[in,out] r Input/output polynomial.
281
+ */
309
282
  MLK_INTERNAL_API
310
283
  void mlk_poly_invntt_tomont(mlk_poly *r)
311
284
  __contract__(