pq_crypto 0.6.5 → 0.6.7

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 (157) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +233 -0
  3. data/README.md +16 -3
  4. data/SECURITY.md +46 -0
  5. data/ext/pqcrypto/extconf.rb +8 -1
  6. data/ext/pqcrypto/pq_externalmu.c +35 -0
  7. data/ext/pqcrypto/pqcrypto_native_api.h +91 -75
  8. data/ext/pqcrypto/pqcrypto_ruby_secure.c +97 -9
  9. data/ext/pqcrypto/pqcrypto_secure.c +95 -33
  10. data/ext/pqcrypto/pqcrypto_secure.h +66 -48
  11. data/ext/pqcrypto/pqcrypto_version.h +1 -1
  12. data/ext/pqcrypto/vendor/.vendored +7 -7
  13. data/ext/pqcrypto/vendor/mldsa-native/BUILDING.md +5 -2
  14. data/ext/pqcrypto/vendor/mldsa-native/LICENSE +21 -2
  15. data/ext/pqcrypto/vendor/mldsa-native/README.md +20 -7
  16. data/ext/pqcrypto/vendor/mldsa-native/RELEASE.md +160 -0
  17. data/ext/pqcrypto/vendor/mldsa-native/SECURITY.md +1 -1
  18. data/ext/pqcrypto/vendor/mldsa-native/mldsa/README.md +2 -2
  19. data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native.c +85 -59
  20. data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native.h +292 -348
  21. data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native_asm.S +122 -76
  22. data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native_config.h +184 -86
  23. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/cbmc.h +49 -4
  24. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/common.h +49 -81
  25. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/context.h +152 -0
  26. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/ct.h +25 -12
  27. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/debug.c +2 -0
  28. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/debug.h +2 -0
  29. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/fips202x4.c +2 -2
  30. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/keccakf1600.c +9 -11
  31. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/auto.h +19 -11
  32. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_scalar_aarch64_asm.S +6 -4
  33. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_v84a_aarch64_asm.S +7 -4
  34. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x2_v84a_aarch64_asm.S +7 -4
  35. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_scalar_hybrid_aarch64_asm.S +12 -9
  36. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_v84a_scalar_hybrid_aarch64_asm.S +12 -9
  37. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x1_scalar.h +1 -1
  38. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x1_v84a.h +3 -2
  39. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x2_v84a.h +3 -2
  40. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x4_v8a_scalar.h +6 -1
  41. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x4_v8a_v84a_scalar.h +3 -2
  42. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/api.h +11 -11
  43. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/mve.h +9 -22
  44. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.S +8 -5
  45. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.c +1 -0
  46. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/{state_extract_bytes_x4_mve.S → keccak_f1600_x4_state_extract_bytes_mve.S} +14 -14
  47. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/{state_xor_bytes_x4_mve.S → keccak_f1600_x4_state_xor_bytes_mve.S} +12 -12
  48. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/auto.h +5 -4
  49. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/keccak_f1600_x4_avx2.h +2 -2
  50. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/fips202_native_x86_64.h +1 -0
  51. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/keccak_f1600_x4_avx2_asm.S +36 -2
  52. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/meta.h +62 -4
  53. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/arith_native_aarch64.h +87 -54
  54. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/{intt_aarch64_asm.S → mldsa_intt_aarch64_asm.S} +39 -6
  55. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/{ntt_aarch64_asm.S → mldsa_ntt_aarch64_asm.S} +39 -6
  56. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/{pointwise_montgomery_aarch64_asm.S → mldsa_pointwise_montgomery_aarch64_asm.S} +25 -3
  57. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/{poly_caddq_aarch64_asm.S → mldsa_poly_caddq_aarch64_asm.S} +19 -3
  58. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/{poly_chknorm_aarch64_asm.S → mldsa_poly_chknorm_aarch64_asm.S} +24 -3
  59. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/{poly_decompose_32_aarch64_asm.S → mldsa_poly_decompose_32_aarch64_asm.S} +25 -3
  60. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/{poly_decompose_88_aarch64_asm.S → mldsa_poly_decompose_88_aarch64_asm.S} +25 -3
  61. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/{poly_use_hint_32_aarch64_asm.S → mldsa_poly_use_hint_32_aarch64_asm.S} +25 -3
  62. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/{poly_use_hint_88_aarch64_asm.S → mldsa_poly_use_hint_88_aarch64_asm.S} +25 -3
  63. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/{mld_polyvecl_pointwise_acc_montgomery_l4_aarch64_asm.S → mldsa_polyvecl_pointwise_acc_montgomery_l4_aarch64_asm.S} +31 -3
  64. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/{mld_polyvecl_pointwise_acc_montgomery_l5_aarch64_asm.S → mldsa_polyvecl_pointwise_acc_montgomery_l5_aarch64_asm.S} +31 -3
  65. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/{mld_polyvecl_pointwise_acc_montgomery_l7_aarch64_asm.S → mldsa_polyvecl_pointwise_acc_montgomery_l7_aarch64_asm.S} +31 -3
  66. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/{polyz_unpack_17_aarch64_asm.S → mldsa_polyz_unpack_17_aarch64_asm.S} +31 -3
  67. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/{polyz_unpack_19_aarch64_asm.S → mldsa_polyz_unpack_19_aarch64_asm.S} +31 -3
  68. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/{rej_uniform_aarch64_asm.S → mldsa_rej_uniform_aarch64_asm.S} +48 -15
  69. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/{rej_uniform_eta2_aarch64_asm.S → mldsa_rej_uniform_eta2_aarch64_asm.S} +42 -9
  70. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/{rej_uniform_eta4_aarch64_asm.S → mldsa_rej_uniform_eta4_aarch64_asm.S} +42 -9
  71. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/api.h +11 -3
  72. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/meta.h +3 -2
  73. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/meta.h +28 -28
  74. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/arith_native_x86_64.h +171 -49
  75. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/{intt_avx2_asm.S → mldsa_intt_avx2_asm.S} +23 -1
  76. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/{ntt_avx2_asm.S → mldsa_ntt_avx2_asm.S} +23 -1
  77. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/{nttunpack_avx2_asm.S → mldsa_nttunpack_avx2_asm.S} +17 -1
  78. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/{pointwise_acc_l4_avx2_asm.S → mldsa_pointwise_acc_l4_avx2_asm.S} +37 -3
  79. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/{pointwise_acc_l5_avx2_asm.S → mldsa_pointwise_acc_l5_avx2_asm.S} +37 -3
  80. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/{pointwise_acc_l7_avx2_asm.S → mldsa_pointwise_acc_l7_avx2_asm.S} +37 -3
  81. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/{pointwise_avx2_asm.S → mldsa_pointwise_avx2_asm.S} +31 -3
  82. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/{poly_caddq_avx2_asm.S → mldsa_poly_caddq_avx2_asm.S} +18 -9
  83. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_poly_chknorm_avx2_asm.S +176 -0
  84. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_poly_decompose_32_avx2_asm.S +490 -0
  85. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_poly_decompose_88_avx2_asm.S +489 -0
  86. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_poly_use_hint_32_avx2_asm.S +123 -0
  87. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_poly_use_hint_88_avx2_asm.S +125 -0
  88. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_polyz_unpack_17_avx2_asm.S +355 -0
  89. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_polyz_unpack_19_avx2_asm.S +355 -0
  90. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_rej_uniform_avx2_asm.S +132 -0
  91. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_rej_uniform_eta2_avx2_asm.S +205 -0
  92. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_rej_uniform_eta4_avx2_asm.S +176 -0
  93. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/packing.c +27 -36
  94. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/packing.h +42 -8
  95. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/params.h +93 -17
  96. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly.c +74 -15
  97. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly.h +97 -11
  98. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly_kl.c +7 -38
  99. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly_kl.h +49 -7
  100. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec.c +16 -17
  101. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec.h +26 -9
  102. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec_lazy.c +3 -0
  103. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec_lazy.h +18 -19
  104. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/reduce.h +15 -3
  105. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/rounding.h +28 -6
  106. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/sign.c +311 -246
  107. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/sign.h +245 -240
  108. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/sys.h +64 -5
  109. data/ext/pqcrypto/vendor/mlkem-native/BUILDING.md +5 -2
  110. data/ext/pqcrypto/vendor/mlkem-native/LICENSE +21 -3
  111. data/ext/pqcrypto/vendor/mlkem-native/README.md +2 -2
  112. data/ext/pqcrypto/vendor/mlkem-native/RELEASE.md +113 -0
  113. data/ext/pqcrypto/vendor/mlkem-native/mlkem/README.md +2 -2
  114. data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native.c +17 -27
  115. data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native.h +68 -151
  116. data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native_asm.S +17 -27
  117. data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native_config.h +46 -44
  118. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/cbmc.h +25 -0
  119. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/common.h +37 -6
  120. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/context.h +9 -0
  121. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/fips202.h +2 -2
  122. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/keccakf1600.c +8 -8
  123. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x1_scalar.h +1 -1
  124. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x1_v84a.h +3 -3
  125. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x2_v84a.h +3 -3
  126. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x4_v8a_scalar.h +2 -2
  127. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x4_v8a_v84a_scalar.h +3 -3
  128. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/api.h +11 -11
  129. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/mve.h +3 -3
  130. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/keccak_f1600_x4_avx2.h +2 -2
  131. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/indcpa.h +14 -11
  132. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/kem.c +28 -11
  133. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/kem.h +39 -14
  134. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/meta.h +10 -10
  135. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/meta.h +20 -20
  136. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/sys.h +5 -5
  137. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/verify.h +11 -10
  138. data/lib/pq_crypto/internal.rb +10 -0
  139. data/lib/pq_crypto/kem.rb +47 -5
  140. data/lib/pq_crypto/key.rb +14 -8
  141. data/lib/pq_crypto/pkcs8.rb +13 -5
  142. data/lib/pq_crypto/signature.rb +34 -9
  143. data/lib/pq_crypto/spki.rb +4 -2
  144. data/lib/pq_crypto/version.rb +1 -1
  145. data/lib/pq_crypto.rb +9 -0
  146. data/script/vendor_libs.rb +6 -6
  147. metadata +40 -38
  148. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_chknorm_avx2.c +0 -52
  149. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_decompose_32_avx2.c +0 -157
  150. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_decompose_88_avx2.c +0 -157
  151. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_use_hint_32_avx2.c +0 -103
  152. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_use_hint_88_avx2.c +0 -105
  153. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/polyz_unpack_17_avx2.c +0 -94
  154. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/polyz_unpack_19_avx2.c +0 -96
  155. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/rej_uniform_avx2.c +0 -126
  156. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/rej_uniform_eta2_avx2.c +0 -157
  157. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/rej_uniform_eta4_avx2.c +0 -141
