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
@@ -0,0 +1,464 @@
1
+ /*
2
+ * Copyright (c) The mlkem-native project authors
3
+ * SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
4
+ */
5
+
6
+ /* References
7
+ * ==========
8
+ *
9
+ * - [FIPS203]
10
+ * FIPS 203 Module-Lattice-Based Key-Encapsulation Mechanism Standard
11
+ * National Institute of Standards and Technology
12
+ * https://csrc.nist.gov/pubs/fips/203/final
13
+ *
14
+ * - [REF]
15
+ * CRYSTALS-Kyber C reference implementation
16
+ * Bos, Ducas, Kiltz, Lepoint, Lyubashevsky, Schanck, Schwabe, Seiler, Stehlé
17
+ * https://github.com/pq-crystals/kyber/tree/main/ref
18
+ *
19
+ * - [libmceliece]
20
+ * libmceliece implementation of Classic McEliece
21
+ * Bernstein, Chou
22
+ * https://lib.mceliece.org/
23
+ *
24
+ * - [optblocker]
25
+ * PQC forum post on opt-blockers using volatile globals
26
+ * Daniel J. Bernstein
27
+ * https://groups.google.com/a/list.nist.gov/g/pqc-forum/c/hqbtIGFKIpU/m/H14H0wOlBgAJ
28
+ */
29
+
30
+ #ifndef MLK_VERIFY_H
31
+ #define MLK_VERIFY_H
32
+
33
+
34
+ #include "cbmc.h"
35
+ #include "common.h"
36
+
37
+ /* Constant-time comparisons and conditional operations
38
+
39
+ We reduce the risk for compilation into variable-time code
40
+ through the use of 'value barriers'.
41
+
42
+ Functionally, a value barrier is a no-op. To the compiler, however,
43
+ it constitutes an arbitrary modification of its input, and therefore
44
+ harden's value propagation and range analysis.
45
+
46
+ We consider two approaches to implement a value barrier:
47
+ - An empty inline asm block which marks the target value as clobbered.
48
+ - XOR'ing with the value of a volatile global that's set to 0;
49
+ see @[optblocker] for a discussion of this idea, and
50
+ @[libmceliece, inttypes/crypto_intN.h] for an implementation.
51
+
52
+ The first approach is cheap because it only prevents the compiler
53
+ from reasoning about the value of the variable past the barrier,
54
+ but does not directly generate additional instructions.
55
+
56
+ The second approach generates redundant loads and XOR operations
57
+ and therefore comes at a higher runtime cost. However, it appears
58
+ more robust towards optimization, as compilers should never drop
59
+ a volatile load.
60
+
61
+ We use the empty-ASM value barrier for GCC and clang, and fall
62
+ back to the global volatile barrier otherwise.
63
+
64
+ The global value barrier can be forced by setting
65
+ MLK_CONFIG_NO_ASM_VALUE_BARRIER.
66
+
67
+ */
68
+
69
+ #if defined(MLK_HAVE_INLINE_ASM) && !defined(MLK_CONFIG_NO_ASM_VALUE_BARRIER)
70
+ #define MLK_USE_ASM_VALUE_BARRIER
71
+ #endif
72
+
73
+ #if !defined(MLK_USE_ASM_VALUE_BARRIER)
74
+
75
+ /*
76
+ * Declaration of global volatile that the global value barrier
77
+ * is loading from and masking with.
78
+ */
79
+ #define mlk_ct_opt_blocker_u64 MLK_NAMESPACE(ct_opt_blocker_u64)
80
+ extern volatile uint64_t mlk_ct_opt_blocker_u64;
81
+
82
+ /* Helper functions for obtaining global masks of various sizes */
83
+
84
+ /* This contract is not proved but treated as an axiom.
85
+ *
86
+ * Its validity relies on the assumption that the global opt-blocker
87
+ * constant mlk_ct_opt_blocker_u64 is not modified.
88
+ */
89
+ static MLK_INLINE uint64_t mlk_ct_get_optblocker_u64(void)
90
+ __contract__(ensures(return_value == 0)) { return mlk_ct_opt_blocker_u64; }
91
+
92
+ static MLK_INLINE uint8_t mlk_ct_get_optblocker_u8(void)
93
+ __contract__(ensures(return_value == 0)) { return (uint8_t)mlk_ct_get_optblocker_u64(); }
94
+
95
+ static MLK_INLINE uint32_t mlk_ct_get_optblocker_u32(void)
96
+ __contract__(ensures(return_value == 0)) { return (uint32_t)mlk_ct_get_optblocker_u64(); }
97
+
98
+ static MLK_INLINE int32_t mlk_ct_get_optblocker_i32(void)
99
+ __contract__(ensures(return_value == 0)) { return (int32_t)mlk_ct_get_optblocker_u64(); }
100
+
101
+ /* Opt-blocker based implementation of value barriers */
102
+ static MLK_INLINE uint32_t mlk_value_barrier_u32(uint32_t b)
103
+ __contract__(ensures(return_value == b)) { return (b ^ mlk_ct_get_optblocker_u32()); }
104
+
105
+ static MLK_INLINE int32_t mlk_value_barrier_i32(int32_t b)
106
+ __contract__(ensures(return_value == b)) { return (b ^ mlk_ct_get_optblocker_i32()); }
107
+
108
+ static MLK_INLINE uint8_t mlk_value_barrier_u8(uint8_t b)
109
+ __contract__(ensures(return_value == b)) { return (b ^ mlk_ct_get_optblocker_u8()); }
110
+
111
+ #else /* !MLK_USE_ASM_VALUE_BARRIER */
112
+
113
+ static MLK_INLINE uint32_t mlk_value_barrier_u32(uint32_t b)
114
+ __contract__(ensures(return_value == b))
115
+ {
116
+ __asm__ volatile("" : "+r"(b));
117
+ return b;
118
+ }
119
+
120
+ static MLK_INLINE int32_t mlk_value_barrier_i32(int32_t b)
121
+ __contract__(ensures(return_value == b))
122
+ {
123
+ __asm__ volatile("" : "+r"(b));
124
+ return b;
125
+ }
126
+
127
+ static MLK_INLINE uint8_t mlk_value_barrier_u8(uint8_t b)
128
+ __contract__(ensures(return_value == b))
129
+ {
130
+ __asm__ volatile("" : "+r"(b));
131
+ return b;
132
+ }
133
+
134
+ #endif /* MLK_USE_ASM_VALUE_BARRIER */
135
+
136
+ #ifdef CBMC
137
+ #pragma CPROVER check push
138
+ #pragma CPROVER check disable "conversion"
139
+ #endif
140
+ /*************************************************
141
+ * Name: mlk_cast_uint16_to_int16
142
+ *
143
+ * Description: Cast uint16 value to int16
144
+ *
145
+ * Returns: For uint16_t x, the unique y in int16_t
146
+ * so that x == y mod 2^16.
147
+ *
148
+ * Concretely:
149
+ * - x < 32768: returns x
150
+ * - x >= 32768: returns x - 65536
151
+ *
152
+ **************************************************/
153
+ static MLK_ALWAYS_INLINE int16_t mlk_cast_uint16_to_int16(uint16_t x)
154
+ {
155
+ /*
156
+ * PORTABILITY: This relies on uint16_t -> int16_t
157
+ * being implemented as the inverse of int16_t -> uint16_t,
158
+ * which is implementation-defined (C99 6.3.1.3 (3))
159
+ * CBMC (correctly) fails to prove this conversion is OK,
160
+ * so we have to suppress that check here
161
+ */
162
+ return (int16_t)x;
163
+ }
164
+ #ifdef CBMC
165
+ #pragma CPROVER check pop
166
+ #endif
167
+
168
+ /*************************************************
169
+ * Name: mlk_cast_int32_to_uint16
170
+ *
171
+ * Description: Cast int32 value to uint16 as per C standard.
172
+ *
173
+ * Returns: For int32_t x, the unique y in uint16_t
174
+ * so that x == y mod 2^16.
175
+ **************************************************/
176
+ static MLK_ALWAYS_INLINE uint16_t mlk_cast_int32_to_uint16(int32_t x)
177
+ {
178
+ return (uint16_t)(x & (int32_t)UINT16_MAX);
179
+ }
180
+
181
+ /*************************************************
182
+ * Name: mlk_cast_int16_to_uint16
183
+ *
184
+ * Description: Cast int16 value to uint16 as per C standard.
185
+ *
186
+ * Returns: For int16_t x, the unique y in uint16_t
187
+ * so that x == y mod 2^16.
188
+ **************************************************/
189
+ static MLK_ALWAYS_INLINE uint16_t mlk_cast_int16_to_uint16(int32_t x)
190
+ {
191
+ return mlk_cast_int32_to_uint16((int32_t)x);
192
+ }
193
+
194
+ /*************************************************
195
+ * Name: mlk_ct_cmask_neg_i16
196
+ *
197
+ * Description: Return 0 if input is non-negative, and -1 otherwise.
198
+ *
199
+ * Arguments: uint16_t x: Value to be converted into a mask
200
+ *
201
+ **************************************************/
202
+
203
+ /* Reference: Embedded in polynomial compression function in the
204
+ * reference implementation @[REF].
205
+ * - Used as part of signed->unsigned conversion for modular
206
+ * representatives to detect whether the input is negative.
207
+ * This happen in `mlk_poly_reduce()` here, and as part of
208
+ * polynomial compression functions in the reference
209
+ * implementation. See `mlk_poly_reduce()`.
210
+ * - We use value barriers to reduce the risk of
211
+ * compiler-introduced branches. */
212
+ static MLK_INLINE uint16_t mlk_ct_cmask_neg_i16(int16_t x)
213
+ __contract__(ensures(return_value == ((x < 0) ? 0xFFFF : 0)))
214
+ {
215
+ int32_t tmp = mlk_value_barrier_i32((int32_t)x);
216
+ tmp >>= 16;
217
+ return mlk_cast_int32_to_uint16(tmp);
218
+ }
219
+
220
+ /*************************************************
221
+ * Name: mlk_ct_cmask_nonzero_u16
222
+ *
223
+ * Description: Return 0 if input is zero, and -1 otherwise.
224
+ *
225
+ * Arguments: uint16_t x: Value to be converted into a mask
226
+ *
227
+ **************************************************/
228
+
229
+ /* Reference: Embedded in `cmov_int16()` in the reference implementation @[REF].
230
+ * - Use value barrier and shift instead of `b = -b` to
231
+ * convert condition into mask. */
232
+ static MLK_INLINE uint16_t mlk_ct_cmask_nonzero_u16(uint16_t x)
233
+ __contract__(ensures(return_value == ((x == 0) ? 0 : 0xFFFF)))
234
+ {
235
+ int32_t tmp = mlk_value_barrier_i32(-((int32_t)x));
236
+ tmp >>= 16;
237
+ return mlk_cast_int32_to_uint16(tmp);
238
+ }
239
+
240
+ /*************************************************
241
+ * Name: mlk_ct_cmask_nonzero_u8
242
+ *
243
+ * Description: Return 0 if input is zero, and -1 otherwise.
244
+ *
245
+ * Arguments: uint8_t x: Value to be converted into a mask
246
+ *
247
+ **************************************************/
248
+
249
+ /* Reference: Embedded in `verify()` and `cmov()` in the
250
+ * reference implementation @[REF].
251
+ * - We include a value barrier not present in the
252
+ * reference implementation, to prevent the compiler
253
+ * from realizing that this function returns a mask. */
254
+ static MLK_INLINE uint8_t mlk_ct_cmask_nonzero_u8(uint8_t x)
255
+ __contract__(ensures(return_value == ((x == 0) ? 0 : 0xFF)))
256
+ {
257
+ uint16_t mask = mlk_ct_cmask_nonzero_u16((uint16_t)x);
258
+ return (uint8_t)(mask & 0xFF);
259
+ }
260
+
261
+ /*************************************************
262
+ * Name: mlk_ct_sel_int16
263
+ *
264
+ * Description: Functionally equivalent to cond ? a : b,
265
+ * but implemented with guards against
266
+ * compiler-introduced branches.
267
+ *
268
+ * Arguments: int16_t a: First alternative
269
+ * int16_t b: Second alternative
270
+ * uint16_t cond: Condition variable.
271
+ *
272
+ * Specification:
273
+ * - With `a = MLKEM_Q_HALF` and `b=0`, this essentially
274
+ * implements `Decompress_1` @[FIPS203, Eq (4.8)] in `mlk_poly_frommsg()`.
275
+ * - With `a = x + MLKEM_Q`, `b = x`, and `cond` indicating whether `x`
276
+ * is negative, implements signed->unsigned conversion of modular
277
+ * representatives. Questions of representation are not considered
278
+ * in the specification @[FIPS203, Section 2.4.1, "The pseudocode is
279
+ * agnostic regarding how an integer modulo 𝑚 is represented in
280
+ * actual implementations"].
281
+ *
282
+ **************************************************/
283
+
284
+ /* Reference: Embedded in polynomial compression function in the
285
+ * reference implementation @[REF].
286
+ * - Used as part of signed->unsigned conversion for modular
287
+ * representatives. This happen in `mlk_poly_reduce()` here,
288
+ * and as part of polynomial compression functions in @[REF].
289
+ * See `mlk_poly_reduce()`.
290
+ * - Barrier to reduce the risk of compiler-introduced branches.
291
+ * For `a = MLKEM_Q_HALF` and `b=0`, also embedded in
292
+ * `poly_frommsg()` from the reference implementation, which uses
293
+ * `cmov_int16()` instead. */
294
+ static MLK_INLINE int16_t mlk_ct_sel_int16(int16_t a, int16_t b, uint16_t cond)
295
+ __contract__(ensures(return_value == (cond ? a : b)))
296
+ {
297
+ uint16_t au = mlk_cast_int16_to_uint16(a);
298
+ uint16_t bu = mlk_cast_int16_to_uint16(b);
299
+ uint16_t res = bu ^ (mlk_ct_cmask_nonzero_u16(cond) & (au ^ bu));
300
+ return mlk_cast_uint16_to_int16(res);
301
+ }
302
+
303
+ /*************************************************
304
+ * Name: mlk_ct_sel_uint8
305
+ *
306
+ * Description: Functionally equivalent to cond ? a : b,
307
+ * but implemented with guards against
308
+ * compiler-introduced branches.
309
+ *
310
+ * Arguments: uint8_t a: First alternative
311
+ * uint8_t b: Second alternative
312
+ * uuint8_t cond: Condition variable.
313
+ *
314
+ **************************************************/
315
+
316
+ /* Reference: Embedded into `cmov()` in the reference implementation @[REF].
317
+ * - Use value barrier to get mask from condition value. */
318
+ static MLK_INLINE uint8_t mlk_ct_sel_uint8(uint8_t a, uint8_t b, uint8_t cond)
319
+ __contract__(ensures(return_value == (cond ? a : b)))
320
+ {
321
+ return b ^ (mlk_ct_cmask_nonzero_u8(cond) & (a ^ b));
322
+ }
323
+
324
+ /*************************************************
325
+ * Name: mlk_ct_memcmp
326
+ *
327
+ * Description: Compare two arrays for equality in constant time.
328
+ *
329
+ * Arguments: const uint8_t *a: pointer to first byte array
330
+ * const uint8_t *b: pointer to second byte array
331
+ * size_t len: length of the byte arrays, upper-bounded
332
+ * to UINT16_MAX to control proof complexity
333
+ * only.
334
+ *
335
+ * Returns 0 if the byte arrays are equal, 0xFF otherwise.
336
+ *
337
+ * Specification:
338
+ * - Used to securely compute conditional move in
339
+ * @[FIPS203, Algorithm 18 (ML-KEM.Decaps_Internal, L9-11]
340
+ *
341
+ **************************************************/
342
+
343
+ /* Reference: `cmov()` in the reference implementation @[REF]
344
+ * - We return `uint8_t`, not `int`.
345
+ * - We use an additional XOR-accumulator in the comparison loop
346
+ * which prevents early abort if the OR-accumulator is 0xFF.
347
+ * - We use a value barrier to convert the OR-accumulator into
348
+ * a mask. The reference implementation uses a shift which the
349
+ * compiler can argue to result in either 0 of 0xFF..FF. */
350
+ static MLK_INLINE uint8_t mlk_ct_memcmp(const uint8_t *a, const uint8_t *b,
351
+ const size_t len)
352
+ __contract__(
353
+ requires(len <= UINT16_MAX)
354
+ requires(memory_no_alias(a, len))
355
+ requires(memory_no_alias(b, len))
356
+ ensures((return_value == 0) || (return_value == 0xFF))
357
+ ensures((return_value == 0) == forall(i, 0, len, (a[i] == b[i]))))
358
+ {
359
+ uint8_t r = 0, s = 0;
360
+ unsigned i;
361
+
362
+ for (i = 0; i < len; i++)
363
+ __loop__(
364
+ invariant(i <= len)
365
+ invariant((r == 0) == (forall(k, 0, i, (a[k] == b[k])))))
366
+ {
367
+ r |= a[i] ^ b[i];
368
+ /* s is useless, but prevents the loop from being aborted once r=0xff. */
369
+ s ^= a[i] ^ b[i];
370
+ }
371
+
372
+ /*
373
+ * - Convert r into a mask; this may not be necessary, but is an additional
374
+ * safeguard
375
+ * towards leaking information about a and b.
376
+ * - XOR twice with s, separated by a value barrier, to prevent the compile
377
+ * from dropping the s computation in the loop.
378
+ */
379
+ return (mlk_value_barrier_u8(mlk_ct_cmask_nonzero_u8(r) ^ s) ^ s);
380
+ }
381
+
382
+ /*************************************************
383
+ * Name: mlk_ct_cmov_zero
384
+ *
385
+ * Description: Copy len bytes from x to r if b is zero;
386
+ * don't modify x if b is non-zero.
387
+ * assumes two's complement representation of negative integers.
388
+ * Runs in constant time.
389
+ *
390
+ * Arguments: uint8_t *r: pointer to output byte array
391
+ * const uint8_t *x: pointer to input byte array
392
+ * size_t len: Amount of bytes to be copied
393
+ * uint8_t b: Condition value.
394
+ *
395
+ * Specification:
396
+ * - Used to securely compute conditional move in
397
+ * @[FIPS203, Algorithm 18 (ML-KEM.Decaps_Internal, L9-11]
398
+ *
399
+ **************************************************/
400
+
401
+ /* Reference: `cmov()` in the reference implementation @[REF].
402
+ * - We move if condition value is `0`, not `1`.
403
+ * - We use `mlk_ct_sel_uint8` for constant-time selection. */
404
+ static MLK_INLINE void mlk_ct_cmov_zero(uint8_t *r, const uint8_t *x,
405
+ size_t len, uint8_t b)
406
+ __contract__(
407
+ requires(len <= MLK_MAX_BUFFER_SIZE)
408
+ requires(memory_no_alias(r, len))
409
+ requires(memory_no_alias(x, len))
410
+ assigns(memory_slice(r, len))
411
+ ensures(forall(i, 0, len, (r[i] == (b == 0 ? x[i] : old(r)[i])))))
412
+ {
413
+ size_t i;
414
+ for (i = 0; i < len; i++)
415
+ __loop__(
416
+ invariant(i <= len)
417
+ invariant(forall(k, 0, i, r[k] == (b == 0 ? x[k] : loop_entry(r)[k]))))
418
+ {
419
+ r[i] = mlk_ct_sel_uint8(r[i], x[i], b);
420
+ }
421
+ }
422
+
423
+ /*************************************************
424
+ * Name: mlk_zeroize
425
+ *
426
+ * Description: Force-zeroize a buffer.
427
+ *
428
+ * Arguments: uint8_t *r: pointer to byte array to be zeroed
429
+ * size_t len: Amount of bytes to be zeroed
430
+ *
431
+ * Specification: Used to implement
432
+ * @[FIPS203, Section 3.3, Destruction of intermediate values]
433
+ *
434
+ **************************************************/
435
+
436
+ /* Reference: Not present in the reference implementation @[REF]. */
437
+ #if !defined(MLK_CONFIG_CUSTOM_ZEROIZE)
438
+ #if defined(MLK_SYS_WINDOWS)
439
+ #include <windows.h>
440
+ static MLK_INLINE void mlk_zeroize(void *ptr, size_t len)
441
+ __contract__(
442
+ requires(memory_no_alias(ptr, len))
443
+ assigns(memory_slice(ptr, len))) { SecureZeroMemory(ptr, len); }
444
+ #elif defined(MLK_HAVE_INLINE_ASM)
445
+ #include <string.h>
446
+ static MLK_INLINE void mlk_zeroize(void *ptr, size_t len)
447
+ __contract__(
448
+ requires(memory_no_alias(ptr, len))
449
+ assigns(memory_slice(ptr, len)))
450
+ {
451
+ mlk_memset(ptr, 0, len);
452
+ /* This follows OpenSSL and seems sufficient to prevent the compiler
453
+ * from optimizing away the memset.
454
+ *
455
+ * If there was a reliable way to detect availability of memset_s(),
456
+ * that would be preferred. */
457
+ __asm__ volatile("" : : "r"(ptr) : "memory");
458
+ }
459
+ #else /* !MLK_SYS_WINDOWS && MLK_HAVE_INLINE_ASM */
460
+ #error No plausibly-secure implementation of mlk_zeroize available. Please provide your own using MLK_CONFIG_CUSTOM_ZEROIZE.
461
+ #endif /* !MLK_SYS_WINDOWS && !MLK_HAVE_INLINE_ASM */
462
+ #endif /* !MLK_CONFIG_CUSTOM_ZEROIZE */
463
+
464
+ #endif /* !MLK_VERIFY_H */
@@ -0,0 +1,30 @@
1
+ /*
2
+ * Copyright (c) The mlkem-native project authors
3
+ * SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
4
+ */
5
+
6
+ /*
7
+ * WARNING: This file is auto-generated from scripts/autogen
8
+ * in the mlkem-native repository.
9
+ * Do not modify it directly.
10
+ */
11
+
12
+
13
+ /*
14
+ * Table of zeta values used in the reference NTT and inverse NTT.
15
+ * See autogen for details.
16
+ */
17
+ static MLK_ALIGN const int16_t mlk_zetas[128] = {
18
+ -1044, -758, -359, -1517, 1493, 1422, 287, 202, -171, 622, 1577,
19
+ 182, 962, -1202, -1474, 1468, 573, -1325, 264, 383, -829, 1458,
20
+ -1602, -130, -681, 1017, 732, 608, -1542, 411, -205, -1571, 1223,
21
+ 652, -552, 1015, -1293, 1491, -282, -1544, 516, -8, -320, -666,
22
+ -1618, -1162, 126, 1469, -853, -90, -271, 830, 107, -1421, -247,
23
+ -951, -398, 961, -1508, -725, 448, -1065, 677, -1275, -1103, 430,
24
+ 555, 843, -1251, 871, 1550, 105, 422, 587, 177, -235, -291,
25
+ -460, 1574, 1653, -246, 778, 1159, -147, -777, 1483, -602, 1119,
26
+ -1590, 644, -872, 349, 418, 329, -156, -75, 817, 1097, 603,
27
+ 610, 1322, -1285, -1465, 384, -1215, -136, 1218, -1335, -874, 220,
28
+ -1187, -1659, -1185, -1530, -1278, 794, -1510, -854, -870, 478, -108,
29
+ -308, 996, 991, 958, -1460, 1522, 1628,
30
+ };
@@ -0,0 +1,200 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PQCrypto
4
+ module AlgorithmRegistry
5
+ class << self
6
+ def entries
7
+ @entries ||= begin
8
+ {
9
+ ml_kem_512: {
10
+ family: :ml_kem,
11
+ legacy_oid: nil,
12
+ standard_oid: "2.16.840.1.101.3.4.4.1",
13
+ public_key_bytes: PQCrypto::ML_KEM_512_PUBLIC_KEY_BYTES,
14
+ secret_key_bytes: PQCrypto::ML_KEM_512_SECRET_KEY_BYTES,
15
+ ciphertext_bytes: PQCrypto::ML_KEM_512_CIPHERTEXT_BYTES,
16
+ shared_secret_bytes: PQCrypto::ML_KEM_512_SHARED_SECRET_BYTES,
17
+ signature_bytes: nil,
18
+ description: "Pure ML-KEM-512 primitive (FIPS 203).",
19
+ }.freeze,
20
+ ml_kem_768: {
21
+ family: :ml_kem,
22
+ legacy_oid: "2.25.186599352125448088867056807454444238446",
23
+ standard_oid: "2.16.840.1.101.3.4.4.2",
24
+ public_key_bytes: PQCrypto::ML_KEM_PUBLIC_KEY_BYTES,
25
+ secret_key_bytes: PQCrypto::ML_KEM_SECRET_KEY_BYTES,
26
+ ciphertext_bytes: PQCrypto::ML_KEM_CIPHERTEXT_BYTES,
27
+ shared_secret_bytes: PQCrypto::ML_KEM_SHARED_SECRET_BYTES,
28
+ signature_bytes: nil,
29
+ description: "Pure ML-KEM-768 primitive (FIPS 203).",
30
+ }.freeze,
31
+ ml_kem_1024: {
32
+ family: :ml_kem,
33
+ legacy_oid: nil,
34
+ standard_oid: "2.16.840.1.101.3.4.4.3",
35
+ public_key_bytes: PQCrypto::ML_KEM_1024_PUBLIC_KEY_BYTES,
36
+ secret_key_bytes: PQCrypto::ML_KEM_1024_SECRET_KEY_BYTES,
37
+ ciphertext_bytes: PQCrypto::ML_KEM_1024_CIPHERTEXT_BYTES,
38
+ shared_secret_bytes: PQCrypto::ML_KEM_1024_SHARED_SECRET_BYTES,
39
+ signature_bytes: nil,
40
+ description: "Pure ML-KEM-1024 primitive (FIPS 203).",
41
+ }.freeze,
42
+ ml_kem_768_x25519_xwing: {
43
+ family: :ml_kem_hybrid,
44
+ legacy_oid: "1.3.6.1.4.1.62253.25722",
45
+ standard_oid: nil,
46
+ public_key_bytes: PQCrypto::HYBRID_KEM_PUBLIC_KEY_BYTES,
47
+ secret_key_bytes: PQCrypto::HYBRID_KEM_SECRET_KEY_BYTES,
48
+ ciphertext_bytes: PQCrypto::HYBRID_KEM_CIPHERTEXT_BYTES,
49
+ shared_secret_bytes: PQCrypto::HYBRID_KEM_SHARED_SECRET_BYTES,
50
+ signature_bytes: nil,
51
+ description: "Hybrid KEM: ML-KEM-768 + X25519 combined via X-Wing SHA3-256 combiner (draft-connolly-cfrg-xwing-kem).",
52
+ }.freeze,
53
+ ml_dsa_44: {
54
+ family: :ml_dsa,
55
+ legacy_oid: nil,
56
+ standard_oid: "2.16.840.1.101.3.4.3.17",
57
+ public_key_bytes: PQCrypto::SIGN_44_PUBLIC_KEY_BYTES,
58
+ secret_key_bytes: PQCrypto::SIGN_44_SECRET_KEY_BYTES,
59
+ ciphertext_bytes: nil,
60
+ shared_secret_bytes: nil,
61
+ signature_bytes: PQCrypto::SIGN_44_BYTES,
62
+ description: "ML-DSA-44 signature primitive (FIPS 204).",
63
+ }.freeze,
64
+ ml_dsa_65: {
65
+ family: :ml_dsa,
66
+ legacy_oid: "2.25.305232938483772195555080795650659207792",
67
+ standard_oid: "2.16.840.1.101.3.4.3.18",
68
+ public_key_bytes: PQCrypto::SIGN_PUBLIC_KEY_BYTES,
69
+ secret_key_bytes: PQCrypto::SIGN_SECRET_KEY_BYTES,
70
+ ciphertext_bytes: nil,
71
+ shared_secret_bytes: nil,
72
+ signature_bytes: PQCrypto::SIGN_BYTES,
73
+ description: "ML-DSA-65 signature primitive (FIPS 204).",
74
+ }.freeze,
75
+ ml_dsa_87: {
76
+ family: :ml_dsa,
77
+ legacy_oid: nil,
78
+ standard_oid: "2.16.840.1.101.3.4.3.19",
79
+ public_key_bytes: PQCrypto::SIGN_87_PUBLIC_KEY_BYTES,
80
+ secret_key_bytes: PQCrypto::SIGN_87_SECRET_KEY_BYTES,
81
+ ciphertext_bytes: nil,
82
+ shared_secret_bytes: nil,
83
+ signature_bytes: PQCrypto::SIGN_87_BYTES,
84
+ description: "ML-DSA-87 signature primitive (FIPS 204).",
85
+ }.freeze,
86
+ }.freeze
87
+ end
88
+ end
89
+
90
+ def fetch(symbol)
91
+ entries.fetch(symbol) do
92
+ raise UnsupportedAlgorithmError, "Unsupported algorithm: #{symbol.inspect}"
93
+ end
94
+ end
95
+
96
+ def legacy_oid(symbol)
97
+ fetch(symbol).fetch(:legacy_oid)
98
+ end
99
+
100
+ def standard_oid(symbol)
101
+ oid = fetch(symbol).fetch(:standard_oid)
102
+ raise SerializationError, "No standard OID registered for #{symbol.inspect}" if oid.nil?
103
+
104
+ oid
105
+ end
106
+
107
+ def by_legacy_oid(oid)
108
+ legacy_oid_index.fetch(oid, nil)
109
+ end
110
+
111
+ def by_standard_oid(oid)
112
+ standard_oid_index.fetch(oid, nil)
113
+ end
114
+
115
+ def supported_kems
116
+ supported_by_family(:ml_kem)
117
+ end
118
+
119
+ def supported_hybrid_kems
120
+ supported_by_family(:ml_kem_hybrid)
121
+ end
122
+
123
+ def supported_signatures
124
+ supported_by_family(:ml_dsa)
125
+ end
126
+
127
+ def legacy_metadata_view
128
+ @legacy_metadata_view ||= entries.each_with_object({}) do |(algorithm, entry), view|
129
+ oid = entry.fetch(:legacy_oid)
130
+ next if oid.nil?
131
+
132
+ view[algorithm] = {
133
+ family: entry.fetch(:family),
134
+ oid: oid,
135
+ }.freeze
136
+ end.freeze
137
+ end
138
+
139
+ def details_for_family(family)
140
+ @details_for_family ||= {}
141
+ @details_for_family[family] ||= begin
142
+ entries.each_with_object({}) do |(algorithm, entry), details|
143
+ next unless entry.fetch(:family) == family
144
+
145
+ details[algorithm] = details_entry(algorithm, entry)
146
+ end.freeze
147
+ end
148
+ end
149
+
150
+ private
151
+
152
+ def supported_by_family(family)
153
+ supported_by_family_cache[family] ||= entries.each_with_object([]) do |(algorithm, entry), supported|
154
+ supported << algorithm if entry.fetch(:family) == family
155
+ end.freeze
156
+ end
157
+
158
+ def supported_by_family_cache
159
+ @supported_by_family_cache ||= {}
160
+ end
161
+
162
+ def legacy_oid_index
163
+ @legacy_oid_index ||= entries.each_with_object({}) do |(algorithm, entry), index|
164
+ oid = entry.fetch(:legacy_oid)
165
+ index[oid] = algorithm unless oid.nil?
166
+ end.freeze
167
+ end
168
+
169
+ def standard_oid_index
170
+ @standard_oid_index ||= entries.each_with_object({}) do |(algorithm, entry), index|
171
+ oid = entry.fetch(:standard_oid)
172
+ index[oid] = algorithm unless oid.nil?
173
+ end.freeze
174
+ end
175
+
176
+ def details_entry(algorithm, entry)
177
+ # :oid intentionally remains an alias for the legacy pqc_container_* OID.
178
+ # Use .standard_oid when an RFC 9935/9881 OID is required.
179
+ detail = {
180
+ name: algorithm,
181
+ family: entry.fetch(:family),
182
+ oid: entry.fetch(:legacy_oid),
183
+ public_key_bytes: entry.fetch(:public_key_bytes),
184
+ secret_key_bytes: entry.fetch(:secret_key_bytes),
185
+ }
186
+
187
+ if entry.fetch(:ciphertext_bytes)
188
+ detail[:ciphertext_bytes] = entry.fetch(:ciphertext_bytes)
189
+ detail[:shared_secret_bytes] = entry.fetch(:shared_secret_bytes)
190
+ end
191
+
192
+ detail[:signature_bytes] = entry.fetch(:signature_bytes) if entry.fetch(:signature_bytes)
193
+ detail[:description] = entry.fetch(:description)
194
+
195
+ detail.freeze
196
+ end
197
+
198
+ end
199
+ end
200
+ end