pq_crypto 0.4.2 → 0.5.1

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 (410) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +27 -2
  3. data/CHANGELOG.md +59 -0
  4. data/GET_STARTED.md +21 -16
  5. data/README.md +26 -0
  6. data/SECURITY.md +22 -16
  7. data/ext/pqcrypto/extconf.rb +183 -99
  8. data/ext/pqcrypto/mldsa_api.h +1 -118
  9. data/ext/pqcrypto/mlkem_api.h +1 -42
  10. data/ext/pqcrypto/pq_externalmu.c +88 -216
  11. data/ext/pqcrypto/pqcrypto_native_api.h +132 -0
  12. data/ext/pqcrypto/pqcrypto_ruby_secure.c +234 -12
  13. data/ext/pqcrypto/pqcrypto_secure.c +429 -334
  14. data/ext/pqcrypto/pqcrypto_secure.h +13 -45
  15. data/ext/pqcrypto/pqcrypto_version.h +1 -1
  16. data/ext/pqcrypto/randombytes.h +9 -0
  17. data/ext/pqcrypto/vendor/.vendored +12 -5
  18. data/ext/pqcrypto/vendor/mldsa-native/BUILDING.md +105 -0
  19. data/ext/pqcrypto/vendor/mldsa-native/LICENSE +286 -0
  20. data/ext/pqcrypto/vendor/mldsa-native/META.yml +24 -0
  21. data/ext/pqcrypto/vendor/mldsa-native/README.md +221 -0
  22. data/ext/pqcrypto/vendor/mldsa-native/SECURITY.md +8 -0
  23. data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native.c +721 -0
  24. data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native.h +975 -0
  25. data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native_asm.S +724 -0
  26. data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native_config.h +723 -0
  27. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/cbmc.h +166 -0
  28. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/common.h +321 -0
  29. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/ct.c +21 -0
  30. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/ct.h +385 -0
  31. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/debug.c +73 -0
  32. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/debug.h +130 -0
  33. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/fips202.c +277 -0
  34. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/fips202.h +244 -0
  35. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/fips202x4.c +182 -0
  36. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/fips202x4.h +117 -0
  37. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/keccakf1600.c +438 -0
  38. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/keccakf1600.h +105 -0
  39. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/auto.h +71 -0
  40. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/fips202_native_aarch64.h +62 -0
  41. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_scalar_asm.S +376 -0
  42. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_v84a_asm.S +204 -0
  43. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x2_v84a_asm.S +259 -0
  44. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_scalar_hybrid_asm.S +1077 -0
  45. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_v84a_scalar_hybrid_asm.S +987 -0
  46. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccakf1600_round_constants.c +41 -0
  47. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x1_scalar.h +26 -0
  48. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x1_v84a.h +35 -0
  49. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x2_v84a.h +37 -0
  50. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x4_v8a_scalar.h +27 -0
  51. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x4_v8a_v84a_scalar.h +36 -0
  52. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/api.h +69 -0
  53. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/README.md +10 -0
  54. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/mve.h +32 -0
  55. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/fips202_native_armv81m.h +20 -0
  56. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.S +638 -0
  57. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.c +136 -0
  58. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccakf1600_round_constants.c +52 -0
  59. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/auto.h +29 -0
  60. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/KeccakP_1600_times4_SIMD256.c +488 -0
  61. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/KeccakP_1600_times4_SIMD256.h +16 -0
  62. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/xkcp.h +31 -0
  63. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/meta.h +247 -0
  64. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/aarch64_zetas.c +231 -0
  65. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/arith_native_aarch64.h +150 -0
  66. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/intt.S +753 -0
  67. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l4.S +129 -0
  68. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l5.S +145 -0
  69. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l7.S +177 -0
  70. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/ntt.S +653 -0
  71. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/pointwise_montgomery.S +79 -0
  72. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_caddq_asm.S +53 -0
  73. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_chknorm_asm.S +55 -0
  74. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_decompose_32_asm.S +85 -0
  75. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_decompose_88_asm.S +85 -0
  76. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_use_hint_32_asm.S +102 -0
  77. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_use_hint_88_asm.S +110 -0
  78. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/polyz_unpack_17_asm.S +72 -0
  79. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/polyz_unpack_19_asm.S +69 -0
  80. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/polyz_unpack_table.c +40 -0
  81. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_asm.S +189 -0
  82. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_eta2_asm.S +135 -0
  83. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_eta4_asm.S +128 -0
  84. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_eta_table.c +543 -0
  85. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_table.c +62 -0
  86. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/api.h +649 -0
  87. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/meta.h +23 -0
  88. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/meta.h +315 -0
  89. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/arith_native_x86_64.h +124 -0
  90. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/consts.c +157 -0
  91. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/consts.h +27 -0
  92. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/intt.S +2311 -0
  93. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/ntt.S +2383 -0
  94. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/nttunpack.S +239 -0
  95. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise.S +131 -0
  96. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l4.S +139 -0
  97. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l5.S +155 -0
  98. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l7.S +187 -0
  99. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_caddq_avx2.c +61 -0
  100. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_chknorm_avx2.c +52 -0
  101. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_decompose_32_avx2.c +155 -0
  102. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_decompose_88_avx2.c +155 -0
  103. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_use_hint_32_avx2.c +102 -0
  104. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_use_hint_88_avx2.c +104 -0
  105. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/polyz_unpack_17_avx2.c +91 -0
  106. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/polyz_unpack_19_avx2.c +93 -0
  107. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/rej_uniform_avx2.c +126 -0
  108. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/rej_uniform_eta2_avx2.c +155 -0
  109. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/rej_uniform_eta4_avx2.c +139 -0
  110. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/rej_uniform_table.c +160 -0
  111. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/packing.c +293 -0
  112. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/packing.h +224 -0
  113. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/params.h +77 -0
  114. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly.c +991 -0
  115. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly.h +393 -0
  116. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly_kl.c +946 -0
  117. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly_kl.h +360 -0
  118. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec.c +877 -0
  119. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec.h +725 -0
  120. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/randombytes.h +26 -0
  121. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/reduce.h +139 -0
  122. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/rounding.h +249 -0
  123. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/sign.c +1511 -0
  124. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/sign.h +806 -0
  125. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/symmetric.h +68 -0
  126. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/sys.h +268 -0
  127. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/zetas.inc +55 -0
  128. data/ext/pqcrypto/vendor/mlkem-native/BUILDING.md +104 -0
  129. data/ext/pqcrypto/vendor/mlkem-native/LICENSE +294 -0
  130. data/ext/pqcrypto/vendor/mlkem-native/META.yml +30 -0
  131. data/ext/pqcrypto/vendor/mlkem-native/README.md +223 -0
  132. data/ext/pqcrypto/vendor/mlkem-native/RELEASE.md +86 -0
  133. data/ext/pqcrypto/vendor/mlkem-native/SECURITY.md +8 -0
  134. data/ext/pqcrypto/vendor/mlkem-native/mlkem/README.md +23 -0
  135. data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native.c +660 -0
  136. data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native.h +538 -0
  137. data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native_asm.S +681 -0
  138. data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native_config.h +709 -0
  139. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/cbmc.h +174 -0
  140. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/common.h +274 -0
  141. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/compress.c +717 -0
  142. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/compress.h +688 -0
  143. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/debug.c +64 -0
  144. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/debug.h +128 -0
  145. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/fips202.c +251 -0
  146. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/fips202.h +158 -0
  147. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/fips202x4.c +208 -0
  148. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/fips202x4.h +80 -0
  149. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/keccakf1600.c +463 -0
  150. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/keccakf1600.h +98 -0
  151. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/auto.h +70 -0
  152. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/fips202_native_aarch64.h +69 -0
  153. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccak_f1600_x1_scalar_asm.S +375 -0
  154. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccak_f1600_x1_v84a_asm.S +203 -0
  155. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccak_f1600_x2_v84a_asm.S +258 -0
  156. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_scalar_hybrid_asm.S +1076 -0
  157. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_v84a_scalar_hybrid_asm.S +986 -0
  158. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccakf1600_round_constants.c +46 -0
  159. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x1_scalar.h +25 -0
  160. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x1_v84a.h +34 -0
  161. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x2_v84a.h +35 -0
  162. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x4_v8a_scalar.h +26 -0
  163. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x4_v8a_v84a_scalar.h +35 -0
  164. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/api.h +117 -0
  165. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/README.md +10 -0
  166. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/mve.h +79 -0
  167. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/fips202_native_armv81m.h +35 -0
  168. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.S +667 -0
  169. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.c +40 -0
  170. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/keccakf1600_round_constants.c +51 -0
  171. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/state_extract_bytes_x4_mve.S +290 -0
  172. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/state_xor_bytes_x4_mve.S +314 -0
  173. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/auto.h +28 -0
  174. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/keccak_f1600_x4_avx2.h +33 -0
  175. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/src/fips202_native_x86_64.h +41 -0
  176. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/src/keccak_f1600_x4_avx2.S +451 -0
  177. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/src/keccakf1600_constants.c +51 -0
  178. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/indcpa.c +622 -0
  179. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/indcpa.h +156 -0
  180. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/kem.c +446 -0
  181. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/kem.h +326 -0
  182. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/README.md +16 -0
  183. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/meta.h +122 -0
  184. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/aarch64_zetas.c +174 -0
  185. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/arith_native_aarch64.h +177 -0
  186. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/intt.S +628 -0
  187. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/ntt.S +562 -0
  188. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/poly_mulcache_compute_asm.S +127 -0
  189. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/poly_reduce_asm.S +150 -0
  190. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/poly_tobytes_asm.S +117 -0
  191. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/poly_tomont_asm.S +98 -0
  192. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/polyvec_basemul_acc_montgomery_cached_asm_k2.S +261 -0
  193. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/polyvec_basemul_acc_montgomery_cached_asm_k3.S +314 -0
  194. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/polyvec_basemul_acc_montgomery_cached_asm_k4.S +368 -0
  195. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/rej_uniform_asm.S +226 -0
  196. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/rej_uniform_table.c +542 -0
  197. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/api.h +637 -0
  198. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/meta.h +25 -0
  199. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/README.md +11 -0
  200. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/meta.h +128 -0
  201. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/arith_native_riscv64.h +45 -0
  202. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/rv64v_debug.c +81 -0
  203. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/rv64v_debug.h +145 -0
  204. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/rv64v_izetas.inc +27 -0
  205. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/rv64v_poly.c +805 -0
  206. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/rv64v_zetas.inc +27 -0
  207. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/rv64v_zetas_basemul.inc +39 -0
  208. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/README.md +4 -0
  209. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/meta.h +304 -0
  210. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/arith_native_x86_64.h +309 -0
  211. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/compress_consts.c +94 -0
  212. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/compress_consts.h +45 -0
  213. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/consts.c +102 -0
  214. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/consts.h +25 -0
  215. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/intt.S +719 -0
  216. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mulcache_compute.S +90 -0
  217. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/ntt.S +639 -0
  218. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/nttfrombytes.S +193 -0
  219. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/ntttobytes.S +181 -0
  220. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/nttunpack.S +174 -0
  221. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/poly_compress_d10.S +382 -0
  222. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/poly_compress_d11.S +448 -0
  223. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/poly_compress_d4.S +163 -0
  224. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/poly_compress_d5.S +220 -0
  225. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/poly_decompress_d10.S +228 -0
  226. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/poly_decompress_d11.S +277 -0
  227. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/poly_decompress_d4.S +180 -0
  228. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/poly_decompress_d5.S +192 -0
  229. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/polyvec_basemul_acc_montgomery_cached_asm_k2.S +502 -0
  230. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/polyvec_basemul_acc_montgomery_cached_asm_k3.S +750 -0
  231. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/polyvec_basemul_acc_montgomery_cached_asm_k4.S +998 -0
  232. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/reduce.S +218 -0
  233. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/rej_uniform_asm.S +103 -0
  234. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/rej_uniform_table.c +544 -0
  235. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/tomont.S +155 -0
  236. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/params.h +76 -0
  237. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/poly.c +572 -0
  238. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/poly.h +317 -0
  239. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/poly_k.c +502 -0
  240. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/poly_k.h +668 -0
  241. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/randombytes.h +60 -0
  242. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/sampling.c +362 -0
  243. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/sampling.h +118 -0
  244. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/symmetric.h +70 -0
  245. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/sys.h +260 -0
  246. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/verify.c +20 -0
  247. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/verify.h +464 -0
  248. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/zetas.inc +30 -0
  249. data/lib/pq_crypto/hybrid_kem.rb +10 -1
  250. data/lib/pq_crypto/version.rb +1 -1
  251. data/lib/pq_crypto.rb +5 -1
  252. data/script/vendor_libs.rb +228 -154
  253. metadata +236 -160
  254. data/ext/pqcrypto/vendor/pqclean/common/aes.c +0 -639
  255. data/ext/pqcrypto/vendor/pqclean/common/aes.h +0 -64
  256. data/ext/pqcrypto/vendor/pqclean/common/compat.h +0 -73
  257. data/ext/pqcrypto/vendor/pqclean/common/crypto_declassify.h +0 -7
  258. data/ext/pqcrypto/vendor/pqclean/common/fips202.c +0 -928
  259. data/ext/pqcrypto/vendor/pqclean/common/fips202.h +0 -166
  260. data/ext/pqcrypto/vendor/pqclean/common/keccak2x/feat.S +0 -168
  261. data/ext/pqcrypto/vendor/pqclean/common/keccak2x/fips202x2.c +0 -684
  262. data/ext/pqcrypto/vendor/pqclean/common/keccak2x/fips202x2.h +0 -60
  263. data/ext/pqcrypto/vendor/pqclean/common/keccak4x/KeccakP-1600-times4-SIMD256.c +0 -1028
  264. data/ext/pqcrypto/vendor/pqclean/common/keccak4x/KeccakP-1600-times4-SnP.h +0 -50
  265. data/ext/pqcrypto/vendor/pqclean/common/keccak4x/KeccakP-1600-unrolling.macros +0 -198
  266. data/ext/pqcrypto/vendor/pqclean/common/keccak4x/Makefile +0 -8
  267. data/ext/pqcrypto/vendor/pqclean/common/keccak4x/Makefile.Microsoft_nmake +0 -8
  268. data/ext/pqcrypto/vendor/pqclean/common/keccak4x/SIMD256-config.h +0 -3
  269. data/ext/pqcrypto/vendor/pqclean/common/keccak4x/align.h +0 -34
  270. data/ext/pqcrypto/vendor/pqclean/common/keccak4x/brg_endian.h +0 -142
  271. data/ext/pqcrypto/vendor/pqclean/common/nistseedexpander.c +0 -101
  272. data/ext/pqcrypto/vendor/pqclean/common/nistseedexpander.h +0 -39
  273. data/ext/pqcrypto/vendor/pqclean/common/randombytes.c +0 -355
  274. data/ext/pqcrypto/vendor/pqclean/common/randombytes.h +0 -27
  275. data/ext/pqcrypto/vendor/pqclean/common/sha2.c +0 -769
  276. data/ext/pqcrypto/vendor/pqclean/common/sha2.h +0 -173
  277. data/ext/pqcrypto/vendor/pqclean/common/sp800-185.c +0 -156
  278. data/ext/pqcrypto/vendor/pqclean/common/sp800-185.h +0 -27
  279. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/LICENSE +0 -5
  280. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/Makefile +0 -19
  281. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/Makefile.Microsoft_nmake +0 -23
  282. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/api.h +0 -18
  283. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/cbd.c +0 -83
  284. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/cbd.h +0 -11
  285. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/indcpa.c +0 -327
  286. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/indcpa.h +0 -22
  287. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/kem.c +0 -164
  288. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/kem.h +0 -23
  289. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/ntt.c +0 -146
  290. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/ntt.h +0 -14
  291. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/params.h +0 -36
  292. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/poly.c +0 -311
  293. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/poly.h +0 -37
  294. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/polyvec.c +0 -198
  295. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/polyvec.h +0 -26
  296. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/reduce.c +0 -41
  297. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/reduce.h +0 -13
  298. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/symmetric-shake.c +0 -71
  299. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/symmetric.h +0 -30
  300. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/verify.c +0 -67
  301. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/verify.h +0 -13
  302. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/LICENSE +0 -5
  303. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/Makefile +0 -19
  304. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/Makefile.Microsoft_nmake +0 -23
  305. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/api.h +0 -18
  306. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/cbd.c +0 -108
  307. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/cbd.h +0 -11
  308. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/indcpa.c +0 -327
  309. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/indcpa.h +0 -22
  310. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/kem.c +0 -164
  311. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/kem.h +0 -23
  312. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/ntt.c +0 -146
  313. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/ntt.h +0 -14
  314. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/params.h +0 -36
  315. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/poly.c +0 -299
  316. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/poly.h +0 -37
  317. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/polyvec.c +0 -188
  318. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/polyvec.h +0 -26
  319. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/reduce.c +0 -41
  320. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/reduce.h +0 -13
  321. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/symmetric-shake.c +0 -71
  322. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/symmetric.h +0 -30
  323. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/verify.c +0 -67
  324. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/verify.h +0 -13
  325. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/LICENSE +0 -5
  326. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/Makefile +0 -19
  327. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/Makefile.Microsoft_nmake +0 -23
  328. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/api.h +0 -18
  329. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/cbd.c +0 -83
  330. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/cbd.h +0 -11
  331. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/indcpa.c +0 -327
  332. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/indcpa.h +0 -22
  333. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/kem.c +0 -164
  334. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/kem.h +0 -23
  335. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/ntt.c +0 -146
  336. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/ntt.h +0 -14
  337. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/params.h +0 -36
  338. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/poly.c +0 -299
  339. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/poly.h +0 -37
  340. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/polyvec.c +0 -188
  341. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/polyvec.h +0 -26
  342. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/reduce.c +0 -41
  343. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/reduce.h +0 -13
  344. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/symmetric-shake.c +0 -71
  345. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/symmetric.h +0 -30
  346. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/verify.c +0 -67
  347. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/verify.h +0 -13
  348. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-44/clean/LICENSE +0 -5
  349. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-44/clean/Makefile +0 -19
  350. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-44/clean/Makefile.Microsoft_nmake +0 -23
  351. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-44/clean/api.h +0 -50
  352. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-44/clean/ntt.c +0 -98
  353. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-44/clean/ntt.h +0 -10
  354. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-44/clean/packing.c +0 -261
  355. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-44/clean/packing.h +0 -31
  356. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-44/clean/params.h +0 -44
  357. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-44/clean/poly.c +0 -848
  358. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-44/clean/poly.h +0 -52
  359. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-44/clean/polyvec.c +0 -415
  360. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-44/clean/polyvec.h +0 -65
  361. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-44/clean/reduce.c +0 -69
  362. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-44/clean/reduce.h +0 -17
  363. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-44/clean/rounding.c +0 -98
  364. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-44/clean/rounding.h +0 -14
  365. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-44/clean/sign.c +0 -407
  366. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-44/clean/sign.h +0 -47
  367. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-44/clean/symmetric-shake.c +0 -26
  368. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-44/clean/symmetric.h +0 -34
  369. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/LICENSE +0 -5
  370. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/Makefile +0 -19
  371. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/Makefile.Microsoft_nmake +0 -23
  372. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/api.h +0 -50
  373. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/ntt.c +0 -98
  374. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/ntt.h +0 -10
  375. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/packing.c +0 -261
  376. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/packing.h +0 -31
  377. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/params.h +0 -44
  378. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/poly.c +0 -799
  379. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/poly.h +0 -52
  380. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/polyvec.c +0 -415
  381. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/polyvec.h +0 -65
  382. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/reduce.c +0 -69
  383. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/reduce.h +0 -17
  384. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/rounding.c +0 -92
  385. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/rounding.h +0 -14
  386. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/sign.c +0 -407
  387. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/sign.h +0 -47
  388. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/symmetric-shake.c +0 -26
  389. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/symmetric.h +0 -34
  390. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-87/clean/LICENSE +0 -5
  391. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-87/clean/Makefile +0 -19
  392. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-87/clean/Makefile.Microsoft_nmake +0 -23
  393. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-87/clean/api.h +0 -50
  394. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-87/clean/ntt.c +0 -98
  395. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-87/clean/ntt.h +0 -10
  396. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-87/clean/packing.c +0 -261
  397. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-87/clean/packing.h +0 -31
  398. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-87/clean/params.h +0 -44
  399. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-87/clean/poly.c +0 -823
  400. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-87/clean/poly.h +0 -52
  401. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-87/clean/polyvec.c +0 -415
  402. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-87/clean/polyvec.h +0 -65
  403. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-87/clean/reduce.c +0 -69
  404. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-87/clean/reduce.h +0 -17
  405. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-87/clean/rounding.c +0 -92
  406. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-87/clean/rounding.h +0 -14
  407. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-87/clean/sign.c +0 -407
  408. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-87/clean/sign.h +0 -47
  409. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-87/clean/symmetric-shake.c +0 -26
  410. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-87/clean/symmetric.h +0 -34