data/lib/pq_crypto/kem.rb CHANGED
@@ -14,18 +14,24 @@ module PQCrypto
14
14
  keypair_from_seed: :native_ml_kem_512_keypair_from_seed,
15
15
  encapsulate: :native_ml_kem_512_encapsulate,
16
16
  decapsulate: :native_ml_kem_512_decapsulate,
17
+ check_public_key: :native_ml_kem_512_check_public_key,
18
+ check_secret_key: :native_ml_kem_512_check_secret_key,
17
19
  }.freeze,
18
20
  ml_kem_768: {
19
21
  keypair: :native_ml_kem_keypair,
20
22
  keypair_from_seed: :native_ml_kem_keypair_from_seed,
21
23
  encapsulate: :native_ml_kem_encapsulate,
22
24
  decapsulate: :native_ml_kem_decapsulate,
25
+ check_public_key: :native_ml_kem_check_public_key,
26
+ check_secret_key: :native_ml_kem_check_secret_key,
23
27
  }.freeze,
24
28
  ml_kem_1024: {
25
29
  keypair: :native_ml_kem_1024_keypair,
26
30
  keypair_from_seed: :native_ml_kem_1024_keypair_from_seed,
27
31
  encapsulate: :native_ml_kem_1024_encapsulate,
28
32
  decapsulate: :native_ml_kem_1024_decapsulate,
33
+ check_public_key: :native_ml_kem_1024_check_public_key,
34
+ check_secret_key: :native_ml_kem_1024_check_secret_key,
29
35
  }.freeze,
