pq_crypto 0.3.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 (328) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +56 -0
  3. data/CHANGELOG.md +62 -0
  4. data/GET_STARTED.md +366 -40
  5. data/README.md +76 -233
  6. data/SECURITY.md +107 -82
  7. data/ext/pqcrypto/extconf.rb +169 -87
  8. data/ext/pqcrypto/mldsa_api.h +1 -48
  9. data/ext/pqcrypto/mlkem_api.h +1 -18
  10. data/ext/pqcrypto/pq_externalmu.c +89 -204
  11. data/ext/pqcrypto/pqcrypto_native_api.h +129 -0
  12. data/ext/pqcrypto/pqcrypto_ruby_secure.c +484 -84
  13. data/ext/pqcrypto/pqcrypto_secure.c +203 -78
  14. data/ext/pqcrypto/pqcrypto_secure.h +53 -14
  15. data/ext/pqcrypto/pqcrypto_version.h +7 -0
  16. data/ext/pqcrypto/randombytes.h +9 -0
  17. data/ext/pqcrypto/vendor/.vendored +10 -5
  18. data/ext/pqcrypto/vendor/mldsa-native/BUILDING.md +105 -0
  19. data/ext/pqcrypto/vendor/mldsa-native/LICENSE +286 -0
  20. data/ext/pqcrypto/vendor/mldsa-native/META.yml +24 -0
  21. data/ext/pqcrypto/vendor/mldsa-native/README.md +221 -0
  22. data/ext/pqcrypto/vendor/mldsa-native/SECURITY.md +8 -0
  23. data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native.c +721 -0
  24. data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native.h +975 -0
  25. data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native_asm.S +724 -0
  26. data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native_config.h +723 -0
  27. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/cbmc.h +166 -0
  28. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/common.h +321 -0
  29. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/ct.c +21 -0
  30. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/ct.h +385 -0
  31. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/debug.c +73 -0
  32. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/debug.h +130 -0
  33. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/fips202.c +277 -0
  34. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/fips202.h +244 -0
  35. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/fips202x4.c +182 -0
  36. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/fips202x4.h +117 -0
  37. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/keccakf1600.c +438 -0
  38. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/keccakf1600.h +105 -0
  39. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/auto.h +71 -0
  40. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/fips202_native_aarch64.h +62 -0
  41. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_scalar_asm.S +376 -0
  42. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_v84a_asm.S +204 -0
  43. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x2_v84a_asm.S +259 -0
  44. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_scalar_hybrid_asm.S +1077 -0
  45. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_v84a_scalar_hybrid_asm.S +987 -0
  46. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccakf1600_round_constants.c +41 -0
  47. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x1_scalar.h +26 -0
  48. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x1_v84a.h +35 -0
  49. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x2_v84a.h +37 -0
  50. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x4_v8a_scalar.h +27 -0
  51. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x4_v8a_v84a_scalar.h +36 -0
  52. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/api.h +69 -0
  53. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/README.md +10 -0
  54. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/mve.h +32 -0
  55. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/fips202_native_armv81m.h +20 -0
  56. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.S +638 -0
  57. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.c +136 -0
  58. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccakf1600_round_constants.c +52 -0
  59. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/auto.h +29 -0
  60. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/KeccakP_1600_times4_SIMD256.c +488 -0
  61. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/KeccakP_1600_times4_SIMD256.h +16 -0
  62. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/xkcp.h +31 -0
  63. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/meta.h +247 -0
  64. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/aarch64_zetas.c +231 -0
  65. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/arith_native_aarch64.h +150 -0
  66. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/intt.S +753 -0
  67. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l4.S +129 -0
  68. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l5.S +145 -0
  69. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l7.S +177 -0
  70. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/ntt.S +653 -0
  71. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/pointwise_montgomery.S +79 -0
  72. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_caddq_asm.S +53 -0
  73. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_chknorm_asm.S +55 -0
  74. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_decompose_32_asm.S +85 -0
  75. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_decompose_88_asm.S +85 -0
  76. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_use_hint_32_asm.S +102 -0
  77. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_use_hint_88_asm.S +110 -0
  78. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/polyz_unpack_17_asm.S +72 -0
  79. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/polyz_unpack_19_asm.S +69 -0
  80. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/polyz_unpack_table.c +40 -0
  81. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_asm.S +189 -0
  82. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_eta2_asm.S +135 -0
  83. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_eta4_asm.S +128 -0
  84. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_eta_table.c +543 -0
  85. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_table.c +62 -0
  86. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/api.h +649 -0
  87. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/meta.h +23 -0
  88. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/meta.h +315 -0
  89. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/arith_native_x86_64.h +124 -0
  90. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/consts.c +157 -0
  91. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/consts.h +27 -0
  92. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/intt.S +2311 -0
  93. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/ntt.S +2383 -0
  94. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/nttunpack.S +239 -0
  95. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise.S +131 -0
  96. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l4.S +139 -0
  97. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l5.S +155 -0
  98. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l7.S +187 -0
  99. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_caddq_avx2.c +61 -0
  100. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_chknorm_avx2.c +52 -0
  101. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_decompose_32_avx2.c +155 -0
  102. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_decompose_88_avx2.c +155 -0
  103. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_use_hint_32_avx2.c +102 -0
  104. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_use_hint_88_avx2.c +104 -0
  105. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/polyz_unpack_17_avx2.c +91 -0
  106. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/polyz_unpack_19_avx2.c +93 -0
  107. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/rej_uniform_avx2.c +126 -0
  108. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/rej_uniform_eta2_avx2.c +155 -0
  109. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/rej_uniform_eta4_avx2.c +139 -0
  110. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/rej_uniform_table.c +160 -0
  111. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/packing.c +293 -0
  112. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/packing.h +224 -0
  113. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/params.h +77 -0
  114. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly.c +991 -0
  115. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly.h +393 -0
  116. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly_kl.c +946 -0
  117. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly_kl.h +360 -0
  118. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec.c +877 -0
  119. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec.h +725 -0
  120. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/randombytes.h +26 -0
  121. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/reduce.h +139 -0
  122. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/rounding.h +249 -0
  123. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/sign.c +1511 -0
  124. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/sign.h +806 -0
  125. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/symmetric.h +68 -0
  126. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/sys.h +268 -0
  127. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/zetas.inc +55 -0
  128. data/ext/pqcrypto/vendor/mlkem-native/BUILDING.md +104 -0
  129. data/ext/pqcrypto/vendor/mlkem-native/LICENSE +294 -0
  130. data/ext/pqcrypto/vendor/mlkem-native/META.yml +30 -0
  131. data/ext/pqcrypto/vendor/mlkem-native/README.md +223 -0
  132. data/ext/pqcrypto/vendor/mlkem-native/RELEASE.md +86 -0
  133. data/ext/pqcrypto/vendor/mlkem-native/SECURITY.md +8 -0
  134. data/ext/pqcrypto/vendor/mlkem-native/mlkem/README.md +23 -0
  135. data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native.c +660 -0
  136. data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native.h +538 -0
  137. data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native_asm.S +681 -0
  138. data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native_config.h +709 -0
  139. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/cbmc.h +174 -0
  140. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/common.h +274 -0
  141. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/compress.c +717 -0
  142. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/compress.h +688 -0
  143. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/debug.c +64 -0
  144. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/debug.h +128 -0
  145. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/fips202.c +251 -0
  146. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/fips202.h +158 -0
  147. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/fips202x4.c +208 -0
  148. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/fips202x4.h +80 -0
  149. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/keccakf1600.c +463 -0
  150. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/keccakf1600.h +98 -0
  151. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/auto.h +70 -0
  152. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/fips202_native_aarch64.h +69 -0
  153. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccak_f1600_x1_scalar_asm.S +375 -0
  154. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccak_f1600_x1_v84a_asm.S +203 -0
  155. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccak_f1600_x2_v84a_asm.S +258 -0
  156. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_scalar_hybrid_asm.S +1076 -0
  157. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_v84a_scalar_hybrid_asm.S +986 -0
  158. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccakf1600_round_constants.c +46 -0
  159. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x1_scalar.h +25 -0
  160. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x1_v84a.h +34 -0
  161. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x2_v84a.h +35 -0
  162. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x4_v8a_scalar.h +26 -0
  163. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x4_v8a_v84a_scalar.h +35 -0
  164. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/api.h +117 -0
  165. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/README.md +10 -0
  166. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/mve.h +79 -0
  167. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/fips202_native_armv81m.h +35 -0
  168. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.S +667 -0
  169. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.c +40 -0
  170. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/keccakf1600_round_constants.c +51 -0
  171. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/state_extract_bytes_x4_mve.S +290 -0
  172. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/state_xor_bytes_x4_mve.S +314 -0
  173. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/auto.h +28 -0
  174. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/keccak_f1600_x4_avx2.h +33 -0
  175. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/src/fips202_native_x86_64.h +41 -0
  176. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/src/keccak_f1600_x4_avx2.S +451 -0
  177. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/src/keccakf1600_constants.c +51 -0
  178. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/indcpa.c +622 -0
  179. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/indcpa.h +156 -0
  180. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/kem.c +446 -0
  181. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/kem.h +326 -0
  182. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/README.md +16 -0
  183. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/meta.h +122 -0
  184. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/aarch64_zetas.c +174 -0
  185. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/arith_native_aarch64.h +177 -0
  186. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/intt.S +628 -0
  187. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/ntt.S +562 -0
  188. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/poly_mulcache_compute_asm.S +127 -0
  189. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/poly_reduce_asm.S +150 -0
  190. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/poly_tobytes_asm.S +117 -0
  191. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/poly_tomont_asm.S +98 -0
  192. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/polyvec_basemul_acc_montgomery_cached_asm_k2.S +261 -0
  193. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/polyvec_basemul_acc_montgomery_cached_asm_k3.S +314 -0
  194. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/polyvec_basemul_acc_montgomery_cached_asm_k4.S +368 -0
  195. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/rej_uniform_asm.S +226 -0
  196. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/rej_uniform_table.c +542 -0
  197. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/api.h +637 -0
  198. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/meta.h +25 -0
  199. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/README.md +11 -0
  200. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/meta.h +128 -0
  201. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/arith_native_riscv64.h +45 -0
  202. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/rv64v_debug.c +81 -0
  203. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/rv64v_debug.h +145 -0
  204. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/rv64v_izetas.inc +27 -0
  205. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/rv64v_poly.c +805 -0
  206. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/rv64v_zetas.inc +27 -0
  207. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/rv64v_zetas_basemul.inc +39 -0
  208. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/README.md +4 -0
  209. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/meta.h +304 -0
  210. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/arith_native_x86_64.h +309 -0
  211. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/compress_consts.c +94 -0
  212. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/compress_consts.h +45 -0
  213. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/consts.c +102 -0
  214. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/consts.h +25 -0
  215. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/intt.S +719 -0
  216. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mulcache_compute.S +90 -0
  217. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/ntt.S +639 -0
  218. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/nttfrombytes.S +193 -0
  219. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/ntttobytes.S +181 -0
  220. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/nttunpack.S +174 -0
  221. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/poly_compress_d10.S +382 -0
  222. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/poly_compress_d11.S +448 -0
  223. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/poly_compress_d4.S +163 -0
  224. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/poly_compress_d5.S +220 -0
  225. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/poly_decompress_d10.S +228 -0
  226. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/poly_decompress_d11.S +277 -0
  227. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/poly_decompress_d4.S +180 -0
  228. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/poly_decompress_d5.S +192 -0
  229. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/polyvec_basemul_acc_montgomery_cached_asm_k2.S +502 -0
  230. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/polyvec_basemul_acc_montgomery_cached_asm_k3.S +750 -0
  231. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/polyvec_basemul_acc_montgomery_cached_asm_k4.S +998 -0
  232. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/reduce.S +218 -0
  233. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/rej_uniform_asm.S +103 -0
  234. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/rej_uniform_table.c +544 -0
  235. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/tomont.S +155 -0
  236. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/params.h +76 -0
  237. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/poly.c +572 -0
  238. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/poly.h +317 -0
  239. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/poly_k.c +502 -0
  240. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/poly_k.h +668 -0
  241. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/randombytes.h +60 -0
  242. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/sampling.c +362 -0
  243. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/sampling.h +118 -0
  244. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/symmetric.h +70 -0
  245. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/sys.h +260 -0
  246. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/verify.c +20 -0
  247. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/verify.h +464 -0
  248. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/zetas.inc +30 -0
  249. data/lib/pq_crypto/algorithm_registry.rb +200 -0
  250. data/lib/pq_crypto/hybrid_kem.rb +1 -12
  251. data/lib/pq_crypto/kem.rb +104 -13
  252. data/lib/pq_crypto/pkcs8.rb +387 -0
  253. data/lib/pq_crypto/serialization.rb +1 -14
  254. data/lib/pq_crypto/signature.rb +123 -17
  255. data/lib/pq_crypto/spki.rb +131 -0
  256. data/lib/pq_crypto/version.rb +1 -1
  257. data/lib/pq_crypto.rb +79 -20
  258. data/script/vendor_libs.rb +88 -155
  259. metadata +241 -73
  260. data/ext/pqcrypto/vendor/pqclean/common/aes.c +0 -639
  261. data/ext/pqcrypto/vendor/pqclean/common/aes.h +0 -64
  262. data/ext/pqcrypto/vendor/pqclean/common/compat.h +0 -73
  263. data/ext/pqcrypto/vendor/pqclean/common/crypto_declassify.h +0 -7
  264. data/ext/pqcrypto/vendor/pqclean/common/fips202.c +0 -928
  265. data/ext/pqcrypto/vendor/pqclean/common/fips202.h +0 -166
  266. data/ext/pqcrypto/vendor/pqclean/common/keccak2x/feat.S +0 -168
  267. data/ext/pqcrypto/vendor/pqclean/common/keccak2x/fips202x2.c +0 -684
  268. data/ext/pqcrypto/vendor/pqclean/common/keccak2x/fips202x2.h +0 -60
  269. data/ext/pqcrypto/vendor/pqclean/common/keccak4x/KeccakP-1600-times4-SIMD256.c +0 -1028
  270. data/ext/pqcrypto/vendor/pqclean/common/keccak4x/KeccakP-1600-times4-SnP.h +0 -50
  271. data/ext/pqcrypto/vendor/pqclean/common/keccak4x/KeccakP-1600-unrolling.macros +0 -198
  272. data/ext/pqcrypto/vendor/pqclean/common/keccak4x/Makefile +0 -8
  273. data/ext/pqcrypto/vendor/pqclean/common/keccak4x/Makefile.Microsoft_nmake +0 -8
  274. data/ext/pqcrypto/vendor/pqclean/common/keccak4x/SIMD256-config.h +0 -3
  275. data/ext/pqcrypto/vendor/pqclean/common/keccak4x/align.h +0 -34
  276. data/ext/pqcrypto/vendor/pqclean/common/keccak4x/brg_endian.h +0 -142
  277. data/ext/pqcrypto/vendor/pqclean/common/nistseedexpander.c +0 -101
  278. data/ext/pqcrypto/vendor/pqclean/common/nistseedexpander.h +0 -39
  279. data/ext/pqcrypto/vendor/pqclean/common/randombytes.c +0 -355
  280. data/ext/pqcrypto/vendor/pqclean/common/randombytes.h +0 -27
  281. data/ext/pqcrypto/vendor/pqclean/common/sha2.c +0 -769
  282. data/ext/pqcrypto/vendor/pqclean/common/sha2.h +0 -173
  283. data/ext/pqcrypto/vendor/pqclean/common/sp800-185.c +0 -156
  284. data/ext/pqcrypto/vendor/pqclean/common/sp800-185.h +0 -27
  285. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/LICENSE +0 -5
  286. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/Makefile +0 -19
  287. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/Makefile.Microsoft_nmake +0 -23
  288. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/api.h +0 -18
  289. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/cbd.c +0 -83
  290. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/cbd.h +0 -11
  291. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/indcpa.c +0 -327
  292. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/indcpa.h +0 -22
  293. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/kem.c +0 -164
  294. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/kem.h +0 -23
  295. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/ntt.c +0 -146
  296. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/ntt.h +0 -14
  297. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/params.h +0 -36
  298. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/poly.c +0 -299
  299. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/poly.h +0 -37
  300. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/polyvec.c +0 -188
  301. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/polyvec.h +0 -26
  302. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/reduce.c +0 -41
  303. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/reduce.h +0 -13
  304. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/symmetric-shake.c +0 -71
  305. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/symmetric.h +0 -30
  306. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/verify.c +0 -67
  307. data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/verify.h +0 -13
  308. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/LICENSE +0 -5
  309. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/Makefile +0 -19
  310. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/Makefile.Microsoft_nmake +0 -23
  311. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/api.h +0 -50
  312. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/ntt.c +0 -98
  313. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/ntt.h +0 -10
  314. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/packing.c +0 -261
  315. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/packing.h +0 -31
  316. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/params.h +0 -44
  317. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/poly.c +0 -799
  318. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/poly.h +0 -52
  319. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/polyvec.c +0 -415
  320. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/polyvec.h +0 -65
  321. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/reduce.c +0 -69
  322. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/reduce.h +0 -17
  323. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/rounding.c +0 -92
  324. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/rounding.h +0 -14
  325. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/sign.c +0 -407
  326. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/sign.h +0 -47
  327. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/symmetric-shake.c +0 -26
  328. data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/symmetric.h +0 -34
