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
@@ -11,45 +11,37 @@
11
11
 
12
12
  #if !defined(MLK_CONFIG_NO_RANDOMIZED_API)
13
13
  #if !defined(MLK_CONFIG_CUSTOM_RANDOMBYTES)
14
- /*************************************************
15
- * Name: randombytes
14
+ /**
15
+ * Fill a buffer with cryptographically secure random bytes.
16
16
  *
17
- * Description: Fill a buffer with cryptographically secure random bytes.
17
+ * mlkem-native does not provide an implementation of this function.
18
+ * It must be provided by the consumer.
18
19
  *
19
- * mlkem-native does not provide an implementation of this
20
- * function. It must be provided by the consumer.
20
+ * To use a custom random byte source with a different name or signature,
21
+ * set MLK_CONFIG_CUSTOM_RANDOMBYTES and define mlk_randombytes directly.
21
22
  *
22
- * To use a custom random byte source with a different name
23
- * or signature, set MLK_CONFIG_CUSTOM_RANDOMBYTES and define
24
- * mlk_randombytes directly.
23
+ * @param[out] out Output buffer.
24
+ * @param outlen Number of random bytes to write.
25
25
  *
26
- * Arguments: - uint8_t *out: pointer to output buffer
27
- * - size_t outlen: number of random bytes to write
28
- *
29
- * Returns: 0 on success, non-zero on failure.
30
- * On failure, top-level APIs return MLK_ERR_RNG_FAIL.
31
- *
32
- **************************************************/
26
+ * @retval 0 Success.
27
+ * @retval other Failure; top-level APIs propagate this as MLK_ERR_RNG_FAIL.
28
+ */
33
29
  int randombytes(uint8_t *out, size_t outlen);
34
30
 
35
- /*************************************************
36
- * Name: mlk_randombytes
31
+ /**
32
+ * Internal wrapper around randombytes().
37
33
  *
38
- * Description: Internal wrapper around randombytes().
34
+ * Fills a buffer with cryptographically secure random bytes.
39
35
  *
40
- * Fill a buffer with cryptographically secure random bytes.
36
+ * This function can be replaced by setting MLK_CONFIG_CUSTOM_RANDOMBYTES
37
+ * and defining mlk_randombytes directly.
41
38
  *
42
- * This function can be replaced by setting
43
- * MLK_CONFIG_CUSTOM_RANDOMBYTES and defining mlk_randombytes
44
- * directly.
39
+ * @param[out] out Output buffer.
40
+ * @param outlen Number of random bytes to write.
45
41
  *
46
- * Arguments: - uint8_t *out: pointer to output buffer
47
- * - size_t outlen: number of random bytes to write
48
- *
49
- * Returns: 0 on success, non-zero on failure.
50
- * On failure, top-level APIs return MLK_ERR_RNG_FAIL.
51
- *
52
- **************************************************/
42
+ * @retval 0 Success.
43
+ * @retval other Failure; top-level APIs propagate this as MLK_ERR_RNG_FAIL.
44
+ */
53
45
  MLK_MUST_CHECK_RETURN_VALUE
54
46
  static MLK_INLINE int mlk_randombytes(uint8_t *out, size_t outlen)