30
36
  }.freeze
31
37
 
@@ -68,12 +74,18 @@ module PQCrypto
68
74
  SecretKey.new(resolve_algorithm!(resolved_algorithm), bytes)
69
75
  end
70
76
 
71
- def secret_key_from_pkcs8_der(der, passphrase: nil)
72
- secret_key_from_decoded_pkcs8(*PKCS8.decode_der(der, passphrase: passphrase))
77
+ def secret_key_from_pkcs8_der(der, passphrase: nil, require_encrypted: false)
78
+ require_encrypted = Internal.strict_boolean!(require_encrypted, name: "require_encrypted")
79
+ secret_key_from_decoded_pkcs8(
80
+ *PKCS8.decode_der(der, passphrase: passphrase, require_encrypted: require_encrypted)
81
+ )
73
82
  end
74
83
 
75
- def secret_key_from_pkcs8_pem(pem, passphrase: nil)
76
- secret_key_from_decoded_pkcs8(*PKCS8.decode_pem(pem, passphrase: passphrase))
84
+ def secret_key_from_pkcs8_pem(pem, passphrase: nil, require_encrypted: false)
85
+ require_encrypted = Internal.strict_boolean!(require_encrypted, name: "require_encrypted")
86
+ secret_key_from_decoded_pkcs8(
87
+ *PKCS8.decode_pem(pem, passphrase: passphrase, require_encrypted: require_encrypted)
88
+ )
77
89
  end
78
90
 
79
91
  def public_key_from_spki_der(der, algorithm: nil)
@@ -121,6 +133,10 @@ module PQCrypto
121
133
  end
122
134
  end
123
135
 
136
+ def checkable?(algorithm)
137
+ NATIVE_DISPATCH.key?(algorithm) && NATIVE_DISPATCH.fetch(algorithm).key?(:check_public_key)
138
+ end
139
+
124
140
  def native_method_for(algorithm, operation)
125
141
  NATIVE_DISPATCH.fetch(resolve_algorithm!(algorithm)).fetch(operation)
126
142
  end
@@ -158,8 +174,19 @@ module PQCrypto
158
174
 
159
175
  def initialize(algorithm, bytes)
160
176
  @algorithm = algorithm
161
- @bytes = Internal.binary_string(bytes)
177
+ @bytes = Internal.frozen_binary_string(bytes)
162
178
  validate_length!
179
+ validate_structure!
180
+ end
181
+
182
+ def valid?
183
+ if @algorithm == :ml_kem_768_x25519_xwing
184
+ mlkem_half = @bytes.byteslice(0, KEM.details(:ml_kem_768).fetch(:public_key_bytes))
185
+ return PQCrypto.__send__(:native_ml_kem_check_public_key, mlkem_half)
186
+ end
187
+ return true unless KEM.send(:checkable?, @algorithm)
188
+
189
+ PQCrypto.__send__(KEM.send(:native_method_for, @algorithm, :check_public_key), @bytes)
163
190
  end
164
191
 
165
192
  def to_bytes
@@ -219,6 +246,10 @@ module PQCrypto
219
246
  expected = KEM.details(@algorithm).fetch(:public_key_bytes)
220
247
  raise InvalidKeyError, "Invalid KEM public key length" unless @bytes.bytesize == expected
221
248
  end
