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,4 +1,5 @@
1
1
  #include "pqcrypto_secure.h"
2
+ #include "pqcrypto_version.h"
2
3
 
3
4
  #include <stdio.h>
4
5
  #include <sys/types.h>
@@ -21,12 +22,7 @@
21
22
  #error "OpenSSL 3.0 or later is required for pq_crypto"
22
23
  #endif
23
24
 
24
- #ifndef HAVE_PQCLEAN
25
- #error "PQClean-backed algorithms are required. Run: bundle exec rake vendor"
26
- #endif
27
-
28
- #include "mlkem_api.h"
29
- #include "mldsa_api.h"
25
+ #include "pqcrypto_native_api.h"
30
26
 
31
27
  void pq_secure_wipe(void *ptr, size_t len) {
32
28
  if (ptr == NULL) {
@@ -49,15 +45,6 @@ static int pq_size_add(size_t a, size_t b, size_t *out) {
49
45
  return PQ_SUCCESS;
50
46
  }
51
47
 
52
- static int pq_size_mul(size_t a, size_t b, size_t *out) {
53
- if (!out)
54
- return PQ_ERROR_BUFFER;
55
- if (a != 0 && SIZE_MAX / a < b)
56
- return PQ_ERROR_BUFFER;
57
- *out = a * b;
58
- return PQ_SUCCESS;
59
- }
60
-
61
48
  static int pq_is_pem_whitespace(char c) {
62
49
  return c == '\n' || c == '\r' || c == ' ' || c == '\t';
63
50
  }
@@ -231,8 +218,7 @@ static int xwing_expand_secret_key(hybrid_expanded_secret_key_t *expanded_key,
231
218
  if (EVP_DigestFinalXOF(ctx, expanded, sizeof(expanded)) != 1)
232
219
  goto cleanup;
233
220
 
234
- ret = PQCLEAN_MLKEM768_CLEAN_crypto_kem_keypair_derand(expanded_key->mlkem_pk,
235
- expanded_key->mlkem_sk, expanded);
221
+ ret = pqcr_mlkem768_keypair_derand(expanded_key->mlkem_pk, expanded_key->mlkem_sk, expanded);
236
222
  if (ret != 0) {
237
223
  ret = PQ_ERROR_KEYPAIR;
238
224
  goto cleanup;
@@ -256,99 +242,238 @@ cleanup:
256
242
  return ret;
257
243
  }
258
244
 
259
- int pq_mlkem_keypair(uint8_t *pk, uint8_t *sk) {
260
- return PQCLEAN_MLKEM768_CLEAN_crypto_kem_keypair(pk, sk) == 0 ? PQ_SUCCESS : PQ_ERROR_KEYPAIR;
261
- }
245
+ #define PQ_MLKEM_VARIANTS(X) \
246
+ X(mlkem, pqcr_mlkem768) \
247
+ X(mlkem512, pqcr_mlkem512) \
248
+ X(mlkem1024, pqcr_mlkem1024)
249
+
250
+ #define PQ_DEFINE_MLKEM_SHIMS(prefix, native) \
251
+ int pq_##prefix##_keypair(uint8_t *pk, uint8_t *sk) { \
252
+ if (!pk || !sk) { \
253
+ return PQ_ERROR_BUFFER; \
254
+ } \
255
+ return native##_keypair(pk, sk) == 0 ? PQ_SUCCESS : PQ_ERROR_KEYPAIR; \
256
+ } \
257
+ int pq_##prefix##_keypair_from_seed(uint8_t *pk, uint8_t *sk, const uint8_t *seed64) {\
258
+ if (!pk || !sk || !seed64) { \
259
+ return PQ_ERROR_BUFFER; \
260
+ } \
261
+ return native##_keypair_derand(pk, sk, seed64) == 0 ? PQ_SUCCESS \
262
+ : PQ_ERROR_KEYPAIR; \
263
+ } \
264
+ int pq_##prefix##_encapsulate(uint8_t *ct, uint8_t *ss, const uint8_t *pk) { \
265
+ if (!ct || !ss || !pk) { \
266
+ return PQ_ERROR_BUFFER; \
267
+ } \
268
+ return native##_enc(ct, ss, pk) == 0 ? PQ_SUCCESS : PQ_ERROR_ENCAPSULATE; \
269
+ } \
270
+ int pq_##prefix##_decapsulate(uint8_t *ss, const uint8_t *ct, const uint8_t *sk) { \
271
+ if (!ss || !ct || !sk) { \
272
+ return PQ_ERROR_BUFFER; \
273
+ } \
274
+ return native##_dec(ss, ct, sk) == 0 ? PQ_SUCCESS : PQ_ERROR_DECAPSULATE; \
275
+ }
262
276
 
