pq_crypto 0.6.7 → 0.6.9

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 (214) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +20 -0
  3. data/README.md +1 -3
  4. data/ext/pqcrypto/pqcrypto_ruby_secure.c +41 -11
  5. data/ext/pqcrypto/pqcrypto_secure.c +501 -296
  6. data/ext/pqcrypto/pqcrypto_version.h +1 -1
  7. data/ext/pqcrypto/vendor/.vendored +7 -7
  8. data/ext/pqcrypto/vendor/mldsa-native/BUILDING.md +71 -0
  9. data/ext/pqcrypto/vendor/mldsa-native/README.md +26 -11
  10. data/ext/pqcrypto/vendor/mldsa-native/RELEASE.md +77 -150
  11. data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native.c +93 -40
  12. data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native.h +74 -59
  13. data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native_asm.S +106 -40
  14. data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native_config.h +94 -92
  15. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/capability.h +31 -0
  16. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/cbmc.h +55 -4
  17. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/common.h +30 -0
  18. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/context.h +1 -0
  19. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/debug.c +1 -0
  20. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/fips202.h +1 -0
  21. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_scalar_aarch64_asm.S +5 -2
  22. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_v84a_aarch64_asm.S +4 -4
  23. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x2_v84a_aarch64_asm.S +4 -4
  24. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_scalar_hybrid_aarch64_asm.S +8 -3
  25. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_v84a_scalar_hybrid_aarch64_asm.S +8 -4
  26. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/mve.h +12 -0
  27. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.S +4 -2
  28. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccak_f1600_x4_state_extract_bytes_mve.S +37 -19
  29. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccak_f1600_x4_state_xor_bytes_mve.S +37 -19
  30. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/auto.h +3 -8
  31. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/auto.h +53 -0
  32. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/keccak_f1600_x1_avx512.h +38 -0
  33. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/keccak_f1600_x4_avx512.h +38 -0
  34. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/fips202_native_x86_64.h +24 -0
  35. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/keccak_f1600_x1_avx512_asm.S +574 -0
  36. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/keccak_f1600_x4_avx2_asm.S +46 -18
  37. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/keccak_f1600_x4_avx512_asm.S +679 -0
  38. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/keccakf1600_constants.c +13 -4
  39. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/meta.h +6 -4
  40. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/arith_native_aarch64.h +5 -6
  41. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_intt_aarch64_asm.S +4 -2
  42. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_ntt_aarch64_asm.S +4 -2
  43. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_pointwise_montgomery_aarch64_asm.S +6 -4
  44. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_poly_caddq_aarch64_asm.S +4 -2
  45. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_poly_chknorm_aarch64_asm.S +6 -4
  46. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_poly_decompose_32_aarch64_asm.S +4 -3
  47. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_poly_decompose_88_aarch64_asm.S +4 -3
  48. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_poly_use_hint_32_aarch64_asm.S +4 -3
  49. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_poly_use_hint_88_aarch64_asm.S +4 -3
  50. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_polyvecl_pointwise_acc_montgomery_l4_aarch64_asm.S +4 -2
  51. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_polyvecl_pointwise_acc_montgomery_l5_aarch64_asm.S +4 -2
  52. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_polyvecl_pointwise_acc_montgomery_l7_aarch64_asm.S +4 -2
  53. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_polyz_unpack_17_aarch64_asm.S +5 -3
  54. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_polyz_unpack_19_aarch64_asm.S +5 -3
  55. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_rej_uniform_aarch64_asm.S +110 -120
  56. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_rej_uniform_eta2_aarch64_asm.S +109 -101
  57. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_rej_uniform_eta4_aarch64_asm.S +97 -93
  58. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/api.h +1 -9
  59. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/meta.h +4 -0
  60. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/rv32im/fastmul.h +74 -0
  61. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/rv32im/slowmul.h +77 -0
  62. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/rv32im/src/arith_native_rv32im.h +124 -0
  63. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/rv32im/src/mldsa_intt_rv32im_asm.S +331 -0
  64. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/rv32im/src/mldsa_intt_rv32im_slowmul_asm.S +381 -0
  65. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/rv32im/src/mldsa_ntt_rv32im_asm.S +304 -0
  66. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/rv32im/src/mldsa_ntt_rv32im_slowmul_asm.S +351 -0
  67. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/rv32im/src/mldsa_poly_pointwise_montgomery_rv32im_asm.S +139 -0
  68. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/rv32im/src/rv32im_zetas.c +118 -0
  69. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/meta.h +6 -5
  70. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/arith_native_x86_64.h +2 -3
  71. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_intt_avx2_asm.S +5 -3
  72. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_ntt_avx2_asm.S +5 -3
  73. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_nttunpack_avx2_asm.S +5 -3
  74. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_pointwise_acc_l4_avx2_asm.S +6 -3
  75. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_pointwise_acc_l5_avx2_asm.S +6 -3
  76. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_pointwise_acc_l7_avx2_asm.S +6 -3
  77. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_pointwise_avx2_asm.S +5 -3
  78. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_poly_caddq_avx2_asm.S +5 -3
  79. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_poly_chknorm_avx2_asm.S +7 -5
  80. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_poly_decompose_32_avx2_asm.S +69 -67
  81. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_poly_decompose_88_avx2_asm.S +69 -67
  82. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_poly_use_hint_32_avx2_asm.S +12 -16
  83. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_poly_use_hint_88_avx2_asm.S +14 -18
  84. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_polyz_unpack_17_avx2_asm.S +6 -3
  85. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_polyz_unpack_19_avx2_asm.S +6 -3
  86. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_rej_uniform_avx2_asm.S +5 -3
  87. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_rej_uniform_eta2_avx2_asm.S +5 -3
  88. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_rej_uniform_eta4_avx2_asm.S +5 -3
  89. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/packing.c +23 -27
  90. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/packing.h +21 -42
  91. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/params.h +28 -1
  92. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly.c +87 -28
  93. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly.h +61 -3
  94. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly_kl.c +23 -19
  95. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly_kl.h +30 -0
  96. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec.c +55 -107
  97. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec.h +67 -107
  98. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec_lazy.c +16 -24
  99. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec_lazy.h +27 -21
  100. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/reduce.h +8 -8
  101. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/sign.c +191 -119
  102. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/sign.h +6 -3
  103. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/sys.h +16 -42
  104. data/ext/pqcrypto/vendor/mlkem-native/BUILDING.md +72 -0
  105. data/ext/pqcrypto/vendor/mlkem-native/README.md +9 -5
  106. data/ext/pqcrypto/vendor/mlkem-native/RELEASE.md +64 -312
  107. data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native.c +77 -34
  108. data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native.h +41 -13
  109. data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native_asm.S +89 -33
  110. data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native_config.h +50 -46
  111. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/capability.h +30 -0
  112. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/common.h +30 -0
  113. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/compress.c +1 -0
  114. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/compress.h +4 -5
  115. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/debug.c +1 -0
  116. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/fips202.c +15 -0
  117. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/fips202.h +23 -8
  118. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/fips202x4.c +11 -3
  119. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/fips202x4.h +7 -1
  120. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/keccakf1600.c +8 -0
  121. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/keccakf1600.h +8 -0
  122. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccak_f1600_x1_scalar_aarch64_asm.S +5 -2
  123. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccak_f1600_x1_v84a_aarch64_asm.S +4 -4
  124. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccak_f1600_x2_v84a_aarch64_asm.S +4 -4
  125. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_scalar_hybrid_aarch64_asm.S +8 -3
  126. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_v84a_scalar_hybrid_aarch64_asm.S +8 -4
  127. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.S +4 -2
  128. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/keccak_f1600_x4_state_extract_bytes_mve.S +37 -19
  129. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/keccak_f1600_x4_state_xor_bytes_mve.S +37 -19
  130. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/auto.h +2 -2
  131. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/auto.h +47 -0
  132. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/keccak_f1600_x1_avx512.h +37 -0
  133. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/keccak_f1600_x4_avx512.h +37 -0
  134. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/src/fips202_native_x86_64.h +24 -0
  135. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/src/keccak_f1600_x1_avx512_asm.S +573 -0
  136. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/src/keccak_f1600_x4_avx2_asm.S +46 -18
  137. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/src/keccak_f1600_x4_avx512_asm.S +678 -0
  138. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/src/keccakf1600_constants.c +13 -4
  139. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/indcpa.c +1 -2
  140. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/kem.c +7 -5
  141. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/kem.h +29 -5
  142. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/meta.h +156 -0
  143. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/arith_native_aarch64.h +137 -3
  144. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/compress_d5_table.c +43 -0
  145. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/decompress_d10_table.c +50 -0
  146. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/decompress_d11_table.c +53 -0
  147. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/decompress_d4_table.c +44 -0
  148. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/decompress_d5_table.c +53 -0
  149. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_intt_aarch64_asm.S +5 -3
  150. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_ntt_aarch64_asm.S +4 -2
  151. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_poly_compress_d10_aarch64_asm.S +439 -0
  152. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_poly_compress_d11_aarch64_asm.S +452 -0
  153. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_poly_compress_d4_aarch64_asm.S +106 -0
  154. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_poly_compress_d5_aarch64_asm.S +124 -0
  155. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_poly_decompress_d10_aarch64_asm.S +108 -0
  156. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_poly_decompress_d11_aarch64_asm.S +116 -0
  157. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_poly_decompress_d4_aarch64_asm.S +93 -0
  158. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_poly_decompress_d5_aarch64_asm.S +104 -0
  159. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_poly_frombytes_aarch64_asm.S +84 -0
  160. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_poly_mulcache_compute_aarch64_asm.S +4 -2
  161. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_poly_reduce_aarch64_asm.S +4 -2
  162. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_poly_tobytes_aarch64_asm.S +5 -3
  163. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_poly_tomont_aarch64_asm.S +4 -3
  164. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_polyvec_basemul_acc_montgomery_cached_k2_aarch64_asm.S +4 -2
  165. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_polyvec_basemul_acc_montgomery_cached_k3_aarch64_asm.S +4 -2
  166. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_polyvec_basemul_acc_montgomery_cached_k4_aarch64_asm.S +4 -2
  167. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_rej_uniform_aarch64_asm.S +112 -104
  168. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/api.h +0 -1
  169. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/meta.h +2 -2
  170. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/README.md +2 -2
  171. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/meta.h +16 -21
  172. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/arith_native_ppc64le.h +1 -0
  173. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/consts.c +2 -2
  174. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/mlkem_intt_ppc_asm.S +6 -5
  175. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/mlkem_ntt_ppc_asm.S +6 -5
  176. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/mlkem_poly_tomont_ppc_asm.S +6 -5
  177. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/mlkem_reduce_ppc_asm.S +6 -5
  178. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/rv64v_debug.c +5 -4
  179. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/rv64v_debug.h +2 -2
  180. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/rv64v_poly.c +1 -1
  181. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/arith_native_x86_64.h +5 -5
  182. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_intt_avx2_asm.S +36 -33
  183. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_ntt_avx2_asm.S +67 -65
  184. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_nttfrombytes_avx2_asm.S +8 -5
  185. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_ntttobytes_avx2_asm.S +6 -3
  186. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_nttunpack_avx2_asm.S +5 -3
  187. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_poly_compress_d10_avx2_asm.S +7 -5
  188. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_poly_compress_d11_avx2_asm.S +7 -4
  189. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_poly_compress_d4_avx2_asm.S +7 -5
  190. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_poly_compress_d5_avx2_asm.S +7 -4
  191. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_poly_decompress_d10_avx2_asm.S +7 -4
  192. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_poly_decompress_d11_avx2_asm.S +6 -4
  193. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_poly_decompress_d4_avx2_asm.S +7 -4
  194. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_poly_decompress_d5_avx2_asm.S +6 -4
  195. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_poly_mulcache_compute_avx2_asm.S +5 -3
  196. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_polyvec_basemul_acc_montgomery_cached_k2_avx2_asm.S +118 -115
  197. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_polyvec_basemul_acc_montgomery_cached_k3_avx2_asm.S +174 -171
  198. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_polyvec_basemul_acc_montgomery_cached_k4_avx2_asm.S +230 -227
  199. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_reduce_avx2_asm.S +17 -15
  200. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_rej_uniform_avx2_asm.S +7 -6
  201. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_tomont_avx2_asm.S +5 -3
  202. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/poly_k.c +4 -9
  203. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/poly_k.h +1 -1
  204. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/sys.h +31 -44
  205. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/verify.h +1 -1
  206. data/lib/pq_crypto/internal.rb +10 -0
  207. data/lib/pq_crypto/kem.rb +5 -10
  208. data/lib/pq_crypto/pkcs8/der.rb +26 -11
  209. data/lib/pq_crypto/pkcs8/private_key_choice.rb +21 -25
  210. data/lib/pq_crypto/signature.rb +28 -40
  211. data/lib/pq_crypto/spki.rb +36 -23
  212. data/lib/pq_crypto/version.rb +1 -1
  213. data/script/vendor_libs.rb +6 -6
  214. metadata +36 -1