249
+
250
+ def validate_structure!
251
+ raise InvalidKeyError, "Invalid #{@algorithm} public key: FIPS 203 modulus check failed" unless valid?
252
+ end
222
253
  end
223
254
 
224
255
  class SecretKey
@@ -230,6 +261,13 @@ module PQCrypto
230
261
  @seed = seed.nil? ? nil : Internal.binary_string(seed)
231
262
  validate_length!
232
263
  validate_seed_length! if @seed
264
+ validate_structure!
265
+ end
266
+
267
+ def valid?
268
+ return true unless KEM.send(:checkable?, @algorithm)
269
+
270
+ PQCrypto.__send__(KEM.send(:native_method_for, @algorithm, :check_secret_key), @bytes)
233
271
  end
234
272
 
235
273
  def self.from_seed(algorithm, seed)
@@ -298,6 +336,10 @@ module PQCrypto
298
336
  raise InvalidKeyError, "Invalid KEM secret key length" unless @bytes.bytesize == expected
299
337
  end
300
338
 
339
+ def validate_structure!
340
+ raise InvalidKeyError, "Invalid #{@algorithm} secret key: FIPS 203 hash check failed" unless valid?
341
+ end
342
+
301
343
  def pkcs8_material(format)
302
344
  case format
303
345
  when :expanded
data/lib/pq_crypto/key.rb CHANGED
@@ -17,22 +17,24 @@ module PQCrypto
17
17
  end
18
18
  end
19
19
 
20
- def from_pem(pem, passphrase: nil)
20
+ def from_pem(pem, passphrase: nil, require_encrypted: false)
21
+ require_encrypted = Internal.strict_boolean!(require_encrypted, name: "require_encrypted")
21
22
  text = String(pem)
22
23
  if text.include?(SPKI::PEM_BEGIN)
23
24
  public_key_from_spki_pem(text)
24
25
  elsif text.include?(PKCS8::PEM_BEGIN) || text.include?(PKCS8::ENCRYPTED_PEM_BEGIN)
25
- secret_key_from_pkcs8_pem(text, passphrase: passphrase)
26
+ secret_key_from_pkcs8_pem(text, passphrase: passphrase, require_encrypted: require_encrypted)
26
27
  else
27
28
  raise SerializationError, "Unsupported PEM label for PQCrypto::Key.from_pem"
28
29
  end
29
30
  end
30
31
 
31
- def from_der(der, passphrase: nil)
32
+ def from_der(der, passphrase: nil, require_encrypted: false)
33
+ require_encrypted = Internal.strict_boolean!(require_encrypted, name: "require_encrypted")
32
34
  public_key_from_spki_der(der)
33
35
  rescue SerializationError => spki_error
34
36
  begin
35
- secret_key_from_pkcs8_der(der, passphrase: passphrase)
37
+ secret_key_from_pkcs8_der(der, passphrase: passphrase, require_encrypted: require_encrypted)
36
38
  rescue SerializationError => pkcs8_error
37
39
  raise SerializationError,
38
40
  "Unable to decode DER as SPKI or PKCS#8 (SPKI: #{spki_error.message}; PKCS#8: #{pkcs8_error.message})"
@@ -56,12 +58,16 @@ module PQCrypto
56
58
  public_key_from_algorithm_and_bytes(algorithm, bytes)
57
59
  end
58
60
 
59
- def secret_key_from_pkcs8_pem(pem, passphrase: nil)
60
- secret_key_from_decoded_pkcs8(*PKCS8.decode_pem(pem, passphrase: passphrase))
61
+ def secret_key_from_pkcs8_pem(pem, passphrase: nil, require_encrypted: false)
62
+ secret_key_from_decoded_pkcs8(
63
+ *PKCS8.decode_pem(pem, passphrase: passphrase, require_encrypted: require_encrypted)
64
+ )
61
65
  end
62
66
 
63
- def secret_key_from_pkcs8_der(der, passphrase: nil)
64
- secret_key_from_decoded_pkcs8(*PKCS8.decode_der(der, passphrase: passphrase))
67
+ def secret_key_from_pkcs8_der(der, passphrase: nil, require_encrypted: false)
68
+ secret_key_from_decoded_pkcs8(
69
+ *PKCS8.decode_der(der, passphrase: passphrase, require_encrypted: require_encrypted)
70
+ )
65
71
  end
66
72
 
67
73
  def secret_key_from_decoded_pkcs8(algorithm, format, material)
@@ -70,10 +70,16 @@ module PQCrypto
70
70
  der = encode_der(algorithm, secret_material, format: format, passphrase: passphrase, iterations: iterations)
71
71
  pkcs8_native { PQCrypto.__send__(:native_pkcs8_der_to_pem, der, !passphrase.nil?) }
72
72
  end
73
-
74
- def decode_der(der, passphrase: nil)
73
+ def decode_der(der, passphrase: nil, require_encrypted: false)
74
+ require_encrypted = Internal.strict_boolean!(require_encrypted, name: "require_encrypted")
75
75
  input = Internal.binary_string(der)
76
- return decode_encrypted_der(input, passphrase: passphrase) if encrypted_der?(input)
76
+ encrypted = encrypted_der?(input)
77
+
78
+ if require_encrypted && !encrypted
79
+ raise SerializationError, "PKCS#8 input is not encrypted, but require_encrypted: true was requested"
80
+ end
81
+
82
+ return decode_encrypted_der(input, passphrase: passphrase) if encrypted
77
83
 