55
47
  __contract__(
@@ -23,6 +23,7 @@
23
23
  #include "debug.h"
24
24
  #include "sampling.h"
25
25
  #include "symmetric.h"
26
+ #include "verify.h"
26
27
 
27
28
  /* Reference: `rej_uniform()` in the reference implementation @[REF].
28
29
  * - Our signature differs from the reference implementation
@@ -53,10 +54,18 @@ __contract__(
53
54
  while (ctr < target && pos + 3 <= buflen)
54
55
  __loop__(
55
56
  invariant(offset <= ctr && ctr <= target && pos <= buflen)
56
- invariant(array_bound(r, 0, ctr, 0, MLKEM_Q)))
57
+ invariant(array_bound(r, 0, ctr, 0, MLKEM_Q))
58
+ decreases(buflen - pos))
57
59
  {
58
- val0 = ((buf[pos + 0] >> 0) | (buf[pos + 1] << 8)) & 0xFFF;
59
- val1 = ((buf[pos + 1] >> 4) | (buf[pos + 2] << 4)) & 0xFFF;
60
+ /* Safety:
61
+ * - The explicit cast to uint16_t ensures that << 8 does
62
+ * not signed-overflow even on a 16-bit system.
63
+ * - The conversion to int16_t is safe due to the explicit 0xFFF
64
+ * truncation.
65
+ */
66
+ val0 = (int16_t)(((buf[pos + 0] >> 0) | ((uint16_t)buf[pos + 1] << 8)) &
67
+ 0xFFF);
68
+ val1 = (int16_t)(((buf[pos + 1] >> 4) | (buf[pos + 2] << 4)) & 0xFFF);
60
69
  pos += 3;
61
70
 
62
71
  if (val0 < MLKEM_Q)
@@ -73,42 +82,36 @@ __contract__(
73
82
  return ctr;
74
83
  }
75
84
 
76
- /*************************************************
77
- * Name: mlk_rej_uniform
85
+ /**
86
+ * Run rejection sampling on uniform random bytes to generate uniform random
87
+ * integers mod MLKEM_Q.
78
88
  *
79
- * Description: Run rejection sampling on uniform random bytes to generate
80
- * uniform random integers mod q
89
+ * @reference{`rej_uniform()` in the reference implementation @[REF]. Our
90
+ * signature differs from the reference in that it adds the offset and always
91
+ * expects the base of the target buffer; this avoids shifting the buffer
92
+ * base in the caller, which is tricky to reason about. Has an optional
93
+ * fallback to a native implementation.}
81
94
  *
82
- * Arguments: - int16_t *r: pointer to output buffer
83
- * - unsigned target: requested number of 16-bit integers
84
- * (uniform mod q).
85
- * Must be <= 4096.
86
- * - unsigned offset: number of 16-bit integers that have
87
- * already been sampled.
88
- * Must be <= target.
89
- * - const uint8_t *buf: pointer to input buffer
90
- * (assumed to be uniform random bytes)
91
- * - unsigned buflen: length of input buffer in bytes
92
- * Must be <= 4096.
93
- * Must be a multiple of 3.
95
+ * @param[out] r Output buffer.
96
+ * @param target Requested number of 16-bit integers (uniform mod MLKEM_Q).
97
+ * Must be <= 4096.
98
+ * @param offset Number of 16-bit integers that have already been
99
+ * sampled. Must be <= @p target.
100
+ * @param[in] buf Input buffer (assumed to be uniform random bytes).
101
+ * @param buflen Length of input buffer in bytes. Must be <= 4096 and a
102
+ * multiple of 3.
94
103
  *
95
- * Note: Strictly speaking, only a few values of buflen near UINT_MAX need
96
- * excluding. The limit of 4096 is somewhat arbitrary but sufficient for all
97
- * uses of this function. Similarly, the actual limit for target is UINT_MAX/2.
104
+ * @note Strictly speaking, only a few values of @p buflen near UINT_MAX need
105
+ * excluding. The limit of 4096 is somewhat arbitrary but sufficient
106
+ * for all uses of this function. Similarly, the actual limit for
107
+ * @p target is UINT_MAX/2.
98
108
  *
99
- * Returns the new offset of sampled 16-bit integers, at most target,
100
- * and at least the initial offset.
101
- * If the new offset is strictly less than len, all of the input buffers
102
- * is guaranteed to have been consumed. If it is equal to len, no information
103
- * is provided on how many bytes of the input buffer have been consumed.
104
- **************************************************/
105
-
106
- /* Reference: `rej_uniform()` in the reference implementation @[REF].
107
- * - Our signature differs from the reference implementation
108
- * in that it adds the offset and always expects the base of the
109
- * target buffer. This avoids shifting the buffer base in the
110
- * caller, which appears tricky to reason about.
111
- * - Optional fallback to native implementation. */
109
+ * @return New offset of sampled 16-bit integers, at most @p target and at
110
+ * least the initial @p offset. If the new offset is strictly less
111
+ * than @p target, the entire input buffer is guaranteed to have been
112
+ * consumed; otherwise no information is provided on how many bytes
113
+ * of the input buffer have been consumed.
114
+ */
112
115
  static unsigned mlk_rej_uniform(int16_t *r, unsigned target, unsigned offset,
113
116
  const uint8_t *buf, unsigned buflen)
114
117
  __contract__(
@@ -248,19 +251,15 @@ void mlk_poly_rej_uniform(mlk_poly *entry, uint8_t seed[MLKEM_SYMBYTES + 2])
248
251
  mlk_zeroize(buf, sizeof(buf));
249
252
  }
250
253
 
251
- /*************************************************
252
- * Name: mlk_load32_littleendian
254
+ /**
255
+ * Load 4 bytes into a 32-bit integer in little-endian order.
253
256
  *
254
- * Description: load 4 bytes into a 32-bit integer
255
- * in little-endian order
257
+ * @reference{`load32_littleendian()` in the reference implementation @[REF].}
256
258
  *
257
- * Arguments: - const uint8_t *x: pointer to input byte array
259
+ * @param[in] x Input byte array.
258
260
  *
259
- * Returns 32-bit unsigned integer loaded from x
260
- *
261
- **************************************************/
262
-
263
- /* Reference: `load32_littleendian()` in the reference implementation @[REF]. */
261
+ * @return 32-bit unsigned integer loaded from @p x.
262
+ */
264
263
  static uint32_t mlk_load32_littleendian(const uint8_t x[4])
265
264
  {
266
265
  uint32_t r;
@@ -279,7 +278,8 @@ void mlk_poly_cbd2(mlk_poly *r, const uint8_t buf[2 * MLKEM_N / 4])
279
278
  for (i = 0; i < MLKEM_N / 8; i++)
280
279
  __loop__(
281
280
  invariant(i <= MLKEM_N / 8)
282
- invariant(array_abs_bound(r->coeffs, 0, 8 * i, 3)))
281
+ invariant(array_abs_bound(r->coeffs, 0, 8 * i, 3))
282
+ decreases(MLKEM_N / 8 - i))
283
283
  {
284
284
  unsigned j;
285
285
  uint32_t t = mlk_load32_littleendian(buf + 4 * i);
@@ -289,30 +289,31 @@ void mlk_poly_cbd2(mlk_poly *r, const uint8_t buf[2 * MLKEM_N / 4])
289
289
  for (j = 0; j < 8; j++)
290
290
  __loop__(
291
291
  invariant(i <= MLKEM_N / 8 && j <= 8)
292
- invariant(array_abs_bound(r->coeffs, 0, 8 * i + j, 3)))
292
+ invariant(array_abs_bound(r->coeffs, 0, 8 * i + j, 3))
293
+ decreases(8 - j))
293
294
  {
294
- const int16_t a = (d >> (4 * j + 0)) & 0x3;
295
- const int16_t b = (d >> (4 * j + 2)) & 0x3;
295
+ /* Safety: The & 0x3 masks each value to 2 bits (range [0, 3]), so the
296
+ * truncation and subsequent subtraction in int16_t is lossless. */
297
+ const int16_t a = (int16_t)((d >> (4 * j + 0)) & 0x3);
298
+ const int16_t b = (int16_t)((d >> (4 * j + 2)) & 0x3);
296
299
  r->coeffs[8 * i + j] = (int16_t)(a - b);
297
300
  }
298
301
  }