@@ -1,44 +1,57 @@
1
1
  #include "pqcrypto_secure.h"
2
2
 
3
+ #include <openssl/evp.h>
4
+
3
5
  #include <stdint.h>
4
6
  #include <stddef.h>
7
+ #include <stdlib.h>
5
8
  #include <string.h>
6
9
 
7
- #include "vendor/pqclean/crypto_sign/ml-dsa-65/clean/params.h"
8
- #include "vendor/pqclean/crypto_sign/ml-dsa-65/clean/packing.h"
9
- #include "vendor/pqclean/crypto_sign/ml-dsa-65/clean/polyvec.h"
10
- #include "vendor/pqclean/crypto_sign/ml-dsa-65/clean/poly.h"
11
- #include "vendor/pqclean/crypto_sign/ml-dsa-65/clean/symmetric.h"
12
- #include "fips202.h"
13
- #include "randombytes.h"
10
+ typedef struct {
11
+ EVP_MD_CTX *ctx;
12
+ } pq_mu_builder_t;
13
+
14
+ static int pq_shake256(uint8_t *out, size_t out_len, const uint8_t *in, size_t in_len) {
15
+ EVP_MD_CTX *ctx = EVP_MD_CTX_new();
16
+ int ret = PQ_ERROR_OPENSSL;
17
+
18
+ if (!ctx) {
19
+ return PQ_ERROR_OPENSSL;
20
+ }
21
+ if (EVP_DigestInit_ex(ctx, EVP_shake256(), NULL) != 1) {
22
+ goto cleanup;
23
+ }
24
+ if (in_len > 0 && EVP_DigestUpdate(ctx, in, in_len) != 1) {
25
+ goto cleanup;
26
+ }
27
+ if (EVP_DigestFinalXOF(ctx, out, out_len) != 1) {
28
+ goto cleanup;
29
+ }
30
+ ret = PQ_SUCCESS;
14
31
 
15
- #if CRHBYTES != PQ_MLDSA_MUBYTES
16
- #error "PQ_MLDSA_MUBYTES must match PQClean's CRHBYTES"
17
- #endif
18
- #if TRBYTES != PQ_MLDSA_TRBYTES
19
- #error "PQ_MLDSA_TRBYTES must match PQClean's TRBYTES"
20
- #endif
32
+ cleanup:
33
+ EVP_MD_CTX_free(ctx);
34
+ return ret;
35
+ }
21
36
 