78
84
  oid, choice_der = private_key_info_from_der(input)
79
85
  algorithm = AlgorithmRegistry.by_standard_oid(oid)
@@ -83,15 +89,17 @@ module PQCrypto
83
89
  PrivateKeyChoice.validate_secret_key_algorithm!(algorithm, entry)
84
90
  PrivateKeyChoice.decode(algorithm, Internal.binary_string(choice_der))
85
91
  rescue ArgumentError => e
92
+ raise if e.message.start_with?("require_encrypted")
86
93
  raise SerializationError, e.message
87
94
  ensure
88
95
  Internal.safe_wipe(choice_der) if defined?(choice_der)
89
96
  end
90
97
 
91
- def decode_pem(pem, passphrase: nil)
98
+ def decode_pem(pem, passphrase: nil, require_encrypted: false)
99
+ require_encrypted = Internal.strict_boolean!(require_encrypted, name: "require_encrypted")
92
100
  _encrypted, der = pkcs8_native { PQCrypto.__send__(:native_pkcs8_pem_to_der, String(pem)) }
93
101
  begin
94
- decode_der(der, passphrase: passphrase)
102
+ decode_der(der, passphrase: passphrase, require_encrypted: require_encrypted)
95
103
  ensure
96
104
  Internal.safe_wipe(der)
97
105
  end
@@ -14,18 +14,21 @@ module PQCrypto
14
14
  sign: :native_ml_dsa_44_sign,
15
15
  verify: :native_ml_dsa_44_verify,
16
16
  keypair_from_seed: :native_ml_dsa_44_keypair_from_seed,
17
+ check_secret_key: :native_ml_dsa_44_check_secret_key,
17
18
  }.freeze,
18
19
  ml_dsa_65: {
19
20
  keypair: :native_sign_keypair,
20
21
  sign: :native_sign,
21
22
  verify: :native_verify,
22
23
  keypair_from_seed: :native_ml_dsa_keypair_from_seed,
24
+ check_secret_key: :native_ml_dsa_check_secret_key,
23
25
  }.freeze,
24
26
  ml_dsa_87: {
25
27
  keypair: :native_ml_dsa_87_keypair,
26
28
  sign: :native_ml_dsa_87_sign,
27
29
  verify: :native_ml_dsa_87_verify,
28
30
  keypair_from_seed: :native_ml_dsa_87_keypair_from_seed,
31
+ check_secret_key: :native_ml_dsa_87_check_secret_key,
29
32
  }.freeze,
30
33
  }.freeze
31
34
 
@@ -33,7 +36,8 @@ module PQCrypto
33
36
  def generate(algorithm = CANONICAL_ALGORITHM)
34
37
  algorithm = resolve_algorithm!(algorithm)
35
38
  public_key, secret_key = PQCrypto.__send__(native_method_for(algorithm, :keypair))
36
- Keypair.new(PublicKey.new(algorithm, public_key), SecretKey.new(algorithm, secret_key))
39
+ Keypair.new(PublicKey.new(algorithm, public_key),
40
+ SecretKey.new(algorithm, secret_key, freshly_generated: true))
37
41
  end
38
42
 
39
43
  def public_key_from_bytes(algorithm, bytes)
@@ -86,12 +90,18 @@ module PQCrypto
86
90
  PublicKey.new(resolve_algorithm!(resolved_algorithm), bytes)
87
91
  end
88
92
 
89
- def secret_key_from_pkcs8_der(der, passphrase: nil)
90
- secret_key_from_decoded_pkcs8(*PKCS8.decode_der(der, passphrase: passphrase))
93
+ def secret_key_from_pkcs8_der(der, passphrase: nil, require_encrypted: false)
94
+ require_encrypted = Internal.strict_boolean!(require_encrypted, name: "require_encrypted")
95
+ secret_key_from_decoded_pkcs8(
96
+ *PKCS8.decode_der(der, passphrase: passphrase, require_encrypted: require_encrypted)
97
+ )
91
98
  end
92
99
 
93
- def secret_key_from_pkcs8_pem(pem, passphrase: nil)
94
- secret_key_from_decoded_pkcs8(*PKCS8.decode_pem(pem, passphrase: passphrase))
100
+ def secret_key_from_pkcs8_pem(pem, passphrase: nil, require_encrypted: false)
101
+ require_encrypted = Internal.strict_boolean!(require_encrypted, name: "require_encrypted")
102
+ secret_key_from_decoded_pkcs8(
103
+ *PKCS8.decode_pem(pem, passphrase: passphrase, require_encrypted: require_encrypted)
104
+ )
95
105
  end
96
106
 
97
107
  def details(algorithm)
@@ -118,7 +128,7 @@ module PQCrypto
118
128
  SecretKey.new(algorithm, material)
119
129
  when :seed
120
130
  _public_key, expanded = PQCrypto.__send__(native_method_for(algorithm, :keypair_from_seed), material)
121
- SecretKey.new(algorithm, expanded, seed: material)
131
+ SecretKey.new(algorithm, expanded, seed: material, freshly_generated: true)
122
132
  when :both
123
133
  _seed, expanded = material
