pq_crypto 0.6.4 → 0.6.6

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 (213) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +180 -0
  3. data/README.md +7 -0
  4. data/ext/pqcrypto/extconf.rb +4 -1
  5. data/ext/pqcrypto/pq_externalmu.c +35 -0
  6. data/ext/pqcrypto/pqcrypto_native_api.h +85 -75
  7. data/ext/pqcrypto/pqcrypto_ruby_secure.c +16 -9
  8. data/ext/pqcrypto/pqcrypto_secure.c +43 -33
  9. data/ext/pqcrypto/pqcrypto_secure.h +52 -47
  10. data/ext/pqcrypto/pqcrypto_version.h +1 -1
  11. data/ext/pqcrypto/vendor/.vendored +7 -7
  12. data/ext/pqcrypto/vendor/mldsa-native/BUILDING.md +5 -2
  13. data/ext/pqcrypto/vendor/mldsa-native/LICENSE +21 -2
  14. data/ext/pqcrypto/vendor/mldsa-native/README.md +20 -7
  15. data/ext/pqcrypto/vendor/mldsa-native/RELEASE.md +160 -0
  16. data/ext/pqcrypto/vendor/mldsa-native/SECURITY.md +1 -1
  17. data/ext/pqcrypto/vendor/mldsa-native/mldsa/README.md +2 -2
  18. data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native.c +85 -59
  19. data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native.h +292 -348
  20. data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native_asm.S +122 -76
  21. data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native_config.h +184 -86
  22. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/cbmc.h +49 -4
  23. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/common.h +49 -81
  24. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/context.h +152 -0
  25. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/ct.h +25 -12
  26. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/debug.c +2 -0
  27. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/debug.h +2 -0
  28. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/fips202x4.c +2 -2
  29. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/keccakf1600.c +9 -11
  30. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/auto.h +19 -11
  31. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_scalar_aarch64_asm.S +6 -4
  32. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_v84a_aarch64_asm.S +7 -4
  33. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x2_v84a_aarch64_asm.S +7 -4
  34. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_scalar_hybrid_aarch64_asm.S +12 -9
  35. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_v84a_scalar_hybrid_aarch64_asm.S +12 -9
  36. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x1_scalar.h +1 -1
  37. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x1_v84a.h +3 -2
  38. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x2_v84a.h +3 -2
  39. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x4_v8a_scalar.h +6 -1
  40. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x4_v8a_v84a_scalar.h +3 -2
  41. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/api.h +11 -11
  42. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/mve.h +9 -22
  43. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.S +8 -5
  44. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.c +1 -0
  45. 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
  46. 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
  47. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/auto.h +5 -4
  48. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/keccak_f1600_x4_avx2.h +2 -2
  49. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/fips202_native_x86_64.h +1 -0
  50. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/keccak_f1600_x4_avx2_asm.S +36 -2
  51. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/meta.h +62 -4
  52. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/arith_native_aarch64.h +87 -54
  53. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/{intt_aarch64_asm.S → mldsa_intt_aarch64_asm.S} +39 -6
  54. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/{ntt_aarch64_asm.S → mldsa_ntt_aarch64_asm.S} +39 -6
  55. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/{pointwise_montgomery_aarch64_asm.S → mldsa_pointwise_montgomery_aarch64_asm.S} +25 -3
  56. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/{poly_caddq_aarch64_asm.S → mldsa_poly_caddq_aarch64_asm.S} +19 -3
  57. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/{poly_chknorm_aarch64_asm.S → mldsa_poly_chknorm_aarch64_asm.S} +24 -3
  58. 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
  59. 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
  60. 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
  61. 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
  62. 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
  63. 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
  64. 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
  65. 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
  66. 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
  67. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/{rej_uniform_aarch64_asm.S → mldsa_rej_uniform_aarch64_asm.S} +48 -15
  68. 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
  69. 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
  70. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/api.h +11 -3
  71. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/meta.h +3 -2
  72. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/meta.h +28 -28
  73. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/arith_native_x86_64.h +171 -49
  74. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/{intt_avx2_asm.S → mldsa_intt_avx2_asm.S} +23 -1
  75. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/{ntt_avx2_asm.S → mldsa_ntt_avx2_asm.S} +23 -1
  76. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/{nttunpack_avx2_asm.S → mldsa_nttunpack_avx2_asm.S} +17 -1
  77. 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
  78. 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
  79. 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
  80. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/{pointwise_avx2_asm.S → mldsa_pointwise_avx2_asm.S} +31 -3
  81. 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
  82. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_poly_chknorm_avx2_asm.S +176 -0
  83. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_poly_decompose_32_avx2_asm.S +490 -0
  84. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_poly_decompose_88_avx2_asm.S +489 -0
  85. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_poly_use_hint_32_avx2_asm.S +123 -0
  86. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_poly_use_hint_88_avx2_asm.S +125 -0
  87. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_polyz_unpack_17_avx2_asm.S +355 -0
  88. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_polyz_unpack_19_avx2_asm.S +355 -0
  89. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_rej_uniform_avx2_asm.S +132 -0
  90. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_rej_uniform_eta2_avx2_asm.S +205 -0
  91. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_rej_uniform_eta4_avx2_asm.S +176 -0
  92. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/packing.c +27 -36
  93. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/packing.h +42 -8
  94. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/params.h +93 -17
  95. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly.c +74 -15
  96. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly.h +97 -11
  97. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly_kl.c +7 -38
  98. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly_kl.h +49 -7
  99. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec.c +16 -17
  100. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec.h +26 -9
  101. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec_lazy.c +3 -0
  102. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec_lazy.h +18 -19
  103. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/reduce.h +15 -3
  104. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/rounding.h +28 -6
  105. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/sign.c +311 -246
  106. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/sign.h +245 -240
  107. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/sys.h +64 -5
  108. data/ext/pqcrypto/vendor/mlkem-native/BUILDING.md +5 -2
  109. data/ext/pqcrypto/vendor/mlkem-native/LICENSE +21 -3
  110. data/ext/pqcrypto/vendor/mlkem-native/README.md +4 -6
  111. data/ext/pqcrypto/vendor/mlkem-native/RELEASE.md +211 -0
  112. data/ext/pqcrypto/vendor/mlkem-native/mlkem/README.md +2 -2
  113. data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native.c +25 -34
  114. data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native.h +79 -142
  115. data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native_asm.S +62 -71
  116. data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native_config.h +77 -39
  117. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/cbmc.h +25 -0
  118. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/common.h +48 -34
  119. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/compress.c +25 -5
  120. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/compress.h +14 -0
  121. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/context.h +51 -0
  122. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/fips202.h +2 -2
  123. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/keccakf1600.c +8 -8
  124. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/auto.h +20 -12
  125. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccak_f1600_x1_scalar_aarch64_asm.S +5 -3
  126. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccak_f1600_x1_v84a_aarch64_asm.S +5 -2
  127. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccak_f1600_x2_v84a_aarch64_asm.S +5 -2
  128. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_scalar_hybrid_aarch64_asm.S +10 -7
  129. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_v84a_scalar_hybrid_aarch64_asm.S +10 -7
  130. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x1_scalar.h +1 -1
  131. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x1_v84a.h +3 -2
  132. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x2_v84a.h +3 -2
  133. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x4_v8a_scalar.h +6 -1
  134. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x4_v8a_v84a_scalar.h +3 -2
  135. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/api.h +11 -11
  136. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/mve.h +8 -22
  137. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.S +8 -5
  138. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/{state_extract_bytes_x4_mve.S → keccak_f1600_x4_state_extract_bytes_mve.S} +14 -14
  139. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/{state_xor_bytes_x4_mve.S → keccak_f1600_x4_state_xor_bytes_mve.S} +12 -12
  140. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/keccak_f1600_x4_avx2.h +2 -2
  141. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/src/keccak_f1600_x4_avx2_asm.S +36 -2
  142. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/indcpa.c +22 -0
  143. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/indcpa.h +20 -11
  144. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/kem.c +39 -11
  145. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/kem.h +64 -15
  146. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/meta.h +44 -2
  147. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/aarch64_zetas.c +2 -0
  148. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/arith_native_aarch64.h +11 -10
  149. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{intt_aarch64_asm.S → mlkem_intt_aarch64_asm.S} +16 -9
  150. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{ntt_aarch64_asm.S → mlkem_ntt_aarch64_asm.S} +10 -7
  151. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{poly_mulcache_compute_aarch64_asm.S → mlkem_poly_mulcache_compute_aarch64_asm.S} +6 -3
  152. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{poly_reduce_aarch64_asm.S → mlkem_poly_reduce_aarch64_asm.S} +6 -3
  153. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{poly_tobytes_aarch64_asm.S → mlkem_poly_tobytes_aarch64_asm.S} +12 -5
  154. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{poly_tomont_aarch64_asm.S → mlkem_poly_tomont_aarch64_asm.S} +11 -5
  155. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{polyvec_basemul_acc_montgomery_cached_k2_aarch64_asm.S → mlkem_polyvec_basemul_acc_montgomery_cached_k2_aarch64_asm.S} +6 -3
  156. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{polyvec_basemul_acc_montgomery_cached_k3_aarch64_asm.S → mlkem_polyvec_basemul_acc_montgomery_cached_k3_aarch64_asm.S} +6 -3
  157. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{polyvec_basemul_acc_montgomery_cached_k4_aarch64_asm.S → mlkem_polyvec_basemul_acc_montgomery_cached_k4_aarch64_asm.S} +6 -3
  158. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{rej_uniform_aarch64_asm.S → mlkem_rej_uniform_aarch64_asm.S} +17 -17
  159. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/api.h +21 -8
  160. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/meta.h +1 -1
  161. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/meta.h +4 -0
  162. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/{intt_ppc_asm.S → mlkem_intt_ppc_asm.S} +29 -5
  163. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/{ntt_ppc_asm.S → mlkem_ntt_ppc_asm.S} +22 -1
  164. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/{poly_tomont_ppc_asm.S → mlkem_poly_tomont_ppc_asm.S} +25 -3
  165. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/{reduce_ppc_asm.S → mlkem_reduce_ppc_asm.S} +22 -1
  166. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/meta.h +4 -0
  167. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/arith_native_riscv64.h +4 -0
  168. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/rv64v_poly.c +6 -2
  169. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/meta.h +45 -25
  170. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/arith_native_x86_64.h +20 -20
  171. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/compress_consts.c +14 -3
  172. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/compress_consts.h +8 -0
  173. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{intt_avx2_asm.S → mlkem_intt_avx2_asm.S} +27 -3
  174. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{ntt_avx2_asm.S → mlkem_ntt_avx2_asm.S} +23 -1
  175. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{nttfrombytes_avx2_asm.S → mlkem_nttfrombytes_avx2_asm.S} +27 -3
  176. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{ntttobytes_avx2_asm.S → mlkem_ntttobytes_avx2_asm.S} +27 -3
  177. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{nttunpack_avx2_asm.S → mlkem_nttunpack_avx2_asm.S} +17 -1
  178. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{poly_compress_d10_avx2_asm.S → mlkem_poly_compress_d10_avx2_asm.S} +34 -3
  179. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{poly_compress_d11_avx2_asm.S → mlkem_poly_compress_d11_avx2_asm.S} +33 -2
  180. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{poly_compress_d4_avx2_asm.S → mlkem_poly_compress_d4_avx2_asm.S} +34 -3
  181. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{poly_compress_d5_avx2_asm.S → mlkem_poly_compress_d5_avx2_asm.S} +33 -2
  182. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{poly_decompress_d10_avx2_asm.S → mlkem_poly_decompress_d10_avx2_asm.S} +32 -3
  183. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{poly_decompress_d11_avx2_asm.S → mlkem_poly_decompress_d11_avx2_asm.S} +32 -2
  184. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{poly_decompress_d4_avx2_asm.S → mlkem_poly_decompress_d4_avx2_asm.S} +32 -3
  185. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{poly_decompress_d5_avx2_asm.S → mlkem_poly_decompress_d5_avx2_asm.S} +32 -2
  186. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{poly_mulcache_compute_avx2_asm.S → mlkem_poly_mulcache_compute_avx2_asm.S} +29 -1
  187. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{polyvec_basemul_acc_montgomery_cached_k2_avx2_asm.S → mlkem_polyvec_basemul_acc_montgomery_cached_k2_avx2_asm.S} +35 -1
  188. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{polyvec_basemul_acc_montgomery_cached_k3_avx2_asm.S → mlkem_polyvec_basemul_acc_montgomery_cached_k3_avx2_asm.S} +35 -1
  189. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{polyvec_basemul_acc_montgomery_cached_k4_avx2_asm.S → mlkem_polyvec_basemul_acc_montgomery_cached_k4_avx2_asm.S} +35 -1
  190. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{reduce_avx2_asm.S → mlkem_reduce_avx2_asm.S} +17 -1
  191. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{rej_uniform_avx2_asm.S → mlkem_rej_uniform_avx2_asm.S} +40 -7
  192. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{tomont_avx2_asm.S → mlkem_tomont_avx2_asm.S} +20 -3
  193. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/poly.c +7 -2
  194. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/poly.h +6 -0
  195. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/poly_k.c +25 -4
  196. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/poly_k.h +33 -4
  197. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/sampling.c +4 -0
  198. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/sampling.h +4 -0
  199. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/sys.h +21 -3
  200. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/verify.h +11 -10
  201. data/lib/pq_crypto/version.rb +1 -1
  202. data/script/vendor_libs.rb +6 -6
  203. metadata +79 -79
  204. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_chknorm_avx2.c +0 -52
  205. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_decompose_32_avx2.c +0 -157
  206. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_decompose_88_avx2.c +0 -157
  207. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_use_hint_32_avx2.c +0 -103
  208. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_use_hint_88_avx2.c +0 -105
  209. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/polyz_unpack_17_avx2.c +0 -94
  210. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/polyz_unpack_19_avx2.c +0 -96
  211. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/rej_uniform_avx2.c +0 -126
  212. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/rej_uniform_eta2_avx2.c +0 -157
  213. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/rej_uniform_eta4_avx2.c +0 -141