22
37
  int pq_mldsa_extract_tr_from_secret_key(uint8_t *tr_out, const uint8_t *secret_key) {
38
+ uint8_t public_key[MLDSA_PUBLICKEYBYTES];
39
+ int rc;
40
+
23
41
  if (tr_out == NULL || secret_key == NULL) {
24
42
  return PQ_ERROR_BUFFER;
25
43
  }
26
44
 
27
- uint8_t rho[SEEDBYTES];
28
- uint8_t key[SEEDBYTES];
29
- polyveck t0;
30
- polyvecl s1;
31
- polyveck s2;
32
-
33
- PQCLEAN_MLDSA65_CLEAN_unpack_sk(rho, tr_out, key, &t0, &s1, &s2, secret_key);
34
-
35
- pq_secure_wipe(rho, sizeof(rho));
36
- pq_secure_wipe(key, sizeof(key));
37
- pq_secure_wipe(&t0, sizeof(t0));
38
- pq_secure_wipe(&s1, sizeof(s1));
39
- pq_secure_wipe(&s2, sizeof(s2));
45
+ memset(public_key, 0, sizeof(public_key));
46
+ rc = pqcr_mldsa65_pk_from_sk(public_key, secret_key);
47
+ if (rc != 0) {
48
+ pq_secure_wipe(public_key, sizeof(public_key));
49
+ return PQ_ERROR_KEYPAIR;
50
+ }
40
51
 
41
- return PQ_SUCCESS;
52
+ rc = pq_shake256(tr_out, PQ_MLDSA_TRBYTES, public_key, sizeof(public_key));
53
+ pq_secure_wipe(public_key, sizeof(public_key));
54
+ return rc;
42
55
  }