124
134
  SecretKey.new(algorithm, expanded, seed: _seed)
@@ -133,6 +143,10 @@ module PQCrypto
133
143
  NATIVE_DISPATCH.fetch(resolve_algorithm!(algorithm)).fetch(operation)
134
144
  end
135
145
 
146
+ def secret_key_checkable?(algorithm)
147
+ NATIVE_DISPATCH.key?(algorithm) && NATIVE_DISPATCH.fetch(algorithm).key?(:check_secret_key)
148
+ end
149
+
136
150
  def validate_algorithm_match!(expected_algorithm, actual_algorithm)
137
151
  expected = resolve_algorithm!(expected_algorithm)
138
152
  return if expected == actual_algorithm
@@ -264,7 +278,7 @@ module PQCrypto
264
278
 
265
279
  def initialize(algorithm, bytes)
266
280
  @algorithm = algorithm
267
- @bytes = Internal.binary_string(bytes)
281
+ @bytes = Internal.frozen_binary_string(bytes)
268
282
  validate_length!
269
283
  end
270
284
 
@@ -343,18 +357,25 @@ module PQCrypto
343
357
  class SecretKey
344
358
  attr_reader :algorithm
345
359
 
346
- def initialize(algorithm, bytes, seed: nil)
360
+ def initialize(algorithm, bytes, seed: nil, freshly_generated: false)
347
361
  @algorithm = algorithm
348
362
  @bytes = Internal.binary_string(bytes)
349
363
  @seed = seed.nil? ? nil : Internal.binary_string(seed)
350
364
  validate_length!
351
365
  validate_seed_length! if @seed
366
+ validate_structure! unless freshly_generated
367
+ end
368
+
369
+ def valid?
370
+ return true unless Signature.send(:secret_key_checkable?, @algorithm)
371
+
372
+ PQCrypto.__send__(Signature.send(:native_method_for, @algorithm, :check_secret_key), @bytes)
352
373
  end
353
374
 
354
375
  def self.from_seed(algorithm, seed)
355
376
  seed_bytes = Internal.binary_string(seed)
356
377
  _public_key, expanded = PQCrypto.__send__(Signature.send(:native_method_for, algorithm, :keypair_from_seed), seed_bytes)
357
- new(algorithm, expanded, seed: seed_bytes)
378
+ new(algorithm, expanded, seed: seed_bytes, freshly_generated: true)
358
379
  rescue ArgumentError => e
359
380
  raise InvalidKeyError, e.message
360
381
  end
@@ -424,6 +445,10 @@ module PQCrypto
424
445
  raise InvalidKeyError, "Invalid signature secret key length" unless @bytes.bytesize == expected
425
446
  end
426
447
 
448
+ def validate_structure!
449
+ raise InvalidKeyError, "Invalid #{@algorithm} secret key: ML-DSA structure check failed" unless valid?
450
+ end
451
+
427
452
  def pkcs8_material(format)
428
453
  case format
429
454
  when :expanded
@@ -26,7 +26,7 @@ module PQCrypto
26
26
  ]),
27
27
  OpenSSL::ASN1::BitString.new(bytes),
28
28
  ]).to_der.b
29
- rescue OpenSSL::ASN1::ASN1Error => e
29
+ rescue OpenSSL::OpenSSLError, TypeError => e
30
30
  raise SerializationError, e.message
31
31
  end
32
32
 
@@ -63,6 +63,8 @@ module PQCrypto
63
63
  end
64
64
 
65
65
  [algorithm, bytes]
66
+ rescue OpenSSL::OpenSSLError, TypeError => e
67
+ raise SerializationError, e.message
66
68
  end
67
69
 
68
70
  def decode_pem(pem)
@@ -74,7 +76,7 @@ module PQCrypto
74
76
 
75
77
  def decode_asn1(der)
76
78
  OpenSSL::ASN1.decode(der)
77
- rescue OpenSSL::ASN1::ASN1Error => e
79
+ rescue OpenSSL::OpenSSLError, TypeError => e
78
80
  raise SerializationError, e.message
79
81
  end
80
82
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PQCrypto
4
- VERSION = "0.6.5"
4
+ VERSION = "0.6.7"
5
5
  end
data/lib/pq_crypto.rb CHANGED
@@ -65,6 +65,15 @@ module PQCrypto
65
65
  ml_kem_1024_keypair_from_seed
66
66
  ml_kem_1024_encapsulate
67
67
  ml_kem_1024_decapsulate
68
+ ml_kem_check_public_key
69
+ ml_kem_check_secret_key
70
+ ml_kem_512_check_public_key
71
+ ml_kem_512_check_secret_key
72
+ ml_kem_1024_check_public_key
73
+ ml_kem_1024_check_secret_key
74
+ ml_dsa_check_secret_key
75
+ ml_dsa_44_check_secret_key
76
+ ml_dsa_87_check_secret_key
68
77
  hybrid_kem_keypair
69
78
  hybrid_kem_encapsulate
70
79
  hybrid_kem_expand_secret_key