@@ -16,6 +16,11 @@
16
16
  * FIPS 204 Module-Lattice-Based Digital Signature Standard
17
17
  * National Institute of Standards and Technology
18
18
  * https://csrc.nist.gov/pubs/fips/204/final
19
+ *
20
+ * - [FIPS204_UPDATES]
21
+ * FIPS 204 Potential Updates (Errata)
22
+ * National Institute of Standards and Technology
23
+ * https://csrc.nist.gov/files/pubs/fips/204/final/docs/fips-204-potential-updates.xlsx
19
24
  */
20
25
 
21
26
  #ifndef MLD_CONFIG_H
@@ -49,7 +54,7 @@
49
54
  *
50
55
  * When you need to build mldsa-native in multiple configurations,
51
56
  * using varying MLD_CONFIG_FILE can be more convenient
52
- * then configuring everything through CFLAGS.
57
+ * than configuring everything through CFLAGS.
53
58
  *
54
59
  * To use, MLD_CONFIG_FILE _must_ be defined prior
55
60
  * to the inclusion of any mldsa-native headers. For example,
@@ -111,8 +116,8 @@
111
116
  *
112
117
  * By default, mldsa-native includes support for generating key
113
118
  * pairs. If you don't need this, set MLD_CONFIG_NO_KEYPAIR_API