43
56
 
44
57
  int pq_mldsa_compute_tr_from_public_key(uint8_t *tr_out, const uint8_t *public_key) {
@@ -46,8 +59,7 @@ int pq_mldsa_compute_tr_from_public_key(uint8_t *tr_out, const uint8_t *public_k
46
59
  return PQ_ERROR_BUFFER;
47
60
  }
48
61
 
49
- shake256(tr_out, TRBYTES, public_key, PQCLEAN_MLDSA65_CLEAN_CRYPTO_PUBLICKEYBYTES);
50
- return PQ_SUCCESS;
62
+ return pq_shake256(tr_out, PQ_MLDSA_TRBYTES, public_key, MLDSA_PUBLICKEYBYTES);
51
63
  }
52
64
 
53
65
  int pq_sign_mu(uint8_t *signature, size_t *signature_len, const uint8_t *mu,
@@ -56,109 +68,9 @@ int pq_sign_mu(uint8_t *signature, size_t *signature_len, const uint8_t *mu,
56
68
  return PQ_ERROR_BUFFER;
57
69
  }
58
70
 
59
- unsigned int n;
60
- uint8_t rho[SEEDBYTES];
61
- uint8_t tr_unused[TRBYTES];
62
- uint8_t key[SEEDBYTES];
63
- uint8_t rnd[RNDBYTES];
64
- uint8_t mu_local[CRHBYTES];
65
- uint8_t rhoprime[CRHBYTES];
66
- uint16_t nonce = 0;
67
- polyvecl mat[K], s1, y, z;
68
- polyveck t0, s2, w1, w0, h;
69
- poly cp;
70
- shake256incctx state;
71
-
72
- PQCLEAN_MLDSA65_CLEAN_unpack_sk(rho, tr_unused, key, &t0, &s1, &s2, secret_key);
73
- pq_secure_wipe(tr_unused, sizeof(tr_unused));
74
-
75
- memcpy(mu_local, mu, CRHBYTES);
76
-
77
- randombytes(rnd, RNDBYTES);
78
-
79
- {
80
- uint8_t kr[SEEDBYTES + RNDBYTES + CRHBYTES];
81
- memcpy(kr, key, SEEDBYTES);
82
- memcpy(kr + SEEDBYTES, rnd, RNDBYTES);
83
- memcpy(kr + SEEDBYTES + RNDBYTES, mu_local, CRHBYTES);
84
- shake256(rhoprime, CRHBYTES, kr, sizeof(kr));
85
- pq_secure_wipe(kr, sizeof(kr));
86
- }
87
-
88
- PQCLEAN_MLDSA65_CLEAN_polyvec_matrix_expand(mat, rho);
89
- PQCLEAN_MLDSA65_CLEAN_polyvecl_ntt(&s1);
90
- PQCLEAN_MLDSA65_CLEAN_polyveck_ntt(&s2);
91
- PQCLEAN_MLDSA65_CLEAN_polyveck_ntt(&t0);
92
-
93
- rej:
94
- PQCLEAN_MLDSA65_CLEAN_polyvecl_uniform_gamma1(&y, rhoprime, nonce++);
95
-
96
- z = y;
97
- PQCLEAN_MLDSA65_CLEAN_polyvecl_ntt(&z);
98
- PQCLEAN_MLDSA65_CLEAN_polyvec_matrix_pointwise_montgomery(&w1, mat, &z);
99
- PQCLEAN_MLDSA65_CLEAN_polyveck_reduce(&w1);
100
- PQCLEAN_MLDSA65_CLEAN_polyveck_invntt_tomont(&w1);
101
-
102
- PQCLEAN_MLDSA65_CLEAN_polyveck_caddq(&w1);
103
- PQCLEAN_MLDSA65_CLEAN_polyveck_decompose(&w1, &w0, &w1);
104
- PQCLEAN_MLDSA65_CLEAN_polyveck_pack_w1(signature, &w1);
105
-
106
- shake256_inc_init(&state);
107
- shake256_inc_absorb(&state, mu_local, CRHBYTES);
108
- shake256_inc_absorb(&state, signature, K * POLYW1_PACKEDBYTES);
109
- shake256_inc_finalize(&state);
110
- shake256_inc_squeeze(signature, CTILDEBYTES, &state);
111
- shake256_inc_ctx_release(&state);
112
-
113
- PQCLEAN_MLDSA65_CLEAN_poly_challenge(&cp, signature);
114
- PQCLEAN_MLDSA65_CLEAN_poly_ntt(&cp);
115
-
116
- PQCLEAN_MLDSA65_CLEAN_polyvecl_pointwise_poly_montgomery(&z, &cp, &s1);
117
- PQCLEAN_MLDSA65_CLEAN_polyvecl_invntt_tomont(&z);
118
- PQCLEAN_MLDSA65_CLEAN_polyvecl_add(&z, &z, &y);
119
- PQCLEAN_MLDSA65_CLEAN_polyvecl_reduce(&z);
120
- if (PQCLEAN_MLDSA65_CLEAN_polyvecl_chknorm(&z, GAMMA1 - BETA)) {
121
- goto rej;
122
- }
123
-
124
- PQCLEAN_MLDSA65_CLEAN_polyveck_pointwise_poly_montgomery(&h, &cp, &s2);
125
- PQCLEAN_MLDSA65_CLEAN_polyveck_invntt_tomont(&h);
126
- PQCLEAN_MLDSA65_CLEAN_polyveck_sub(&w0, &w0, &h);
127
- PQCLEAN_MLDSA65_CLEAN_polyveck_reduce(&w0);
128
- if (PQCLEAN_MLDSA65_CLEAN_polyveck_chknorm(&w0, GAMMA2 - BETA)) {
129
- goto rej;
130
- }
131
-
132
- PQCLEAN_MLDSA65_CLEAN_polyveck_pointwise_poly_montgomery(&h, &cp, &t0);
133
- PQCLEAN_MLDSA65_CLEAN_polyveck_invntt_tomont(&h);
134
- PQCLEAN_MLDSA65_CLEAN_polyveck_reduce(&h);
135
- if (PQCLEAN_MLDSA65_CLEAN_polyveck_chknorm(&h, GAMMA2)) {
136
- goto rej;
137
- }
138
-
139
- PQCLEAN_MLDSA65_CLEAN_polyveck_add(&w0, &w0, &h);
140
- n = PQCLEAN_MLDSA65_CLEAN_polyveck_make_hint(&h, &w0, &w1);
141
- if (n > OMEGA) {
142
- goto rej;
143
- }
144
-
145
- PQCLEAN_MLDSA65_CLEAN_pack_sig(signature, signature, &z, &h);
146
- *signature_len = PQCLEAN_MLDSA65_CLEAN_CRYPTO_BYTES;
147
-
148
- pq_secure_wipe(rho, sizeof(rho));
149
- pq_secure_wipe(key, sizeof(key));
150
- pq_secure_wipe(rnd, sizeof(rnd));
151
- pq_secure_wipe(mu_local, sizeof(mu_local));
152
- pq_secure_wipe(rhoprime, sizeof(rhoprime));
153
- pq_secure_wipe(&s1, sizeof(s1));
154
- pq_secure_wipe(&s2, sizeof(s2));
155
- pq_secure_wipe(&t0, sizeof(t0));
156
- pq_secure_wipe(&y, sizeof(y));
157
- pq_secure_wipe(&z, sizeof(z));
158
- pq_secure_wipe(&w0, sizeof(w0));
159
- pq_secure_wipe(&cp, sizeof(cp));
160
-
161
- return PQ_SUCCESS;
71
+ return pqcr_mldsa65_signature_extmu(signature, signature_len, mu, secret_key) == 0
72
+ ? PQ_SUCCESS
73
+ : PQ_ERROR_SIGN;
162
74
  }