@@ -124,30 +124,34 @@ __contract__(
124
124
  );
125
125
  #endif /* !MLD_CONFIG_REDUCE_RAM || MLD_UNIT_TEST */
126
126
 
127
- #if !defined(MLD_CONFIG_NO_KEYPAIR_API) || !defined(MLD_CONFIG_NO_VERIFY_API)
127
+ #if (!defined(MLD_CONFIG_NO_KEYPAIR_API) && \
128
+ !defined(MLD_CONFIG_CORE_API_ONLY)) || \
129
+ !defined(MLD_CONFIG_NO_VERIFY_API)
128
130
  #define mld_polyvecl_chknorm MLD_NAMESPACE_KL(polyvecl_chknorm)
129
131
  /**
130
132
  * Check infinity norm of polynomials in vector of length MLDSA_L. Assumes
131
133
  * input mld_polyvecl to be reduced by polyvecl_reduce().
132
134
  *
133
135
  * @param[in] v Pointer to vector.
134
- * @param B Norm bound.
136
+ * @param B Norm bound. Must be MLDSA_GAMMA1 - MLDSA_BETA or
137
+ * MLDSA_ETA + 1, the only bounds used by the library.
135
138
  *
136
139
  * @return 0 if norm of all polynomials is strictly smaller than
137
- * B <= (MLDSA_Q-1)/8 and 0xFFFFFFFF otherwise.
140
+ * B and 0xFFFFFFFF otherwise.
138
141
  */