@@ -13,17 +13,17 @@ MANIFEST_PATH = File.join(VENDOR_DIR, ".vendored")
13
13
  PINS = {
14
14
  mlkem: {
15
15
  repo: "https://github.com/pq-code-package/mlkem-native.git",
16
- ref: "v1.3.0",
17
- commit: "398050c877ff4353c96305c6434b63528accfc37",
18
- tree_sha256: "3cd7af93cde256f73ce5ffde3ac3accd31e4361616e275f1bf1c39d462c2149e",
16
+ ref: "v2.0.0",
17
+ commit: "d1b2fe782888bdb761a50336012923180be7f502",
18
+ tree_sha256: "18bfa9ea4e2232bdf56f8ec374b62d10e50b99a30cb08aafc18d0b97e00cd06f",
19
19
  target: "mlkem-native",
20
20
  source_dir: "mlkem"
21
21
  },
22
22
  mldsa: {
23
23
  repo: "https://github.com/pq-code-package/mldsa-native.git",
24
- ref: "v1.0.0-beta2",
25
- commit: "9b0ee84f4cf399043eca59eca4e5f8531ca1d61b",
26
- tree_sha256: "2887f59926c18a877e8c5a5e30727e84497c357032093d00d7135aedf53f011e",
24
+ ref: "v2.0.0",
25
+ commit: "834a90d5e846ffa1e1611bd24e160bb2e9b86d35",
26
+ tree_sha256: "25b3c3949d2ed37d1ad5d4722c8476d13deb2a0bb945f12444f463378d69375d",
27
27
  target: "mldsa-native",
28
28
  source_dir: "mldsa"
29
29
  }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pq_crypto
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.5
4
+ version: 0.6.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roman Haydarov
@@ -82,6 +82,7 @@ files:
82
82
  - ext/pqcrypto/vendor/mldsa-native/LICENSE
83
83
  - ext/pqcrypto/vendor/mldsa-native/META.yml
84
84
  - ext/pqcrypto/vendor/mldsa-native/README.md
85
+ - ext/pqcrypto/vendor/mldsa-native/RELEASE.md
85
86
  - ext/pqcrypto/vendor/mldsa-native/SECURITY.md
86
87
  - ext/pqcrypto/vendor/mldsa-native/mldsa/README.md
87
88
  - ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native.c
@@ -90,6 +91,7 @@ files:
90
91
  - ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native_config.h
91
92
  - ext/pqcrypto/vendor/mldsa-native/mldsa/src/cbmc.h
92
93
  - ext/pqcrypto/vendor/mldsa-native/mldsa/src/common.h
94
+ - ext/pqcrypto/vendor/mldsa-native/mldsa/src/context.h
93
95
  - ext/pqcrypto/vendor/mldsa-native/mldsa/src/ct.c
94
96
  - ext/pqcrypto/vendor/mldsa-native/mldsa/src/ct.h
95
97
  - ext/pqcrypto/vendor/mldsa-native/mldsa/src/debug.c
@@ -119,9 +121,9 @@ files:
119
121
  - ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/fips202_native_armv81m.h
120
122
  - ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.S
121
123
  - ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.c
124
+ - ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccak_f1600_x4_state_extract_bytes_mve.S
125
+ - ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccak_f1600_x4_state_xor_bytes_mve.S
122
126
  - ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccakf1600_round_constants.c
123
- - ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/state_extract_bytes_x4_mve.S
124
- - ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/state_xor_bytes_x4_mve.S
125
127
  - ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/auto.h
126
128
  - ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/keccak_f1600_x4_avx2.h
127
129
  - ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/fips202_native_x86_64.h
@@ -130,24 +132,24 @@ files:
130
132
  - ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/meta.h
131
133
  - ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/aarch64_zetas.c
132
134
  - ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/arith_native_aarch64.h
133
- - ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/intt_aarch64_asm.S
134
- - ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l4_aarch64_asm.S
135
- - ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l5_aarch64_asm.S
136
- - ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l7_aarch64_asm.S
137
- - ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/ntt_aarch64_asm.S
138
- - ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/pointwise_montgomery_aarch64_asm.S
139
- - ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_caddq_aarch64_asm.S
140
- - ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_chknorm_aarch64_asm.S
141
- - ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_decompose_32_aarch64_asm.S
142
- - ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_decompose_88_aarch64_asm.S
143
- - ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_use_hint_32_aarch64_asm.S
144
- - ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_use_hint_88_aarch64_asm.S
145
- - ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/polyz_unpack_17_aarch64_asm.S
146
- - ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/polyz_unpack_19_aarch64_asm.S
135
+ - ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_intt_aarch64_asm.S
136
+ - ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_ntt_aarch64_asm.S
137
+ - ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_pointwise_montgomery_aarch64_asm.S
138
+ - ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_poly_caddq_aarch64_asm.S
139
+ - ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_poly_chknorm_aarch64_asm.S
140
+ - ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_poly_decompose_32_aarch64_asm.S
141
+ - ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_poly_decompose_88_aarch64_asm.S
142
+ - ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_poly_use_hint_32_aarch64_asm.S
143
+ - ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_poly_use_hint_88_aarch64_asm.S
144
+ - ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_polyvecl_pointwise_acc_montgomery_l4_aarch64_asm.S
145
+ - ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_polyvecl_pointwise_acc_montgomery_l5_aarch64_asm.S
146
+ - ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_polyvecl_pointwise_acc_montgomery_l7_aarch64_asm.S
147
+ - ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_polyz_unpack_17_aarch64_asm.S
148
+ - ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_polyz_unpack_19_aarch64_asm.S
149
+ - ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_rej_uniform_aarch64_asm.S
150
+ - ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_rej_uniform_eta2_aarch64_asm.S
151
+ - ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_rej_uniform_eta4_aarch64_asm.S
147
152
  - ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/polyz_unpack_table.c
148
- - ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_aarch64_asm.S
149
- - ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_eta2_aarch64_asm.S
150
- - ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_eta4_aarch64_asm.S
151
153
  - ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_eta_table.c
152
154
  - ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_table.c
153
155
  - ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/api.h
@@ -156,24 +158,24 @@ files:
156
158
  - ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/arith_native_x86_64.h
157
159
  - ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/consts.c
158
160
  - ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/consts.h
159
- - ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/intt_avx2_asm.S
160
- - ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/ntt_avx2_asm.S
161
- - ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/nttunpack_avx2_asm.S
162
- - ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l4_avx2_asm.S
163
- - ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l5_avx2_asm.S
164
- - ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l7_avx2_asm.S
165
- - ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_avx2_asm.S
166
- - ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_caddq_avx2_asm.S
167
- - ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_chknorm_avx2.c
168
- - ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_decompose_32_avx2.c
169
- - ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_decompose_88_avx2.c
170
- - ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_use_hint_32_avx2.c
171
- - ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_use_hint_88_avx2.c
172
- - ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/polyz_unpack_17_avx2.c
173
- - ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/polyz_unpack_19_avx2.c
174
- - ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/rej_uniform_avx2.c
175
- - ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/rej_uniform_eta2_avx2.c
176
- - ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/rej_uniform_eta4_avx2.c
161
+ - ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_intt_avx2_asm.S
162
+ - ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_ntt_avx2_asm.S
163
+ - ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_nttunpack_avx2_asm.S
164
+ - ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_pointwise_acc_l4_avx2_asm.S
165
+ - ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_pointwise_acc_l5_avx2_asm.S
166
+ - ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_pointwise_acc_l7_avx2_asm.S
167
+ - ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_pointwise_avx2_asm.S
168
+ - ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_poly_caddq_avx2_asm.S
169
+ - ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_poly_chknorm_avx2_asm.S
170
+ - ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_poly_decompose_32_avx2_asm.S
171
+ - ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_poly_decompose_88_avx2_asm.S
172
+ - ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_poly_use_hint_32_avx2_asm.S
173
+ - ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_poly_use_hint_88_avx2_asm.S
174
+ - ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_polyz_unpack_17_avx2_asm.S
175
+ - ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_polyz_unpack_19_avx2_asm.S
176
+ - ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_rej_uniform_avx2_asm.S
177
+ - ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_rej_uniform_eta2_avx2_asm.S
178
+ - ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_rej_uniform_eta4_avx2_asm.S
177
179
  - ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/rej_uniform_table.c
178
180
  - ext/pqcrypto/vendor/mldsa-native/mldsa/src/packing.c
179
181
  - ext/pqcrypto/vendor/mldsa-native/mldsa/src/packing.h
@@ -1,52 +0,0 @@
1
- /*
2
- * Copyright (c) The mldsa-native project authors
3
- * SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
4
- */
5
-
6
- /* References
7
- * ==========
8
- *
9
- * - [REF_AVX2]
10
- * CRYSTALS-Dilithium optimized AVX2 implementation
11
- * Bai, Ducas, Kiltz, Lepoint, Lyubashevsky, Schwabe, Seiler, Stehlé
12
- * https://github.com/pq-crystals/dilithium/tree/master/avx2
13
- */
14
-
15
- /*
16
- * This file is derived from the public domain
17
- * AVX2 Dilithium implementation @[REF_AVX2].
18
- */
19
-
20
- #include "../../../common.h"
21
-
22
- #if defined(MLD_ARITH_BACKEND_X86_64_DEFAULT) && \
23
- !defined(MLD_CONFIG_MULTILEVEL_NO_SHARED)
24
-
25
- #include <immintrin.h>
26
- #include "arith_native_x86_64.h"
27
-
28
- int mld_poly_chknorm_avx2(const int32_t *a, int32_t B)
29
- {
30
- unsigned int i;
31
- __m256i f, t;
32
- const __m256i bound = _mm256_set1_epi32(B - 1);
33
-
34
- t = _mm256_setzero_si256();
35
- for (i = 0; i < MLDSA_N / 8; i++)
36
- {
37
- f = _mm256_load_si256((const __m256i *)&a[8 * i]);
38
- f = _mm256_abs_epi32(f);
39
- f = _mm256_cmpgt_epi32(f, bound);
40
- t = _mm256_or_si256(t, f);
41
- }
42
-
43
- return 1 - _mm256_testz_si256(t, t);
44
- }
45
-
46
- #else /* MLD_ARITH_BACKEND_X86_64_DEFAULT && !MLD_CONFIG_MULTILEVEL_NO_SHARED \
47
- */
48
-
49
- MLD_EMPTY_CU(avx2_poly_chknorm)
50
-
51
- #endif /* !(MLD_ARITH_BACKEND_X86_64_DEFAULT && \
52
- !MLD_CONFIG_MULTILEVEL_NO_SHARED) */