299
302
  }
300
303
 
301
304
  #if defined(MLK_CONFIG_MULTILEVEL_WITH_SHARED) || MLKEM_ETA1 == 3
302
- /*************************************************
303
- * Name: mlk_load24_littleendian
305
+ /**
306
+ * Load 3 bytes into a 32-bit integer in little-endian order.
304
307
  *
305
- * Description: load 3 bytes into a 32-bit integer
306
- * in little-endian order.
307
- * This function is only needed for ML-KEM-512
308
+ * This function is only needed for ML-KEM-512.
308
309
  *
309
- * Arguments: - const uint8_t *x: pointer to input byte array
310
+ * @reference{`load24_littleendian()` in the reference implementation @[REF].}
310
311
  *
311
- * Returns 32-bit unsigned integer loaded from x (most significant byte is zero)
312
+ * @param[in] x Input byte array.
312
313
  *
313
- **************************************************/
314
-
315
- /* Reference: `load24_littleendian()` in the reference implementation @[REF]. */
314
+ * @return 32-bit unsigned integer loaded from @p x (most significant byte
315
+ * is zero).
316
+ */
316
317
  static uint32_t mlk_load24_littleendian(const uint8_t x[3])
317
318
  {
318
319
  uint32_t r;
@@ -330,7 +331,8 @@ void mlk_poly_cbd3(mlk_poly *r, const uint8_t buf[3 * MLKEM_N / 4])
330
331
  for (i = 0; i < MLKEM_N / 4; i++)
331
332
  __loop__(
332
333
  invariant(i <= MLKEM_N / 4)
333
- invariant(array_abs_bound(r->coeffs, 0, 4 * i, 4)))
334
+ invariant(array_abs_bound(r->coeffs, 0, 4 * i, 4))
335
+ decreases(MLKEM_N / 4 - i))
334
336
  {
335
337
  unsigned j;
336
338
  const uint32_t t = mlk_load24_littleendian(buf + 3 * i);
@@ -341,10 +343,13 @@ void mlk_poly_cbd3(mlk_poly *r, const uint8_t buf[3 * MLKEM_N / 4])
341
343
  for (j = 0; j < 4; j++)
342
344
  __loop__(
343
345
  invariant(i <= MLKEM_N / 4 && j <= 4)
344
- invariant(array_abs_bound(r->coeffs, 0, 4 * i + j, 4)))
346
+ invariant(array_abs_bound(r->coeffs, 0, 4 * i + j, 4))
347
+ decreases(4 - j))
345
348
  {
346
- const int16_t a = (d >> (6 * j + 0)) & 0x7;
347
- const int16_t b = (d >> (6 * j + 3)) & 0x7;
349
+ /* Safety: The & 0x7 masks each value to 3 bits (range [0, 7]), so the
350
+ * truncation and subsequent subtraction in int16_t is lossless. */
351
+ const int16_t a = (int16_t)((d >> (6 * j + 0)) & 0x7);
352
+ const int16_t b = (int16_t)((d >> (6 * j + 3)) & 0x7);
348
353
  r->coeffs[4 * i + j] = (int16_t)(a - b);
349
354
  }