139
142
  MLD_INTERNAL_API
140
143
  MLD_MUST_CHECK_RETURN_VALUE
141
144
  uint32_t mld_polyvecl_chknorm(const mld_polyvecl *v, int32_t B)
142
145
  __contract__(
143
146
  requires(memory_no_alias(v, sizeof(mld_polyvecl)))
144
- requires(0 <= B && B <= (MLDSA_Q - 1) / 8)
147
+ requires(B == MLDSA_GAMMA1 - MLDSA_BETA || B == MLDSA_ETA + 1)
145
148
  requires(forall(k0, 0, MLDSA_L,
146
149
  array_bound(v->vec[k0].coeffs, 0, MLDSA_N, -MLD_REDUCE32_RANGE_MAX, MLD_REDUCE32_RANGE_MAX)))
147
150
  ensures(return_value == 0 || return_value == 0xFFFFFFFF)
148
151
  ensures((return_value == 0) == forall(k1, 0, MLDSA_L, array_abs_bound(v->vec[k1].coeffs, 0, MLDSA_N, B)))
149
152
  );
150
- #endif /* !MLD_CONFIG_NO_KEYPAIR_API || !MLD_CONFIG_NO_VERIFY_API */
153
+ #endif /* (!MLD_CONFIG_NO_KEYPAIR_API && !MLD_CONFIG_CORE_API_ONLY) || \
154
+ !MLD_CONFIG_NO_VERIFY_API */
151
155
 
152
156
  /** Vector of MLDSA_K polynomials. */
153
157
  typedef struct
@@ -238,134 +242,87 @@ __contract__(
238
242
  );
239
243
  #endif /* !MLD_CONFIG_NO_SIGN_API || MLD_UNIT_TEST */
240
244
 
241
- #if !defined(MLD_CONFIG_NO_KEYPAIR_API)
242
- #define mld_polyveck_chknorm MLD_NAMESPACE_KL(polyveck_chknorm)
245
+ #if !defined(MLD_CONFIG_NO_KEYPAIR_API) && !defined(MLD_CONFIG_CORE_API_ONLY)
246
+ #define mld_polyveck_unpack_eta_chknorm \
247
+ MLD_NAMESPACE_KL(polyveck_unpack_eta_chknorm)
243
248
  /**
244
- * Check infinity norm of polynomials in vector of length MLDSA_K. Assumes
245
- * input mld_polyveck to be reduced by polyveck_reduce().
249
+ * Check the infinity norm of a bit-packed vector of MLDSA_K polynomials.
246
250
  *
247
- * @param[in] v Pointer to vector.
248
- * @param B Norm bound.
251
+ * Each polynomial is unpacked into the scratch buffer and checked in turn.
252
+ *
253
+ * @param[in] r Input byte array with bit-packed polynomial vector.
254
+ * @param B Norm bound.
255
+ * @param[out] scratch Scratch buffer for the polynomial being checked.
249
256
  *
250
- * @return 0 if norm of all polynomials are strictly smaller than
257
+ * @return 0 if the norm of all polynomials is strictly smaller than
251
258
  * B <= (MLDSA_Q-1)/8 and 0xFFFFFFFF otherwise.
252
259
  */
253
260
  MLD_INTERNAL_API
254
261
  MLD_MUST_CHECK_RETURN_VALUE
255
- uint32_t mld_polyveck_chknorm(const mld_polyveck *v, int32_t B)
262
+ uint32_t mld_polyveck_unpack_eta_chknorm(
263
+ const uint8_t r[MLDSA_K * MLDSA_POLYETA_PACKEDBYTES], int32_t B,
264
+ mld_poly *scratch)
256
265
  __contract__(
257
- requires(memory_no_alias(v, sizeof(mld_polyveck)))
266
+ requires(memory_no_alias(r, MLDSA_K * MLDSA_POLYETA_PACKEDBYTES))
267
+ requires(memory_no_alias(scratch, sizeof(mld_poly)))
258
268
  requires(0 <= B && B <= (MLDSA_Q - 1) / 8)
259
- requires(forall(k0, 0, MLDSA_K,
260
- array_bound(v->vec[k0].coeffs, 0, MLDSA_N,
261
- -MLD_REDUCE32_RANGE_MAX, MLD_REDUCE32_RANGE_MAX)))
269
+ assigns(memory_slice(scratch, sizeof(mld_poly)))
262
270
  ensures(return_value == 0 || return_value == 0xFFFFFFFF)
263
- ensures((return_value == 0) == forall(k1, 0, MLDSA_K, array_abs_bound(v->vec[k1].coeffs, 0, MLDSA_N, B)))
264
271
  );