163
75
 
164
76
  int pq_verify_mu(const uint8_t *signature, size_t signature_len, const uint8_t *mu,
@@ -166,71 +78,33 @@ int pq_verify_mu(const uint8_t *signature, size_t signature_len, const uint8_t *
166
78
  if (signature == NULL || mu == NULL || public_key == NULL) {
167
79
  return PQ_ERROR_BUFFER;
168
80
  }
169
- if (signature_len != PQCLEAN_MLDSA65_CLEAN_CRYPTO_BYTES) {
81
+ if (signature_len != MLDSA_BYTES) {
170
82
  return PQ_ERROR_VERIFY;
171
83
  }
172
84
 
173
- unsigned int i;
174
- uint8_t buf[K * POLYW1_PACKEDBYTES];
175
- uint8_t rho[SEEDBYTES];
176
- uint8_t c[CTILDEBYTES];
177
- uint8_t c2[CTILDEBYTES];
178
- poly cp;
179
- polyvecl mat[K], z;
180
- polyveck t1, w1, h;
181
- shake256incctx state;
85
+ return pqcr_mldsa65_verify_extmu(signature, signature_len, mu, public_key) == 0
86
+ ? PQ_SUCCESS
87
+ : PQ_ERROR_VERIFY;
88
+ }
182
89
 
183
- PQCLEAN_MLDSA65_CLEAN_unpack_pk(rho, &t1, public_key);
184
- if (PQCLEAN_MLDSA65_CLEAN_unpack_sig(c, &z, &h, signature)) {
185
- return PQ_ERROR_VERIFY;
186
- }
187
- if (PQCLEAN_MLDSA65_CLEAN_polyvecl_chknorm(&z, GAMMA1 - BETA)) {
188
- return PQ_ERROR_VERIFY;
90
+ void *pq_mu_builder_new(void) {
91
+ pq_mu_builder_t *builder = (pq_mu_builder_t *)calloc(1, sizeof(*builder));
92
+ if (builder == NULL) {
93
+ return NULL;
189
94
  }
190
95
 
191
- PQCLEAN_MLDSA65_CLEAN_poly_challenge(&cp, c);
192
- PQCLEAN_MLDSA65_CLEAN_polyvec_matrix_expand(mat, rho);
193
-
194
- PQCLEAN_MLDSA65_CLEAN_polyvecl_ntt(&z);
195
- PQCLEAN_MLDSA65_CLEAN_polyvec_matrix_pointwise_montgomery(&w1, mat, &z);
196
-
197
- PQCLEAN_MLDSA65_CLEAN_poly_ntt(&cp);
198
- PQCLEAN_MLDSA65_CLEAN_polyveck_shiftl(&t1);
199
- PQCLEAN_MLDSA65_CLEAN_polyveck_ntt(&t1);
200
- PQCLEAN_MLDSA65_CLEAN_polyveck_pointwise_poly_montgomery(&t1, &cp, &t1);
201
-
202
- PQCLEAN_MLDSA65_CLEAN_polyveck_sub(&w1, &w1, &t1);
203
- PQCLEAN_MLDSA65_CLEAN_polyveck_reduce(&w1);
204
- PQCLEAN_MLDSA65_CLEAN_polyveck_invntt_tomont(&w1);
205
-
206
- PQCLEAN_MLDSA65_CLEAN_polyveck_caddq(&w1);
207
- PQCLEAN_MLDSA65_CLEAN_polyveck_use_hint(&w1, &w1, &h);
208
- PQCLEAN_MLDSA65_CLEAN_polyveck_pack_w1(buf, &w1);
209
-
210
- shake256_inc_init(&state);
211
- shake256_inc_absorb(&state, mu, CRHBYTES);
212
- shake256_inc_absorb(&state, buf, K * POLYW1_PACKEDBYTES);
213
- shake256_inc_finalize(&state);
214
- shake256_inc_squeeze(c2, CTILDEBYTES, &state);
215
- shake256_inc_ctx_release(&state);
216
-
217
- for (i = 0; i < CTILDEBYTES; ++i) {
218
- if (c[i] != c2[i]) {
219
- return PQ_ERROR_VERIFY;
220
- }
96
+ builder->ctx = EVP_MD_CTX_new();
97
+ if (builder->ctx == NULL) {
98
+ free(builder);
99
+ return NULL;
221
100
  }
222
-
223
- return PQ_SUCCESS;
224
- }
225
-
226
- void *pq_mu_builder_new(void) {
227
- shake256incctx *state = (shake256incctx *)malloc(sizeof(shake256incctx));
228
- if (state == NULL) {
101
+ if (EVP_DigestInit_ex(builder->ctx, EVP_shake256(), NULL) != 1) {
102
+ EVP_MD_CTX_free(builder->ctx);
103
+ free(builder);
229
104
  return NULL;
230
105
  }
231
106
 
232
- shake256_inc_init(state);
233
- return state;
107
+ return builder;
234
108
  }
235
109
 
236
110
  int pq_mu_builder_init(void *state_ptr, const uint8_t *tr, const uint8_t *ctx, size_t ctxlen) {
@@ -244,16 +118,19 @@ int pq_mu_builder_init(void *state_ptr, const uint8_t *tr, const uint8_t *ctx, s
244
118
  return PQ_ERROR_BUFFER;
245
119
  }
246
120
 
247
- shake256incctx *state = (shake256incctx *)state_ptr;
248
-
121
+ pq_mu_builder_t *builder = (pq_mu_builder_t *)state_ptr;
249
122
  uint8_t prefix[2];
250
123
  prefix[0] = 0x00;
251
124
  prefix[1] = (uint8_t)ctxlen;
252
125
 
253
- shake256_inc_absorb(state, tr, TRBYTES);
254
- shake256_inc_absorb(state, prefix, sizeof(prefix));
255
- if (ctxlen > 0) {
256
- shake256_inc_absorb(state, ctx, ctxlen);
126
+ if (EVP_DigestUpdate(builder->ctx, tr, PQ_MLDSA_TRBYTES) != 1) {
127
+ return PQ_ERROR_OPENSSL;
128
+ }
129
+ if (EVP_DigestUpdate(builder->ctx, prefix, sizeof(prefix)) != 1) {
130
+ return PQ_ERROR_OPENSSL;
131
+ }
132
+ if (ctxlen > 0 && EVP_DigestUpdate(builder->ctx, ctx, ctxlen) != 1) {
133
+ return PQ_ERROR_OPENSSL;
257
134
  }
258
135
  return PQ_SUCCESS;
259
136
  }
@@ -269,9 +146,8 @@ int pq_mu_builder_absorb(void *state_ptr, const uint8_t *chunk, size_t chunk_len
269
146
  return PQ_ERROR_BUFFER;
270
147
  }
271
148
 
272
- shake256incctx *state = (shake256incctx *)state_ptr;
273
- shake256_inc_absorb(state, chunk, chunk_len);
274
- return PQ_SUCCESS;
149
+ pq_mu_builder_t *builder = (pq_mu_builder_t *)state_ptr;
150
+ return EVP_DigestUpdate(builder->ctx, chunk, chunk_len) == 1 ? PQ_SUCCESS : PQ_ERROR_OPENSSL;
275
151
  }
276
152
 
277
153
  int pq_mu_builder_finalize(void *state_ptr, uint8_t *mu_out) {
@@ -279,11 +155,17 @@ int pq_mu_builder_finalize(void *state_ptr, uint8_t *mu_out) {
279
155
  return PQ_ERROR_BUFFER;
280
156
  }
281
157
 
282
- shake256incctx *state = (shake256incctx *)state_ptr;
283
- shake256_inc_finalize(state);
284
- shake256_inc_squeeze(mu_out, CRHBYTES, state);
285
- shake256_inc_ctx_release(state);
286
- free(state);
158
+ pq_mu_builder_t *builder = (pq_mu_builder_t *)state_ptr;
159
+ if (EVP_DigestFinalXOF(builder->ctx, mu_out, PQ_MLDSA_MUBYTES) != 1) {
160
+ EVP_MD_CTX_free(builder->ctx);
161
+ builder->ctx = NULL;
162
+ free(builder);
163
+ return PQ_ERROR_OPENSSL;
164
+ }
165
+
166
+ EVP_MD_CTX_free(builder->ctx);
167
+ builder->ctx = NULL;
168
+ free(builder);
287
169
  return PQ_SUCCESS;
288
170
  }
289
171
 
@@ -291,7 +173,10 @@ void pq_mu_builder_release(void *state_ptr) {
291
173
  if (state_ptr == NULL) {
292
174
  return;
293
175
  }
294
- shake256incctx *state = (shake256incctx *)state_ptr;
295
- shake256_inc_ctx_release(state);
296
- free(state);
176
+ pq_mu_builder_t *builder = (pq_mu_builder_t *)state_ptr;
177
+ if (builder->ctx != NULL) {
178
+ EVP_MD_CTX_free(builder->ctx);
179
+ builder->ctx = NULL;
180
+ }
181
+ free(builder);
297
182
  }
@@ -0,0 +1,129 @@
1
+ #ifndef PQCRYPTO_NATIVE_API_H
2
+ #define PQCRYPTO_NATIVE_API_H
3
+
4
+ #include <stddef.h>
5
+ #include <stdint.h>
6
+
7
+ /*
8
+ * pq_crypto now builds only against PQ Code Package native libraries:
9
+ * vendor/mlkem-native/mlkem
10
+ * vendor/mldsa-native/mldsa
11
+ *
12
+ * The concrete public symbols below are produced by compiling each package as a
13
+ * multi-level build with:
14
+ * MLK_CONFIG_NAMESPACE_PREFIX=pqcr_mlkem
15
+ * MLD_CONFIG_NAMESPACE_PREFIX=pqcr_mldsa
16
+ * and MLK/MLD_CONFIG_MULTILEVEL_BUILD enabled. Do not add PQClean aliases here:
17
+ * we want one backend only so build/runtime failures point at the new stack.
18
+ */
19
+
20
+ #define MLKEM512_SECRETKEYBYTES 1632
21
+ #define MLKEM512_PUBLICKEYBYTES 800
22
+ #define MLKEM512_CIPHERTEXTBYTES 768
23
+ #define MLKEM512_SHAREDSECRETBYTES 32
24
+
25
+ #define MLKEM768_SECRETKEYBYTES 2400
26
+ #define MLKEM768_PUBLICKEYBYTES 1184
27
+ #define MLKEM768_CIPHERTEXTBYTES 1088
28
+ #define MLKEM768_SHAREDSECRETBYTES 32
29
+
30
+ #define MLKEM1024_SECRETKEYBYTES 3168
31
+ #define MLKEM1024_PUBLICKEYBYTES 1568
32
+ #define MLKEM1024_CIPHERTEXTBYTES 1568
33
+ #define MLKEM1024_SHAREDSECRETBYTES 32
34
+
35
+ #define MLKEM_PUBLICKEYBYTES MLKEM768_PUBLICKEYBYTES
36
+ #define MLKEM_SECRETKEYBYTES MLKEM768_SECRETKEYBYTES
37
+ #define MLKEM_CIPHERTEXTBYTES MLKEM768_CIPHERTEXTBYTES
38
+ #define MLKEM_SHAREDSECRETBYTES MLKEM768_SHAREDSECRETBYTES
39
+
40
+ #define MLDSA44_SECRETKEYBYTES 2560
41
+ #define MLDSA44_PUBLICKEYBYTES 1312
42
+ #define MLDSA44_BYTES 2420
43
+
44
+ #define MLDSA65_SECRETKEYBYTES 4032
45
+ #define MLDSA65_PUBLICKEYBYTES 1952
46
+ #define MLDSA65_BYTES 3309
47
+
48
+ #define MLDSA87_SECRETKEYBYTES 4896
49
+ #define MLDSA87_PUBLICKEYBYTES 2592
50
+ #define MLDSA87_BYTES 4627
51
+
52
+ #define MLDSA_PUBLICKEYBYTES MLDSA65_PUBLICKEYBYTES
53
+ #define MLDSA_SECRETKEYBYTES MLDSA65_SECRETKEYBYTES
54
+ #define MLDSA_BYTES MLDSA65_BYTES
55
+ #define MLDSA_SEEDBYTES 32
56
+ #define MLDSA_RNDBYTES 32
57
+ #define MLDSA_TRBYTES 64
58
+ #define MLDSA_CRHBYTES 64
59
+ #define MLDSA_DOMAIN_SEPARATION_MAX_BYTES (2 + 255 + 11 + 64)
60
+ #define MLDSA_PREHASH_NONE 0
61
+
62
+ /* mlkem-native symbols: namespace prefix pqcr_mlkem + level suffix. */
63
+ int pqcr_mlkem512_keypair(uint8_t *pk, uint8_t *sk);
64
+ int pqcr_mlkem512_keypair_derand(uint8_t *pk, uint8_t *sk, const uint8_t *coins);
65
+ int pqcr_mlkem512_enc(uint8_t *ct, uint8_t *ss, const uint8_t *pk);
66
+ int pqcr_mlkem512_enc_derand(uint8_t *ct, uint8_t *ss, const uint8_t *pk, const uint8_t *coins);
67
+ int pqcr_mlkem512_dec(uint8_t *ss, const uint8_t *ct, const uint8_t *sk);
68
+
69
+ int pqcr_mlkem768_keypair(uint8_t *pk, uint8_t *sk);
70
+ int pqcr_mlkem768_keypair_derand(uint8_t *pk, uint8_t *sk, const uint8_t *coins);
71
+ int pqcr_mlkem768_enc(uint8_t *ct, uint8_t *ss, const uint8_t *pk);
72
+ int pqcr_mlkem768_enc_derand(uint8_t *ct, uint8_t *ss, const uint8_t *pk, const uint8_t *coins);
73
+ int pqcr_mlkem768_dec(uint8_t *ss, const uint8_t *ct, const uint8_t *sk);
74
+
75
+ int pqcr_mlkem1024_keypair(uint8_t *pk, uint8_t *sk);
76
+ int pqcr_mlkem1024_keypair_derand(uint8_t *pk, uint8_t *sk, const uint8_t *coins);
77
+ int pqcr_mlkem1024_enc(uint8_t *ct, uint8_t *ss, const uint8_t *pk);
78
+ int pqcr_mlkem1024_enc_derand(uint8_t *ct, uint8_t *ss, const uint8_t *pk, const uint8_t *coins);
79
+ int pqcr_mlkem1024_dec(uint8_t *ss, const uint8_t *ct, const uint8_t *sk);
80
+
81
+ /* mldsa-native symbols: namespace prefix pqcr_mldsa + level suffix. */
82
+ int pqcr_mldsa44_keypair(uint8_t *pk, uint8_t *sk);
83
+ int pqcr_mldsa44_keypair_internal(uint8_t *pk, uint8_t *sk, const uint8_t seed[MLDSA_SEEDBYTES]);
84
+ int pqcr_mldsa44_signature(uint8_t *sig, size_t *siglen, const uint8_t *m, size_t mlen,
85
+ const uint8_t *ctx, size_t ctxlen, const uint8_t *sk);
86
+ int pqcr_mldsa44_signature_internal(uint8_t *sig, size_t *siglen, const uint8_t *m,
87
+ size_t mlen, const uint8_t *pre, size_t prelen,
88
+ const uint8_t rnd[MLDSA_RNDBYTES], const uint8_t *sk,
89
+ int externalmu);
90
+ int pqcr_mldsa44_verify(const uint8_t *sig, size_t siglen, const uint8_t *m, size_t mlen,
91
+ const uint8_t *ctx, size_t ctxlen, const uint8_t *pk);
92
+ size_t pqcr_mldsa44_prepare_domain_separation_prefix(
93
+ uint8_t prefix[MLDSA_DOMAIN_SEPARATION_MAX_BYTES], const uint8_t *ph, size_t phlen,
94
+ const uint8_t *ctx, size_t ctxlen, int hashalg);
95
+
96
+ int pqcr_mldsa65_keypair(uint8_t *pk, uint8_t *sk);
97
+ int pqcr_mldsa65_keypair_internal(uint8_t *pk, uint8_t *sk, const uint8_t seed[MLDSA_SEEDBYTES]);
98
+ int pqcr_mldsa65_signature(uint8_t *sig, size_t *siglen, const uint8_t *m, size_t mlen,
99
+ const uint8_t *ctx, size_t ctxlen, const uint8_t *sk);
100
+ int pqcr_mldsa65_signature_internal(uint8_t *sig, size_t *siglen, const uint8_t *m,
101
+ size_t mlen, const uint8_t *pre, size_t prelen,
102
+ const uint8_t rnd[MLDSA_RNDBYTES], const uint8_t *sk,
103
+ int externalmu);
104
+ int pqcr_mldsa65_verify(const uint8_t *sig, size_t siglen, const uint8_t *m, size_t mlen,
105
+ const uint8_t *ctx, size_t ctxlen, const uint8_t *pk);
106
+ size_t pqcr_mldsa65_prepare_domain_separation_prefix(
107
+ uint8_t prefix[MLDSA_DOMAIN_SEPARATION_MAX_BYTES], const uint8_t *ph, size_t phlen,
108
+ const uint8_t *ctx, size_t ctxlen, int hashalg);
109
+ int pqcr_mldsa65_signature_extmu(uint8_t *sig, size_t *siglen, const uint8_t mu[MLDSA_CRHBYTES],
110
+ const uint8_t *sk);
111
+ int pqcr_mldsa65_verify_extmu(const uint8_t *sig, size_t siglen, const uint8_t mu[MLDSA_CRHBYTES],
112
+ const uint8_t *pk);
113
+ int pqcr_mldsa65_pk_from_sk(uint8_t *pk, const uint8_t *sk);
114
+
115
+ int pqcr_mldsa87_keypair(uint8_t *pk, uint8_t *sk);
116
+ int pqcr_mldsa87_keypair_internal(uint8_t *pk, uint8_t *sk, const uint8_t seed[MLDSA_SEEDBYTES]);
117
+ int pqcr_mldsa87_signature(uint8_t *sig, size_t *siglen, const uint8_t *m, size_t mlen,
118
+ const uint8_t *ctx, size_t ctxlen, const uint8_t *sk);
119
+ int pqcr_mldsa87_signature_internal(uint8_t *sig, size_t *siglen, const uint8_t *m,
120
+ size_t mlen, const uint8_t *pre, size_t prelen,
121
+ const uint8_t rnd[MLDSA_RNDBYTES], const uint8_t *sk,
122
+ int externalmu);
123
+ int pqcr_mldsa87_verify(const uint8_t *sig, size_t siglen, const uint8_t *m, size_t mlen,
124
+ const uint8_t *ctx, size_t ctxlen, const uint8_t *pk);
125
+ size_t pqcr_mldsa87_prepare_domain_separation_prefix(
126
+ uint8_t prefix[MLDSA_DOMAIN_SEPARATION_MAX_BYTES], const uint8_t *ph, size_t phlen,
127
+ const uint8_t *ctx, size_t ctxlen, int hashalg);
128
+
129
+ #endif