114
- * to exclude crypto_sign_keypair, crypto_sign_keypair_internal,
115
- * crypto_sign_pk_from_sk, and all internal APIs only needed by
119
+ * to exclude keypair, keypair_internal,
120
+ * pk_from_sk, and all internal APIs only needed by
116
121
  * those functions.
117
122
  */
118
123
  /* #define MLD_CONFIG_NO_KEYPAIR_API */
@@ -122,10 +127,10 @@
122
127
  *
123
128
  * By default, mldsa-native includes support for creating
124
129
  * signatures. If you don't need this, set MLD_CONFIG_NO_SIGN_API
125
- * to exclude crypto_sign, crypto_sign_signature,
126
- * crypto_sign_signature_extmu, crypto_sign_signature_internal,
127
- * crypto_sign_signature_pre_hash_internal,
128
- * crypto_sign_signature_pre_hash_shake256, and all internal APIs
130
+ * to exclude signature,
131
+ * signature_extmu, signature_internal,
132
+ * signature_pre_hash_internal,
133
+ * signature_pre_hash_shake256, and all internal APIs
129
134
  * only needed by those functions.
130
135
  */
131
136
  /* #define MLD_CONFIG_NO_SIGN_API */
@@ -135,11 +140,10 @@
135
140
  *
136
141
  * By default, mldsa-native includes support for verifying