265
272
 
266
- #endif /* !MLD_CONFIG_NO_KEYPAIR_API */
273
+ #endif /* !MLD_CONFIG_NO_KEYPAIR_API && !MLD_CONFIG_CORE_API_ONLY */
267
274
 
268
275
  #if !defined(MLD_CONFIG_NO_SIGN_API)
269
- #define mld_polyveck_decompose MLD_NAMESPACE_KL(polyveck_decompose)
276
+ #define mld_polyveck_decompose_pack_w1 \
277
+ MLD_NAMESPACE_KL(polyveck_decompose_pack_w1)
270
278
  /**
271
279
  * For all coefficients a of polynomials in vector of length MLDSA_K, compute
272
280
  * high and low bits a0, a1 such a mod^+ MLDSA_Q = a1*ALPHA + a0 with
273
281
  * -ALPHA/2 < a0 <= ALPHA/2 except a1 = (MLDSA_Q-1)/ALPHA where we set
274
282
  * a1 = 0 and -ALPHA/2 <= a0 = a mod MLDSA_Q - MLDSA_Q < 0. Assumes
275
- * coefficients to be standard representatives.
283
+ * coefficients to be standard representatives. The low bits replace the input
284
+ * vector, the high bits are bit-packed into r.
285
+ *
286
+ * Decomposing and packing are fused so that the high bits are never held as a
287
+ * vector of polynomials, saving MLDSA_K * sizeof(mld_poly) bytes. During
288
+ * MakeHint, a single entry of w1 is instead unpacked on demand.
276
289
  *
277
- * @reference{The reference implementation has the input polynomial as a
278
- * separate argument that may be aliased with either of the outputs. Removing
279
- * the aliasing eases CBMC proofs.}
290
+ * @spec{Combines @[FIPS204, Algorithm 36, Decompose] with
291
+ * @[FIPS204, Algorithm 28, w1Encode].}
280
292
  *
281
- * @param[out] v1 Pointer to output vector of polynomials with
282
- * coefficients a1.
283
- * @param[in,out] v0 Pointer to input/output vector of polynomials. Output
284
- * polynomial has coefficients a0.
293
+ * @reference{The reference implementation has the Decompose input as a separate
294
+ * argument that may be aliased with either of the outputs. Removing the
295
+ * aliasing eases CBMC proofs.}
296
+ *
297
+ * @param[out] r Pointer to output byte array with at least
298
+ * MLDSA_K * MLDSA_POLYW1_PACKEDBYTES bytes.
299
+ * @param[in,out] v0 Pointer to input/output vector of polynomials. Output
300
+ * polynomials have coefficients a0.
301
+ * @param[out] scratch Scratch polynomial holding the high bits of the
302
+ * polynomial currently being packed.
285
303
  */
286
304
  MLD_INTERNAL_API
287
- void mld_polyveck_decompose(mld_polyveck *v1, mld_polyveck *v0)
305
+ void mld_polyveck_decompose_pack_w1(
306
+ uint8_t r[MLDSA_K * MLDSA_POLYW1_PACKEDBYTES], mld_polyveck *v0,
307
+ mld_poly *scratch)
288
308
  __contract__(
289
- requires(memory_no_alias(v1, sizeof(mld_polyveck)))
309
+ requires(memory_no_alias(r, MLDSA_K * MLDSA_POLYW1_PACKEDBYTES))
290
310
  requires(memory_no_alias(v0, sizeof(mld_polyveck)))
311
+ requires(memory_no_alias(scratch, sizeof(mld_poly)))
291
312
  requires(forall(k0, 0, MLDSA_K,
292
313
  array_bound(v0->vec[k0].coeffs, 0, MLDSA_N, 0, MLDSA_Q)))
293
- assigns(memory_slice(v1, sizeof(mld_polyveck)))
314
+ assigns(memory_slice(r, MLDSA_K * MLDSA_POLYW1_PACKEDBYTES))
294
315
  assigns(memory_slice(v0, sizeof(mld_polyveck)))
316
+ assigns(memory_slice(scratch, sizeof(mld_poly)))
295
317
  ensures(forall(k1, 0, MLDSA_K,
296
- array_bound(v1->vec[k1].coeffs, 0, MLDSA_N, 0, (MLDSA_Q-1)/(2*MLDSA_GAMMA2))))
297
- ensures(forall(k2, 0, MLDSA_K,
298
- array_abs_bound(v0->vec[k2].coeffs, 0, MLDSA_N, MLDSA_GAMMA2+1)))
318
+ array_abs_bound(v0->vec[k1].coeffs, 0, MLDSA_N, MLDSA_GAMMA2+1)))
299
319
  );
300
320
  #endif /* !MLD_CONFIG_NO_SIGN_API */
301
321
 
