pq_crypto 0.4.2 → 0.5.0

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 (408) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +25 -0
  3. data/GET_STARTED.md +21 -16
  4. data/README.md +26 -0
  5. data/SECURITY.md +22 -16
  6. data/ext/pqcrypto/extconf.rb +148 -99
  7. data/ext/pqcrypto/mldsa_api.h +1 -118
  8. data/ext/pqcrypto/mlkem_api.h +1 -42
  9. data/ext/pqcrypto/pq_externalmu.c +88 -216
  10. data/ext/pqcrypto/pqcrypto_native_api.h +129 -0
  11. data/ext/pqcrypto/pqcrypto_ruby_secure.c +0 -3
  12. data/ext/pqcrypto/pqcrypto_secure.c +135 -117
  13. data/ext/pqcrypto/pqcrypto_secure.h +1 -42
  14. data/ext/pqcrypto/pqcrypto_version.h +1 -1
  15. data/ext/pqcrypto/randombytes.h +9 -0
  16. data/ext/pqcrypto/vendor/.vendored +10 -5
  17. data/ext/pqcrypto/vendor/mldsa-native/BUILDING.md +105 -0
  18. data/ext/pqcrypto/vendor/mldsa-native/LICENSE +286 -0
  19. data/ext/pqcrypto/vendor/mldsa-native/META.yml +24 -0
  20. data/ext/pqcrypto/vendor/mldsa-native/README.md +221 -0
  21. data/ext/pqcrypto/vendor/mldsa-native/SECURITY.md +8 -0
  22. data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native.c +721 -0
  23. data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native.h +975 -0
  24. data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native_asm.S +724 -0
  25. data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native_config.h +723 -0
  26. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/cbmc.h +166 -0
  27. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/common.h +321 -0
  28. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/ct.c +21 -0
  29. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/ct.h +385 -0
  30. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/debug.c +73 -0
  31. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/debug.h +130 -0
  32. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/fips202.c +277 -0
  33. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/fips202.h +244 -0
  34. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/fips202x4.c +182 -0
  35. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/fips202x4.h +117 -0
  36. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/keccakf1600.c +438 -0
  37. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/keccakf1600.h +105 -0
  38. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/auto.h +71 -0
  39. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/fips202_native_aarch64.h +62 -0
  40. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_scalar_asm.S +376 -0
  41. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_v84a_asm.S +204 -0
  42. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x2_v84a_asm.S +259 -0
  43. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_scalar_hybrid_asm.S +1077 -0
  44. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_v84a_scalar_hybrid_asm.S +987 -0
  45. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccakf1600_round_constants.c +41 -0
  46. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x1_scalar.h +26 -0
  47. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x1_v84a.h +35 -0
  48. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x2_v84a.h +37 -0
  49. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x4_v8a_scalar.h +27 -0
  50. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x4_v8a_v84a_scalar.h +36 -0
  51. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/api.h +69 -0
  52. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/README.md +10 -0
  53. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/mve.h +32 -0
  54. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/fips202_native_armv81m.h +20 -0
  55. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.S +638 -0
  56. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.c +136 -0
  57. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccakf1600_round_constants.c +52 -0
  58. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/auto.h +29 -0
  59. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/KeccakP_1600_times4_SIMD256.c +488 -0
  60. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/KeccakP_1600_times4_SIMD256.h +16 -0
  61. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/xkcp.h +31 -0
  62. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/meta.h +247 -0
  63. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/aarch64_zetas.c +231 -0
  64. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/arith_native_aarch64.h +150 -0
  65. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/intt.S +753 -0
  66. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l4.S +129 -0
  67. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l5.S +145 -0
  68. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l7.S +177 -0
  69. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/ntt.S +653 -0
  70. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/pointwise_montgomery.S +79 -0
  71. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_caddq_asm.S +53 -0
  72. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_chknorm_asm.S +55 -0
  73. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_decompose_32_asm.S +85 -0
  74. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_decompose_88_asm.S +85 -0
  75. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_use_hint_32_asm.S +102 -0
  76. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_use_hint_88_asm.S +110 -0
  77. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/polyz_unpack_17_asm.S +72 -0
  78. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/polyz_unpack_19_asm.S +69 -0
  79. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/polyz_unpack_table.c +40 -0
  80. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_asm.S +189 -0
  81. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_eta2_asm.S +135 -0
  82. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_eta4_asm.S +128 -0
  83. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_eta_table.c +543 -0
  84. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_table.c +62 -0
  85. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/api.h +649 -0
  86. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/meta.h +23 -0
  87. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/meta.h +315 -0
  88. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/arith_native_x86_64.h +124 -0
  89. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/consts.c +157 -0
  90. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/consts.h +27 -0
  91. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/intt.S +2311 -0
  92. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/ntt.S +2383 -0
  93. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/nttunpack.S +239 -0
  94. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise.S +131 -0
  95. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l4.S +139 -0
  96. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l5.S +155 -0
  97. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l7.S +187 -0
  98. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_caddq_avx2.c +61 -0
  99. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_chknorm_avx2.c +52 -0
  100. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_decompose_32_avx2.c +155 -0
  101. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_decompose_88_avx2.c +155 -0
  102. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_use_hint_32_avx2.c +102 -0
  103. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_use_hint_88_avx2.c +104 -0
  104. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/polyz_unpack_17_avx2.c +91 -0
  105. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/polyz_unpack_19_avx2.c +93 -0
  106. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/rej_uniform_avx2.c +126 -0
  107. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/rej_uniform_eta2_avx2.c +155 -0
  108. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/rej_uniform_eta4_avx2.c +139 -0
  109. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/rej_uniform_table.c +160 -0
  110. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/packing.c +293 -0
  111. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/packing.h +224 -0
  112. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/params.h +77 -0
  113. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly.c +991 -0
  114. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly.h +393 -0
  115. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly_kl.c +946 -0
  116. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly_kl.h +360 -0
  117. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec.c +877 -0
  118. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec.h +725 -0
  119. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/randombytes.h +26 -0
  120. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/reduce.h +139 -0
  121. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/rounding.h +249 -0
  122. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/sign.c +1511 -0
  123. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/sign.h +806 -0
  124. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/symmetric.h +68 -0
  125. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/sys.h +268 -0
  126. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/zetas.inc +55 -0
  127. data/ext/pqcrypto/vendor/mlkem-native/BUILDING.md +104 -0
  128. data/ext/pqcrypto/vendor/mlkem-native/LICENSE +294 -0
  129. data/ext/pqcrypto/vendor/mlkem-native/META.yml +30 -0
  130. data/ext/pqcrypto/vendor/mlkem-native/README.md +223 -0
  131. data/ext/pqcrypto/vendor/mlkem-native/RELEASE.md +86 -0
  132. data/ext/pqcrypto/vendor/mlkem-native/SECURITY.md +8 -0
  133. data/ext/pqcrypto/vendor/mlkem-native/mlkem/README.md +23 -0
  134. data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native.c +660 -0
  135. data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native.h +538 -0
  136. data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native_asm.S +681 -0
  137. data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native_config.h +709 -0
  138. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/cbmc.h +174 -0
  139. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/common.h +274 -0
  140. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/compress.c +717 -0
  141. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/compress.h +688 -0
  142. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/debug.c +64 -0
  143. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/debug.h +128 -0
  144. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/fips202.c +251 -0
  145. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/fips202.h +158 -0
  146. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/fips202x4.c +208 -0
  147. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/fips202x4.h +80 -0
  148. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/keccakf1600.c +463 -0
  149. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/keccakf1600.h +98 -0
  150. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/auto.h +70 -0
  151. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/fips202_native_aarch64.h +69 -0
  152. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccak_f1600_x1_scalar_asm.S +375 -0
  153. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccak_f1600_x1_v84a_asm.S +203 -0
  154. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccak_f1600_x2_v84a_asm.S +258 -0
  155. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_scalar_hybrid_asm.S +1076 -0
  156. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_v84a_scalar_hybrid_asm.S +986 -0
  157. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccakf1600_round_constants.c +46 -0
  158. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x1_scalar.h +25 -0
  159. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x1_v84a.h +34 -0
  160. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x2_v84a.h +35 -0
  161. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x4_v8a_scalar.h +26 -0
  162. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x4_v8a_v84a_scalar.h +35 -0
  163. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/api.h +117 -0
  164. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/README.md +10 -0
  165. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/mve.h +79 -0
  166. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/fips202_native_armv81m.h +35 -0
  167. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.S +667 -0
  168. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.c +40 -0
  169. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/keccakf1600_round_constants.c +51 -0
  170. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/state_extract_bytes_x4_mve.S +290 -0
  171. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/state_xor_bytes_x4_mve.S +314 -0
  172. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/auto.h +28 -0
  173. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/keccak_f1600_x4_avx2.h +33 -0
  174. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/src/fips202_native_x86_64.h +41 -0
  175. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/src/keccak_f1600_x4_avx2.S +451 -0
  176. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/src/keccakf1600_constants.c +51 -0
  177. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/indcpa.c +622 -0
  178. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/indcpa.h +156 -0
  179. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/kem.c +446 -0
  180. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/kem.h +326 -0
  181. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/README.md +16 -0
  182. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/meta.h +122 -0
  183. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/aarch64_zetas.c +174 -0
  184. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/arith_native_aarch64.h +177 -0
  185. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/intt.S +628 -0
  186. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/ntt.S +562 -0
  187. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/poly_mulcache_compute_asm.S +127 -0
  188. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/poly_reduce_asm.S +150 -0
  189. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/poly_tobytes_asm.S +117 -0
  190. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/poly_tomont_asm.S +98 -0
  191. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/polyvec_basemul_acc_montgomery_cached_asm_k2.S +261 -0
  192. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/polyvec_basemul_acc_montgomery_cached_asm_k3.S +314 -0
  193. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/polyvec_basemul_acc_montgomery_cached_asm_k4.S +368 -0
  194. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/rej_uniform_asm.S +226 -0
  195. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/rej_uniform_table.c +542 -0
  196. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/api.h +637 -0
  197. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/meta.h +25 -0
  198. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/README.md +11 -0
  199. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/meta.h +128 -0
  200. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/arith_native_riscv64.h +45 -0
  201. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/rv64v_debug.c +81 -0
  202. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/rv64v_debug.h +145 -0
  203. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/rv64v_izetas.inc +27 -0
  204. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/rv64v_poly.c +805 -0
  205. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/rv64v_zetas.inc +27 -0
  206. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/rv64v_zetas_basemul.inc +39 -0
  207. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/README.md +4 -0
  208. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/meta.h +304 -0
  209. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/arith_native_x86_64.h +309 -0
  210. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/compress_consts.c +94 -0
  211. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/compress_consts.h +45 -0
  212. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/consts.c +102 -0
  213. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/consts.h +25 -0
  214. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/intt.S +719 -0
  215. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mulcache_compute.S +90 -0
  216. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/ntt.S +639 -0
  217. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/nttfrombytes.S +193 -0
  218. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/ntttobytes.S +181 -0
  219. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/nttunpack.S +174 -0
  220. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/poly_compress_d10.S +382 -0
  221. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/poly_compress_d11.S +448 -0
  222. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/poly_compress_d4.S +163 -0
  223. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/poly_compress_d5.S +220 -0
  224. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/poly_decompress_d10.S +228 -0
  225. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/poly_decompress_d11.S +277 -0
  226. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/poly_decompress_d4.S +180 -0
  227. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/poly_decompress_d5.S +192 -0
  228. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/polyvec_basemul_acc_montgomery_cached_asm_k2.S +502 -0
  229. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/polyvec_basemul_acc_montgomery_cached_asm_k3.S +750 -0
  230. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/polyvec_basemul_acc_montgomery_cached_asm_k4.S +998 -0
  231. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/reduce.S +218 -0
  232. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/rej_uniform_asm.S +103 -0
  233. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/rej_uniform_table.c +544 -0
  234. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/tomont.S +155 -0
  235. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/params.h +76 -0
  236. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/poly.c +572 -0
  237. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/poly.h +317 -0
  238. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/poly_k.c +502 -0
  239. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/poly_k.h +668 -0
  240. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/randombytes.h +60 -0
  241. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/sampling.c +362 -0
  242. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/sampling.h +118 -0
  243. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/symmetric.h +70 -0
  244. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/sys.h +260 -0
  245. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/verify.c +20 -0
  246. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/verify.h +464 -0
  247. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/zetas.inc +30 -0
  248. data/lib/pq_crypto/version.rb +1 -1
  249. data/lib/pq_crypto.rb +1 -1
  250. data/script/vendor_libs.rb +88 -159
  251. metadata +236 -160
  252. data/ext/pqcrypto/vendor/pqclean/common/aes.c +0 -639
  253. data/ext/pqcrypto/vendor/pqclean/common/aes.h +0 -64
  254. data/ext/pqcrypto/vendor/pqclean/common/compat.h +0 -73
  255. data/ext/pqcrypto/vendor/pqclean/common/crypto_declassify.h +0 -7
  256. data/ext/pqcrypto/vendor/pqclean/common/fips202.c +0 -928
  257. data/ext/pqcrypto/vendor/pqclean/common/fips202.h +0 -166
  258. data/ext/pqcrypto/vendor/pqclean/common/keccak2x/feat.S +0 -168
  259. data/ext/pqcrypto/vendor/pqclean/common/keccak2x/fips202x2.c +0 -684
  260. data/ext/pqcrypto/vendor/pqclean/common/keccak2x/fips202x2.h +0 -60
  261. data/ext/pqcrypto/vendor/pqclean/common/keccak4x/KeccakP-1600-times4-SIMD256.c +0 -1028
  262. data/ext/pqcrypto/vendor/pqclean/common/keccak4x/KeccakP-1600-times4-SnP.h +0 -50
  263. data/ext/pqcrypto/vendor/pqclean/common/keccak4x/KeccakP-1600-unrolling.macros +0 -198
  264. data/ext/pqcrypto/vendor/pqclean/common/keccak4x/Makefile +0 -8
  265. data/ext/pqcrypto/vendor/pqclean/common/keccak4x/Makefile.Microsoft_nmake +0 -8
  266. data/ext/pqcrypto/vendor/pqclean/common/keccak4x/SIMD256-config.h +0 -3
  267. data/ext/pqcrypto/vendor/pqclean/common/keccak4x/align.h +0 -34
  268. data/ext/pqcrypto/vendor/pqclean/common/keccak4x/brg_endian.h +0 -142
  269. data/ext/pqcrypto/vendor/pqclean/common/nistseedexpander.c +0 -101
  270. data/ext/pqcrypto/vendor/pqclean/common/nistseedexpander.h +0 -39
  271. data/ext/pqcrypto/vendor/pqclean/common/randombytes.c +0 -355
  272. data/ext/pqcrypto/vendor/pqclean/common/randombytes.h +0 -27
  273. data/ext/pqcrypto/vendor/pqclean/common/sha2.c +0 -769
  274. data/ext/pqcrypto/vendor/pqclean/common/sha2.h +0 -173
  275. data/ext/pqcrypto/vendor/pqclean/common/sp800-185.c +0 -156
  276. data/ext/pqcrypto/vendor/pqclean/common/sp800-185.h +0 -27
  277. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/LICENSE +0 -5
  278. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/Makefile +0 -19
  279. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/Makefile.Microsoft_nmake +0 -23
  280. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/api.h +0 -18
  281. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/cbd.c +0 -83
  282. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/cbd.h +0 -11
  283. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/indcpa.c +0 -327
  284. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/indcpa.h +0 -22
  285. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/kem.c +0 -164
  286. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/kem.h +0 -23
  287. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/ntt.c +0 -146
  288. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/ntt.h +0 -14
  289. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/params.h +0 -36
  290. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/poly.c +0 -311
  291. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/poly.h +0 -37
  292. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/polyvec.c +0 -198
  293. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/polyvec.h +0 -26
  294. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/reduce.c +0 -41
  295. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/reduce.h +0 -13
  296. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/symmetric-shake.c +0 -71
  297. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/symmetric.h +0 -30
  298. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/verify.c +0 -67
  299. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/verify.h +0 -13
  300. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/LICENSE +0 -5
  301. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/Makefile +0 -19
  302. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/Makefile.Microsoft_nmake +0 -23
  303. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/api.h +0 -18
  304. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/cbd.c +0 -108
  305. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/cbd.h +0 -11
  306. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/indcpa.c +0 -327
  307. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/indcpa.h +0 -22
  308. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/kem.c +0 -164
  309. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/kem.h +0 -23
  310. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/ntt.c +0 -146
  311. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/ntt.h +0 -14
  312. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/params.h +0 -36
  313. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/poly.c +0 -299
  314. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/poly.h +0 -37
  315. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/polyvec.c +0 -188
  316. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/polyvec.h +0 -26
  317. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/reduce.c +0 -41
  318. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/reduce.h +0 -13
  319. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/symmetric-shake.c +0 -71
  320. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/symmetric.h +0 -30
  321. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/verify.c +0 -67
  322. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/verify.h +0 -13
  323. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/LICENSE +0 -5
  324. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/Makefile +0 -19
  325. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/Makefile.Microsoft_nmake +0 -23
  326. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/api.h +0 -18
  327. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/cbd.c +0 -83
  328. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/cbd.h +0 -11
  329. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/indcpa.c +0 -327
  330. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/indcpa.h +0 -22
  331. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/kem.c +0 -164
  332. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/kem.h +0 -23
  333. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/ntt.c +0 -146
  334. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/ntt.h +0 -14
  335. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/params.h +0 -36
  336. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/poly.c +0 -299
  337. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/poly.h +0 -37
  338. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/polyvec.c +0 -188
  339. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/polyvec.h +0 -26
  340. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/reduce.c +0 -41
  341. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/reduce.h +0 -13
  342. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/symmetric-shake.c +0 -71
  343. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/symmetric.h +0 -30
  344. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/verify.c +0 -67
  345. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/verify.h +0 -13
  346. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-44/clean/LICENSE +0 -5
  347. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-44/clean/Makefile +0 -19
  348. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-44/clean/Makefile.Microsoft_nmake +0 -23
  349. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-44/clean/api.h +0 -50
  350. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-44/clean/ntt.c +0 -98
  351. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-44/clean/ntt.h +0 -10
  352. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-44/clean/packing.c +0 -261
  353. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-44/clean/packing.h +0 -31
  354. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-44/clean/params.h +0 -44
  355. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-44/clean/poly.c +0 -848
  356. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-44/clean/poly.h +0 -52
  357. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-44/clean/polyvec.c +0 -415
  358. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-44/clean/polyvec.h +0 -65
  359. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-44/clean/reduce.c +0 -69
  360. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-44/clean/reduce.h +0 -17
  361. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-44/clean/rounding.c +0 -98
  362. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-44/clean/rounding.h +0 -14
  363. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-44/clean/sign.c +0 -407
  364. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-44/clean/sign.h +0 -47
  365. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-44/clean/symmetric-shake.c +0 -26
  366. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-44/clean/symmetric.h +0 -34
  367. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/LICENSE +0 -5
  368. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/Makefile +0 -19
  369. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/Makefile.Microsoft_nmake +0 -23
  370. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/api.h +0 -50
  371. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/ntt.c +0 -98
  372. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/ntt.h +0 -10
  373. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/packing.c +0 -261
  374. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/packing.h +0 -31
  375. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/params.h +0 -44
  376. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/poly.c +0 -799
  377. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/poly.h +0 -52
  378. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/polyvec.c +0 -415
  379. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/polyvec.h +0 -65
  380. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/reduce.c +0 -69
  381. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/reduce.h +0 -17
  382. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/rounding.c +0 -92
  383. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/rounding.h +0 -14
  384. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/sign.c +0 -407
  385. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/sign.h +0 -47
  386. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/symmetric-shake.c +0 -26
  387. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/symmetric.h +0 -34
  388. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-87/clean/LICENSE +0 -5
  389. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-87/clean/Makefile +0 -19
  390. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-87/clean/Makefile.Microsoft_nmake +0 -23
  391. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-87/clean/api.h +0 -50
  392. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-87/clean/ntt.c +0 -98
  393. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-87/clean/ntt.h +0 -10
  394. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-87/clean/packing.c +0 -261
  395. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-87/clean/packing.h +0 -31
  396. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-87/clean/params.h +0 -44
  397. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-87/clean/poly.c +0 -823
  398. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-87/clean/poly.h +0 -52
  399. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-87/clean/polyvec.c +0 -415
  400. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-87/clean/polyvec.h +0 -65
  401. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-87/clean/reduce.c +0 -69
  402. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-87/clean/reduce.h +0 -17
  403. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-87/clean/rounding.c +0 -92
  404. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-87/clean/rounding.h +0 -14
  405. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-87/clean/sign.c +0 -407
  406. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-87/clean/sign.h +0 -47
  407. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-87/clean/symmetric-shake.c +0 -26
  408. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-87/clean/symmetric.h +0 -34