137
142
  * signatures. If you don't need this, set
138
- * MLD_CONFIG_NO_VERIFY_API to exclude crypto_sign_open,
139
- * crypto_sign_verify, crypto_sign_verify_extmu,
140
- * crypto_sign_verify_internal,
141
- * crypto_sign_verify_pre_hash_internal,
142
- * crypto_sign_verify_pre_hash_shake256, and all internal APIs
143
+ * MLD_CONFIG_NO_VERIFY_API to exclude verify,
144
+ * verify_extmu, verify_internal,
145
+ * verify_pre_hash_internal,
146
+ * verify_pre_hash_shake256, and all internal APIs
143
147
  * only needed by those functions.
144
148
  */
145
149
  /* #define MLD_CONFIG_NO_VERIFY_API */
@@ -148,8 +152,8 @@
148
152
  * MLD_CONFIG_CORE_API_ONLY
149
153
  *
150
154
  * Set this to remove all public APIs except
151
- * crypto_sign_keypair_internal, crypto_sign_signature_internal,
152
- * and crypto_sign_verify_internal.
155
+ * keypair_internal, signature_internal,
156
+ * and verify_internal.
153
157
  */
154
158
  /* #define MLD_CONFIG_CORE_API_ONLY */
155
159
 
@@ -157,32 +161,19 @@
157
161
  * MLD_CONFIG_NO_RANDOMIZED_API
158
162
  *
159
163
  * If this option is set, mldsa-native will be built without the
160
- * randomized API functions (crypto_sign_keypair,
161
- * crypto_sign, crypto_sign_signature, and
162
- * crypto_sign_signature_extmu).
164
+ * randomized API functions (keypair,
165
+ * signature, and signature_extmu).
163
166
  * This allows users to build mldsa-native without providing a
164
167
  * randombytes() implementation if they only need the
165
168
  * internal deterministic API
166
- * (crypto_sign_keypair_internal, crypto_sign_signature_internal).
169
+ * (keypair_internal, signature_internal).
167
170
  *
168
171
  * @note This option is incompatible with MLD_CONFIG_KEYGEN_PCT
169
172
  * as the current PCT implementation requires
170
- * crypto_sign_signature().
173
+ * signature().
171
174
  */
172
175
  /* #define MLD_CONFIG_NO_RANDOMIZED_API */
173
176
 
174
- /**
175
- * MLD_CONFIG_NO_SUPERCOP
176
- *
177
- * By default, mldsa_native.h exposes the mldsa-native API in the
178
- * SUPERCOP naming convention (crypto_sign_xxx). If you don't need
179
- * this, set MLD_CONFIG_NO_SUPERCOP.
180
- *
181
- * @note You must set this for a multi-level build as the SUPERCOP
182
- * naming does not disambiguate between the parameter sets.
183
- */
184
- /* #define MLD_CONFIG_NO_SUPERCOP */
185
-
186
177
  /**
187
178
  * MLD_CONFIG_CONSTANTS_ONLY
188
179
  *
@@ -213,14 +204,17 @@
213
204
  * code will be included in the build, including code needed only
214
205
  * for other parameter sets.
215
206
  *
216
- * Example: TODO: add example
207
+ * Example: mld_polyw1_pack_88 is only needed for
208
+ * MLD_CONFIG_PARAMETER_SET == 44. Yet, if this option is set for a
209
+ * build with MLD_CONFIG_PARAMETER_SET == 65/87, it would be included.
217
210
  *
218
211
  * To build mldsa-native with support for all parameter sets,
219
212
  * build it three times -- once per parameter set -- and set the
220
213
  * option MLD_CONFIG_MULTILEVEL_WITH_SHARED for exactly one of
221
214
  * them, and MLD_CONFIG_MULTILEVEL_NO_SHARED for the others.
215
+ * MLD_CONFIG_MULTILEVEL_BUILD should be set for all of them.
222
216
  *
223
- * See examples/multilevel_build_mldsa for an example.
217
+ * See examples/multilevel_build for an example.
224
218
  *
225
219
  * This can also be set using CFLAGS.
226
220
  */
@@ -239,8 +233,9 @@
239
233
  * build it three times -- once per parameter set -- and set the
240
234
  * option MLD_CONFIG_MULTILEVEL_WITH_SHARED for exactly one of
241
235
  * them, and MLD_CONFIG_MULTILEVEL_NO_SHARED for the others.
236
+ * MLD_CONFIG_MULTILEVEL_BUILD should be set for all of them.
242
237
  *
243
- * See examples/multilevel_build_mldsa for an example.
238
+ * See examples/multilevel_build for an example.
244
239
  *
245
240
  * This can also be set using CFLAGS.
246
241
  */
@@ -252,8 +247,8 @@
252
247
  * This is only relevant for single compilation unit (SCU)