302
- #if !defined(MLD_CONFIG_NO_SIGN_API)
303
- #define mld_polyveck_pack_w1 MLD_NAMESPACE_KL(polyveck_pack_w1)
304
- /**
305
- * Bit-pack polynomial vector w1 with coefficients in [0, 15] or [0, 43]. Input
306
- * coefficients are assumed to be standard representatives.
307
- *
308
- * @spec{Implements @[FIPS204, Algorithm 28, w1Encode].}
309
- *
310
- * @param[out] r Pointer to output byte array with at least
311
- * MLDSA_K * MLDSA_POLYW1_PACKEDBYTES bytes.
312
- * @param[in] w1 Pointer to input polynomial vector.
313
- */
314
- MLD_INTERNAL_API
315
- void mld_polyveck_pack_w1(uint8_t r[MLDSA_K * MLDSA_POLYW1_PACKEDBYTES],
316
- const mld_polyveck *w1)
317
- __contract__(
318
- requires(memory_no_alias(r, MLDSA_K * MLDSA_POLYW1_PACKEDBYTES))
319
- requires(memory_no_alias(w1, sizeof(mld_polyveck)))
320
- requires(forall(k1, 0, MLDSA_K,
321
- array_bound(w1->vec[k1].coeffs, 0, MLDSA_N, 0, (MLDSA_Q-1)/(2*MLDSA_GAMMA2))))
322
- assigns(memory_slice(r, MLDSA_K * MLDSA_POLYW1_PACKEDBYTES))
323
- );
324
- #endif /* !MLD_CONFIG_NO_SIGN_API */
325
-
326
- #if !defined(MLD_CONFIG_NO_KEYPAIR_API)
327
- #define mld_polyveck_pack_eta MLD_NAMESPACE_KL(polyveck_pack_eta)
328
- /**
329
- * Bit-pack polynomial vector with coefficients in [-MLDSA_ETA, MLDSA_ETA].
330
- *
331
- * @param[out] r Pointer to output byte array with
332
- * MLDSA_K * MLDSA_POLYETA_PACKEDBYTES bytes.
333
- * @param[in] p Pointer to input polynomial vector.
334
- */
335
- MLD_INTERNAL_API
336
- void mld_polyveck_pack_eta(uint8_t r[MLDSA_K * MLDSA_POLYETA_PACKEDBYTES],
337
- const mld_polyveck *p)
338
- __contract__(
339
- requires(memory_no_alias(r, MLDSA_K * MLDSA_POLYETA_PACKEDBYTES))
340
- requires(memory_no_alias(p, sizeof(mld_polyveck)))
341
- requires(forall(k1, 0, MLDSA_K,
342
- array_abs_bound(p->vec[k1].coeffs, 0, MLDSA_N, MLDSA_ETA + 1)))
343
- assigns(memory_slice(r, MLDSA_K * MLDSA_POLYETA_PACKEDBYTES))
344
- );
345
-
346
- #define mld_polyvecl_pack_eta MLD_NAMESPACE_KL(polyvecl_pack_eta)
347
- /**
348
- * Bit-pack polynomial vector with coefficients in [-MLDSA_ETA, MLDSA_ETA].
349
- *
350
- * @param[out] r Pointer to output byte array with
351
- * MLDSA_L * MLDSA_POLYETA_PACKEDBYTES bytes.
352
- * @param[in] p Pointer to input polynomial vector.
353
- */
354
- MLD_INTERNAL_API
355
- void mld_polyvecl_pack_eta(uint8_t r[MLDSA_L * MLDSA_POLYETA_PACKEDBYTES],
356
- const mld_polyvecl *p)
357
- __contract__(
358
- requires(memory_no_alias(r, MLDSA_L * MLDSA_POLYETA_PACKEDBYTES))
359
- requires(memory_no_alias(p, sizeof(mld_polyvecl)))
360
- requires(forall(k1, 0, MLDSA_L,
361
- array_abs_bound(p->vec[k1].coeffs, 0, MLDSA_N, MLDSA_ETA + 1)))
362
- assigns(memory_slice(r, MLDSA_L * MLDSA_POLYETA_PACKEDBYTES))
363
- );
364
-
365
- #endif /* !MLD_CONFIG_NO_KEYPAIR_API */
366
-
367
- #if !defined(MLD_CONFIG_NO_KEYPAIR_API) || \
368
- (!defined(MLD_CONFIG_NO_SIGN_API) && \
322
+ #if (!defined(MLD_CONFIG_NO_KEYPAIR_API) && \
323
+ !defined(MLD_CONFIG_CORE_API_ONLY)) || \
324
+ ((!defined(MLD_CONFIG_NO_KEYPAIR_API) || \
325
+ !defined(MLD_CONFIG_NO_SIGN_API)) && \
369
326
  (!defined(MLD_CONFIG_REDUCE_RAM) || defined(MLD_UNIT_TEST)))
370
327
  #define mld_polyvecl_unpack_eta MLD_NAMESPACE_KL(polyvecl_unpack_eta)
371
328
  /**
@@ -384,7 +341,8 @@ __contract__(
384
341
  ensures(forall(k1, 0, MLDSA_L,
385
342
  array_bound(p->vec[k1].coeffs, 0, MLDSA_N, MLD_POLYETA_UNPACK_LOWER_BOUND, MLDSA_ETA + 1)))
386
343
  );
387
- #endif /* !MLD_CONFIG_NO_KEYPAIR_API || (!MLD_CONFIG_NO_SIGN_API && \
344
+ #endif /* (!MLD_CONFIG_NO_KEYPAIR_API && !MLD_CONFIG_CORE_API_ONLY) || \
345
+ ((!MLD_CONFIG_NO_KEYPAIR_API || !MLD_CONFIG_NO_SIGN_API) && \
388
346
  (!MLD_CONFIG_REDUCE_RAM || MLD_UNIT_TEST)) */
389
347
 
390
348
  #if !defined(MLD_CONFIG_NO_VERIFY_API)
@@ -408,9 +366,10 @@ __contract__(
408
366
  );
409
367
  #endif /* !MLD_CONFIG_NO_VERIFY_API */
410
368
 
411
- #if !defined(MLD_CONFIG_NO_KEYPAIR_API) || \
412
- (!defined(MLD_CONFIG_NO_SIGN_API) && \
413
- (!defined(MLD_CONFIG_REDUCE_RAM) || defined(MLD_UNIT_TEST)))
369
+ #if (!defined(MLD_CONFIG_NO_KEYPAIR_API) || \
370
+ !defined(MLD_CONFIG_NO_SIGN_API)) && \
371
+ (!defined(MLD_CONFIG_NO_SIGN_API) || defined(MLD_UNIT_TEST)) && \
372
+ (!defined(MLD_CONFIG_REDUCE_RAM) || defined(MLD_UNIT_TEST))
414
373
  #define mld_polyveck_unpack_eta MLD_NAMESPACE_KL(polyveck_unpack_eta)
415
374
  /**
416
375
  * Unpack polynomial vector with coefficients in [-MLDSA_ETA, MLDSA_ETA].
@@ -428,8 +387,9 @@ __contract__(
428
387
  ensures(forall(k1, 0, MLDSA_K,
429
388
  array_bound(p->vec[k1].coeffs, 0, MLDSA_N, MLD_POLYETA_UNPACK_LOWER_BOUND, MLDSA_ETA + 1)))
430
389
  );
431
- #endif /* !MLD_CONFIG_NO_KEYPAIR_API || (!MLD_CONFIG_NO_SIGN_API && \
432
- (!MLD_CONFIG_REDUCE_RAM || MLD_UNIT_TEST)) */
390
+ #endif /* (!MLD_CONFIG_NO_KEYPAIR_API || !MLD_CONFIG_NO_SIGN_API) && \
391
+ (!MLD_CONFIG_NO_SIGN_API || MLD_UNIT_TEST) && \
392
+ (!MLD_CONFIG_REDUCE_RAM || MLD_UNIT_TEST) */
433
393
 