263
- int pq_mlkem_encapsulate(uint8_t *ct, uint8_t *ss, const uint8_t *pk) {
264
- return PQCLEAN_MLKEM768_CLEAN_crypto_kem_enc(ct, ss, pk) == 0 ? PQ_SUCCESS
265
- : PQ_ERROR_ENCAPSULATE;
266
- }
277
+ PQ_MLKEM_VARIANTS(PQ_DEFINE_MLKEM_SHIMS)
267
278
 
268
- int pq_mlkem_decapsulate(uint8_t *ss, const uint8_t *ct, const uint8_t *sk) {
269
- return PQCLEAN_MLKEM768_CLEAN_crypto_kem_dec(ss, ct, sk) == 0 ? PQ_SUCCESS
270
- : PQ_ERROR_DECAPSULATE;
279
+ #undef PQ_DEFINE_MLKEM_SHIMS
280
+
281
+ static int pq_testing_mlkem_keypair_from_seed_with(uint8_t *public_key, uint8_t *secret_key,
282
+ const uint8_t *seed, size_t seed_len,
283
+ int (*keypair_derand)(uint8_t *, uint8_t *,
284
+ const uint8_t *)) {
285
+ if (!public_key || !secret_key || !seed || seed_len != 64 || !keypair_derand) {
286
+ return PQ_ERROR_BUFFER;
287
+ }
288
+ return keypair_derand(public_key, secret_key, seed) == 0 ? PQ_SUCCESS : PQ_ERROR_KEYPAIR;
271
289
  }
272
290
 
273
- int pq_testing_mlkem_keypair_from_seed(uint8_t *public_key, uint8_t *secret_key,
274
- const uint8_t *seed, size_t seed_len) {
275
- if (!public_key || !secret_key || !seed || seed_len != 64) {
291
+ static int pq_testing_mlkem_encapsulate_from_seed_with(
292
+ uint8_t *ciphertext, uint8_t *shared_secret, const uint8_t *public_key, const uint8_t *seed,
293
+ size_t seed_len, int (*enc_derand)(uint8_t *, uint8_t *, const uint8_t *, const uint8_t *)) {
294
+ if (!ciphertext || !shared_secret || !public_key || !seed || seed_len != 32 || !enc_derand) {
276
295
  return PQ_ERROR_BUFFER;
277
296
  }
278
- return PQCLEAN_MLKEM768_CLEAN_crypto_kem_keypair_derand(public_key, secret_key, seed) == 0
279
- ? PQ_SUCCESS
280
- : PQ_ERROR_KEYPAIR;
297
+ return enc_derand(ciphertext, shared_secret, public_key, seed) == 0 ? PQ_SUCCESS
298
+ : PQ_ERROR_ENCAPSULATE;
281
299
  }
282
300
 
283
- int pq_testing_mlkem_encapsulate_from_seed(uint8_t *ciphertext, uint8_t *shared_secret,
284
- const uint8_t *public_key, const uint8_t *seed,
285
- size_t seed_len) {
286
- if (!ciphertext || !shared_secret || !public_key || !seed || seed_len != 32) {
301
+ #define PQ_DEFINE_MLKEM_TESTING_SHIMS(prefix, native) \
302
+ int pq_testing_##prefix##_keypair_from_seed(uint8_t *public_key, uint8_t *secret_key, \
303
+ const uint8_t *seed, size_t seed_len) { \
304
+ return pq_testing_mlkem_keypair_from_seed_with(public_key, secret_key, seed, seed_len, \
305
+ native##_keypair_derand); \
306
+ } \
307
+ int pq_testing_##prefix##_encapsulate_from_seed(uint8_t *ciphertext, uint8_t *shared_secret,\
308
+ const uint8_t *public_key, \
309
+ const uint8_t *seed, size_t seed_len) { \
310
+ return pq_testing_mlkem_encapsulate_from_seed_with(ciphertext, shared_secret, public_key,\
311
+ seed, seed_len, native##_enc_derand);\
312
+ }
313
+
314
+ PQ_MLKEM_VARIANTS(PQ_DEFINE_MLKEM_TESTING_SHIMS)
315
+
316
+ #undef PQ_DEFINE_MLKEM_TESTING_SHIMS
317
+
318
+ #define PQ_DEFINE_MLDSA_SIGN_KEYPAIR(prefix, native) \
319
+ int pq_##prefix##_keypair(uint8_t *public_key, uint8_t *secret_key) { \
320
+ if (!public_key || !secret_key) { \
321
+ return PQ_ERROR_BUFFER; \
322
+ } \
323
+ return native##_keypair(public_key, secret_key) == 0 ? PQ_SUCCESS \
324
+ : PQ_ERROR_KEYPAIR; \
325
+ }
326
+
327
+ PQ_DEFINE_MLDSA_SIGN_KEYPAIR(sign, pqcr_mldsa65)
328
+ PQ_DEFINE_MLDSA_SIGN_KEYPAIR(mldsa44_sign, pqcr_mldsa44)
329
+ PQ_DEFINE_MLDSA_SIGN_KEYPAIR(mldsa87_sign, pqcr_mldsa87)
330
+
331
+ #undef PQ_DEFINE_MLDSA_SIGN_KEYPAIR
332
+
333
+ #define PQ_DEFINE_MLDSA_SIGN(name, native) \
334
+ int pq_##name(uint8_t *signature, size_t *signature_len, const uint8_t *message, \
335
+ size_t message_len, const uint8_t *secret_key) { \
336
+ if (!signature || !signature_len || !secret_key || (message_len > 0 && !message)) {\
337
+ return PQ_ERROR_BUFFER; \
338
+ } \
339
+ return native##_signature(signature, signature_len, message, message_len, NULL, 0,\
340
+ secret_key) == 0 \
341
+ ? PQ_SUCCESS \
342
+ : PQ_ERROR_SIGN; \
343
+ }
344
+
345
+ PQ_DEFINE_MLDSA_SIGN(sign, pqcr_mldsa65)
346
+ PQ_DEFINE_MLDSA_SIGN(mldsa44_sign, pqcr_mldsa44)
347
+ PQ_DEFINE_MLDSA_SIGN(mldsa87_sign, pqcr_mldsa87)
348
+
349
+ #undef PQ_DEFINE_MLDSA_SIGN
350
+
351
+ #define PQ_DEFINE_MLDSA_VERIFY(name, native) \
352
+ int pq_##name(const uint8_t *signature, size_t signature_len, const uint8_t *message, \
353
+ size_t message_len, const uint8_t *public_key) { \
354
+ if (!signature || !public_key || (message_len > 0 && !message)) { \
355
+ return PQ_ERROR_BUFFER; \
356
+ } \
357
+ return native##_verify(signature, signature_len, message, message_len, NULL, 0, \
358
+ public_key) == 0 \
359
+ ? PQ_SUCCESS \
360
+ : PQ_ERROR_VERIFY; \
361
+ }
362
+
363
+ PQ_DEFINE_MLDSA_VERIFY(verify, pqcr_mldsa65)
364
+ PQ_DEFINE_MLDSA_VERIFY(mldsa44_verify, pqcr_mldsa44)
365
+ PQ_DEFINE_MLDSA_VERIFY(mldsa87_verify, pqcr_mldsa87)
366
+
367
+ #undef PQ_DEFINE_MLDSA_VERIFY
368
+
369
+ static int pq_testing_mldsa_sign_from_seed_with(
370
+ uint8_t *signature, size_t *signature_len, const uint8_t *message, size_t message_len,
371
+ const uint8_t *secret_key, const uint8_t *seed, size_t seed_len,
372
+ int (*signature_internal)(uint8_t *, size_t *, const uint8_t *, size_t, const uint8_t *, size_t,
373
+ const uint8_t *, const uint8_t *, int),
374
+ size_t (*prepare_prefix)(uint8_t *, const uint8_t *, size_t, const uint8_t *, size_t, int)) {
375
+ uint8_t pre[MLDSA_DOMAIN_SEPARATION_MAX_BYTES];
376
+ size_t pre_len;
377
+
378
+ if (!signature || !signature_len || !secret_key || !seed || seed_len != MLDSA_RNDBYTES ||
379
+ !signature_internal || !prepare_prefix || (message_len > 0 && !message)) {
287
380
  return PQ_ERROR_BUFFER;
288
381
  }
289
- return PQCLEAN_MLKEM768_CLEAN_crypto_kem_enc_derand(ciphertext, shared_secret, public_key,
290
- seed) == 0
382
+
383
+ /*
384
+ * mldsa-native's signature_internal is lower-level than the public pure
385
+ * ML-DSA signing API. It expects the FIPS 204 domain-separation prefix explicitly. Passing
386
+ * NULL/0 signs CRH(tr, message) instead of CRH(tr, 0x00 || ctxlen || ctx || message),
387
+ * which produces signatures that do not verify through the public pure-ML-DSA API
388
+ * and do not match ACVP/KAT sigGen vectors.
389
+ */
390
+ pre_len = prepare_prefix(pre, NULL, 0, NULL, 0, MLDSA_PREHASH_NONE);
391
+ if (pre_len == 0) {
392
+ return PQ_ERROR_SIGN;
393
+ }
394
+
395
+ return signature_internal(signature, signature_len, message, message_len, pre, pre_len, seed,
396
+ secret_key, 0) == 0
291
397
  ? PQ_SUCCESS
292
- : PQ_ERROR_ENCAPSULATE;
398
+ : PQ_ERROR_SIGN;
293
399
  }