253
248
  * builds of mldsa-native. In this case, it determines whether
254
249
  * directives defined in parameter-set-independent headers should
255
- * be #undef'ined or not at the of the SCU file. This is needed
256
- * in multilevel builds.
250
+ * be #undef'ined or not at the end of the SCU file. This is
251
+ * needed in multilevel builds.
257
252
  *
258
253
  * See examples/multilevel_build_native for an example.
259
254
  *
@@ -264,16 +259,16 @@
264
259
  /**
265
260
  * MLD_CONFIG_USE_NATIVE_BACKEND_ARITH
266
261
  *
267
- * Determines whether an native arithmetic backend should be used.
262
+ * Determines whether a native arithmetic backend should be used.
268
263
  *
269
264
  * The arithmetic backend covers performance-critical functions
270
265
  * such as the number-theoretic transform (NTT).
271
266
  *
272
267
  * If this option is unset, the C backend will be used.
273
268
  *
274
- * If this option is set, the arithmetic backend to be use is
269
+ * If this option is set, the arithmetic backend to be used is
275
270
  * determined by MLD_CONFIG_ARITH_BACKEND_FILE: If the latter is
276
- * unset, the default backend for your the target architecture
271
+ * unset, the default backend for your target architecture
277
272
  * will be used. If set, it must be the name of a backend metadata
278
273
  * file.
279
274
  *
@@ -305,16 +300,16 @@
305
300
  /**
306
301
  * MLD_CONFIG_USE_NATIVE_BACKEND_FIPS202
307
302
  *
308
- * Determines whether an native FIPS202 backend should be used.
303
+ * Determines whether a native FIPS202 backend should be used.
309
304
  *
310
305
  * The FIPS202 backend covers 1x/2x/4x-fold Keccak-f1600, which is
311
306
  * the performance bottleneck of SHA3 and SHAKE.
312
307
  *
313
308
  * If this option is unset, the C backend will be used.
314
309
  *
315
- * If this option is set, the FIPS202 backend to be use is
310
+ * If this option is set, the FIPS202 backend to be used is
316
311
  * determined by MLD_CONFIG_FIPS202_BACKEND_FILE: If the latter is
317
- * unset, the default backend for your the target architecture
312
+ * unset, the default backend for your target architecture
318
313
  * will be used. If set, it must be the name of a backend metadata
319
314
  * file.
320
315
  *
@@ -373,29 +368,36 @@
373
368
  /**
374
369
  * MLD_CONFIG_CUSTOM_ZEROIZE
375
370
  *
376
- * In compliance with @[FIPS204, Section 3.6.3], mldsa-native,
377
- * zeroizes intermediate stack buffers before returning from
378
- * function calls.
379
- *
380
- * Set this option and define `mld_zeroize` if you want to
381
- * use a custom method to zeroize intermediate stack buffers.
382
- * The default implementation uses SecureZeroMemory on Windows
383
- * and a memset + compiler barrier otherwise. If neither of those
384
- * is available on the target platform, compilation will fail,
385
- * and you will need to use MLD_CONFIG_CUSTOM_ZEROIZE to provide
386
- * a custom implementation of `mld_zeroize()`.
387
- *
388
- * @warning The explicit stack zeroization conducted by mldsa-native reduces
389
- * the likelihood of data leaking on the stack, but does not
390
- * eliminate it. The C standard makes no guarantee about where a
391
- * compiler allocates structures and whether/where it makes copies
392
- * of them. Also, in addition to entire structures, there may also
393
- * be potentially exploitable leakage of individual values on the
394
- * stack.
395
- *
396
- * If you need bullet-proof zeroization of the stack, you need to
397
- * consider additional measures instead of what this feature
398
- * provides. In this case, you can set mld_zeroize to a no-op.
371
+ * In compliance with @[FIPS204, Section 3.6.3], mldsa-native zeroizes
372
+ * intermediate buffers before returning from function calls. By default,
373
+ * those buffers are allocated from the stack; if MLD_CONFIG_CUSTOM_ALLOC_FREE
374
+ * is set, they are (mostly -- few exceptions remain at present) allocated from
375
+ * the configured custom allocator.
376
+ *
377
+ * mldsa-native also zeroizes caller-owned output buffers as needed to uphold
378
+ * the API convention that outputs be either unmodified or zeroized upon
379
+ * failure.
380
+ *
381
+ * Set this option and define `mld_zeroize` if you want to use a custom
382
+ * method to zeroize intermediate and output buffers.
383
+ *
384
+ * The default implementation uses SecureZeroMemory on Windows and a
385
+ * memset + compiler barrier otherwise. If neither of those is available on
386
+ * the target platform, compilation will fail, and you will need to use
387
+ * MLD_CONFIG_CUSTOM_ZEROIZE to provide a custom implementation of
388
+ * `mld_zeroize()`.
389
+ *
390
+ * @warning
391
+ * The zeroization conducted by mldsa-native reduces the likelihood of data
392
+ * leaking on the stack or custom allocators, but it does not eliminate it.
393
+ * For example, the C standard makes no guarantee about where a compiler
394
+ * allocates local structures and whether/where it makes copies of them.
395
+ * Also, in addition to entire structures, there may also be potentially
396
+ * exploitable leakage of individual values on the stack. If you need
397
+ * bullet-proof zeroization of the stack, you need to consider additional
398
+ * measures instead of what this feature provides. In this case, you can
399
+ * set mld_zeroize to a no-op. Note that in this case you are also responsible
400
+ * for zeroizing output buffers upon failure.
399
401
  */