434
394
 
435
395
  #endif /* !MLD_POLYVEC_H */
@@ -13,7 +13,6 @@
13
13
  */
14
14
 
15
15
  #include "polyvec_lazy.h"
16
-
17
16
  #include "debug.h"
18
17
 
19
18
  /* This namespacing is not done at the top to avoid a naming conflict
@@ -157,20 +156,19 @@ void mld_polyvec_matrix_pointwise_montgomery_row_eager(mld_poly *t_row,
157
156
 
158
157
  #if !defined(MLD_CONFIG_NO_SIGN_API)
159
158
  MLD_INTERNAL_API
160
- void mld_polyvec_matrix_pointwise_montgomery_yvec_eager(mld_polyveck *w,
161
- mld_polymat_eager *mat,
162
- const mld_yvec_eager *y,
163
- mld_polyvecl *scratch)
159
+ void mld_polyvec_matrix_pointwise_montgomery_yvec_eager(
160
+ mld_polyveck *w, mld_polymat_eager *mat, const mld_yvec_eager *y,
161
+ mld_yvec_scratch_eager *scratch)
164
162
  {
165
163
  unsigned int i;
166
164
  *scratch = y->vec;
167
165
  mld_polyvecl_ntt(scratch);
168
166
 
169
- for (i = 0; i < MLDSA_K; ++i)
167
+ for (i = 0; i < MLDSA_K; i++)
170
168
  __loop__(
171
169
  assigns(i, memory_slice(w, sizeof(mld_polyveck)))
172
170
  invariant(i <= MLDSA_K)
173
- invariant(forall(k0, 0, i,
171
+ invariant(forall(k0, 0, i, MLDSA_K,
174
172
  array_abs_bound(w->vec[k0].coeffs, 0, MLDSA_N, MLDSA_Q)))
175
173
  decreases(MLDSA_K - i)
176
174
  )
@@ -208,7 +206,7 @@ void mld_polyvec_matrix_pointwise_montgomery_row_lazy(mld_poly *t_row,
208
206
  mld_polymat_expand_entry(t_row, seed_ext, 0, (uint8_t)i);
209
207
  mld_poly_pointwise_montgomery(t_row, &v->vec[0]);
210
208
 
211
- for (l = 1; l < MLDSA_L; ++l)
209
+ for (l = 1; l < MLDSA_L; l++)
212
210
  __loop__(
213
211
  assigns(l, object_whole(seed_ext),
214
212
  memory_slice(t_row, sizeof(mld_poly)),
@@ -231,18 +229,12 @@ void mld_polyvec_matrix_pointwise_montgomery_row_lazy(mld_poly *t_row,
231
229
 
232
230
  #if !defined(MLD_CONFIG_NO_SIGN_API)
233
231
  MLD_INTERNAL_API
234
- void mld_polyvec_matrix_pointwise_montgomery_yvec_lazy(mld_polyveck *w,
235
- mld_polymat_lazy *mat,
236
- const mld_yvec_lazy *y,
237
- mld_polyvecl *scratch)
232
+ void mld_polyvec_matrix_pointwise_montgomery_yvec_lazy(
233
+ mld_polyveck *w, mld_polymat_lazy *mat, const mld_yvec_lazy *y,
234
+ mld_yvec_scratch_lazy *scratch)
238
235
  {
239
236
  unsigned int k, l;
240
237
  MLD_ALIGN uint8_t seed_ext[MLD_ALIGN_UP(MLDSA_SEEDBYTES + 2)];
241
- /* Only the first poly of the polyvecl scratch is used. The polyvecl type
242
- * matches the eager variant for API uniformity; in REDUCE_RAM mode the
243
- * polyvecl storage is provided "for free" by the caller's polyveck/polyvecl
244
- * union. */
245
- mld_poly *y_ntt = &scratch->vec[0];
246
238
 
247
239
  mld_memcpy(seed_ext, mat->rho, MLDSA_SEEDBYTES);
248
240
 
@@ -252,7 +244,7 @@ void mld_polyvec_matrix_pointwise_montgomery_yvec_lazy(mld_polyveck *w,
252
244
  assigns(k, l, object_whole(seed_ext),
253
245
  memory_slice(w, sizeof(mld_polyveck)),
254
246
  memory_slice(mat, sizeof(mld_polymat_lazy)),
255
- memory_slice(scratch, sizeof(mld_polyvecl)))
247
+ memory_slice(scratch, sizeof(mld_yvec_scratch_lazy)))
256
248
  invariant(l <= MLDSA_L)