@@ -0,0 +1,156 @@
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
+
15
+ #ifndef MLK_INDCPA_H
16
+ #define MLK_INDCPA_H
17
+
18
+ #include "cbmc.h"
19
+ #include "common.h"
20
+ #include "poly_k.h"
21
+
22
+ #define mlk_gen_matrix MLK_NAMESPACE_K(gen_matrix)
23
+ /*************************************************
24
+ * Name: mlk_gen_matrix
25
+ *
26
+ * Description: Deterministically generate matrix A (or the transpose of A)
27
+ * from a seed. Entries of the matrix are polynomials that look
28
+ * uniformly random. Performs rejection sampling on output of
29
+ * a XOF
30
+ *
31
+ * Arguments: - mlk_polymat a: pointer to output matrix A
32
+ * - const uint8_t *seed: pointer to input seed
33
+ * - int transposed: boolean deciding whether A or A^T is generated
34
+ *
35
+ * Specification: Implements @[FIPS203, Algorithm 13 (K-PKE.KeyGen), L3-7]
36
+ * and @[FIPS203, Algorithm 14 (K-PKE.Encrypt), L4-8].
37
+ * The `transposed` parameter only affects internal presentation.
38
+ *
39
+ **************************************************/
40
+ MLK_INTERNAL_API
41
+ void mlk_gen_matrix(mlk_polymat *a, const uint8_t seed[MLKEM_SYMBYTES],
42
+ int transposed)
43
+ __contract__(
44
+ requires(memory_no_alias(a, sizeof(mlk_polymat)))
45
+ requires(memory_no_alias(seed, MLKEM_SYMBYTES))
46
+ requires(transposed == 0 || transposed == 1)
47
+ assigns(memory_slice(a, sizeof(mlk_polymat)))
48
+ ensures(forall(x, 0, MLKEM_K, forall(y, 0, MLKEM_K,
49
+ array_bound(a->vec[x].vec[y].coeffs, 0, MLKEM_N, 0, MLKEM_Q))))
50
+ );
51
+
52
+ #define mlk_indcpa_keypair_derand \
53
+ MLK_NAMESPACE_K(indcpa_keypair_derand) MLK_CONTEXT_PARAMETERS_3
54
+ /*************************************************
55
+ * Name: mlk_indcpa_keypair_derand
56
+ *
57
+ * Description: Generates public and private key for the CPA-secure
58
+ * public-key encryption scheme underlying ML-KEM
59
+ *
60
+ * Arguments: - uint8_t *pk: pointer to output public key
61
+ * (of length MLKEM_INDCPA_PUBLICKEYBYTES bytes)
62
+ * - uint8_t *sk: pointer to output private key
63
+ * (of length MLKEM_INDCPA_SECRETKEYBYTES bytes)
64
+ * - const uint8_t *coins: pointer to input randomness
65
+ * (of length MLKEM_SYMBYTES bytes)
66
+ *
67
+ * Specification: Implements @[FIPS203, Algorithm 13 (K-PKE.KeyGen)].
68
+ *
69
+ **************************************************/
70
+ MLK_INTERNAL_API
71
+ MLK_MUST_CHECK_RETURN_VALUE
72
+ int mlk_indcpa_keypair_derand(uint8_t pk[MLKEM_INDCPA_PUBLICKEYBYTES],
73
+ uint8_t sk[MLKEM_INDCPA_SECRETKEYBYTES],
74
+ const uint8_t coins[MLKEM_SYMBYTES],
75
+ MLK_CONFIG_CONTEXT_PARAMETER_TYPE context)
76
+ __contract__(
77
+ requires(memory_no_alias(pk, MLKEM_INDCPA_PUBLICKEYBYTES))
78
+ requires(memory_no_alias(sk, MLKEM_INDCPA_SECRETKEYBYTES))
79
+ requires(memory_no_alias(coins, MLKEM_SYMBYTES))
80
+ assigns(memory_slice(pk, MLKEM_INDCPA_PUBLICKEYBYTES))
81
+ assigns(memory_slice(sk, MLKEM_INDCPA_SECRETKEYBYTES))
82
+ ensures(return_value == 0 || return_value == MLK_ERR_FAIL ||
83
+ return_value == MLK_ERR_OUT_OF_MEMORY ||
84
+ return_value == MLK_ERR_RNG_FAIL)
85
+ );
86
+
87
+ #define mlk_indcpa_enc MLK_NAMESPACE_K(indcpa_enc) MLK_CONTEXT_PARAMETERS_4
88
+ /*************************************************
89
+ * Name: mlk_indcpa_enc
90
+ *
91
+ * Description: Encryption function of the CPA-secure
92
+ * public-key encryption scheme underlying Kyber.
93
+ *
94
+ * Arguments: - uint8_t *c: pointer to output ciphertext
95
+ * (of length MLKEM_INDCPA_BYTES bytes)
96
+ * - const uint8_t *m: pointer to input message
97
+ * (of length MLKEM_INDCPA_MSGBYTES bytes)
98
+ * - const uint8_t *pk: pointer to input public key
99
+ * (of length MLKEM_INDCPA_PUBLICKEYBYTES)
100
+ * - const uint8_t *coins: pointer to input random coins used as
101
+ * seed (of length MLKEM_SYMBYTES) to deterministically generate
102
+ * all randomness
103
+ *
104
+ * Specification: Implements @[FIPS203, Algorithm 14 (K-PKE.Encrypt)].
105
+ *
106
+ **************************************************/
107
+ MLK_INTERNAL_API
108
+ MLK_MUST_CHECK_RETURN_VALUE
109
+ int mlk_indcpa_enc(uint8_t c[MLKEM_INDCPA_BYTES],
110
+ const uint8_t m[MLKEM_INDCPA_MSGBYTES],
111
+ const uint8_t pk[MLKEM_INDCPA_PUBLICKEYBYTES],
112
+ const uint8_t coins[MLKEM_SYMBYTES],
113
+ MLK_CONFIG_CONTEXT_PARAMETER_TYPE context)
114
+ __contract__(
115
+ requires(memory_no_alias(c, MLKEM_INDCPA_BYTES))
116
+ requires(memory_no_alias(m, MLKEM_INDCPA_MSGBYTES))
117
+ requires(memory_no_alias(pk, MLKEM_INDCPA_PUBLICKEYBYTES))
118
+ requires(memory_no_alias(coins, MLKEM_SYMBYTES))
119
+ assigns(memory_slice(c, MLKEM_INDCPA_BYTES))
120
+ ensures(return_value == 0 || return_value == MLK_ERR_FAIL ||
121
+ return_value == MLK_ERR_OUT_OF_MEMORY)
122
+ );
123
+
124
+ #define mlk_indcpa_dec MLK_NAMESPACE_K(indcpa_dec) MLK_CONTEXT_PARAMETERS_3
125
+ /*************************************************
126
+ * Name: mlk_indcpa_dec
127
+ *
128
+ * Description: Decryption function of the CPA-secure
129
+ * public-key encryption scheme underlying Kyber.
130
+ *
131
+ * Arguments: - uint8_t *m: pointer to output decrypted message
132
+ * (of length MLKEM_INDCPA_MSGBYTES)
133
+ * - const uint8_t *c: pointer to input ciphertext
134
+ * (of length MLKEM_INDCPA_BYTES)
135
+ * - const uint8_t *sk: pointer to input secret key
136
+ * (of length MLKEM_INDCPA_SECRETKEYBYTES)
137
+ *
138
+ * Specification: Implements @[FIPS203, Algorithm 15 (K-PKE.Decrypt)].
139
+ *
140
+ **************************************************/
141
+ MLK_INTERNAL_API
142
+ MLK_MUST_CHECK_RETURN_VALUE
143
+ int mlk_indcpa_dec(uint8_t m[MLKEM_INDCPA_MSGBYTES],
144
+ const uint8_t c[MLKEM_INDCPA_BYTES],
145
+ const uint8_t sk[MLKEM_INDCPA_SECRETKEYBYTES],
146
+ MLK_CONFIG_CONTEXT_PARAMETER_TYPE context)
147
+ __contract__(
148
+ requires(memory_no_alias(c, MLKEM_INDCPA_BYTES))
149
+ requires(memory_no_alias(m, MLKEM_INDCPA_MSGBYTES))
150
+ requires(memory_no_alias(sk, MLKEM_INDCPA_SECRETKEYBYTES))
151
+ assigns(memory_slice(m, MLKEM_INDCPA_MSGBYTES))
152
+ ensures(return_value == 0 || return_value == MLK_ERR_FAIL ||
153
+ return_value == MLK_ERR_OUT_OF_MEMORY)
154
+ );
155
+
156
+ #endif /* !MLK_INDCPA_H */
@@ -0,0 +1,446 @@
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
+ * - [FIPS140_3_IG]
10
+ * Implementation Guidance for FIPS 140-3 and the Cryptographic Module
11
+ * Validation Program
12
+ * National Institute of Standards and Technology
13
+ * https://csrc.nist.gov/projects/cryptographic-module-validation-program/fips-140-3-ig-announcements
14
+ *
15
+ * - [FIPS203]
16
+ * FIPS 203 Module-Lattice-Based Key-Encapsulation Mechanism Standard
17
+ * National Institute of Standards and Technology
18
+ * https://csrc.nist.gov/pubs/fips/203/final
19
+ *
20
+ * - [REF]
21
+ * CRYSTALS-Kyber C reference implementation
22
+ * Bos, Ducas, Kiltz, Lepoint, Lyubashevsky, Schanck, Schwabe, Seiler, Stehlé
23
+ * https://github.com/pq-crystals/kyber/tree/main/ref
24
+ */
25
+
26
+ #include "kem.h"
27
+
28
+ #include "indcpa.h"
29
+ #include "randombytes.h"
30
+ #include "symmetric.h"
31
+ #include "verify.h"
32
+
33
+ /* Parameter set namespacing
34
+ * This is to facilitate building multiple instances
35
+ * of mlkem-native (e.g. with varying security levels)
36
+ * within a single compilation unit. */
37
+ #define mlk_check_pct MLK_ADD_PARAM_SET(mlk_check_pct) MLK_CONTEXT_PARAMETERS_2
38
+ /* End of parameter set namespacing */
39
+
40
+ /* Reference: Not implemented in the reference implementation @[REF]. */
41
+ MLK_EXTERNAL_API
42
+ MLK_MUST_CHECK_RETURN_VALUE
43
+ int mlk_kem_check_pk(const uint8_t pk[MLKEM_INDCCA_PUBLICKEYBYTES],
44
+ MLK_CONFIG_CONTEXT_PARAMETER_TYPE context)
45
+ {
46
+ int ret = 0;
47
+ MLK_ALLOC(p, mlk_polyvec, 1, context);
48
+ MLK_ALLOC(p_reencoded, uint8_t, MLKEM_POLYVECBYTES, context);
49
+
50
+ if (p == NULL || p_reencoded == NULL)
51
+ {
52
+ ret = MLK_ERR_OUT_OF_MEMORY;
53
+ goto cleanup;
54
+ }
55
+
56
+ mlk_polyvec_frombytes(p, pk);
57
+ mlk_polyvec_reduce(p);
58
+ mlk_polyvec_tobytes(p_reencoded, p);
59
+
60
+ /* We use a constant-time memcmp here to avoid having to
61
+ * declassify the PK before the PCT has succeeded. */
62
+ ret = mlk_ct_memcmp(pk, p_reencoded, MLKEM_POLYVECBYTES) ? MLK_ERR_FAIL : 0;
63
+
64
+ cleanup:
65
+ /* Specification: Partially implements
66
+ * @[FIPS203, Section 3.3, Destruction of intermediate values] */
67
+ MLK_FREE(p_reencoded, uint8_t, MLKEM_POLYVECBYTES, context);
68
+ MLK_FREE(p, mlk_polyvec, 1, context);
69
+ return ret;
70
+ }
71
+
72
+
73
+ /* Reference: Not implemented in the reference implementation @[REF]. */
74
+ MLK_EXTERNAL_API
75
+ MLK_MUST_CHECK_RETURN_VALUE
76
+ int mlk_kem_check_sk(const uint8_t sk[MLKEM_INDCCA_SECRETKEYBYTES],
77
+ MLK_CONFIG_CONTEXT_PARAMETER_TYPE context)
78
+ {
79
+ int ret = 0;
80
+ MLK_ALLOC(test, uint8_t, MLKEM_SYMBYTES, context);
81
+
82
+ if (test == NULL)
83
+ {
84
+ ret = MLK_ERR_OUT_OF_MEMORY;
85
+ goto cleanup;
86
+ }
87
+
88
+ /*
89
+ * The parts of `sk` being hashed and compared here are public, so
90
+ * no public information is leaked through the runtime or the return value
91
+ * of this function.
92
+ */
93
+
94
+ /* Declassify the public part of the secret key */
95
+ MLK_CT_TESTING_DECLASSIFY(sk + MLKEM_INDCPA_SECRETKEYBYTES,
96
+ MLKEM_INDCCA_PUBLICKEYBYTES);
97
+ MLK_CT_TESTING_DECLASSIFY(
98
+ sk + MLKEM_INDCCA_SECRETKEYBYTES - 2 * MLKEM_SYMBYTES, MLKEM_SYMBYTES);
99
+
100
+ mlk_hash_h(test, sk + MLKEM_INDCPA_SECRETKEYBYTES,
101
+ MLKEM_INDCCA_PUBLICKEYBYTES);
102
+ /* This doesn't have to be a constant-time memcmp, but it's the only place
103
+ * in the library where a normal memcmp would be used otherwise, so for sake
104
+ * of minimizing stdlib dependency, we use our constant-time one anyway. */
105
+ ret = mlk_ct_memcmp(sk + MLKEM_INDCCA_SECRETKEYBYTES - 2 * MLKEM_SYMBYTES,
106
+ test, MLKEM_SYMBYTES)
107
+ ? MLK_ERR_FAIL
108
+ : 0;
109
+
110
+ cleanup:
111
+ /* Specification: Partially implements
112
+ * @[FIPS203, Section 3.3, Destruction of intermediate values] */
113
+ MLK_FREE(test, uint8_t, MLKEM_SYMBYTES, context);
114
+ return ret;
115
+ }
116
+
117
+ MLK_MUST_CHECK_RETURN_VALUE
118
+ static int mlk_check_pct(uint8_t const pk[MLKEM_INDCCA_PUBLICKEYBYTES],
119
+ uint8_t const sk[MLKEM_INDCCA_SECRETKEYBYTES],
120
+ MLK_CONFIG_CONTEXT_PARAMETER_TYPE context)
121
+ __contract__(
122
+ requires(memory_no_alias(pk, MLKEM_INDCCA_PUBLICKEYBYTES))
123
+ requires(memory_no_alias(sk, MLKEM_INDCCA_SECRETKEYBYTES))
124
+ ensures(return_value == 0 || return_value == MLK_ERR_FAIL ||
125
+ return_value == MLK_ERR_OUT_OF_MEMORY ||
126
+ return_value == MLK_ERR_RNG_FAIL)
127
+ );
128
+
129
+ #if defined(MLK_CONFIG_KEYGEN_PCT)
130
+ /* Specification:
131
+ * Partially implements 'Pairwise Consistency Test' @[FIPS140_3_IG, p.87] and
132
+ * @[FIPS203, Section 7.1, Pairwise Consistency]. */
133
+
134
+ /* Reference: Not implemented in the reference implementation @[REF]. */
135
+ MLK_MUST_CHECK_RETURN_VALUE
136
+ static int mlk_check_pct(uint8_t const pk[MLKEM_INDCCA_PUBLICKEYBYTES],
137
+ uint8_t const sk[MLKEM_INDCCA_SECRETKEYBYTES],
138
+ MLK_CONFIG_CONTEXT_PARAMETER_TYPE context)
139
+ {
140
+ int ret = 0;
141
+ MLK_ALLOC(ct, uint8_t, MLKEM_INDCCA_CIPHERTEXTBYTES, context);
142
+ MLK_ALLOC(ss_enc, uint8_t, MLKEM_SSBYTES, context);
143
+ MLK_ALLOC(ss_dec, uint8_t, MLKEM_SSBYTES, context);
144
+
145
+ if (ct == NULL || ss_enc == NULL || ss_dec == NULL)
146
+ {
147
+ ret = MLK_ERR_OUT_OF_MEMORY;
148
+ goto cleanup;
149
+ }
150
+
151
+ ret = mlk_kem_enc(ct, ss_enc, pk, context);
152
+ if (ret != 0)
153
+ {
154
+ goto cleanup;
155
+ }
156
+
157
+ ret = mlk_kem_dec(ss_dec, ct, sk, context);
158
+ if (ret != 0)
159
+ {
160
+ goto cleanup;
161
+ }
162
+
163
+ #if defined(MLK_CONFIG_KEYGEN_PCT_BREAKAGE_TEST)
164
+ /* Deliberately break PCT for testing purposes */
165
+ if (mlk_break_pct())
166
+ {
167
+ ss_enc[0] = ~ss_enc[0];
168
+ }
169
+ #endif /* MLK_CONFIG_KEYGEN_PCT_BREAKAGE_TEST */
170
+
171
+ ret = mlk_ct_memcmp(ss_enc, ss_dec, MLKEM_SSBYTES);
172
+ /* The result of the PCT is public. */
173
+ MLK_CT_TESTING_DECLASSIFY(&ret, sizeof(ret));
174
+
175
+ if (ret != 0)
176
+ {
177
+ ret = MLK_ERR_FAIL;
178
+ }
179
+
180
+ cleanup:
181
+
182
+ /* Specification: Partially implements
183
+ * @[FIPS203, Section 3.3, Destruction of intermediate values] */
184
+ MLK_FREE(ss_dec, uint8_t, MLKEM_SSBYTES, context);
185
+ MLK_FREE(ss_enc, uint8_t, MLKEM_SSBYTES, context);
186
+ MLK_FREE(ct, uint8_t, MLKEM_INDCCA_CIPHERTEXTBYTES, context);
187
+ return ret;
188
+ }
189
+ #else /* MLK_CONFIG_KEYGEN_PCT */
190
+ MLK_MUST_CHECK_RETURN_VALUE
191
+ static int mlk_check_pct(uint8_t const pk[MLKEM_INDCCA_PUBLICKEYBYTES],
192
+ uint8_t const sk[MLKEM_INDCCA_SECRETKEYBYTES],
193
+ MLK_CONFIG_CONTEXT_PARAMETER_TYPE context)
194
+ {
195
+ /* Skip PCT */
196
+ ((void)pk);
197
+ ((void)sk);
198
+ #if defined(MLK_CONFIG_CONTEXT_PARAMETER)
199
+ ((void)context);
200
+ #endif
201
+ return 0;
202
+ }
203
+ #endif /* !MLK_CONFIG_KEYGEN_PCT */
204
+
205
+ /* Reference: `crypto_kem_keypair_derand()` in the reference implementation
206
+ * @[REF].
207
+ * - We optionally include PCT which is not present in
208
+ * the reference code. */
209
+ MLK_EXTERNAL_API
210
+ int mlk_kem_keypair_derand(uint8_t pk[MLKEM_INDCCA_PUBLICKEYBYTES],
211
+ uint8_t sk[MLKEM_INDCCA_SECRETKEYBYTES],
212
+ const uint8_t coins[2 * MLKEM_SYMBYTES],
213
+ MLK_CONFIG_CONTEXT_PARAMETER_TYPE context)
214
+ {
215
+ int ret;
216
+
217
+ ret = mlk_indcpa_keypair_derand(pk, sk, coins, context);
218
+ if (ret != 0)
219
+ {
220
+ goto cleanup;
221
+ }
222
+
223
+ mlk_memcpy(sk + MLKEM_INDCPA_SECRETKEYBYTES, pk, MLKEM_INDCCA_PUBLICKEYBYTES);
224
+ mlk_hash_h(sk + MLKEM_INDCCA_SECRETKEYBYTES - 2 * MLKEM_SYMBYTES, pk,
225
+ MLKEM_INDCCA_PUBLICKEYBYTES);
226
+ /* Value z for pseudo-random output on reject */
227
+ mlk_memcpy(sk + MLKEM_INDCCA_SECRETKEYBYTES - MLKEM_SYMBYTES,
228
+ coins + MLKEM_SYMBYTES, MLKEM_SYMBYTES);
229
+
230
+ /* Declassify public key */
231
+ MLK_CT_TESTING_DECLASSIFY(pk, MLKEM_INDCCA_PUBLICKEYBYTES);
232
+
233
+ /* Pairwise Consistency Test (PCT) @[FIPS140_3_IG, p.87] */
234
+ ret = mlk_check_pct(pk, sk, context);
235
+ if (ret != 0)
236
+ {
237
+ goto cleanup;
238
+ }
239
+
240
+ cleanup:
241
+ if (ret != 0)
242
+ {
243
+ mlk_zeroize(pk, MLKEM_INDCCA_PUBLICKEYBYTES);
244
+ mlk_zeroize(sk, MLKEM_INDCCA_SECRETKEYBYTES);
245
+ }
246
+
247
+ return ret;
248
+ }
249
+
250
+ #if !defined(MLK_CONFIG_NO_RANDOMIZED_API)
251
+ /* Reference: `crypto_kem_keypair()` in the reference implementation @[REF]
252
+ * - We zeroize the stack buffer */
253
+ MLK_EXTERNAL_API
254
+ int mlk_kem_keypair(uint8_t pk[MLKEM_INDCCA_PUBLICKEYBYTES],
255
+ uint8_t sk[MLKEM_INDCCA_SECRETKEYBYTES],
256
+ MLK_CONFIG_CONTEXT_PARAMETER_TYPE context)
257
+ {
258
+ int ret = 0;
259
+ MLK_ALLOC(coins, uint8_t, 2 * MLKEM_SYMBYTES, context);
260
+
261
+ if (coins == NULL)
262
+ {
263
+ ret = MLK_ERR_OUT_OF_MEMORY;
264
+ goto cleanup;
265
+ }
266
+
267
+ /* Acquire necessary randomness, and mark it as secret. */
268
+ if (mlk_randombytes(coins, 2 * MLKEM_SYMBYTES) != 0)
269
+ {
270
+ ret = MLK_ERR_RNG_FAIL;
271
+ goto cleanup;
272
+ }
273
+
274
+ MLK_CT_TESTING_SECRET(coins, 2 * MLKEM_SYMBYTES);
275
+
276
+ ret = mlk_kem_keypair_derand(pk, sk, coins, context);
277
+
278
+ cleanup:
279
+ /* Specification: Partially implements
280
+ * @[FIPS203, Section 3.3, Destruction of intermediate values] */
281
+ MLK_FREE(coins, uint8_t, 2 * MLKEM_SYMBYTES, context);
282
+ return ret;
283
+ }
284
+ #endif /* !MLK_CONFIG_NO_RANDOMIZED_API */
285
+
286
+ /* Reference: `crypto_kem_enc_derand()` in the reference implementation @[REF]
287
+ * - We include public key check
288
+ * - We include stack buffer zeroization */
289
+ MLK_EXTERNAL_API
290
+ int mlk_kem_enc_derand(uint8_t ct[MLKEM_INDCCA_CIPHERTEXTBYTES],
291
+ uint8_t ss[MLKEM_SSBYTES],
292
+ const uint8_t pk[MLKEM_INDCCA_PUBLICKEYBYTES],
293
+ const uint8_t coins[MLKEM_SYMBYTES],
294
+ MLK_CONFIG_CONTEXT_PARAMETER_TYPE context)
295
+ {
296
+ int ret = 0;
297
+ MLK_ALLOC(buf, uint8_t, 2 * MLKEM_SYMBYTES, context);
298
+ MLK_ALLOC(kr, uint8_t, 2 * MLKEM_SYMBYTES, context);
299
+
300
+ if (buf == NULL || kr == NULL)
301
+ {
302
+ ret = MLK_ERR_OUT_OF_MEMORY;
303
+ goto cleanup;
304
+ }
305
+
306
+ /* Specification: Implements @[FIPS203, Section 7.2, Modulus check] */
307
+ ret = mlk_kem_check_pk(pk, context);
308
+ if (ret != 0)
309
+ {
310
+ goto cleanup;
311
+ }
312
+
313
+ mlk_memcpy(buf, coins, MLKEM_SYMBYTES);
314
+
315
+ /* Multitarget countermeasure for coins + contributory KEM */
316
+ mlk_hash_h(buf + MLKEM_SYMBYTES, pk, MLKEM_INDCCA_PUBLICKEYBYTES);
317
+ mlk_hash_g(kr, buf, 2 * MLKEM_SYMBYTES);
318
+
319
+ /* coins are in kr+MLKEM_SYMBYTES */
320
+ ret = mlk_indcpa_enc(ct, buf, pk, kr + MLKEM_SYMBYTES, context);
321
+ if (ret != 0)
322
+ {
323
+ goto cleanup;
324
+ }
325
+
326
+ mlk_memcpy(ss, kr, MLKEM_SYMBYTES);
327
+
328
+ cleanup:
329
+ /* Specification: Partially implements
330
+ * @[FIPS203, Section 3.3, Destruction of intermediate values] */
331
+ MLK_FREE(kr, uint8_t, 2 * MLKEM_SYMBYTES, context);
332
+ MLK_FREE(buf, uint8_t, 2 * MLKEM_SYMBYTES, context);
333
+ return ret;
334
+ }
335
+
336
+ #if !defined(MLK_CONFIG_NO_RANDOMIZED_API)
337
+ /* Reference: `crypto_kem_enc()` in the reference implementation @[REF]
338
+ * - We include stack buffer zeroization */
339
+ MLK_EXTERNAL_API
340
+ int mlk_kem_enc(uint8_t ct[MLKEM_INDCCA_CIPHERTEXTBYTES],
341
+ uint8_t ss[MLKEM_SSBYTES],
342
+ const uint8_t pk[MLKEM_INDCCA_PUBLICKEYBYTES],
343
+ MLK_CONFIG_CONTEXT_PARAMETER_TYPE context)
344
+ {
345
+ int ret = 0;
346
+ MLK_ALLOC(coins, uint8_t, MLKEM_SYMBYTES, context);
347
+
348
+ if (coins == NULL)
349
+ {
350
+ ret = MLK_ERR_OUT_OF_MEMORY;
351
+ goto cleanup;
352
+ }
353
+
354
+ if (mlk_randombytes(coins, MLKEM_SYMBYTES) != 0)
355
+ {
356
+ ret = MLK_ERR_RNG_FAIL;
357
+ goto cleanup;
358
+ }
359
+
360
+ MLK_CT_TESTING_SECRET(coins, MLKEM_SYMBYTES);
361
+
362
+ ret = mlk_kem_enc_derand(ct, ss, pk, coins, context);
363
+
364
+ cleanup:
365
+ /* Specification: Partially implements
366
+ * @[FIPS203, Section 3.3, Destruction of intermediate values] */
367
+ MLK_FREE(coins, uint8_t, MLKEM_SYMBYTES, context);
368
+ return ret;
369
+ }
370
+ #endif /* !MLK_CONFIG_NO_RANDOMIZED_API */
371
+
372
+ /* Reference: `crypto_kem_dec()` in the reference implementation @[REF]
373
+ * - We include secret key check
374
+ * - We include stack buffer zeroization */
375
+ MLK_EXTERNAL_API
376
+ int mlk_kem_dec(uint8_t ss[MLKEM_SSBYTES],
377
+ const uint8_t ct[MLKEM_INDCCA_CIPHERTEXTBYTES],
378
+ const uint8_t sk[MLKEM_INDCCA_SECRETKEYBYTES],
379
+ MLK_CONFIG_CONTEXT_PARAMETER_TYPE context)
380
+ {
381
+ int ret = 0;
382
+ uint8_t fail;
383
+ const uint8_t *pk = sk + MLKEM_INDCPA_SECRETKEYBYTES;
384
+ MLK_ALLOC(buf, uint8_t, 2 * MLKEM_SYMBYTES, context);
385
+ MLK_ALLOC(kr, uint8_t, 2 * MLKEM_SYMBYTES, context);
386
+ MLK_ALLOC(tmp, uint8_t, MLKEM_SYMBYTES + MLKEM_INDCCA_CIPHERTEXTBYTES,
387
+ context);
388
+
389
+ if (buf == NULL || kr == NULL || tmp == NULL)
390
+ {
391
+ ret = MLK_ERR_OUT_OF_MEMORY;
392
+ goto cleanup;
393
+ }
394
+
395
+ /* Specification: Implements @[FIPS203, Section 7.3, Hash check] */
396
+ ret = mlk_kem_check_sk(sk, context);
397
+ if (ret != 0)
398
+ {
399
+ goto cleanup;
400
+ }
401
+
402
+ ret = mlk_indcpa_dec(buf, ct, sk, context);
403
+ if (ret != 0)
404
+ {
405
+ goto cleanup;
406
+ }
407
+
408
+ /* Multitarget countermeasure for coins + contributory KEM */
409
+ mlk_memcpy(buf + MLKEM_SYMBYTES,
410
+ sk + MLKEM_INDCCA_SECRETKEYBYTES - 2 * MLKEM_SYMBYTES,
411
+ MLKEM_SYMBYTES);
412
+ mlk_hash_g(kr, buf, 2 * MLKEM_SYMBYTES);
413
+
414
+ /* Recompute and compare ciphertext */
415
+ /* coins are in kr+MLKEM_SYMBYTES */
416
+ ret = mlk_indcpa_enc(tmp, buf, pk, kr + MLKEM_SYMBYTES, context);
417
+ if (ret != 0)
418
+ {
419
+ goto cleanup;
420
+ }
421
+
422
+ fail = mlk_ct_memcmp(ct, tmp, MLKEM_INDCCA_CIPHERTEXTBYTES);
423
+
424
+ /* Compute rejection key */
425
+ mlk_memcpy(tmp, sk + MLKEM_INDCCA_SECRETKEYBYTES - MLKEM_SYMBYTES,
426
+ MLKEM_SYMBYTES);
427
+ mlk_memcpy(tmp + MLKEM_SYMBYTES, ct, MLKEM_INDCCA_CIPHERTEXTBYTES);
428
+ mlk_hash_j(ss, tmp, MLKEM_SYMBYTES + MLKEM_INDCCA_CIPHERTEXTBYTES);
429
+
430
+ /* Copy true key to return buffer if fail is 0 */
431
+ mlk_ct_cmov_zero(ss, kr, MLKEM_SYMBYTES, fail);
432
+
433
+ cleanup:
434
+ /* Specification: Partially implements
435
+ * @[FIPS203, Section 3.3, Destruction of intermediate values] */
436
+ MLK_FREE(tmp, uint8_t, MLKEM_SYMBYTES + MLKEM_INDCCA_CIPHERTEXTBYTES,
437
+ context);
438
+ MLK_FREE(kr, uint8_t, 2 * MLKEM_SYMBYTES, context);
439
+ MLK_FREE(buf, uint8_t, 2 * MLKEM_SYMBYTES, context);
440
+
441
+ return ret;
442
+ }
443
+
444
+ /* To facilitate single-compilation-unit (SCU) builds, undefine all macros.
445
+ * Don't modify by hand -- this is auto-generated by scripts/autogen. */
446
+ #undef mlk_check_pct