400
402
  /* #define MLD_CONFIG_CUSTOM_ZEROIZE
401
403
  #if !defined(__ASSEMBLER__)
@@ -412,8 +414,8 @@
412
414
  * MLD_CONFIG_CUSTOM_RANDOMBYTES
413
415
  *
414
416
  * mldsa-native does not provide a secure randombytes
415
- * implementation. Such an implementation has to provided by the
416
- * consumer.
417
+ * implementation. Such an implementation has to be provided by
418
+ * the consumer.
417
419
  *
418
420
  * If this option is not set, mldsa-native expects a function
419
421
  * int randombytes(uint8_t *out, size_t outlen).
@@ -440,9 +442,9 @@
440
442
  * mldsa-native backends may rely on specific hardware features.
441
443
  * Those backends will only be included in an mldsa-native build
442
444
  * if support for the respective features is enabled at
443
- * compile-time. However, when building for a heteroneous set
445
+ * compile-time. However, when building for a heterogeneous set
444
446
  * of CPUs to run the resulting binary/library on, feature
445
- * detection at _runtime_ is needed to decided whether a backend
447
+ * detection at _runtime_ is needed to decide whether a backend
446
448
  * can be used or not.
447
449
  *
448
450
  * Set this option and define `mld_sys_check_capability` if you
@@ -488,7 +490,7 @@
488
490
  *
489
491
  * @warning This option is experimental. Its scope, configuration and
490
492
  * function/macro signatures may change at any time. We expect a
491
- * stable API for v2.
493
+ * stable API in a future version.
492
494
  *
493
495
  * @note Even if this option is set, some allocations further down
494
496
  * the call stack will still be made from the stack. Those will
@@ -592,7 +594,7 @@
592
594
  * function.
593
595
  *
594
596
  * If this option is set, MLD_CONFIG_USE_NATIVE_BACKEND_FIPS202 and
595
- * and MLD_CONFIG_USE_NATIVE_BACKEND_ARITH will be ignored, and no
597
+ * MLD_CONFIG_USE_NATIVE_BACKEND_ARITH will be ignored, and no
596
598
  * native backends will be used.
597
599
  */
598
600
  /* #define MLD_CONFIG_NO_ASM */
@@ -618,8 +620,8 @@
618
620
  * generated keypair before it can be exported.
619
621
  *
620
622
  * Set this option if such a check should be implemented.
621
- * In this case, crypto_sign_keypair_internal and
622
- * crypto_sign_keypair will return a non-zero error code if the
623
+ * In this case, keypair_internal and
624
+ * keypair will return MLD_ERR_PCT_FAIL if the
623
625
  * PCT failed.
624
626
  *
625
627
  * @note This feature will drastically lower the performance of
@@ -627,7 +629,7 @@
627
629
  *
628
630
  * @note This option is incompatible with MLD_CONFIG_NO_SIGN_API
629
631
  * and MLD_CONFIG_NO_VERIFY_API as the current PCT implementation
630
- * requires crypto_sign_signature() and crypto_sign_verify().
632
+ * requires signature() and verify().
631
633
  */
632
634
  /* #define MLD_CONFIG_KEYGEN_PCT */
633
635
 
@@ -661,9 +663,9 @@
661
663
  * This is useful in timing-sensitive environments that
662
664
  * require a deterministic worst-case bound on signing time.
663
665
  *
664
- * For FIPS 204 compliance, this value MUST be at least 814,
665
- * cf. @[FIPS204, Appendix C], which is chosen so that the
666
- * signing failure rate is < 2^{-256}.
666
+ * For FIPS 204 compliance, this value MUST be at least 821,
667
+ * cf. @[FIPS204, Appendix C] and @[FIPS204_UPDATES], which is
668
+ * chosen so that the signing failure rate is < 2^{-256}.
667
669
  *
668
670
  * Default: Largest possible value before internal counters
669
671
  * would overflow. This is larger than the FIPS204 bound.
@@ -671,7 +673,7 @@
671
673
  * In particular, in the default configuration, the signing
672
674
  * failure rate is < 2^{-256}.
673
675
  */
674
- /* #define MLD_CONFIG_MAX_SIGNING_ATTEMPTS 814 */
676
+ /* #define MLD_CONFIG_MAX_SIGNING_ATTEMPTS 821 */
675
677
 
676
678
  /**
677
679
  * MLD_CONFIG_SERIAL_FIPS202_ONLY
@@ -698,24 +700,116 @@
698
700
  /**
699
701
  * MLD_CONFIG_CONTEXT_PARAMETER
700
702
  *
701
- * Set this to add a context parameter that is provided to public
702
- * API functions and is then available in custom callbacks.
703
+ * Set this to add a caller-supplied context parameter to the public API
704
+ * functions, which is then forwarded unchanged to the custom callbacks
705
+ * (allocation, and signing hooks below).
706
+ *
707
+ * When this option is set, every public API function gains a trailing
708
+ * parameter
709
+ *
710
+ * MLD_CONFIG_CONTEXT_PARAMETER_TYPE context
711
+ *
712
+ * as its last argument; its type is configured via
713
+ * MLD_CONFIG_CONTEXT_PARAMETER_TYPE (see below). mldsa-native treats this
714
+ * value as opaque: it never dereferences it and only passes it on to the
715
+ * configurable hook macros. It is meant to carry per-caller state -- e.g. a
716
+ * pointer to a memory pool for the allocation hooks, or the resume state for
717
+ * the signing hooks -- into those hooks.
718
+ *
719
+ * When this option is unset (the default), no extra parameter is added and
720
+ * the hook macros never receive a context argument.
703
721
  *
704
- * The type of the context parameter is configured via
705
- * MLD_CONFIG_CONTEXT_PARAMETER_TYPE.
722
+ * The hooks that receive the context are the allocation hooks (see
723
+ * MLD_CONFIG_CUSTOM_ALLOC_FREE) and the signing hooks (see
724
+ * MLD_CONFIG_SIGN_HOOK_RESUME / _ATTEMPT / _FINISH); each is documented with
725
+ * its own option below.
706
726
  */