@@ -0,0 +1,622 @@
1
+ /*
2
+ * Copyright (c) The mlkem-native project authors
3
+ * SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
4
+ */
5
+
6
+ /* References
7
+ * ==========
8
+ *
9
+ * - [FIPS203]
10
+ * FIPS 203 Module-Lattice-Based Key-Encapsulation Mechanism Standard
11
+ * National Institute of Standards and Technology
12
+ * https://csrc.nist.gov/pubs/fips/203/final
13
+ *
14
+ * - [REF]
15
+ * CRYSTALS-Kyber C reference implementation
16
+ * Bos, Ducas, Kiltz, Lepoint, Lyubashevsky, Schanck, Schwabe, Seiler, Stehlé
17
+ * https://github.com/pq-crystals/kyber/tree/main/ref
18
+ */
19
+
20
+ #include "indcpa.h"
21
+
22
+ #include "debug.h"
23
+ #include "randombytes.h"
24
+ #include "sampling.h"
25
+ #include "symmetric.h"
26
+
27
+ /* Parameter set namespacing
28
+ * This is to facilitate building multiple instances
29
+ * of mlkem-native (e.g. with varying parameter sets)
30
+ * within a single compilation unit. */
31
+ #define mlk_pack_pk MLK_ADD_PARAM_SET(mlk_pack_pk)
32
+ #define mlk_unpack_pk MLK_ADD_PARAM_SET(mlk_unpack_pk)
33
+ #define mlk_pack_sk MLK_ADD_PARAM_SET(mlk_pack_sk)
34
+ #define mlk_unpack_sk MLK_ADD_PARAM_SET(mlk_unpack_sk)
35
+ #define mlk_pack_ciphertext MLK_ADD_PARAM_SET(mlk_pack_ciphertext)
36
+ #define mlk_unpack_ciphertext MLK_ADD_PARAM_SET(mlk_unpack_ciphertext)
37
+ #define mlk_matvec_mul MLK_ADD_PARAM_SET(mlk_matvec_mul)
38
+ #define mlk_polyvec_permute_bitrev_to_custom \
39
+ MLK_ADD_PARAM_SET(mlk_polyvec_permute_bitrev_to_custom)
40
+ #define mlk_polymat_permute_bitrev_to_custom \
41
+ MLK_ADD_PARAM_SET(mlk_polymat_permute_bitrev_to_custom)
42
+ /* End of parameter set namespacing */
43
+
44
+ /*************************************************
45
+ * Name: mlk_pack_pk
46
+ *
47
+ * Description: Serialize the public key as concatenation of the
48
+ * serialized vector of polynomials pk
49
+ * and the public seed used to generate the matrix A.
50
+ *
51
+ * Arguments: uint8_t *r: pointer to the output serialized public key
52
+ * mlk_polyvec pk: pointer to the input public-key mlk_polyvec.
53
+ * Must have coefficients within [0,..,q-1].
54
+ * const uint8_t *seed: pointer to the input public seed
55
+ *
56
+ * Specification:
57
+ * Implements @[FIPS203, Algorithm 13 (K-PKE.KeyGen), L19]
58
+ *
59
+ **************************************************/
60
+ static void mlk_pack_pk(uint8_t r[MLKEM_INDCPA_PUBLICKEYBYTES],
61
+ const mlk_polyvec *pk,
62
+ const uint8_t seed[MLKEM_SYMBYTES])
63
+ {
64
+ mlk_assert_bound_2d(pk->vec, MLKEM_K, MLKEM_N, 0, MLKEM_Q);
65
+ mlk_polyvec_tobytes(r, pk);
66
+ mlk_memcpy(r + MLKEM_POLYVECBYTES, seed, MLKEM_SYMBYTES);
67
+ }
68
+
69
+ /*************************************************
70
+ * Name: mlk_unpack_pk
71
+ *
72
+ * Description: De-serialize public key from a byte array;
73
+ * approximate inverse of mlk_pack_pk
74
+ *
75
+ * Arguments: - mlk_polyvec pk: pointer to output public-key polynomial
76
+ * vector Coefficients will be normalized to [0,..,q-1].
77
+ * - uint8_t *seed: pointer to output seed to generate matrix A
78
+ * - const uint8_t *packedpk: pointer to input serialized public
79
+ * key.
80
+ *
81
+ * Specification:
82
+ * Implements @[FIPS203, Algorithm 14 (K-PKE.Encrypt), L2-3]
83
+ *
84
+ **************************************************/
85
+ static void mlk_unpack_pk(mlk_polyvec *pk, uint8_t seed[MLKEM_SYMBYTES],
86
+ const uint8_t packedpk[MLKEM_INDCPA_PUBLICKEYBYTES])
87
+ {
88
+ mlk_polyvec_frombytes(pk, packedpk);
89
+ mlk_memcpy(seed, packedpk + MLKEM_POLYVECBYTES, MLKEM_SYMBYTES);
90
+
91
+ /* NOTE: If a modulus check was conducted on the PK, we know at this
92
+ * point that the coefficients of `pk` are unsigned canonical. The
93
+ * specifications and proofs, however, do _not_ assume this, and instead
94
+ * work with the easily provable bound by MLKEM_UINT12_LIMIT. */
95
+ }
96
+
97
+ /*************************************************
98
+ * Name: mlk_pack_sk
99
+ *
100
+ * Description: Serialize the secret key
101
+ *
102
+ * Arguments: - uint8_t *r: pointer to output serialized secret key
103
+ * - mlk_polyvec sk: pointer to input vector of polynomials
104
+ * (secret key)
105
+ *
106
+ * Specification:
107
+ * Implements @[FIPS203, Algorithm 13 (K-PKE.KeyGen), L20]
108
+ *
109
+ **************************************************/
110
+ static void mlk_pack_sk(uint8_t r[MLKEM_INDCPA_SECRETKEYBYTES],
111
+ const mlk_polyvec *sk)
112
+ {
113
+ mlk_assert_bound_2d(sk->vec, MLKEM_K, MLKEM_N, 0, MLKEM_Q);
114
+ mlk_polyvec_tobytes(r, sk);
115
+ }
116
+
117
+ /*************************************************
118
+ * Name: mlk_unpack_sk
119
+ *
120
+ * Description: De-serialize the secret key; inverse of mlk_pack_sk
121
+ *
122
+ * Arguments: - mlk_polyvec sk: pointer to output vector of polynomials
123
+ * (secret key)
124
+ * - const uint8_t *packedsk: pointer to input serialized secret
125
+ * key
126
+ *
127
+ * Specification:
128
+ * Implements @[FIPS203, Algorithm 15 (K-PKE.Decrypt), L5]
129
+ *
130
+ **************************************************/
131
+ static void mlk_unpack_sk(mlk_polyvec *sk,
132
+ const uint8_t packedsk[MLKEM_INDCPA_SECRETKEYBYTES])
133
+ {
134
+ mlk_polyvec_frombytes(sk, packedsk);
135
+ }
136
+
137
+ /*************************************************
138
+ * Name: mlk_pack_ciphertext
139
+ *
140
+ * Description: Serialize the ciphertext as concatenation of the
141
+ * compressed and serialized vector of polynomials b
142
+ * and the compressed and serialized polynomial v
143
+ *
144
+ * Arguments: uint8_t *r: pointer to the output serialized ciphertext
145
+ * mlk_poly *pk: pointer to the input vector of polynomials b
146
+ * mlk_poly *v: pointer to the input polynomial v
147
+ *
148
+ * Specification:
149
+ * Implements @[FIPS203, Algorithm 14 (K-PKE.Encrypt), L22-23]
150
+ *
151
+ **************************************************/
152
+ static void mlk_pack_ciphertext(uint8_t r[MLKEM_INDCPA_BYTES],
153
+ const mlk_polyvec *b, mlk_poly *v)
154
+ {
155
+ mlk_polyvec_compress_du(r, b);
156
+ mlk_poly_compress_dv(r + MLKEM_POLYVECCOMPRESSEDBYTES_DU, v);
157
+ }
158
+
159
+ /*************************************************
160
+ * Name: mlk_unpack_ciphertext
161
+ *
162
+ * Description: De-serialize and decompress ciphertext from a byte array;
163
+ * approximate inverse of mlk_pack_ciphertext
164
+ *
165
+ * Arguments: - mlk_polyvec b: pointer to the output vector of polynomials b
166
+ * - mlk_poly *v: pointer to the output polynomial v
167
+ * - const uint8_t *c: pointer to the input serialized ciphertext
168
+ *
169
+ * Specification:
170
+ * Implements @[FIPS203, Algorithm 15 (K-PKE.Decrypt), L1-4]
171
+ *
172
+ **************************************************/
173
+ static void mlk_unpack_ciphertext(mlk_polyvec *b, mlk_poly *v,
174
+ const uint8_t c[MLKEM_INDCPA_BYTES])
175
+ {
176
+ mlk_polyvec_decompress_du(b, c);
177
+ mlk_poly_decompress_dv(v, c + MLKEM_POLYVECCOMPRESSEDBYTES_DU);
178
+ }
179
+
180
+ /* Helper function to ensure that the polynomial entries in the output
181
+ * of gen_matrix use the standard (bitreversed) ordering of coefficients.
182
+ * No-op unless a native backend with a custom ordering is used.
183
+ *
184
+ * We don't inline this into gen_matrix to avoid having to split the CBMC
185
+ * proof for gen_matrix based on MLK_USE_NATIVE_NTT_CUSTOM_ORDER. */
186
+ static void mlk_polyvec_permute_bitrev_to_custom(mlk_polyvec *v)
187
+ __contract__(
188
+ /* We don't specify that this should be a permutation, but only
189
+ * that it does not change the bound established at the end of mlk_gen_matrix. */
190
+ requires(memory_no_alias(v, sizeof(mlk_polyvec)))
191
+ requires(forall(x, 0, MLKEM_K,
192
+ array_bound(v->vec[x].coeffs, 0, MLKEM_N, 0, MLKEM_Q)))
193
+ assigns(memory_slice(v, sizeof(mlk_polyvec)))
194
+ ensures(forall(x, 0, MLKEM_K,
195
+ array_bound(v->vec[x].coeffs, 0, MLKEM_N, 0, MLKEM_Q))))
196
+ {
197
+ #if defined(MLK_USE_NATIVE_NTT_CUSTOM_ORDER)
198
+ unsigned i;
199
+ for (i = 0; i < MLKEM_K; i++)
200
+ __loop__(
201
+ assigns(i, memory_slice(v, sizeof(mlk_polyvec)))
202
+ invariant(i <= MLKEM_K)
203
+ invariant(forall(x, 0, MLKEM_K,
204
+ array_bound(v->vec[x].coeffs, 0, MLKEM_N, 0, MLKEM_Q))))
205
+ {
206
+ mlk_poly_permute_bitrev_to_custom(v->vec[i].coeffs);
207
+ }
208
+ #else /* MLK_USE_NATIVE_NTT_CUSTOM_ORDER */
209
+ /* Nothing to do */
210
+ (void)v;
211
+ #endif /* !MLK_USE_NATIVE_NTT_CUSTOM_ORDER */
212
+ }
213
+
214
+ static void mlk_polymat_permute_bitrev_to_custom(mlk_polymat *a)
215
+ __contract__(
216
+ /* We don't specify that this should be a permutation, but only
217
+ * that it does not change the bound established at the end of mlk_gen_matrix. */
218
+ requires(memory_no_alias(a, sizeof(mlk_polymat)))
219
+ requires(forall(x, 0, MLKEM_K, forall(y, 0, MLKEM_K,
220
+ array_bound(a->vec[x].vec[y].coeffs, 0, MLKEM_N, 0, MLKEM_Q))))
221
+ assigns(memory_slice(a, sizeof(mlk_polymat)))
222
+ ensures(forall(x, 0, MLKEM_K, forall(y, 0, MLKEM_K,
223
+ array_bound(a->vec[x].vec[y].coeffs, 0, MLKEM_N, 0, MLKEM_Q)))))
224
+ {
225
+ unsigned i;
226
+ for (i = 0; i < MLKEM_K; i++)
227
+ __loop__(
228
+ assigns(i, memory_slice(a, sizeof(mlk_polymat)))
229
+ invariant(i <= MLKEM_K)
230
+ invariant(forall(x, 0, MLKEM_K, forall(y, 0, MLKEM_K,
231
+ array_bound(a->vec[x].vec[y].coeffs, 0, MLKEM_N, 0, MLKEM_Q)))))
232
+ {
233
+ mlk_polyvec_permute_bitrev_to_custom(&a->vec[i]);
234
+ }
235
+ }
236
+
237
+ /* Reference: `gen_matrix()` in the reference implementation @[REF].
238
+ * - We use a special subroutine to generate 4 polynomials
239
+ * at a time, to be able to leverage batched Keccak-f1600
240
+ * implementations. The reference implementation generates
241
+ * one matrix entry a time.
242
+ *
243
+ * Not static for benchmarking */
244
+ MLK_INTERNAL_API
245
+ void mlk_gen_matrix(mlk_polymat *a, const uint8_t seed[MLKEM_SYMBYTES],
246
+ int transposed)
247
+ {
248
+ unsigned i, j;
249
+ MLK_ALIGN uint8_t seed_ext[4][MLK_ALIGN_UP(MLKEM_SYMBYTES + 2)];
250
+
251
+ for (j = 0; j < 4; j++)
252
+ {
253
+ mlk_memcpy(seed_ext[j], seed, MLKEM_SYMBYTES);
254
+ }
255
+
256
+ #if !defined(MLK_CONFIG_SERIAL_FIPS202_ONLY)
257
+ /* Sample 4 matrix entries a time. */
258
+ for (i = 0; i < (MLKEM_K * MLKEM_K / 4) * 4; i += 4)
259
+ {
260
+ for (j = 0; j < 4; j++)
261
+ {
262
+ uint8_t x, y;
263
+ /* MLKEM_K <= 4, so the values fit in uint8_t. */
264
+ x = (uint8_t)((i + j) / MLKEM_K);
265
+ y = (uint8_t)((i + j) % MLKEM_K);
266
+ if (transposed)
267
+ {
268
+ seed_ext[j][MLKEM_SYMBYTES + 0] = x;
269
+ seed_ext[j][MLKEM_SYMBYTES + 1] = y;
270
+ }
271
+ else
272
+ {
273
+ seed_ext[j][MLKEM_SYMBYTES + 0] = y;
274
+ seed_ext[j][MLKEM_SYMBYTES + 1] = x;
275
+ }
276
+ }
277
+
278
+ mlk_poly_rej_uniform_x4(&a->vec[i / MLKEM_K].vec[i % MLKEM_K],
279
+ &a->vec[(i + 1) / MLKEM_K].vec[(i + 1) % MLKEM_K],
280
+ &a->vec[(i + 2) / MLKEM_K].vec[(i + 2) % MLKEM_K],
281
+ &a->vec[(i + 3) / MLKEM_K].vec[(i + 3) % MLKEM_K],
282
+ seed_ext);
283
+ }
284
+ #else /* !MLK_CONFIG_SERIAL_FIPS202_ONLY */
285
+ /* When using serial FIPS202, sample all entries individually. */
286
+ i = 0;
287
+ #endif /* MLK_CONFIG_SERIAL_FIPS202_ONLY */
288
+
289
+ /* For MLKEM_K == 3, sample the last entry individually.
290
+ * When MLK_CONFIG_SERIAL_FIPS202_ONLY is set, sample all entries
291
+ * individually. */
292
+ for (; i < MLKEM_K * MLKEM_K; i++)
293
+ {
294
+ uint8_t x, y;
295
+ /* MLKEM_K <= 4, so the values fit in uint8_t. */
296
+ x = (uint8_t)(i / MLKEM_K);
297
+ y = (uint8_t)(i % MLKEM_K);
298
+
299
+ if (transposed)
300
+ {
301
+ seed_ext[0][MLKEM_SYMBYTES + 0] = x;
302
+ seed_ext[0][MLKEM_SYMBYTES + 1] = y;
303
+ }
304
+ else
305
+ {
306
+ seed_ext[0][MLKEM_SYMBYTES + 0] = y;
307
+ seed_ext[0][MLKEM_SYMBYTES + 1] = x;
308
+ }
309
+
310
+ mlk_poly_rej_uniform(&a->vec[i / MLKEM_K].vec[i % MLKEM_K], seed_ext[0]);
311
+ }
312
+
313
+ mlk_assert(i == MLKEM_K * MLKEM_K);
314
+
315
+ /*
316
+ * The public matrix is generated in NTT domain. If the native backend
317
+ * uses a custom order in NTT domain, permute A accordingly.
318
+ */
319
+ mlk_polymat_permute_bitrev_to_custom(a);
320
+
321
+ /* Specification: Partially implements
322
+ * @[FIPS203, Section 3.3, Destruction of intermediate values] */
323
+ mlk_zeroize(seed_ext, sizeof(seed_ext));
324
+ }
325
+
326
+ /*************************************************
327
+ * Name: mlk_matvec_mul
328
+ *
329
+ * Description: Computes matrix-vector product in NTT domain,
330
+ * via Montgomery multiplication.
331
+ *
332
+ * Arguments: - mlk_polyvec out: Pointer to output polynomial vector
333
+ * - mlk_polymat a: Input matrix. Must be in NTT domain
334
+ * and have coefficients of absolute value < 4096.
335
+ * - mlk_polyvec v: Input polynomial vector. Must be in NTT
336
+ * domain.
337
+ * - mlk_polyvec vc: Mulcache for v, computed via
338
+ * mlk_polyvec_mulcache_compute().
339
+ *
340
+ * Specification: Implements @[FIPS203, Section 2.4.7, Eq (2.12), (2.13)]
341
+ *
342
+ **************************************************/
343
+ static void mlk_matvec_mul(mlk_polyvec *out, const mlk_polymat *a,
344
+ const mlk_polyvec *v, const mlk_polyvec_mulcache *vc)
345
+ __contract__(
346
+ requires(memory_no_alias(out, sizeof(mlk_polyvec)))
347
+ requires(memory_no_alias(a, sizeof(mlk_polymat)))
348
+ requires(memory_no_alias(v, sizeof(mlk_polyvec)))
349
+ requires(memory_no_alias(vc, sizeof(mlk_polyvec_mulcache)))
350
+ requires(forall(k0, 0, MLKEM_K,
351
+ forall(k1, 0, MLKEM_K,
352
+ array_bound(a->vec[k0].vec[k1].coeffs, 0, MLKEM_N, 0, MLKEM_UINT12_LIMIT))))
353
+ assigns(memory_slice(out, sizeof(mlk_polyvec))))
354
+ {
355
+ unsigned i;
356
+ for (i = 0; i < MLKEM_K; i++)
357
+ __loop__(
358
+ assigns(i, memory_slice(out, sizeof(mlk_polyvec)))
359
+ invariant(i <= MLKEM_K))
360
+ {
361
+ mlk_polyvec_basemul_acc_montgomery_cached(&out->vec[i], &a->vec[i], v, vc);
362
+ }
363
+ }
364
+
365
+ /* Reference: `indcpa_keypair_derand()` in the reference implementation @[REF].
366
+ * - We use x4-batched versions of `poly_getnoise` to leverage
367
+ * batched x4-batched Keccak-f1600.
368
+ * - We use a different implementation of `gen_matrix()` which
369
+ * uses x4-batched Keccak-f1600 (see `mlk_gen_matrix()` above).
370
+ * - We use a mulcache to speed up matrix-vector multiplication.
371
+ * - We include buffer zeroization.
372
+ */
373
+ MLK_INTERNAL_API
374
+ int mlk_indcpa_keypair_derand(uint8_t pk[MLKEM_INDCPA_PUBLICKEYBYTES],
375
+ uint8_t sk[MLKEM_INDCPA_SECRETKEYBYTES],
376
+ const uint8_t coins[MLKEM_SYMBYTES],
377
+ MLK_CONFIG_CONTEXT_PARAMETER_TYPE context)
378
+ {
379
+ int ret = 0;
380
+ const uint8_t *publicseed;
381
+ const uint8_t *noiseseed;
382
+ MLK_ALLOC(buf, uint8_t, 2 * MLKEM_SYMBYTES, context);
383
+ MLK_ALLOC(coins_with_domain_separator, uint8_t, MLKEM_SYMBYTES + 1, context);
384
+ MLK_ALLOC(a, mlk_polymat, 1, context);
385
+ MLK_ALLOC(e, mlk_polyvec, 1, context);
386
+ MLK_ALLOC(pkpv, mlk_polyvec, 1, context);
387
+ MLK_ALLOC(skpv, mlk_polyvec, 1, context);
388
+ MLK_ALLOC(skpv_cache, mlk_polyvec_mulcache, 1, context);
389
+
390
+ if (buf == NULL || coins_with_domain_separator == NULL || a == NULL ||
391
+ e == NULL || pkpv == NULL || skpv == NULL || skpv_cache == NULL)
392
+ {
393
+ ret = MLK_ERR_OUT_OF_MEMORY;
394
+ goto cleanup;
395
+ }
396
+
397
+ publicseed = buf;
398
+ noiseseed = buf + MLKEM_SYMBYTES;
399
+
400
+ /* Concatenate coins with MLKEM_K for domain separation of security levels */
401
+ mlk_memcpy(coins_with_domain_separator, coins, MLKEM_SYMBYTES);
402
+ coins_with_domain_separator[MLKEM_SYMBYTES] = MLKEM_K;
403
+
404
+ mlk_hash_g(buf, coins_with_domain_separator, MLKEM_SYMBYTES + 1);
405
+
406
+ /*
407
+ * Declassify the public seed.
408
+ * Required to use it in conditional-branches in rejection sampling.
409
+ * This is needed because all output of randombytes is marked as secret
410
+ * (=undefined)
411
+ */
412
+ MLK_CT_TESTING_DECLASSIFY(publicseed, MLKEM_SYMBYTES);
413
+
414
+ mlk_gen_matrix(a, publicseed, 0 /* no transpose */);
415
+
416
+ #if MLKEM_K == 2
417
+ mlk_poly_getnoise_eta1_4x(&skpv->vec[0], &skpv->vec[1], &e->vec[0],
418
+ &e->vec[1], noiseseed, 0, 1, 2, 3);
419
+ #elif MLKEM_K == 3
420
+ /*
421
+ * Only the first three output buffers are needed.
422
+ * The laster parameter is a dummy that's overwritten later.
423
+ */
424
+ mlk_poly_getnoise_eta1_4x(&skpv->vec[0], &skpv->vec[1], &skpv->vec[2], NULL,
425
+ noiseseed, 0, 1, 2, 0xFF /* irrelevant */);
426
+ /* Same here */
427
+ mlk_poly_getnoise_eta1_4x(&e->vec[0], &e->vec[1], &e->vec[2], NULL, noiseseed,
428
+ 3, 4, 5, 0xFF /* irrelevant */);
429
+ #elif MLKEM_K == 4
430
+ mlk_poly_getnoise_eta1_4x(&skpv->vec[0], &skpv->vec[1], &skpv->vec[2],
431
+ &skpv->vec[3], noiseseed, 0, 1, 2, 3);
432
+ mlk_poly_getnoise_eta1_4x(&e->vec[0], &e->vec[1], &e->vec[2], &e->vec[3],
433
+ noiseseed, 4, 5, 6, 7);
434
+ #endif /* MLKEM_K == 4 */
435
+
436
+ mlk_polyvec_ntt(skpv);
437
+ mlk_polyvec_ntt(e);
438
+
439
+ mlk_polyvec_mulcache_compute(skpv_cache, skpv);
440
+ mlk_matvec_mul(pkpv, a, skpv, skpv_cache);
441
+ mlk_polyvec_tomont(pkpv);
442
+
443
+ mlk_polyvec_add(pkpv, e);
444
+ mlk_polyvec_reduce(pkpv);
445
+ mlk_polyvec_reduce(skpv);
446
+
447
+ mlk_pack_sk(sk, skpv);
448
+ mlk_pack_pk(pk, pkpv, publicseed);
449
+
450
+ cleanup:
451
+ /* Specification: Partially implements
452
+ * @[FIPS203, Section 3.3, Destruction of intermediate values] */
453
+ MLK_FREE(skpv_cache, mlk_polyvec_mulcache, 1, context);
454
+ MLK_FREE(skpv, mlk_polyvec, 1, context);
455
+ MLK_FREE(pkpv, mlk_polyvec, 1, context);
456
+ MLK_FREE(e, mlk_polyvec, 1, context);
457
+ MLK_FREE(a, mlk_polymat, 1, context);
458
+ MLK_FREE(coins_with_domain_separator, uint8_t, MLKEM_SYMBYTES + 1, context);
459
+ MLK_FREE(buf, uint8_t, 2 * MLKEM_SYMBYTES, context);
460
+ return ret;
461
+ }
462
+
463
+ /* Reference: `indcpa_enc()` in the reference implementation @[REF].
464
+ * - We use x4-batched versions of `poly_getnoise` to leverage
465
+ * batched x4-batched Keccak-f1600.
466
+ * - We use a different implementation of `gen_matrix()` which
467
+ * uses x4-batched Keccak-f1600 (see `mlk_gen_matrix()` above).
468
+ * - We use a mulcache to speed up matrix-vector multiplication.
469
+ * - We include buffer zeroization.
470
+ */
471
+ MLK_INTERNAL_API
472
+ int mlk_indcpa_enc(uint8_t c[MLKEM_INDCPA_BYTES],
473
+ const uint8_t m[MLKEM_INDCPA_MSGBYTES],
474
+ const uint8_t pk[MLKEM_INDCPA_PUBLICKEYBYTES],
475
+ const uint8_t coins[MLKEM_SYMBYTES],
476
+ MLK_CONFIG_CONTEXT_PARAMETER_TYPE context)
477
+ {
478
+ int ret = 0;
479
+ MLK_ALLOC(seed, uint8_t, MLKEM_SYMBYTES, context);
480
+ MLK_ALLOC(at, mlk_polymat, 1, context);
481
+ MLK_ALLOC(sp, mlk_polyvec, 1, context);
482
+ MLK_ALLOC(pkpv, mlk_polyvec, 1, context);
483
+ MLK_ALLOC(ep, mlk_polyvec, 1, context);
484
+ MLK_ALLOC(b, mlk_polyvec, 1, context);
485
+ MLK_ALLOC(v, mlk_poly, 1, context);
486
+ MLK_ALLOC(k, mlk_poly, 1, context);
487
+ MLK_ALLOC(epp, mlk_poly, 1, context);
488
+ MLK_ALLOC(sp_cache, mlk_polyvec_mulcache, 1, context);
489
+
490
+ if (seed == NULL || at == NULL || sp == NULL || pkpv == NULL || ep == NULL ||
491
+ b == NULL || v == NULL || k == NULL || epp == NULL || sp_cache == NULL)
492
+ {
493
+ ret = MLK_ERR_OUT_OF_MEMORY;
494
+ goto cleanup;
495
+ }
496
+
497
+ mlk_unpack_pk(pkpv, seed, pk);
498
+ mlk_poly_frommsg(k, m);
499
+
500
+ /*
501
+ * Declassify the public seed.
502
+ * Required to use it in conditional-branches in rejection sampling.
503
+ * This is needed because in re-encryption the publicseed originated from sk
504
+ * which is marked undefined.
505
+ */
506
+ MLK_CT_TESTING_DECLASSIFY(seed, MLKEM_SYMBYTES);
507
+
508
+ mlk_gen_matrix(at, seed, 1 /* transpose */);
509
+
510
+ #if MLKEM_K == 2
511
+ mlk_poly_getnoise_eta1122_4x(&sp->vec[0], &sp->vec[1], &ep->vec[0],
512
+ &ep->vec[1], coins, 0, 1, 2, 3);
513
+ mlk_poly_getnoise_eta2(epp, coins, 4);
514
+ #elif MLKEM_K == 3
515
+ /*
516
+ * In this call, only the first three output buffers are needed.
517
+ * The last parameter is a dummy that's overwritten later.
518
+ */
519
+ mlk_poly_getnoise_eta1_4x(&sp->vec[0], &sp->vec[1], &sp->vec[2], NULL, coins,
520
+ 0, 1, 2, 0xFF /* irrelevant */);
521
+ /* The fourth output buffer in this call _is_ used. */
522
+ mlk_poly_getnoise_eta2_4x(&ep->vec[0], &ep->vec[1], &ep->vec[2], epp, coins,
523
+ 3, 4, 5, 6);
524
+ #elif MLKEM_K == 4
525
+ mlk_poly_getnoise_eta1_4x(&sp->vec[0], &sp->vec[1], &sp->vec[2], &sp->vec[3],
526
+ coins, 0, 1, 2, 3);
527
+ mlk_poly_getnoise_eta2_4x(&ep->vec[0], &ep->vec[1], &ep->vec[2], &ep->vec[3],
528
+ coins, 4, 5, 6, 7);
529
+ mlk_poly_getnoise_eta2(epp, coins, 8);
530
+ #endif /* MLKEM_K == 4 */
531
+
532
+ mlk_polyvec_ntt(sp);
533
+
534
+ mlk_polyvec_mulcache_compute(sp_cache, sp);
535
+ mlk_matvec_mul(b, at, sp, sp_cache);
536
+ mlk_polyvec_basemul_acc_montgomery_cached(v, pkpv, sp, sp_cache);
537
+
538
+ mlk_polyvec_invntt_tomont(b);
539
+ mlk_poly_invntt_tomont(v);
540
+
541
+ mlk_polyvec_add(b, ep);
542
+ mlk_poly_add(v, epp);
543
+ mlk_poly_add(v, k);
544
+
545
+ mlk_polyvec_reduce(b);
546
+ mlk_poly_reduce(v);
547
+
548
+ mlk_pack_ciphertext(c, b, v);
549
+
550
+ cleanup:
551
+ /* Specification: Partially implements
552
+ * @[FIPS203, Section 3.3, Destruction of intermediate values] */
553
+ MLK_FREE(sp_cache, mlk_polyvec_mulcache, 1, context);
554
+ MLK_FREE(epp, mlk_poly, 1, context);
555
+ MLK_FREE(k, mlk_poly, 1, context);
556
+ MLK_FREE(v, mlk_poly, 1, context);
557
+ MLK_FREE(b, mlk_polyvec, 1, context);
558
+ MLK_FREE(ep, mlk_polyvec, 1, context);
559
+ MLK_FREE(pkpv, mlk_polyvec, 1, context);
560
+ MLK_FREE(sp, mlk_polyvec, 1, context);
561
+ MLK_FREE(at, mlk_polymat, 1, context);
562
+ MLK_FREE(seed, uint8_t, MLKEM_SYMBYTES, context);
563
+ return ret;
564
+ }
565
+
566
+ /* Reference: `indcpa_dec()` in the reference implementation @[REF].
567
+ * - We use a mulcache for the scalar product.
568
+ * - We include buffer zeroization. */
569
+ MLK_INTERNAL_API
570
+ int mlk_indcpa_dec(uint8_t m[MLKEM_INDCPA_MSGBYTES],
571
+ const uint8_t c[MLKEM_INDCPA_BYTES],
572
+ const uint8_t sk[MLKEM_INDCPA_SECRETKEYBYTES],
573
+ MLK_CONFIG_CONTEXT_PARAMETER_TYPE context)
574
+ {
575
+ int ret = 0;
576
+ MLK_ALLOC(b, mlk_polyvec, 1, context);
577
+ MLK_ALLOC(skpv, mlk_polyvec, 1, context);
578
+ MLK_ALLOC(v, mlk_poly, 1, context);
579
+ MLK_ALLOC(sb, mlk_poly, 1, context);
580
+ MLK_ALLOC(b_cache, mlk_polyvec_mulcache, 1, context);
581
+
582
+ if (b == NULL || skpv == NULL || v == NULL || sb == NULL || b_cache == NULL)
583
+ {
584
+ ret = MLK_ERR_OUT_OF_MEMORY;
585
+ goto cleanup;
586
+ }
587
+
588
+ mlk_unpack_ciphertext(b, v, c);
589
+ mlk_unpack_sk(skpv, sk);
590
+
591
+ mlk_polyvec_ntt(b);
592
+ mlk_polyvec_mulcache_compute(b_cache, b);
593
+ mlk_polyvec_basemul_acc_montgomery_cached(sb, skpv, b, b_cache);
594
+ mlk_poly_invntt_tomont(sb);
595
+
596
+ mlk_poly_sub(v, sb);
597
+ mlk_poly_reduce(v);
598
+
599
+ mlk_poly_tomsg(m, v);
600
+
601
+ cleanup:
602
+ /* Specification: Partially implements
603
+ * @[FIPS203, Section 3.3, Destruction of intermediate values] */
604
+ MLK_FREE(b_cache, mlk_polyvec_mulcache, 1, context);
605
+ MLK_FREE(sb, mlk_poly, 1, context);
606
+ MLK_FREE(v, mlk_poly, 1, context);
607
+ MLK_FREE(skpv, mlk_polyvec, 1, context);
608
+ MLK_FREE(b, mlk_polyvec, 1, context);
609
+ return ret;
610
+ }
611
+
612
+ /* To facilitate single-compilation-unit (SCU) builds, undefine all macros.
613
+ * Don't modify by hand -- this is auto-generated by scripts/autogen. */
614
+ #undef mlk_pack_pk
615
+ #undef mlk_unpack_pk
616
+ #undef mlk_pack_sk
617
+ #undef mlk_unpack_sk
618
+ #undef mlk_pack_ciphertext
619
+ #undef mlk_unpack_ciphertext
620
+ #undef mlk_matvec_mul
621
+ #undef mlk_polyvec_permute_bitrev_to_custom
622
+ #undef mlk_polymat_permute_bitrev_to_custom