350
355
  }
@@ -20,59 +20,52 @@
20
20
  #include "poly.h"
21
21
 
22
22
  #define mlk_poly_cbd2 MLK_NAMESPACE(poly_cbd2)
23
- /*************************************************
24
- * Name: mlk_poly_cbd2
23
+ /**
24
+ * Given an array of uniformly random bytes, compute a polynomial with
25
+ * coefficients distributed according to a centered binomial distribution
26
+ * with parameter eta=2.
25
27
  *
26
- * Description: Given an array of uniformly random bytes, compute
27
- * polynomial with coefficients distributed according to
28
- * a centered binomial distribution with parameter eta=2
28
+ * @spec{Implements @[FIPS203, Algorithm 8, SamplePolyCBD_2].}
29
29
  *
30
- * Arguments: - mlk_poly *r: pointer to output polynomial
31
- * - const uint8_t *buf: pointer to input byte array
32
- *
33
- * Specification: Implements @[FIPS203, Algorithm 8, SamplePolyCBD_2]
34
- *
35
- **************************************************/
30
+ * @param[out] r Output polynomial.
31
+ * @param[in] buf Input byte array.
32
+ */
36
33
  MLK_INTERNAL_API
37
34
  void mlk_poly_cbd2(mlk_poly *r, const uint8_t buf[2 * MLKEM_N / 4]);
38
35
 
39
36
  #if defined(MLK_CONFIG_MULTILEVEL_WITH_SHARED) || MLKEM_ETA1 == 3
40
37
  #define mlk_poly_cbd3 MLK_NAMESPACE(poly_cbd3)