294
400
 
295
- int pq_sign_keypair(uint8_t *public_key, uint8_t *secret_key) {
296
- return PQCLEAN_MLDSA65_CLEAN_crypto_sign_keypair(public_key, secret_key) == 0
297
- ? PQ_SUCCESS
298
- : PQ_ERROR_KEYPAIR;
401
+ int pq_mldsa44_keypair_from_seed(uint8_t *public_key, uint8_t *secret_key, const uint8_t *seed32) {
402
+ if (!public_key || !secret_key || !seed32) {
403
+ return PQ_ERROR_BUFFER;
404
+ }
405
+ return pqcr_mldsa44_keypair_internal(public_key, secret_key, seed32) == 0 ? PQ_SUCCESS
406
+ : PQ_ERROR_KEYPAIR;
299
407
  }
300
408
 
301
- int pq_sign(uint8_t *signature, size_t *signature_len, const uint8_t *message, size_t message_len,
302
- const uint8_t *secret_key) {
303
- return PQCLEAN_MLDSA65_CLEAN_crypto_sign_signature(signature, signature_len, message,
304
- message_len, secret_key) == 0
305
- ? PQ_SUCCESS
306
- : PQ_ERROR_SIGN;
409
+ int pq_mldsa_keypair_from_seed(uint8_t *public_key, uint8_t *secret_key, const uint8_t *seed32) {
410
+ if (!public_key || !secret_key || !seed32) {
411
+ return PQ_ERROR_BUFFER;
412
+ }
413
+ return pqcr_mldsa65_keypair_internal(public_key, secret_key, seed32) == 0 ? PQ_SUCCESS
414
+ : PQ_ERROR_KEYPAIR;
307
415
  }
308
416
 
309
- int pq_verify(const uint8_t *signature, size_t signature_len, const uint8_t *message,
310
- size_t message_len, const uint8_t *public_key) {
311
- return PQCLEAN_MLDSA65_CLEAN_crypto_sign_verify(signature, signature_len, message, message_len,
312
- public_key) == 0
313
- ? PQ_SUCCESS
314
- : PQ_ERROR_VERIFY;
417
+ int pq_mldsa87_keypair_from_seed(uint8_t *public_key, uint8_t *secret_key, const uint8_t *seed32) {
418
+ if (!public_key || !secret_key || !seed32) {
419
+ return PQ_ERROR_BUFFER;
420
+ }
421
+ return pqcr_mldsa87_keypair_internal(public_key, secret_key, seed32) == 0 ? PQ_SUCCESS
422
+ : PQ_ERROR_KEYPAIR;
315
423
  }
316
424
 
317
425
  int pq_testing_mldsa_keypair_from_seed(uint8_t *public_key, uint8_t *secret_key,
318
426
  const uint8_t *seed, size_t seed_len) {
319
- int rc;
320
- if (!public_key || !secret_key || !seed) {
427
+ if (seed_len != MLDSA_SEEDBYTES) {
321
428
  return PQ_ERROR_BUFFER;
322
429
  }
430
+ return pq_mldsa_keypair_from_seed(public_key, secret_key, seed);
431
+ }
323
432
 
324
- if (seed_len != 32) {
433
+ int pq_testing_mldsa44_keypair_from_seed(uint8_t *public_key, uint8_t *secret_key,
434
+ const uint8_t *seed, size_t seed_len) {
435
+ if (seed_len != MLDSA_SEEDBYTES) {
325
436
  return PQ_ERROR_BUFFER;
326
437
  }
438
+ return pq_mldsa44_keypair_from_seed(public_key, secret_key, seed);
439
+ }
327
440
 
328
- pq_testing_set_seed(seed, seed_len);
329
- rc = PQCLEAN_MLDSA65_CLEAN_crypto_sign_keypair(public_key, secret_key);
330
- pq_testing_clear_seed();
331
- return rc == 0 ? PQ_SUCCESS : PQ_ERROR_KEYPAIR;
441
+ int pq_testing_mldsa87_keypair_from_seed(uint8_t *public_key, uint8_t *secret_key,
442
+ const uint8_t *seed, size_t seed_len) {
443
+ if (seed_len != MLDSA_SEEDBYTES) {
444
+ return PQ_ERROR_BUFFER;
445
+ }
446
+ return pq_mldsa87_keypair_from_seed(public_key, secret_key, seed);
332
447
  }
333
448
 
334
449
  int pq_testing_mldsa_sign_from_seed(uint8_t *signature, size_t *signature_len,
335
450
  const uint8_t *message, size_t message_len,
336
451
  const uint8_t *secret_key, const uint8_t *seed,
337
452
  size_t seed_len) {
338
- int rc;
339
- if (!signature || !signature_len || !secret_key || !seed) {
340
- return PQ_ERROR_BUFFER;
341
- }
453
+ return pq_testing_mldsa_sign_from_seed_with(signature, signature_len, message, message_len,
454
+ secret_key, seed, seed_len,
455
+ pqcr_mldsa65_signature_internal,
456
+ pqcr_mldsa65_prepare_domain_separation_prefix);
457
+ }
342
458
 
343
- if (seed_len != 32) {
344
- return PQ_ERROR_BUFFER;
345
- }
459
+ int pq_testing_mldsa44_sign_from_seed(uint8_t *signature, size_t *signature_len,
460
+ const uint8_t *message, size_t message_len,
461
+ const uint8_t *secret_key, const uint8_t *seed,
462
+ size_t seed_len) {
463
+ return pq_testing_mldsa_sign_from_seed_with(signature, signature_len, message, message_len,
464
+ secret_key, seed, seed_len,
465
+ pqcr_mldsa44_signature_internal,
466
+ pqcr_mldsa44_prepare_domain_separation_prefix);
467
+ }
346
468
 
347
- pq_testing_set_seed(seed, seed_len);
348
- rc = PQCLEAN_MLDSA65_CLEAN_crypto_sign_signature(signature, signature_len, message, message_len,
349
- secret_key);
350
- pq_testing_clear_seed();
351
- return rc == 0 ? PQ_SUCCESS : PQ_ERROR_SIGN;
469
+ int pq_testing_mldsa87_sign_from_seed(uint8_t *signature, size_t *signature_len,
470
+ const uint8_t *message, size_t message_len,
471
+ const uint8_t *secret_key, const uint8_t *seed,
472
+ size_t seed_len) {
473
+ return pq_testing_mldsa_sign_from_seed_with(signature, signature_len, message, message_len,
474
+ secret_key, seed, seed_len,
475
+ pqcr_mldsa87_signature_internal,
476
+ pqcr_mldsa87_prepare_domain_separation_prefix);
352
477
  }
353
478
 
354
479
  int pq_hybrid_kem_keypair(uint8_t *public_key, uint8_t *secret_key) {
@@ -405,7 +530,7 @@ int pq_hybrid_kem_encapsulate(uint8_t *ciphertext, uint8_t *shared_secret,
405
530
  memset(x25519_ss, 0, sizeof(x25519_ss));
406
531
  memset(x25519_ephemeral_sk, 0, sizeof(x25519_ephemeral_sk));
407
532
 
408
- if (PQCLEAN_MLKEM768_CLEAN_crypto_kem_enc(ct.mlkem_ct, mlkem_ss, pk.mlkem_pk) != 0) {
533
+ if (pqcr_mlkem768_enc(ct.mlkem_ct, mlkem_ss, pk.mlkem_pk) != 0) {
409
534
  ret = PQ_ERROR_ENCAPSULATE;
410
535
  goto cleanup;
411
536
  }
@@ -459,7 +584,7 @@ int pq_hybrid_kem_decapsulate(uint8_t *shared_secret, const uint8_t *ciphertext,
459
584
  goto cleanup;
460
585
  }
461
586
 
462
- if (PQCLEAN_MLKEM768_CLEAN_crypto_kem_dec(mlkem_ss, ct.mlkem_ct, expanded.mlkem_sk) != 0) {
587
+ if (pqcr_mlkem768_dec(mlkem_ss, ct.mlkem_ct, expanded.mlkem_sk) != 0) {
463
588
  ret = PQ_ERROR_DECAPSULATE;
464
589
  goto cleanup;
465
590
  }
@@ -959,5 +1084,5 @@ int pq_secret_key_from_pqc_container_pem(char **algorithm_out, uint8_t **key_out
959
1084
  }
960
1085
 
961
1086
  const char *pq_version(void) {
962
- return "0.3.2";
1087
+ return PQCRYPTO_VERSION;
963
1088
  }
@@ -5,20 +5,7 @@
5
5
  #include <stdlib.h>
6
6
  #include <string.h>
7
7
 
8
- #ifndef HAVE_PQCLEAN
9
- #error "PQClean sources are required to build pq_crypto. Run: bundle exec rake vendor"
10
- #endif
11
-
12
- #include "mlkem_api.h"
13
- #include "mldsa_api.h"
14
- #define MLKEM_PUBLICKEYBYTES PQCLEAN_MLKEM768_CLEAN_CRYPTO_PUBLICKEYBYTES
15
- #define MLKEM_SECRETKEYBYTES PQCLEAN_MLKEM768_CLEAN_CRYPTO_SECRETKEYBYTES
16
- #define MLKEM_CIPHERTEXTBYTES PQCLEAN_MLKEM768_CLEAN_CRYPTO_CIPHERTEXTBYTES
17
- #define MLKEM_SHAREDSECRETBYTES PQCLEAN_MLKEM768_CLEAN_CRYPTO_BYTES
18
-
19
- #define MLDSA_PUBLICKEYBYTES 1952
20
- #define MLDSA_SECRETKEYBYTES 4032
21
- #define MLDSA_BYTES 3309
8
+ #include "pqcrypto_native_api.h"
22
9
 
23
10
  #define X25519_PUBLICKEYBYTES 32
24
11
  #define X25519_SECRETKEYBYTES 32
@@ -78,15 +65,45 @@ _Static_assert(sizeof(hybrid_ciphertext_t) == HYBRID_CIPHERTEXTBYTES,
78
65
  void pq_secure_wipe(void *ptr, size_t len);
79
66
 
80
67
  int pq_mlkem_keypair(uint8_t *public_key, uint8_t *secret_key);
68
+ int pq_mlkem512_keypair(uint8_t *public_key, uint8_t *secret_key);
69
+ int pq_mlkem1024_keypair(uint8_t *public_key, uint8_t *secret_key);
70
+ int pq_mlkem_keypair_from_seed(uint8_t *public_key, uint8_t *secret_key,
71
+ const uint8_t *seed64);
72
+ int pq_mlkem512_keypair_from_seed(uint8_t *public_key, uint8_t *secret_key,
73
+ const uint8_t *seed64);
74
+ int pq_mlkem1024_keypair_from_seed(uint8_t *public_key, uint8_t *secret_key,
75
+ const uint8_t *seed64);
81
76
  int pq_mlkem_encapsulate(uint8_t *ciphertext, uint8_t *shared_secret, const uint8_t *public_key);
77
+ int pq_mlkem512_encapsulate(uint8_t *ciphertext, uint8_t *shared_secret, const uint8_t *public_key);
78
+ int pq_mlkem1024_encapsulate(uint8_t *ciphertext, uint8_t *shared_secret, const uint8_t *public_key);
82
79
  int pq_mlkem_decapsulate(uint8_t *shared_secret, const uint8_t *ciphertext,
83
80
  const uint8_t *secret_key);
81
+ int pq_mlkem512_decapsulate(uint8_t *shared_secret, const uint8_t *ciphertext,
82
+ const uint8_t *secret_key);
83
+ int pq_mlkem1024_decapsulate(uint8_t *shared_secret, const uint8_t *ciphertext,
84
+ const uint8_t *secret_key);
84
85
 
85
86
  int pq_sign_keypair(uint8_t *public_key, uint8_t *secret_key);
87
+ int pq_mldsa44_sign_keypair(uint8_t *public_key, uint8_t *secret_key);
88
+ int pq_mldsa87_sign_keypair(uint8_t *public_key, uint8_t *secret_key);
89
+ int pq_mldsa44_keypair_from_seed(uint8_t *public_key, uint8_t *secret_key,
90
+ const uint8_t *seed32);
91
+ int pq_mldsa_keypair_from_seed(uint8_t *public_key, uint8_t *secret_key,
92
+ const uint8_t *seed32);
93
+ int pq_mldsa87_keypair_from_seed(uint8_t *public_key, uint8_t *secret_key,
94
+ const uint8_t *seed32);
86
95
  int pq_sign(uint8_t *signature, size_t *signature_len, const uint8_t *message, size_t message_len,
87
96
  const uint8_t *secret_key);
97
+ int pq_mldsa44_sign(uint8_t *signature, size_t *signature_len, const uint8_t *message, size_t message_len,
98
+ const uint8_t *secret_key);
99
+ int pq_mldsa87_sign(uint8_t *signature, size_t *signature_len, const uint8_t *message, size_t message_len,
100
+ const uint8_t *secret_key);
88
101
  int pq_verify(const uint8_t *signature, size_t signature_len, const uint8_t *message,
89
102
  size_t message_len, const uint8_t *public_key);
103
+ int pq_mldsa44_verify(const uint8_t *signature, size_t signature_len, const uint8_t *message,
104
+ size_t message_len, const uint8_t *public_key);
105
+ int pq_mldsa87_verify(const uint8_t *signature, size_t signature_len, const uint8_t *message,
106
+ size_t message_len, const uint8_t *public_key);
90
107
 
91
108
  int pq_public_key_to_pqc_container_der(uint8_t **output, size_t *output_len,
92
109
  const uint8_t *public_key,
@@ -115,15 +132,37 @@ int pq_secret_key_from_pqc_container_pem(char **algorithm_out, uint8_t **key_out
115
132
 
116
133
  int pq_testing_mlkem_keypair_from_seed(uint8_t *public_key, uint8_t *secret_key,
117
134
  const uint8_t *seed, size_t seed_len);
135
+ int pq_testing_mlkem512_keypair_from_seed(uint8_t *public_key, uint8_t *secret_key,
136
+ const uint8_t *seed, size_t seed_len);
137
+ int pq_testing_mlkem1024_keypair_from_seed(uint8_t *public_key, uint8_t *secret_key,
138
+ const uint8_t *seed, size_t seed_len);
118
139
  int pq_testing_mlkem_encapsulate_from_seed(uint8_t *ciphertext, uint8_t *shared_secret,
119
140
  const uint8_t *public_key, const uint8_t *seed,
120
141
  size_t seed_len);
142
+ int pq_testing_mlkem512_encapsulate_from_seed(uint8_t *ciphertext, uint8_t *shared_secret,
143
+ const uint8_t *public_key, const uint8_t *seed,
144
+ size_t seed_len);
145
+ int pq_testing_mlkem1024_encapsulate_from_seed(uint8_t *ciphertext, uint8_t *shared_secret,
146
+ const uint8_t *public_key, const uint8_t *seed,
147
+ size_t seed_len);
121
148
  int pq_testing_mldsa_keypair_from_seed(uint8_t *public_key, uint8_t *secret_key,
122
149
  const uint8_t *seed, size_t seed_len);
150
+ int pq_testing_mldsa44_keypair_from_seed(uint8_t *public_key, uint8_t *secret_key,
151
+ const uint8_t *seed, size_t seed_len);
152
+ int pq_testing_mldsa87_keypair_from_seed(uint8_t *public_key, uint8_t *secret_key,
153
+ const uint8_t *seed, size_t seed_len);
123
154
  int pq_testing_mldsa_sign_from_seed(uint8_t *signature, size_t *signature_len,
124
155
  const uint8_t *message, size_t message_len,
125
156
  const uint8_t *secret_key, const uint8_t *seed,
126
157
  size_t seed_len);
158
+ int pq_testing_mldsa44_sign_from_seed(uint8_t *signature, size_t *signature_len,
159
+ const uint8_t *message, size_t message_len,
160
+ const uint8_t *secret_key, const uint8_t *seed,
161
+ size_t seed_len);
162
+ int pq_testing_mldsa87_sign_from_seed(uint8_t *signature, size_t *signature_len,
163
+ const uint8_t *message, size_t message_len,
164
+ const uint8_t *secret_key, const uint8_t *seed,
165
+ size_t seed_len);
127
166
 
128
167
  void pq_testing_set_seed(const uint8_t *seed, size_t len);
129
168
  void pq_testing_clear_seed(void);
@@ -0,0 +1,7 @@
1
+ /* Generated by extconf.rb from lib/pq_crypto/version.rb. Do not edit. */
2
+ #ifndef PQCRYPTO_VERSION_H
3
+ #define PQCRYPTO_VERSION_H
4
+
5
+ #define PQCRYPTO_VERSION "0.5.0"
6
+
7
+ #endif
@@ -0,0 +1,9 @@
1
+ #ifndef PQCRYPTO_RANDOMBYTES_H
2
+ #define PQCRYPTO_RANDOMBYTES_H
3
+
4
+ #include <stddef.h>
5
+ #include <stdint.h>
6
+
7
+ int randombytes(uint8_t *output, size_t n);
8
+
9
+ #endif
@@ -1,5 +1,10 @@
1
- pqclean_version=2cc64716044832eea747234ddbffc06746ab815d
2
- pqclean_url=https://github.com/PQClean/PQClean/archive/2cc64716044832eea747234ddbffc06746ab815d.tar.gz
3
- pqclean_archive_sha256=0e92076a79082a8d220e27227f37b280fb2ce050af412babd2bc755ab37b871a
4
- pqclean_strip=PQClean-2cc64716044832eea747234ddbffc06746ab815d
5
- pqclean_tree_sha256=2af0c3ec2cbe3b06805c39d3d1389ee7a9b0b29a83183328374a0db55f56c19e
1
+ backend=PQ Code Package native only
2
+ pqclean=removed
3
+ mlkem_native_repo=https://github.com/pq-code-package/mlkem-native.git
4
+ mlkem_native_ref=v1.1.0
5
+ mlkem_native_commit=d2cae2be522a67bfae26100fdb520576f1b2ef90
6
+ mlkem_native_tree_sha256=368ad66b3a8092dd919d5646eb8507b8336e8f9f09c43b779dbf864700b5b8fb
7
+ mldsa_native_repo=https://github.com/pq-code-package/mldsa-native.git
8
+ mldsa_native_ref=v1.0.0-beta
9
+ mldsa_native_commit=db65535319d9750d75d34c6d170677415f9d2c46
10
+ mldsa_native_tree_sha256=9c73cd6c185bb6885a7cf0ecb56a5282a5657aa5e6c32f68f442d941baa92b3d
@@ -0,0 +1,105 @@
1
+ [//]: # (SPDX-License-Identifier: CC-BY-4.0)
2
+
3
+ # Building mldsa-native
4
+
5
+ ### Prerequisites
6
+
7
+ To build **mldsa-native**, you need `make` and a C90 compiler. To use the test scripts, you need Python3 (>= 3.7).
8
+
9
+ ### By hand
10
+
11
+ See [mldsa](mldsa).
12
+
13
+ ### Using `make`
14
+
15
+ You can build and test **mldsa-native** as follows:
16
+
17
+ ```bash
18
+ make test # With native code backend (if available)
19
+ make OPT=0 test # With C backend
20
+ ```
21
+
22
+ To merely build test components, use the following `make` targets:
23
+
24
+ ```bash
25
+ make func
26
+ make kat
27
+ make acvp
28
+ ```
29
+
30
+ To run them, add `run_`:
31
+
32
+ ```bash
33
+ make run_func
34
+ make run_kat
35
+ make run_acvp
36
+ ```
37
+
38
+ The resulting binaries can be found in `test/build` (their full path is printed by `make`).
39
+
40
+ For benchmarking, specify the cycle counting method. Currently, **mldsa-native** is supporting NO, PERF, PMU, and MAC:
41
+ * `NO` means that no cycle counting will be used; this can be used to confirm that benchmarks compile fine.
42
+ * `PERF` uses the `perf` kernel module for cycle counting. Does not work on Apple platforms.
43
+ * `PMU` uses direct PMU access if available. On AArch64, this may require you to load a kernel module first, see [here](https://github.com/mupq/pqax?tab=readme-ov-file#enable-access-to-performance-counters). Does not work on Apple platforms.
44
+ * `MAC` is `perf`-based and works on some Apple platforms, at least Apple M1.
45
+
46
+ ```
47
+ # CYCLES has to be one of PERF, PMU, MAC, NO
48
+ sudo make run_bench CYCLES=PERF
49
+ sudo make run_bench_components CYCLES=PERF
50
+ ```
51
+
52
+ ### Using `tests` script
53
+
54
+ For convenience, you can also use the [`./scripts/tests`](scripts/tests) script as a wrapper around `make`. For
55
+ example,
56
+
57
+ ```bash
58
+ ./scripts/tests func
59
+ ```
60
+
61
+ will compile and run functionality tests. Similarly,
62
+
63
+ ```bash
64
+ ./scripts/tests bench -c PERF -r
65
+ ```
66
+
67
+ will compile and run benchmarks, using PERF for cycle counting (`-c PERF`) and running as root (`-r`).
68
+
69
+ For detailed information on how to use the script, please refer to
70
+ `./scripts/tests --help`.
71
+
72
+ ### Windows
73
+
74
+ You can also build **mldsa-native** on Windows using `nmake` and an MSVC compiler.
75
+
76
+ To build and run the tests (only support functional testing for non-opt implementation for now), use the following `nmake` targets:
77
+ ```powershell
78
+ nmke /f .\Makefile.Microsoft_nmake quickcheck
79
+ ```
80
+
81
+ # Checking the proofs
82
+
83
+ ## CBMC
84
+
85
+ ### Prerequisites
86
+
87
+ To run the CBMC proofs, you need specific versions of CBMC and the underlying solvers, e.g. as specified in our `nix` environment; see [nix/cbmc](nix/cbmc/).
88
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for instructions on how to setup and use `nix`.
89
+
90
+ ### Running the CBMC proofs
91
+
92
+ Once you are in the `nix` shell or have all tools setup by hand, use `./scripts/tests cbmc` (or just `tests cbmc` in the `nix` shell) to re-check the CBMC proofs.
93
+ See `tests cbmc --help` for details on the command line options, and [proofs/cbmc](proofs/cbmc) for more details on the CBMC proofs in general.
94
+
95
+ ## HOL-Light
96
+
97
+ ### Prerequisites
98
+
99
+ To run the HOL-Light proofs, you need recent versions of HOL-Light and s2n-bignum, e.g. as specified in our `nix` environment; see [nix/s2n_bignum](nix/s2n_bignum) and [nix/hol_light](nix/hol_light).
100
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for instructions on how to setup and use `nix`.
101
+
102
+ ### Running the HOL-Light proofs
103
+
104
+ Once you are in the `nix` shell or have all tools setup by hand, use `./scripts/tests hol_light` (or just `tests hol_light` in the `nix` shell) to re-check the HOL-Light proofs. Note that depending on the function, they will take a long time. See `tests hol_light --help` for details on the command line options, and [proofs/hol_light](proofs/hol_light) for more details on the HOL-Light proofs in general.
105
+