707
727
  /* #define MLD_CONFIG_CONTEXT_PARAMETER */
708
728
 
709
729
  /**
710
730
  * MLD_CONFIG_CONTEXT_PARAMETER_TYPE
711
731
  *
712
- * Set this to define the type for the context parameter used by
713
- * MLD_CONFIG_CONTEXT_PARAMETER.
732
+ * Set this to define the type of the context parameter added by
733
+ * MLD_CONFIG_CONTEXT_PARAMETER. It can be any C type usable as a function
734
+ * parameter, e.g. `void *` or a pointer to a caller-defined struct such as
735
+ * `struct my_ctx *`.
714
736
  *
715
- * This is only relevant if MLD_CONFIG_CONTEXT_PARAMETER is set.
737
+ * This option must be defined if and only if MLD_CONFIG_CONTEXT_PARAMETER is
738
+ * defined; defining one without the other is a compile-time error.
716
739
  */
717
740
  /* #define MLD_CONFIG_CONTEXT_PARAMETER_TYPE void* */
718
741
 
742
+ /**
743
+ * Signing hooks: MLD_CONFIG_SIGN_HOOK_RESUME / _ATTEMPT / _FINISH
744
+ *
745
+ * Three optional, independent hooks into the ML-DSA signing rejection-sampling
746
+ * loop. Each is enabled by defining the matching option, in which case the
747
+ * integration must provide the corresponding function. If a hook needs
748
+ * per-operation state, enable MLD_CONFIG_CONTEXT_PARAMETER; the context is then
749
+ * appended as the last argument.
750
+ *
751
+ * @warning This feature is experimental. Its scope, configuration and
752
+ * function signatures may change at any time, including after v2.
753
+ *
754
+ * Enabling any of the hooks requires MLD_CONFIG_NO_RANDOMIZED_API (restricting
755
+ * the public API to deterministic operations). This is because the restartable
756
+ * signing as enabled by the signing hooks only produces the uninterrupted
757
+ * signature when the randomness is fixed across calls. A logging-only use
758
+ * (attempt always returns 0; resume/finish merely observe) would be safe with
759
+ * the randomized API too, but for now the requirement is imposed uniformly on
760
+ * all three hooks.
761
+ *
762
+ * Note: Randomized signing is a shim wrapper around deterministic signing, and
763
+ * all helper functions you need to build it are exposed publicly. Thus, if you
764
+ * need a restartable, randomized signing operation, you can build your own by
765
+ * replicating the logic and adding the RNG seed to the restart context. In this
766
+ * case, please also consider letting the mldsa-native maintainers know of your
767
+ * need for randomized, restartable signing, so the feature can be appropriately
768
+ * prioritized.
769
+ *
770
+ * - MLD_CONFIG_SIGN_HOOK_ATTEMPT: int mld_sign_hook_attempt(attempt[, ctxt])
771
+ * Called before each attempt. Returns 0 to proceed, or non-zero to pause:
772
+ * signing then returns MLD_ERR_SIGNING_PAUSED with `attempt` as the resume
773
+ * point (needs MLD_CONFIG_SIGN_HOOK_RESUME to resume; otherwise just aborts).
774
+ * Always returning 0 makes it a logging/benchmarking hook.
775
+ *
776
+ * - MLD_CONFIG_SIGN_HOOK_RESUME: uint16_t mld_sign_hook_resume([ctxt])
777
+ * Returns the attempt to resume from (0 for a fresh operation), i.e. the one
778
+ * recorded when a previous call paused.
779
+ *
780
+ * - MLD_CONFIG_SIGN_HOOK_FINISH: void mld_sign_hook_finish(attempt[, ctxt])
781
+ * Called on success with the succeeding attempt. Observe-only.
782
+ *
783
+ * When an option is unset, the hook is a no-op (resume to 0, attempt proceeds),
784
+ * i.e. ordinary one-shot signing.
785
+ *
786
+ * Independent of MLD_CONFIG_MAX_SIGNING_ATTEMPTS, which is a static upper bound
787
+ * on the number of signing attempts.
788
+ *
789
+ * See test/src/test_sign_hook.c for a worked example using all three.
790
+ */
791
+ /* #define MLD_CONFIG_SIGN_HOOK_RESUME
792
+ #define MLD_CONFIG_SIGN_HOOK_ATTEMPT
793
+ #define MLD_CONFIG_SIGN_HOOK_FINISH
794
+ #if !defined(__ASSEMBLER__)
795
+ #include <stdint.h>
796
+ #include "src/sys.h"
797
+ static MLD_INLINE uint16_t mld_sign_hook_resume(void)
798
+ {
799
+ ... return the attempt to resume from ...
800
+ }
801
+ static MLD_INLINE int mld_sign_hook_attempt(uint16_t attempt)
802
+ {
803
+ ... return non-zero to pause here; for resume, store attempt ...
804
+ return 0;
805
+ }
806
+ static MLD_INLINE void mld_sign_hook_finish(uint16_t attempt)
807
+ {
808
+ ... mark the operation complete (attempt = successful attempt) ...
809
+ }
810
+ #endif
811
+ */
812
+
719
813
  /**
720
814
  * MLD_CONFIG_REDUCE_RAM
721
815
  *
@@ -746,7 +840,11 @@
746
840
  * e.g., PQCP_MLDSA_NATIVE_MLDSA44_
747
841
  */