41
- /*************************************************
42
- * Name: mlk_poly_cbd3
43
- *
44
- * Description: Given an array of uniformly random bytes, compute
45
- * polynomial with coefficients distributed according to
46
- * a centered binomial distribution with parameter eta=3.
47
- * This function is only needed for ML-KEM-512
38
+ /**
39
+ * Given an array of uniformly random bytes, compute a polynomial with
40
+ * coefficients distributed according to a centered binomial distribution
41
+ * with parameter eta=3.
48
42
  *
49
- * Arguments: - mlk_poly *r: pointer to output polynomial
50
- * - const uint8_t *buf: pointer to input byte array
43
+ * This function is only needed for ML-KEM-512.
51
44
  *
52
- * Specification: Implements @[FIPS203, Algorithm 8, SamplePolyCBD_3]
45
+ * @spec{Implements @[FIPS203, Algorithm 8, SamplePolyCBD_3].}
53
46
  *
54
- **************************************************/
47
+ * @param[out] r Output polynomial.
48
+ * @param[in] buf Input byte array.
49
+ */
55
50
  MLK_INTERNAL_API
56
51
  void mlk_poly_cbd3(mlk_poly *r, const uint8_t buf[3 * MLKEM_N / 4]);
57
52
  #endif /* MLK_CONFIG_MULTILEVEL_WITH_SHARED || MLKEM_ETA1 == 3 */
58
53
 
59
54
  #if !defined(MLK_CONFIG_SERIAL_FIPS202_ONLY)
60
55
  #define mlk_poly_rej_uniform_x4 MLK_NAMESPACE(poly_rej_uniform_x4)
61
- /*************************************************
62
- * Name: mlk_poly_rej_uniform_x4
63
- *
64
- * Description: Generate four polynomials using rejection sampling
65
- * on (pseudo-)uniformly random bytes sampled from a seed.
66
- *
67
- * Arguments: - mlk_poly *vec0, *vec1, *vec2, *vec3:
68
- * Pointers to 4 polynomials to be sampled.
69
- * - uint8_t seed[4][MLK_ALIGN_UP(MLKEM_SYMBYTES + 2)]:
70
- * Pointer consecutive array of seed buffers of size
71
- * MLKEM_SYMBYTES + 2 each, plus padding for alignment.
72
- *
73
- * Specification: Implements @[FIPS203, Algorithm 7, SampleNTT]
74
- *
75
- **************************************************/
56
+ /**
57
+ * Generate four polynomials using rejection sampling on (pseudo-)uniformly
58
+ * random bytes sampled from a seed.
59
+ *
60
+ * @spec{Implements @[FIPS203, Algorithm 7, SampleNTT].}
61
+ *
62
+ * @param[out] vec0 Polynomial to be sampled.
63
+ * @param[out] vec1 Polynomial to be sampled.
64
+ * @param[out] vec2 Polynomial to be sampled.
65
+ * @param[out] vec3 Polynomial to be sampled.
66
+ * @param[in] seed Consecutive array of 4 seed buffers of size
67
+ * MLKEM_SYMBYTES + 2 each, plus padding for alignment.
68
+ */
76
69
  MLK_INTERNAL_API