257
249
  invariant(l == 0 ||
258
250
  forall(k0, 0, MLDSA_K,
@@ -261,8 +253,8 @@ void mld_polyvec_matrix_pointwise_montgomery_yvec_lazy(mld_polyveck *w,
261
253
  decreases(MLDSA_L - l)
262
254
  )
263
255
  {
264
- mld_yvec_get_poly_lazy(y_ntt, y, l);
265
- mld_poly_ntt(y_ntt);
256
+ mld_yvec_get_poly_lazy(scratch, y, l);
257
+ mld_poly_ntt(scratch);
266
258
  for (k = 0; k < MLDSA_K; k++)
267
259
  __loop__(
268
260
  assigns(k, object_whole(seed_ext),
@@ -270,10 +262,10 @@ void mld_polyvec_matrix_pointwise_montgomery_yvec_lazy(mld_polyveck *w,
270
262
  memory_slice(mat, sizeof(mld_polymat_lazy)))
271
263
  invariant(k <= MLDSA_K)
272
264
  invariant(l != 0 ||
273
- forall(k1, 0, k,
265
+ forall(k1, 0, k, MLDSA_K,
274
266
  array_abs_bound(w->vec[k1].coeffs, 0, MLDSA_N, MLDSA_Q)))
275
267
  invariant(l == 0 ||
276
- forall(k2, 0, k,
268
+ forall(k2, 0, k, MLDSA_K,
277
269
  array_abs_bound(w->vec[k2].coeffs, 0, MLDSA_N,
278
270
  ((int)l + 1) * MLDSA_Q)))
279
271
  invariant(l == 0 ||
@@ -286,12 +278,12 @@ void mld_polyvec_matrix_pointwise_montgomery_yvec_lazy(mld_polyveck *w,
286
278
  if (l == 0)
287
279
  {
288
280
  mld_polymat_expand_entry(&w->vec[k], seed_ext, 0, (uint8_t)k);
289
- mld_poly_pointwise_montgomery(&w->vec[k], y_ntt);
281
+ mld_poly_pointwise_montgomery(&w->vec[k], scratch);
290
282
  }
291
283
  else
292
284
  {
293
285
  mld_polymat_expand_entry(&mat->cur, seed_ext, (uint8_t)l, (uint8_t)k);
294
- mld_poly_pointwise_montgomery(&mat->cur, y_ntt);
286
+ mld_poly_pointwise_montgomery(&mat->cur, scratch);
295
287
  mld_poly_add(&w->vec[k], &mat->cur);
296
288
  }
297
289
  }
@@ -79,6 +79,9 @@
79
79
  #define mld_yvec_eager MLD_ADD_PARAM_SET(mld_yvec_eager)
80
80
  #define mld_yvec_lazy MLD_ADD_PARAM_SET(mld_yvec_lazy)
81
81
  #define mld_yvec MLD_ADD_PARAM_SET(mld_yvec)
82
+ #define mld_yvec_scratch MLD_ADD_PARAM_SET(mld_yvec_scratch)
83
+ #define mld_yvec_scratch_eager MLD_ADD_PARAM_SET(mld_yvec_scratch_eager)
84
+ #define mld_yvec_scratch_lazy MLD_ADD_PARAM_SET(mld_yvec_scratch_lazy)
82
85
  #define mld_yvec_init_eager MLD_ADD_PARAM_SET(mld_yvec_init_eager)
83
86
  #define mld_yvec_init_lazy MLD_ADD_PARAM_SET(mld_yvec_init_lazy)
84
87
  #define mld_yvec_get_poly_eager MLD_ADD_PARAM_SET(mld_yvec_get_poly_eager)
@@ -127,6 +130,9 @@ typedef struct
127
130
  mld_polyvecl vec; /**< Masking vector y. */
128
131
  } mld_yvec_eager;
129
132
 
133
+ /** Scratch for the eager matrix-vector product: holds NTT(y) in full. */
134
+ typedef mld_polyvecl mld_yvec_scratch_eager;
135
+
130
136
  /** Lazy yvec: store seed and base counter kappa, regenerate y[i] on demand. */
131
137
  typedef struct
132
138
  {
@@ -134,6 +140,9 @@ typedef struct
134
140
  uint16_t kappa; /**< Base counter; component i uses kappa + i. */
135
141
  } mld_yvec_lazy;
136
142
 
143
+ /** Scratch for the lazy matrix-vector product: holds one element of y. */
144
+ typedef mld_poly mld_yvec_scratch_lazy;
145
+
137
146
  #if !defined(MLD_CONFIG_NO_KEYPAIR_API) || !defined(MLD_CONFIG_NO_SIGN_API)
138
147
  /* s1vec */
139
148
 
@@ -275,11 +284,11 @@ __contract__(
275
284
  )
276
285
  {
277
286
  unsigned int i;
278
- for (i = 0; i < MLDSA_K; ++i)
287
+ for (i = 0; i < MLDSA_K; i++)
279
288
  __loop__(
280
289
  assigns(i, memory_slice(t0, sizeof(mld_sk_t0hat_eager)))
281
290
  invariant(i <= MLDSA_K)
282
- invariant(forall(k0, 0, i,
291
+ invariant(forall(k0, 0, i, MLDSA_K,
283
292
  array_bound(t0->vec.vec[k0].coeffs, 0, MLDSA_N,
284
293
  -(1 << (MLDSA_D - 1)) + 1, (1 << (MLDSA_D - 1)) + 1)))
285
294
  decreases(MLDSA_K - i)
@@ -502,21 +511,20 @@ __contract__(
502
511
  * @param[out] scratch Scratch polyvecl for NTT'd copy of y.
503
512
  */
504
513
  MLD_INTERNAL_API
505
- void mld_polyvec_matrix_pointwise_montgomery_yvec_eager(mld_polyveck *w,
506
- mld_polymat_eager *mat,
507
- const mld_yvec_eager *y,
508
- mld_polyvecl *scratch)
514
+ void mld_polyvec_matrix_pointwise_montgomery_yvec_eager(
515
+ mld_polyveck *w, mld_polymat_eager *mat, const mld_yvec_eager *y,
516
+ mld_yvec_scratch_eager *scratch)
509
517
  __contract__(
510
518
  requires(memory_no_alias(w, sizeof(mld_polyveck)))
511
519
  requires(memory_no_alias(mat, sizeof(mld_polymat_eager)))
512
520
  requires(memory_no_alias(y, sizeof(mld_yvec_eager)))
513
- requires(memory_no_alias(scratch, sizeof(mld_polyvecl)))
521
+ requires(memory_no_alias(scratch, sizeof(mld_yvec_scratch_eager)))
514
522
  requires(forall(k1, 0, MLDSA_K, forall(l1, 0, MLDSA_L,
515
523
  array_bound(mat->vec[k1].vec[l1].coeffs, 0, MLDSA_N, 0, MLDSA_Q))))
516
524
  requires(forall(l2, 0, MLDSA_L,
517
525
  array_bound(y->vec.vec[l2].coeffs, 0, MLDSA_N, -(MLDSA_GAMMA1 - 1), MLDSA_GAMMA1 + 1)))
518
526
  assigns(memory_slice(w, sizeof(mld_polyveck)))
519
- assigns(memory_slice(scratch, sizeof(mld_polyvecl)))
527
+ assigns(memory_slice(scratch, sizeof(mld_yvec_scratch_eager)))
520
528
  ensures(forall(k0, 0, MLDSA_K,
521
529
  array_abs_bound(w->vec[k0].coeffs, 0, MLDSA_N, MLD_INTT_BOUND)))
522
530
  );
@@ -569,33 +577,29 @@ __contract__(
569
577
  /**
570
578
  * Compute w = invNTT(A * NTT(y)) for the signing y vector.
571
579
  *
572
- * The lazy variant samples one column of y at a time, NTTs it into
573
- * &scratch->vec[0], and accumulates the matrix-vector product
574
- * column-by-column with on-demand sampling of A[k][l]. Only the first poly of
575
- * the polyvecl scratch is used; the polyvecl type is shared with the eager
576
- * variant for API uniformity (the storage is provided "for free" by the
577
- * caller's polyveck/polyvecl union in REDUCE_RAM mode).
580
+ * The lazy variant samples one element of y at a time, NTTs it into scratch,
581
+ * and accumulates the matrix-vector product column-by-column with on-demand
582
+ * sampling of A[k][l].
578
583
  *
579
584
  * @param[out] w Pointer to output vector.
580
585
  * @param[in,out] mat Pointer to input matrix.
581
586
  * @param[in] y Pointer to y seed/kappa.
582
- * @param[out] scratch Scratch (only &scratch->vec[0] used).
587
+ * @param[out] scratch Scratch for the NTT of the current element of y.
583
588
  */
584
589
  MLD_INTERNAL_API
585
- void mld_polyvec_matrix_pointwise_montgomery_yvec_lazy(mld_polyveck *w,
586
- mld_polymat_lazy *mat,
587
- const mld_yvec_lazy *y,
588
- mld_polyvecl *scratch)
590
+ void mld_polyvec_matrix_pointwise_montgomery_yvec_lazy(
591
+ mld_polyveck *w, mld_polymat_lazy *mat, const mld_yvec_lazy *y,
592
+ mld_yvec_scratch_lazy *scratch)
589
593
  __contract__(
590
594
  requires(memory_no_alias(w, sizeof(mld_polyveck)))
591
595
  requires(memory_no_alias(mat, sizeof(mld_polymat_lazy)))
592
596
  requires(memory_no_alias(y, sizeof(mld_yvec_lazy)))
593
- requires(memory_no_alias(scratch, sizeof(mld_polyvecl)))
597
+ requires(memory_no_alias(scratch, sizeof(mld_yvec_scratch_lazy)))
594
598
  requires(memory_no_alias(y->rhoprime, MLDSA_CRHBYTES))
595
599
  requires(y->kappa <= MLD_MAX_KAPPA)
596
600
  assigns(memory_slice(w, sizeof(mld_polyveck)))
597
601
  assigns(memory_slice(mat, sizeof(mld_polymat_lazy)))
598
- assigns(memory_slice(scratch, sizeof(mld_polyvecl)))
602
+ assigns(memory_slice(scratch, sizeof(mld_yvec_scratch_lazy)))
599
603
  ensures(forall(k0, 0, MLDSA_K,
600
604
  array_abs_bound(w->vec[k0].coeffs, 0, MLDSA_N, MLD_INTT_BOUND)))
601
605
  );
@@ -609,6 +613,7 @@ typedef mld_sk_s2hat_lazy mld_sk_s2hat;
609
613
  typedef mld_sk_t0hat_lazy mld_sk_t0hat;
610
614
  typedef mld_polymat_lazy mld_polymat;
611
615
  typedef mld_yvec_lazy mld_yvec;
616
+ typedef mld_yvec_scratch_lazy mld_yvec_scratch;
612
617
  #define mld_unpack_sk_s1hat mld_unpack_sk_s1hat_lazy
613
618
  #define mld_unpack_sk_s2hat mld_unpack_sk_s2hat_lazy
614
619
  #define mld_unpack_sk_t0hat mld_unpack_sk_t0hat_lazy
@@ -630,6 +635,7 @@ typedef mld_sk_s2hat_eager mld_sk_s2hat;
630
635
  typedef mld_sk_t0hat_eager mld_sk_t0hat;
631
636
  typedef mld_polymat_eager mld_polymat;
632
637
  typedef mld_yvec_eager mld_yvec;
638
+ typedef mld_yvec_scratch_eager mld_yvec_scratch;
633
639
  #define mld_unpack_sk_s1hat mld_unpack_sk_s1hat_eager
634
640
  #define mld_unpack_sk_s2hat mld_unpack_sk_s2hat_eager
635
641
  #define mld_unpack_sk_t0hat mld_unpack_sk_t0hat_eager
@@ -20,9 +20,6 @@
20
20
  #include "ct.h"
21
21
  #include "debug.h"
22
22
 
23
- /* check-magic: -4186625 == pow(2,32,MLDSA_Q) */
24
- #define MLD_MONT (-4186625)
25
-
26
23
  /* Upper bound for domain of mld_reduce32() */
27
24
  #define MLD_REDUCE32_DOMAIN_MAX (INT32_MAX - ((int32_t)1 << 22))
28
25
 
@@ -36,13 +33,11 @@
36
33
  *
37
34
  * @spec{Implements @[FIPS204, Algorithm 49, MontgomeryReduce].}
38
35
  *
39
- * @param a Input integer to be reduced, of absolute value smaller or equal
40
- * to INT64_MAX - 2^31 * MLDSA_Q.
36
+ * @param a Input integer to be reduced, of absolute value smaller than
37
+ * 2^31 * MLDSA_Q.
41
38
  *
42
39
  * @return Integer congruent to a * R^-1 modulo MLDSA_Q, with absolute value
43
- * <= |a| / 2^32 + MLDSA_Q / 2.
44
- * In particular, if |a| < 2^31 * MLDSA_Q, the absolute value of the
45
- * return value is < MLDSA_Q.
40
+ * <= |a| / 2^32 + MLDSA_Q / 2, and in particular < MLDSA_Q.
46
41
  */
47
42
  MLD_MUST_CHECK_RETURN_VALUE
48
43
  static MLD_INLINE int32_t mld_montgomery_reduce(int64_t a)
@@ -114,6 +109,11 @@ __contract__(
114
109
  {
115
110
  int32_t t;
116
111
 
112
+ /*
113
+ * PORTABILITY: Right-shift on a signed integer is, strictly-speaking,
114
+ * implementation-defined for negative left argument. Here,
115
+ * we assume it's sign-preserving "arithmetic" shift right. (C99 6.5.7 (5))
116
+ */
117
117
  t = (a + ((int32_t)1 << 22)) >> 23;
118
118
  t = a - t * MLDSA_Q;
119
119
  mld_assert((t - a) % MLDSA_Q == 0);