748
842
 
749
- #if MLD_CONFIG_PARAMETER_SET == 44
843
+ #if defined(MLD_CONFIG_MULTILEVEL_BUILD)
844
+ /* In a multi-level build the parameter set is appended by the namespacing
845
+ * machinery, so the default prefix must not embed it. */
846
+ #define MLD_DEFAULT_NAMESPACE_PREFIX PQCP_MLDSA_NATIVE_MLDSA
847
+ #elif MLD_CONFIG_PARAMETER_SET == 44
750
848
  #define MLD_DEFAULT_NAMESPACE_PREFIX PQCP_MLDSA_NATIVE_MLDSA44
751
849
  #elif MLD_CONFIG_PARAMETER_SET == 65
752
850
  #define MLD_DEFAULT_NAMESPACE_PREFIX PQCP_MLDSA_NATIVE_MLDSA65
@@ -9,17 +9,28 @@
9
9
  /***************************************************
10
10
  * Basic replacements for __CPROVER_XXX contracts
11
11
  ***************************************************/
12
+ /*
13
+ * The `__contract__` / `__loop__` annotation macros use a
14
+ * leading-double-underscore spelling in line with other CBMC macros.
15
+ * clang-tidy flags these as reserved identifiers; we suppress the diagnostic
16
+ * at each definition site (NOLINT) rather than disabling the check globally,
17
+ * so it stays active for the rest of the tree.
18
+ */
12
19
  #ifndef CBMC
13
20
 
14
- #define __contract__(x)
15
- #define __loop__(x)
21
+ /* clang-format off */
22
+ #define __contract__(x) /* NOLINT(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp) */
23
+ #define __loop__(x) /* NOLINT(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp) */
24
+ /* clang-format on */
16
25
  #define cassert(x)
17
26
 
18
27
  #else /* !CBMC */
19
28
 
20
29
 
21
- #define __contract__(x) x
22
- #define __loop__(x) x
30
+ /* clang-format off */
31
+ #define __contract__(x) x /* NOLINT(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp) */
32
+ #define __loop__(x) x /* NOLINT(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp) */
33
+ /* clang-format on */
23
34
 
24
35
  /* Conditionally expand to __VA_ARGS__ depending on MLD_CONFIG_REDUCE_RAM. */
25
36
  #if defined(MLD_CONFIG_REDUCE_RAM)
@@ -171,8 +182,42 @@
171
182
 
172
183
  #define array_unchanged_u64(array_var, N) \
173
184
  array_unchanged_u64_core(CBMC_CONCAT(_cbmc_idx, __COUNTER__), 0, (N), (array_var))
185
+
186
+ #define array_unchanged_u8_core(qvar, qvar_lb, qvar_ub, array_var) \
187
+ __CPROVER_forall \
188
+ { \
189
+ uint32_t qvar; \
190
+ ((uint32_t) (qvar_lb) <= (qvar) && (qvar) < (uint32_t) (qvar_ub)) ==> \
191
+ ((array_var)[(qvar)]) == (old(* (uint8_t (*)[(qvar_ub)])(array_var)))[(qvar)] \
192
+ }
193
+
194
+ #define array_unchanged_u8(array_var, N) \
195
+ array_unchanged_u8_core(CBMC_CONCAT(_cbmc_idx, __COUNTER__), 0, (N), (array_var))
196
+
197
+ #define array_zeroized_u8_core(qvar, qvar_lb, qvar_ub, array_var) \
198
+ __CPROVER_forall \
199
+ { \
200
+ uint32_t qvar; \
201
+ ((uint32_t) (qvar_lb) <= (qvar) && (qvar) < (uint32_t) (qvar_ub)) ==> \
202
+ ((array_var)[(qvar)]) == 0 \
203
+ }
204
+
205
+ #define array_zeroized_u8(array_var, N) \
206
+ array_zeroized_u8_core(CBMC_CONCAT(_cbmc_idx, __COUNTER__), 0, (N), (array_var))
174
207
  /* clang-format on */
175
208
 
209
+ /*
210
+ * Output-buffer discipline on failure, as documented in API-CONVENTIONS.md:
211
+ * when a function fails, each caller-owned output buffer is left either
212
+ * fully unchanged or fully zeroized -- never holding partially computed or
213
+ * stale data that could be mistaken for a valid result.
214
+ *
215
+ * Note the disjunction is over the buffer as a whole: it is not enough for
216
+ * each byte to be individually either unchanged or zero.
217
+ */
218
+ #define array_unchanged_or_zeroized_u8(array_var, N) \
219
+ (array_unchanged_u8((array_var), (N)) || array_zeroized_u8((array_var), (N)))
220
+
176
221
  /* Wrapper around array_bound operating on absolute values.
177
222
  *
178
223
  * The absolute value bound `k` is exclusive.