77
70
  void mlk_poly_rej_uniform_x4(mlk_poly *vec0, mlk_poly *vec1, mlk_poly *vec2,
78
71
  mlk_poly *vec3,
@@ -94,19 +87,15 @@ __contract__(
94
87
  #endif /* !MLK_CONFIG_SERIAL_FIPS202_ONLY */
95
88
 
96
89
  #define mlk_poly_rej_uniform MLK_NAMESPACE(poly_rej_uniform)
97
- /*************************************************
98
- * Name: mlk_poly_rej_uniform
90
+ /**
91
+ * Generate a polynomial using rejection sampling on (pseudo-)uniformly
92
+ * random bytes sampled from a seed.
99
93
  *
100
- * Description: Generate polynomial using rejection sampling
101
- * on (pseudo-)uniformly random bytes sampled from a seed.
94
+ * @spec{Implements @[FIPS203, Algorithm 7, SampleNTT].}
102
95
  *
103
- * Arguments: - mlk_poly *vec: Pointer to polynomial to be sampled.
104
- * - uint8_t *seed: Pointer to seed buffer of size
105
- * MLKEM_SYMBYTES + 2 each.
106
- *
107
- * Specification: Implements @[FIPS203, Algorithm 7, SampleNTT]
108
- *
109
- **************************************************/
96
+ * @param[out] entry Polynomial to be sampled.
97
+ * @param[in] seed Seed buffer of size MLKEM_SYMBYTES + 2.
98
+ */
110
99
  MLK_INTERNAL_API
111
100
  void mlk_poly_rej_uniform(mlk_poly *entry, uint8_t seed[MLKEM_SYMBYTES + 2])
112
101
  __contract__(
@@ -47,12 +47,13 @@
47
47
  #define MLK_SYS_ARMV81M_MVE
48
48
  #endif
49
49
 
50
- #if defined(__x86_64__)
50
+ /* Check if we're running on an x86_64 system. */
51
+ #if defined(__x86_64__) || defined(_M_X64) || defined(_M_AMD64)
51
52
  #define MLK_SYS_X86_64
52
53
  #if defined(__AVX2__)
53
54
  #define MLK_SYS_X86_64_AVX2
54
55
  #endif
55
- #endif /* __x86_64__ */
56
+ #endif /* __x86_64__ || _M_X64 || _M_AMD64 */
56
57
 
57
58
  #if defined(MLK_SYS_LITTLE_ENDIAN) && defined(__powerpc64__)
58
59
  #define MLK_SYS_PPC64LE
@@ -146,6 +147,22 @@
146
147
  #endif
147
148
  #endif /* !MLK_ALWAYS_INLINE */
148
149
 
150
+ /*
151
+ * MLK_NOINLINE: Prevent inlining.
152
+ * - MSVC: __declspec(noinline)
153
+ * - GCC/Clang: __attribute__((noinline))
154
+ * - Other: empty
155
+ */
156
+ #if !defined(MLK_NOINLINE)
157
+ #if defined(_MSC_VER)
158
+ #define MLK_NOINLINE __declspec(noinline)
159
+ #elif defined(__GNUC__) || defined(__clang__)
160
+ #define MLK_NOINLINE __attribute__((noinline))
161
+ #else
162
+ #define MLK_NOINLINE
163
+ #endif
164
+ #endif /* !MLK_NOINLINE */
165
+
149
166
  #ifndef MLK_STATIC_TESTABLE
150
167
  #define MLK_STATIC_TESTABLE static
151
168
  #endif
@@ -226,6 +243,31 @@
226
243
  #define MLK_MUST_CHECK_RETURN_VALUE
227
244
  #endif
228
245
 
246
+ /* The x86_64 assembly backend uses the SysV calling convention. On Windows,
247
+ * where the Microsoft x64 calling convention is the default, it can still be
248
+ * used with compilers that allow choosing the calling convention per
249
+ * function: GCC and Clang support __attribute__((sysv_abi)), which makes
250
+ * calls to the annotated function follow the SysV calling convention.
251
+ *
252
+ * MLK_SYSV_ABI_SUPPORTED signals that the toolchain can call SysV assembly
253
+ * routines; the x86_64 assembly backend is only enabled if it is defined.
254
+ * MLK_SYSV_ABI is the attribute carried by declarations of x86_64 assembly
255
+ * routines. Both macros can be set externally for toolchains offering an
256
+ * equivalent mechanism that is not recognized here. */
257
+ #if defined(MLK_SYS_X86_64) && !defined(MLK_SYSV_ABI_SUPPORTED)
258
+ #if !defined(MLK_SYS_WINDOWS) || defined(__GNUC__) || defined(__clang__)
259
+ #define MLK_SYSV_ABI_SUPPORTED
260
+ #endif
261
+ #endif
262
+
263
+ #if !defined(MLK_SYSV_ABI)
264
+ #if defined(MLK_SYS_WINDOWS) && defined(MLK_SYSV_ABI_SUPPORTED)
265
+ #define MLK_SYSV_ABI __attribute__((sysv_abi))
266
+ #else
267
+ #define MLK_SYSV_ABI
268
+ #endif
269
+ #endif /* !MLK_SYSV_ABI */
270
+
229
271
  #if !defined(__ASSEMBLER__)
230
272
  /* System capability enumeration */
231
273
  typedef enum