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,717 @@
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 "common.h"
21
+ #if !defined(MLK_CONFIG_MULTILEVEL_NO_SHARED)
22
+
23
+
24
+ #include "cbmc.h"
25
+ #include "compress.h"
26
+ #include "debug.h"
27
+ #include "verify.h"
28
+
29
+ #if defined(MLK_CONFIG_MULTILEVEL_WITH_SHARED) || (MLKEM_K == 2 || MLKEM_K == 3)
30
+ /* Reference: `poly_compress()` in the reference implementation @[REF],
31
+ * for ML-KEM-{512,768}.
32
+ * - In contrast to the reference implementation, we assume
33
+ * unsigned canonical coefficients here.
34
+ * The reference implementation works with coefficients
35
+ * in the range (-MLKEM_Q+1,...,MLKEM_Q-1). */
36
+ MLK_STATIC_TESTABLE void mlk_poly_compress_d4_c(
37
+ uint8_t r[MLKEM_POLYCOMPRESSEDBYTES_D4], const mlk_poly *a)
38
+ __contract__(
39
+ requires(memory_no_alias(r, MLKEM_POLYCOMPRESSEDBYTES_D4))
40
+ requires(memory_no_alias(a, sizeof(mlk_poly)))
41
+ requires(array_bound(a->coeffs, 0, MLKEM_N, 0, MLKEM_Q))
42
+ assigns(memory_slice(r, MLKEM_POLYCOMPRESSEDBYTES_D4))
43
+ )
44
+ {
45
+ unsigned i;
46
+ mlk_assert_bound(a, MLKEM_N, 0, MLKEM_Q);
47
+
48
+ for (i = 0; i < MLKEM_N / 8; i++)
49
+ __loop__(invariant(i <= MLKEM_N / 8))
50
+ {
51
+ unsigned j;
52
+ uint8_t t[8] = {0};
53
+ for (j = 0; j < 8; j++)
54
+ __loop__(
55
+ invariant(i <= MLKEM_N / 8 && j <= 8)
56
+ invariant(array_bound(t, 0, j, 0, 16)))
57
+ {
58
+ t[j] = mlk_scalar_compress_d4(a->coeffs[8 * i + j]);
59
+ }
60
+
61
+ /* All t[i] are 4-bit wide, so the truncations don't alter the value. */
62
+ r[i * 4] = (uint8_t)(t[0] | (t[1] << 4));
63
+ r[i * 4 + 1] = (uint8_t)(t[2] | (t[3] << 4));
64
+ r[i * 4 + 2] = (uint8_t)(t[4] | (t[5] << 4));
65
+ r[i * 4 + 3] = (uint8_t)(t[6] | (t[7] << 4));
66
+ }
67
+ }
68
+
69
+ MLK_INTERNAL_API
70
+ void mlk_poly_compress_d4(uint8_t r[MLKEM_POLYCOMPRESSEDBYTES_D4],
71
+ const mlk_poly *a)
72
+ __contract__(
73
+ requires(memory_no_alias(r, MLKEM_POLYCOMPRESSEDBYTES_D4))
74
+ requires(memory_no_alias(a, sizeof(mlk_poly)))
75
+ requires(array_bound(a->coeffs, 0, MLKEM_N, 0, MLKEM_Q))
76
+ assigns(memory_slice(r, MLKEM_POLYCOMPRESSEDBYTES_D4))
77
+ )
78
+ {
79
+ #if defined(MLK_USE_NATIVE_POLY_COMPRESS_D4)
80
+ int ret;
81
+ mlk_assert_bound(a, MLKEM_N, 0, MLKEM_Q);
82
+ ret = mlk_poly_compress_d4_native(r, a->coeffs);
83
+ if (ret == MLK_NATIVE_FUNC_SUCCESS)
84
+ {
85
+ return;
86
+ }
87
+ #endif /* MLK_USE_NATIVE_POLY_COMPRESS_D4 */
88
+
89
+ mlk_poly_compress_d4_c(r, a);
90
+ }
91
+
92
+ /* Reference: Embedded into `polyvec_compress()` in the
93
+ * reference implementation, for ML-KEM-{512,768}.
94
+ * - In contrast to the reference implementation, we assume
95
+ * unsigned canonical coefficients here.
96
+ * The reference implementation works with coefficients
97
+ * in the range (-MLKEM_Q+1,...,MLKEM_Q-1). */
98
+ MLK_STATIC_TESTABLE void mlk_poly_compress_d10_c(
99
+ uint8_t r[MLKEM_POLYCOMPRESSEDBYTES_D10], const mlk_poly *a)
100
+ __contract__(
101
+ requires(memory_no_alias(r, MLKEM_POLYCOMPRESSEDBYTES_D10))
102
+ requires(memory_no_alias(a, sizeof(mlk_poly)))
103
+ requires(array_bound(a->coeffs, 0, MLKEM_N, 0, MLKEM_Q))
104
+ assigns(memory_slice(r, MLKEM_POLYCOMPRESSEDBYTES_D10))
105
+ )
106
+ {
107
+ unsigned j;
108
+ mlk_assert_bound(a, MLKEM_N, 0, MLKEM_Q);
109
+ for (j = 0; j < MLKEM_N / 4; j++)
110
+ __loop__(invariant(j <= MLKEM_N / 4))
111
+ {
112
+ unsigned k;
113
+ uint16_t t[4];
114
+ for (k = 0; k < 4; k++)
115
+ __loop__(
116
+ invariant(k <= 4)
117
+ invariant(forall(r, 0, k, t[r] < (1u << 10))))
118
+ {
119
+ t[k] = mlk_scalar_compress_d10(a->coeffs[4 * j + k]);
120
+ }
121
+
122
+ /*
123
+ * Make all implicit truncation explicit. No data is being
124
+ * truncated for the LHS's since each t[i] is 10-bit in size.
125
+ */
126
+ r[5 * j + 0] = (uint8_t)((t[0] >> 0) & 0xFF);
127
+ r[5 * j + 1] = (uint8_t)((t[0] >> 8) | ((t[1] << 2) & 0xFF));
128
+ r[5 * j + 2] = (uint8_t)((t[1] >> 6) | ((t[2] << 4) & 0xFF));
129
+ r[5 * j + 3] = (uint8_t)((t[2] >> 4) | ((t[3] << 6) & 0xFF));
130
+ r[5 * j + 4] = (uint8_t)(t[3] >> 2);
131
+ }
132
+ }
133
+
134
+ MLK_INTERNAL_API
135
+ void mlk_poly_compress_d10(uint8_t r[MLKEM_POLYCOMPRESSEDBYTES_D10],
136
+ const mlk_poly *a)
137
+ __contract__(
138
+ requires(memory_no_alias(r, MLKEM_POLYCOMPRESSEDBYTES_D10))
139
+ requires(memory_no_alias(a, sizeof(mlk_poly)))
140
+ requires(array_bound(a->coeffs, 0, MLKEM_N, 0, MLKEM_Q))
141
+ assigns(memory_slice(r, MLKEM_POLYCOMPRESSEDBYTES_D10))
142
+ )
143
+ {
144
+ #if defined(MLK_USE_NATIVE_POLY_COMPRESS_D10)
145
+ int ret;
146
+ mlk_assert_bound(a, MLKEM_N, 0, MLKEM_Q);
147
+ ret = mlk_poly_compress_d10_native(r, a->coeffs);
148
+ if (ret == MLK_NATIVE_FUNC_SUCCESS)
149
+ {
150
+ return;
151
+ }
152
+ #endif /* MLK_USE_NATIVE_POLY_COMPRESS_D10 */
153
+
154
+ mlk_poly_compress_d10_c(r, a);
155
+ }
156
+
157
+ /* Reference: `poly_decompress()` in the reference implementation @[REF],
158
+ * for ML-KEM-{512,768}. */
159
+ MLK_STATIC_TESTABLE void mlk_poly_decompress_d4_c(
160
+ mlk_poly *r, const uint8_t a[MLKEM_POLYCOMPRESSEDBYTES_D4])
161
+ __contract__(
162
+ requires(memory_no_alias(r, sizeof(mlk_poly)))
163
+ requires(memory_no_alias(a, MLKEM_POLYCOMPRESSEDBYTES_D4))
164
+ assigns(memory_slice(r, sizeof(mlk_poly)))
165
+ ensures(array_bound(r->coeffs, 0, MLKEM_N, 0, MLKEM_Q))
166
+ )
167
+ {
168
+ unsigned i;
169
+ for (i = 0; i < MLKEM_N / 2; i++)
170
+ __loop__(
171
+ invariant(i <= MLKEM_N / 2)
172
+ invariant(array_bound(r->coeffs, 0, 2 * i, 0, MLKEM_Q)))
173
+ {
174
+ r->coeffs[2 * i + 0] = mlk_scalar_decompress_d4((a[i] >> 0) & 0xF);
175
+ r->coeffs[2 * i + 1] = mlk_scalar_decompress_d4((a[i] >> 4) & 0xF);
176
+ }
177
+
178
+ mlk_assert_bound(r, MLKEM_N, 0, MLKEM_Q);
179
+ }
180
+
181
+ MLK_INTERNAL_API
182
+ void mlk_poly_decompress_d4(mlk_poly *r,
183
+ const uint8_t a[MLKEM_POLYCOMPRESSEDBYTES_D4])
184
+ __contract__(
185
+ requires(memory_no_alias(r, sizeof(mlk_poly)))
186
+ requires(memory_no_alias(a, MLKEM_POLYCOMPRESSEDBYTES_D4))
187
+ assigns(memory_slice(r, sizeof(mlk_poly)))
188
+ ensures(array_bound(r->coeffs, 0, MLKEM_N, 0, MLKEM_Q))
189
+ )
190
+ {
191
+ #if defined(MLK_USE_NATIVE_POLY_DECOMPRESS_D4)
192
+ int ret;
193
+ ret = mlk_poly_decompress_d4_native(r->coeffs, a);
194
+ if (ret == MLK_NATIVE_FUNC_SUCCESS)
195
+ {
196
+ mlk_assert_bound(r, MLKEM_N, 0, MLKEM_Q);
197
+ return;
198
+ }
199
+ #endif /* MLK_USE_NATIVE_POLY_DECOMPRESS_D4 */
200
+
201
+ mlk_poly_decompress_d4_c(r, a);
202
+ }
203
+
204
+ /* Reference: Embedded into `polyvec_decompress()` in the
205
+ * reference implementation, for ML-KEM-{512,768}. */
206
+ MLK_STATIC_TESTABLE void mlk_poly_decompress_d10_c(
207
+ mlk_poly *r, const uint8_t a[MLKEM_POLYCOMPRESSEDBYTES_D10])
208
+ __contract__(
209
+ requires(memory_no_alias(r, sizeof(mlk_poly)))
210
+ requires(memory_no_alias(a, MLKEM_POLYCOMPRESSEDBYTES_D10))
211
+ assigns(memory_slice(r, sizeof(mlk_poly)))
212
+ ensures(array_bound(r->coeffs, 0, MLKEM_N, 0, MLKEM_Q))
213
+ )
214
+ {
215
+ unsigned j;
216
+ for (j = 0; j < MLKEM_N / 4; j++)
217
+ __loop__(
218
+ invariant(j <= MLKEM_N / 4)
219
+ invariant(array_bound(r->coeffs, 0, 4 * j, 0, MLKEM_Q)))
220
+ {
221
+ unsigned k;
222
+ uint16_t t[4];
223
+ uint8_t const *base = &a[5 * j];
224
+
225
+ t[0] = 0x3FF & ((base[0] >> 0) | ((uint16_t)base[1] << 8));
226
+ t[1] = 0x3FF & ((base[1] >> 2) | ((uint16_t)base[2] << 6));
227
+ t[2] = 0x3FF & ((base[2] >> 4) | ((uint16_t)base[3] << 4));
228
+ t[3] = 0x3FF & ((base[3] >> 6) | ((uint16_t)base[4] << 2));
229
+
230
+ for (k = 0; k < 4; k++)
231
+ __loop__(
232
+ invariant(k <= 4)
233
+ invariant(array_bound(r->coeffs, 0, 4 * j + k, 0, MLKEM_Q)))
234
+ {
235
+ r->coeffs[4 * j + k] = mlk_scalar_decompress_d10(t[k]);
236
+ }
237
+ }
238
+
239
+ mlk_assert_bound(r, MLKEM_N, 0, MLKEM_Q);
240
+ }
241
+
242
+ MLK_INTERNAL_API
243
+ void mlk_poly_decompress_d10(mlk_poly *r,
244
+ const uint8_t a[MLKEM_POLYCOMPRESSEDBYTES_D10])
245
+ __contract__(
246
+ requires(memory_no_alias(r, sizeof(mlk_poly)))
247
+ requires(memory_no_alias(a, MLKEM_POLYCOMPRESSEDBYTES_D10))
248
+ assigns(memory_slice(r, sizeof(mlk_poly)))
249
+ ensures(array_bound(r->coeffs, 0, MLKEM_N, 0, MLKEM_Q))
250
+ )
251
+ {
252
+ #if defined(MLK_USE_NATIVE_POLY_DECOMPRESS_D10)
253
+ int ret;
254
+ ret = mlk_poly_decompress_d10_native(r->coeffs, a);
255
+ if (ret == MLK_NATIVE_FUNC_SUCCESS)
256
+ {
257
+ mlk_assert_bound(r, MLKEM_N, 0, MLKEM_Q);
258
+ return;
259
+ }
260
+ #endif /* MLK_USE_NATIVE_POLY_DECOMPRESS_D10 */
261
+
262
+ mlk_poly_decompress_d10_c(r, a);
263
+ }
264
+ #endif /* MLK_CONFIG_MULTILEVEL_WITH_SHARED || MLKEM_K == 2 || MLKEM_K == 3 */
265
+
266
+ #if defined(MLK_CONFIG_MULTILEVEL_WITH_SHARED) || MLKEM_K == 4
267
+ /* Reference: `poly_compress()` in the reference implementation @[REF],
268
+ * for ML-KEM-1024.
269
+ * - In contrast to the reference implementation, we assume
270
+ * unsigned canonical coefficients here.
271
+ * The reference implementation works with coefficients
272
+ * in the range (-MLKEM_Q+1,...,MLKEM_Q-1). */
273
+ MLK_STATIC_TESTABLE void mlk_poly_compress_d5_c(
274
+ uint8_t r[MLKEM_POLYCOMPRESSEDBYTES_D5], const mlk_poly *a)
275
+ __contract__(
276
+ requires(memory_no_alias(r, MLKEM_POLYCOMPRESSEDBYTES_D5))
277
+ requires(memory_no_alias(a, sizeof(mlk_poly)))
278
+ requires(array_bound(a->coeffs, 0, MLKEM_N, 0, MLKEM_Q))
279
+ assigns(memory_slice(r, MLKEM_POLYCOMPRESSEDBYTES_D5))
280
+ )
281
+ {
282
+ unsigned i;
283
+ mlk_assert_bound(a, MLKEM_N, 0, MLKEM_Q);
284
+
285
+ for (i = 0; i < MLKEM_N / 8; i++)
286
+ __loop__(invariant(i <= MLKEM_N / 8))
287
+ {
288
+ unsigned j;
289
+ uint8_t t[8] = {0};
290
+ for (j = 0; j < 8; j++)
291
+ __loop__(
292
+ invariant(i <= MLKEM_N / 8 && j <= 8)
293
+ invariant(array_bound(t, 0, j, 0, 32)))
294
+ {
295
+ t[j] = mlk_scalar_compress_d5(a->coeffs[8 * i + j]);
296
+ }
297
+
298
+ r[i * 5] = (uint8_t)(0xFF & ((t[0] >> 0) | (t[1] << 5)));
299
+ r[i * 5 + 1] = (uint8_t)(0xFF & ((t[1] >> 3) | (t[2] << 2) | (t[3] << 7)));
300
+ r[i * 5 + 2] = (uint8_t)(0xFF & ((t[3] >> 1) | (t[4] << 4)));
301
+ r[i * 5 + 3] = (uint8_t)(0xFF & ((t[4] >> 4) | (t[5] << 1) | (t[6] << 6)));
302
+ r[i * 5 + 4] = (uint8_t)(0xFF & ((t[6] >> 2) | (t[7] << 3)));
303
+ }
304
+ }
305
+
306
+ MLK_INTERNAL_API
307
+ void mlk_poly_compress_d5(uint8_t r[MLKEM_POLYCOMPRESSEDBYTES_D5],
308
+ const mlk_poly *a)
309
+ __contract__(
310
+ requires(memory_no_alias(r, MLKEM_POLYCOMPRESSEDBYTES_D5))
311
+ requires(memory_no_alias(a, sizeof(mlk_poly)))
312
+ requires(array_bound(a->coeffs, 0, MLKEM_N, 0, MLKEM_Q))
313
+ assigns(memory_slice(r, MLKEM_POLYCOMPRESSEDBYTES_D5))
314
+ )
315
+ {
316
+ #if defined(MLK_USE_NATIVE_POLY_COMPRESS_D5)
317
+ int ret;
318
+ mlk_assert_bound(a, MLKEM_N, 0, MLKEM_Q);
319
+ ret = mlk_poly_compress_d5_native(r, a->coeffs);
320
+ if (ret == MLK_NATIVE_FUNC_SUCCESS)
321
+ {
322
+ return;
323
+ }
324
+ #endif /* MLK_USE_NATIVE_POLY_COMPRESS_D5 */
325
+
326
+ mlk_poly_compress_d5_c(r, a);
327
+ }
328
+
329
+ /* Reference: Embedded into `polyvec_compress()` in the
330
+ * reference implementation, for ML-KEM-1024.
331
+ * - In contrast to the reference implementation, we assume
332
+ * unsigned canonical coefficients here.
333
+ * The reference implementation works with coefficients
334
+ * in the range (-MLKEM_Q+1,...,MLKEM_Q-1). */
335
+ MLK_STATIC_TESTABLE void mlk_poly_compress_d11_c(
336
+ uint8_t r[MLKEM_POLYCOMPRESSEDBYTES_D11], const mlk_poly *a)
337
+ __contract__(
338
+ requires(memory_no_alias(r, MLKEM_POLYCOMPRESSEDBYTES_D11))
339
+ requires(memory_no_alias(a, sizeof(mlk_poly)))
340
+ requires(array_bound(a->coeffs, 0, MLKEM_N, 0, MLKEM_Q))
341
+ assigns(memory_slice(r, MLKEM_POLYCOMPRESSEDBYTES_D11))
342
+ )
343
+ {
344
+ unsigned j;
345
+ mlk_assert_bound(a, MLKEM_N, 0, MLKEM_Q);
346
+
347
+ for (j = 0; j < MLKEM_N / 8; j++)
348
+ __loop__(invariant(j <= MLKEM_N / 8))
349
+ {
350
+ unsigned k;
351
+ uint16_t t[8];
352
+ for (k = 0; k < 8; k++)
353
+ __loop__(
354
+ invariant(k <= 8)
355
+ invariant(forall(r, 0, k, t[r] < (1u << 11))))
356
+ {
357
+ t[k] = mlk_scalar_compress_d11(a->coeffs[8 * j + k]);
358
+ }
359
+
360
+ /*
361
+ * Make all implicit truncation explicit. No data is being
362
+ * truncated for the LHS's since each t[i] is 11-bit in size.
363
+ */
364
+ r[11 * j + 0] = (uint8_t)((t[0] >> 0) & 0xFF);
365
+ r[11 * j + 1] = (uint8_t)((t[0] >> 8) | ((t[1] << 3) & 0xFF));
366
+ r[11 * j + 2] = (uint8_t)((t[1] >> 5) | ((t[2] << 6) & 0xFF));
367
+ r[11 * j + 3] = (uint8_t)((t[2] >> 2) & 0xFF);
368
+ r[11 * j + 4] = (uint8_t)((t[2] >> 10) | ((t[3] << 1) & 0xFF));
369
+ r[11 * j + 5] = (uint8_t)((t[3] >> 7) | ((t[4] << 4) & 0xFF));
370
+ r[11 * j + 6] = (uint8_t)((t[4] >> 4) | ((t[5] << 7) & 0xFF));
371
+ r[11 * j + 7] = (uint8_t)((t[5] >> 1) & 0xFF);
372
+ r[11 * j + 8] = (uint8_t)((t[5] >> 9) | ((t[6] << 2) & 0xFF));
373
+ r[11 * j + 9] = (uint8_t)((t[6] >> 6) | ((t[7] << 5) & 0xFF));
374
+ r[11 * j + 10] = (uint8_t)(t[7] >> 3);
375
+ }
376
+ }
377
+
378
+ MLK_INTERNAL_API
379
+ void mlk_poly_compress_d11(uint8_t r[MLKEM_POLYCOMPRESSEDBYTES_D11],
380
+ const mlk_poly *a)
381
+ __contract__(
382
+ requires(memory_no_alias(r, MLKEM_POLYCOMPRESSEDBYTES_D11))
383
+ requires(memory_no_alias(a, sizeof(mlk_poly)))
384
+ requires(array_bound(a->coeffs, 0, MLKEM_N, 0, MLKEM_Q))
385
+ assigns(memory_slice(r, MLKEM_POLYCOMPRESSEDBYTES_D11))
386
+ )
387
+ {
388
+ #if defined(MLK_USE_NATIVE_POLY_COMPRESS_D11)
389
+ int ret;
390
+ mlk_assert_bound(a, MLKEM_N, 0, MLKEM_Q);
391
+ ret = mlk_poly_compress_d11_native(r, a->coeffs);
392
+ if (ret == MLK_NATIVE_FUNC_SUCCESS)
393
+ {
394
+ return;
395
+ }
396
+ #endif /* MLK_USE_NATIVE_POLY_COMPRESS_D11 */
397
+
398
+ mlk_poly_compress_d11_c(r, a);
399
+ }
400
+
401
+ /* Reference: `poly_decompress()` in the reference implementation @[REF],
402
+ * for ML-KEM-1024. */
403
+ MLK_STATIC_TESTABLE void mlk_poly_decompress_d5_c(
404
+ mlk_poly *r, const uint8_t a[MLKEM_POLYCOMPRESSEDBYTES_D5])
405
+ __contract__(
406
+ requires(memory_no_alias(r, sizeof(mlk_poly)))
407
+ requires(memory_no_alias(a, MLKEM_POLYCOMPRESSEDBYTES_D5))
408
+ assigns(memory_slice(r, sizeof(mlk_poly)))
409
+ ensures(array_bound(r->coeffs, 0, MLKEM_N, 0, MLKEM_Q))
410
+ )
411
+ {
412
+ unsigned i;
413
+ for (i = 0; i < MLKEM_N / 8; i++)
414
+ __loop__(
415
+ invariant(i <= MLKEM_N / 8)
416
+ invariant(array_bound(r->coeffs, 0, 8 * i, 0, MLKEM_Q)))
417
+ {
418
+ unsigned j;
419
+ uint8_t t[8];
420
+ const unsigned offset = i * 5;
421
+ /*
422
+ * Explicitly truncate to avoid warning about
423
+ * implicit truncation in CBMC and unwind loop for ease
424
+ * of proof.
425
+ */
426
+
427
+ /*
428
+ * Decompress 5 8-bit bytes (so 40 bits) into
429
+ * 8 5-bit values stored in t[]
430
+ */
431
+ t[0] = 0x1F & (a[offset + 0] >> 0);
432
+ t[1] = 0x1F & ((a[offset + 0] >> 5) | (a[offset + 1] << 3));
433
+ t[2] = 0x1F & (a[offset + 1] >> 2);
434
+ t[3] = 0x1F & ((a[offset + 1] >> 7) | (a[offset + 2] << 1));
435
+ t[4] = 0x1F & ((a[offset + 2] >> 4) | (a[offset + 3] << 4));
436
+ t[5] = 0x1F & (a[offset + 3] >> 1);
437
+ t[6] = 0x1F & ((a[offset + 3] >> 6) | (a[offset + 4] << 2));
438
+ t[7] = 0x1F & (a[offset + 4] >> 3);
439
+
440
+ /* and copy to the correct slice in r[] */
441
+ for (j = 0; j < 8; j++)
442
+ __loop__(
443
+ invariant(j <= 8 && i <= MLKEM_N / 8)
444
+ invariant(array_bound(r->coeffs, 0, 8 * i + j, 0, MLKEM_Q)))
445
+ {
446
+ r->coeffs[8 * i + j] = mlk_scalar_decompress_d5(t[j]);
447
+ }
448
+ }
449
+
450
+ mlk_assert_bound(r, MLKEM_N, 0, MLKEM_Q);
451
+ }
452
+
453
+ MLK_INTERNAL_API
454
+ void mlk_poly_decompress_d5(mlk_poly *r,
455
+ const uint8_t a[MLKEM_POLYCOMPRESSEDBYTES_D5])
456
+ __contract__(
457
+ requires(memory_no_alias(r, sizeof(mlk_poly)))
458
+ requires(memory_no_alias(a, MLKEM_POLYCOMPRESSEDBYTES_D5))
459
+ assigns(memory_slice(r, sizeof(mlk_poly)))
460
+ ensures(array_bound(r->coeffs, 0, MLKEM_N, 0, MLKEM_Q))
461
+ )
462
+ {
463
+ #if defined(MLK_USE_NATIVE_POLY_DECOMPRESS_D5)
464
+ int ret;
465
+ ret = mlk_poly_decompress_d5_native(r->coeffs, a);
466
+ if (ret == MLK_NATIVE_FUNC_SUCCESS)
467
+ {
468
+ mlk_assert_bound(r, MLKEM_N, 0, MLKEM_Q);
469
+ return;
470
+ }
471
+ #endif /* MLK_USE_NATIVE_POLY_DECOMPRESS_D5 */
472
+
473
+ mlk_poly_decompress_d5_c(r, a);
474
+ }
475
+
476
+ /* Reference: Embedded into `polyvec_decompress()` in the
477
+ * reference implementation, for ML-KEM-1024. */
478
+ MLK_STATIC_TESTABLE void mlk_poly_decompress_d11_c(
479
+ mlk_poly *r, const uint8_t a[MLKEM_POLYCOMPRESSEDBYTES_D11])
480
+ __contract__(
481
+ requires(memory_no_alias(r, sizeof(mlk_poly)))
482
+ requires(memory_no_alias(a, MLKEM_POLYCOMPRESSEDBYTES_D11))
483
+ assigns(memory_slice(r, sizeof(mlk_poly)))
484
+ ensures(array_bound(r->coeffs, 0, MLKEM_N, 0, MLKEM_Q))
485
+ )
486
+ {
487
+ unsigned j;
488
+ for (j = 0; j < MLKEM_N / 8; j++)
489
+ __loop__(
490
+ invariant(j <= MLKEM_N / 8)
491
+ invariant(array_bound(r->coeffs, 0, 8 * j, 0, MLKEM_Q)))
492
+ {
493
+ unsigned k;
494
+ uint16_t t[8];
495
+ uint8_t const *base = &a[11 * j];
496
+ t[0] = 0x7FF & ((base[0] >> 0) | ((uint16_t)base[1] << 8));
497
+ t[1] = 0x7FF & ((base[1] >> 3) | ((uint16_t)base[2] << 5));
498
+ t[2] = 0x7FF & ((base[2] >> 6) | ((uint16_t)base[3] << 2) |
499
+ ((uint16_t)base[4] << 10));
500
+ t[3] = 0x7FF & ((base[4] >> 1) | ((uint16_t)base[5] << 7));
501
+ t[4] = 0x7FF & ((base[5] >> 4) | ((uint16_t)base[6] << 4));
502
+ t[5] = 0x7FF & ((base[6] >> 7) | ((uint16_t)base[7] << 1) |
503
+ ((uint16_t)base[8] << 9));
504
+ t[6] = 0x7FF & ((base[8] >> 2) | ((uint16_t)base[9] << 6));
505
+ t[7] = 0x7FF & ((base[9] >> 5) | ((uint16_t)base[10] << 3));
506
+
507
+ for (k = 0; k < 8; k++)
508
+ __loop__(
509
+ invariant(k <= 8)
510
+ invariant(array_bound(r->coeffs, 0, 8 * j + k, 0, MLKEM_Q)))
511
+ {
512
+ r->coeffs[8 * j + k] = mlk_scalar_decompress_d11(t[k]);
513
+ }
514
+ }
515
+
516
+ mlk_assert_bound(r, MLKEM_N, 0, MLKEM_Q);
517
+ }
518
+
519
+ MLK_INTERNAL_API
520
+ void mlk_poly_decompress_d11(mlk_poly *r,
521
+ const uint8_t a[MLKEM_POLYCOMPRESSEDBYTES_D11])
522
+ __contract__(
523
+ requires(memory_no_alias(r, sizeof(mlk_poly)))
524
+ requires(memory_no_alias(a, MLKEM_POLYCOMPRESSEDBYTES_D11))
525
+ assigns(memory_slice(r, sizeof(mlk_poly)))
526
+ ensures(array_bound(r->coeffs, 0, MLKEM_N, 0, MLKEM_Q))
527
+ )
528
+ {
529
+ #if defined(MLK_USE_NATIVE_POLY_DECOMPRESS_D11)
530
+ int ret;
531
+ ret = mlk_poly_decompress_d11_native(r->coeffs, a);
532
+ if (ret == MLK_NATIVE_FUNC_SUCCESS)
533
+ {
534
+ mlk_assert_bound(r, MLKEM_N, 0, MLKEM_Q);
535
+ return;
536
+ }
537
+ #endif /* MLK_USE_NATIVE_POLY_DECOMPRESS_D11 */
538
+
539
+ mlk_poly_decompress_d11_c(r, a);
540
+ }
541
+
542
+ #endif /* MLK_CONFIG_MULTILEVEL_WITH_SHARED || MLKEM_K == 4 */
543
+
544
+ /* Reference: `poly_tobytes()` in the reference implementation @[REF].
545
+ * - In contrast to the reference implementation, we assume
546
+ * unsigned canonical coefficients here.
547
+ * The reference implementation works with coefficients
548
+ * in the range (-MLKEM_Q+1,...,MLKEM_Q-1). */
549
+ MLK_STATIC_TESTABLE void mlk_poly_tobytes_c(uint8_t r[MLKEM_POLYBYTES],
550
+ const mlk_poly *a)
551
+ __contract__(
552
+ requires(memory_no_alias(r, MLKEM_POLYBYTES))
553
+ requires(memory_no_alias(a, sizeof(mlk_poly)))
554
+ requires(array_bound(a->coeffs, 0, MLKEM_N, 0, MLKEM_Q))
555
+ assigns(memory_slice(r, MLKEM_POLYBYTES))
556
+ )
557
+ {
558
+ unsigned i;
559
+ mlk_assert_bound(a, MLKEM_N, 0, MLKEM_Q);
560
+
561
+ for (i = 0; i < MLKEM_N / 2; i++)
562
+ __loop__(invariant(i <= MLKEM_N / 2))
563
+ {
564
+ /* The conversion to uint16_t is safe since we assume that
565
+ * the coefficients of `a` are non-negative. */
566
+ const uint16_t t0 = (uint16_t)a->coeffs[2 * i];
567
+ const uint16_t t1 = (uint16_t)a->coeffs[2 * i + 1];
568
+ /*
569
+ * t0 and t1 are both < MLKEM_Q, so contain at most 12 bits each of
570
+ * significant data, so these can be packed into 24 bits or exactly
571
+ * 3 bytes, as follows.
572
+ */
573
+
574
+ /* Least significant bits 0 - 7 of t0. */
575
+ r[3 * i + 0] = (uint8_t)(t0 & 0xFF);
576
+
577
+ /*
578
+ * Most significant bits 8 - 11 of t0 become the least significant
579
+ * nibble of the second byte. The least significant 4 bits
580
+ * of t1 become the upper nibble of the second byte.
581
+ *
582
+ * The conversion to uint8_t does not alter the value.
583
+ */
584
+ r[3 * i + 1] = (uint8_t)((t0 >> 8) | ((t1 << 4) & 0xF0));
585
+
586
+ /* Bits 4 - 11 of t1 become the third byte. The conversion to uint8_t
587
+ * does not alter the value because t1 is 12-bit wide. */
588
+ r[3 * i + 2] = (uint8_t)(t1 >> 4);
589
+ }
590
+ }
591
+
592
+ MLK_INTERNAL_API
593
+ void mlk_poly_tobytes(uint8_t r[MLKEM_POLYBYTES], const mlk_poly *a)
594
+ {
595
+ #if defined(MLK_USE_NATIVE_POLY_TOBYTES)
596
+ int ret;
597
+ mlk_assert_bound(a, MLKEM_N, 0, MLKEM_Q);
598
+ ret = mlk_poly_tobytes_native(r, a->coeffs);
599
+ if (ret == MLK_NATIVE_FUNC_SUCCESS)
600
+ {
601
+ return;
602
+ }
603
+ #endif /* MLK_USE_NATIVE_POLY_TOBYTES */
604
+
605
+ mlk_poly_tobytes_c(r, a);
606
+ }
607
+
608
+ /* Reference: `poly_frombytes()` in the reference implementation @[REF]. */
609
+ MLK_STATIC_TESTABLE void mlk_poly_frombytes_c(mlk_poly *r,
610
+ const uint8_t a[MLKEM_POLYBYTES])
611
+ __contract__(
612
+ requires(memory_no_alias(a, MLKEM_POLYBYTES))
613
+ requires(memory_no_alias(r, sizeof(mlk_poly)))
614
+ assigns(memory_slice(r, sizeof(mlk_poly)))
615
+ ensures(array_bound(r->coeffs, 0, MLKEM_N, 0, MLKEM_UINT12_LIMIT))
616
+ )
617
+ {
618
+ unsigned i;
619
+ for (i = 0; i < MLKEM_N / 2; i++)
620
+ __loop__(
621
+ invariant(i <= MLKEM_N / 2)
622
+ invariant(array_bound(r->coeffs, 0, 2 * i, 0, MLKEM_UINT12_LIMIT)))
623
+ {
624
+ const uint8_t t0 = a[3 * i + 0];
625
+ const uint8_t t1 = a[3 * i + 1];
626
+ const uint8_t t2 = a[3 * i + 2];
627
+ r->coeffs[2 * i + 0] = (int16_t)(t0 | ((t1 << 8) & 0xFFF));
628
+ r->coeffs[2 * i + 1] = (int16_t)((t1 >> 4) | (t2 << 4));
629
+ }
630
+
631
+ /* Note that the coefficients are not canonical */
632
+ mlk_assert_bound(r, MLKEM_N, 0, MLKEM_UINT12_LIMIT);
633
+ }
634
+
635
+ MLK_INTERNAL_API
636
+ void mlk_poly_frombytes(mlk_poly *r, const uint8_t a[MLKEM_POLYBYTES])
637
+ {
638
+ #if defined(MLK_USE_NATIVE_POLY_FROMBYTES)
639
+ int ret;
640
+ ret = mlk_poly_frombytes_native(r->coeffs, a);
641
+ if (ret == MLK_NATIVE_FUNC_SUCCESS)
642
+ {
643
+ return;
644
+ }
645
+ #endif /* MLK_USE_NATIVE_POLY_FROMBYTES */
646
+
647
+ mlk_poly_frombytes_c(r, a);
648
+ }
649
+
650
+ /* Reference: `poly_frommsg()` in the reference implementation @[REF].
651
+ * - We use a value barrier around the bit-selection mask to
652
+ * reduce the risk of compiler-introduced branches.
653
+ * The reference implementation contains the expression
654
+ * `(msg[i] >> j) & 1` which the compiler can reason must
655
+ * be either 0 or 1. */
656
+ MLK_INTERNAL_API
657
+ void mlk_poly_frommsg(mlk_poly *r, const uint8_t msg[MLKEM_INDCPA_MSGBYTES])
658
+ {
659
+ unsigned i;
660
+ #if (MLKEM_INDCPA_MSGBYTES != MLKEM_N / 8)
661
+ #error "MLKEM_INDCPA_MSGBYTES must be equal to MLKEM_N/8 bytes!"
662
+ #endif
663
+
664
+ for (i = 0; i < MLKEM_N / 8; i++)
665
+ __loop__(
666
+ invariant(i <= MLKEM_N / 8)
667
+ invariant(array_bound(r->coeffs, 0, 8 * i, 0, MLKEM_Q)))
668
+ {
669
+ unsigned j;
670
+ for (j = 0; j < 8; j++)
671
+ __loop__(
672
+ invariant(i < MLKEM_N / 8 && j <= 8)
673
+ invariant(array_bound(r->coeffs, 0, 8 * i + j, 0, MLKEM_Q)))
674
+ {
675
+ /* mlk_ct_sel_int16(MLKEM_Q_HALF, 0, b) is `Decompress_1(b != 0)`
676
+ * as per @[FIPS203, Eq (4.8)]. */
677
+
678
+ /* Prevent the compiler from recognizing this as a bit selection */
679
+ uint8_t mask = mlk_value_barrier_u8((uint8_t)(1u << j));
680
+ r->coeffs[8 * i + j] = mlk_ct_sel_int16(MLKEM_Q_HALF, 0, msg[i] & mask);
681
+ }
682
+ }
683
+ mlk_assert_abs_bound(r, MLKEM_N, MLKEM_Q);
684
+ }
685
+
686
+ /* Reference: `poly_tomsg()` in the reference implementation @[REF].
687
+ * - In contrast to the reference implementation, we assume
688
+ * unsigned canonical coefficients here.
689
+ * The reference implementation works with coefficients
690
+ * in the range (-MLKEM_Q+1,...,MLKEM_Q-1).
691
+ */
692
+ MLK_INTERNAL_API
693
+ void mlk_poly_tomsg(uint8_t msg[MLKEM_INDCPA_MSGBYTES], const mlk_poly *a)
694
+ {
695
+ unsigned i;
696
+ mlk_assert_bound(a, MLKEM_N, 0, MLKEM_Q);
697
+
698
+ for (i = 0; i < MLKEM_N / 8; i++)
699
+ __loop__(invariant(i <= MLKEM_N / 8))
700
+ {
701
+ unsigned j;
702
+ msg[i] = 0;
703
+ for (j = 0; j < 8; j++)
704
+ __loop__(
705
+ invariant(i <= MLKEM_N / 8 && j <= 8))
706
+ {
707
+ uint32_t t = mlk_scalar_compress_d1(a->coeffs[8 * i + j]);
708
+ msg[i] |= (uint8_t)(t << j);
709
+ }
710
+ }
711
+ }
712
+
713
+ #else /* !MLK_CONFIG_MULTILEVEL_NO_SHARED */
714
+
715
+ MLK_EMPTY_CU(compress)
716
+
717
+ #endif /* MLK_CONFIG_MULTILEVEL_NO_SHARED */