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
@@ -98,6 +98,13 @@
98
98
  #include "src/native/x86_64/src/mldsa_rej_uniform_eta2_avx2_asm.S"
99
99
  #include "src/native/x86_64/src/mldsa_rej_uniform_eta4_avx2_asm.S"
100
100
  #endif /* MLD_SYS_X86_64 */
101
+ #if defined(MLD_SYS_RISCV32)
102
+ #include "src/native/rv32im/src/mldsa_intt_rv32im_asm.S"
103
+ #include "src/native/rv32im/src/mldsa_intt_rv32im_slowmul_asm.S"
104
+ #include "src/native/rv32im/src/mldsa_ntt_rv32im_asm.S"
105
+ #include "src/native/rv32im/src/mldsa_ntt_rv32im_slowmul_asm.S"
106
+ #include "src/native/rv32im/src/mldsa_poly_pointwise_montgomery_rv32im_asm.S"
107
+ #endif /* MLD_SYS_RISCV32 */
101
108
  #endif /* MLD_CONFIG_USE_NATIVE_BACKEND_ARITH */
102
109
 
103
110
  #if defined(MLD_CONFIG_USE_NATIVE_BACKEND_FIPS202)
@@ -109,7 +116,9 @@
109
116
  #include "src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_v84a_scalar_hybrid_aarch64_asm.S"
110
117
  #endif /* MLD_SYS_AARCH64 */
111
118
  #if defined(MLD_SYS_X86_64)
119
+ #include "src/fips202/native/x86_64/src/keccak_f1600_x1_avx512_asm.S"
112
120
  #include "src/fips202/native/x86_64/src/keccak_f1600_x4_avx2_asm.S"
121
+ #include "src/fips202/native/x86_64/src/keccak_f1600_x4_avx512_asm.S"
113
122
  #endif
114
123
  #if defined(MLD_SYS_ARMV81M_MVE)
115
124
  #include "src/fips202/native/armv81m/src/keccak_f1600_x4_mve.S"
@@ -118,6 +127,13 @@
118
127
  #endif
119
128
  #endif /* MLD_CONFIG_USE_NATIVE_BACKEND_FIPS202 */
120
129
 
130
+ /* Mark the stack non-executable even if no assembly is included above */
131
+ #if defined(__ELF__)
132
+ /* clang-format off */
133
+ .section .note.GNU-stack,"",%progbits
134
+ /* clang-format on */
135
+ #endif
136
+
121
137
 
122
138
  /* Macro #undef's
123
139
  *
@@ -238,6 +254,8 @@
238
254
  #undef MLD_COMMON_H
239
255
  #undef MLD_CONCAT
240
256
  #undef MLD_CONCAT_
257
+ #undef MLD_CT_TESTING_DECLASSIFY
258
+ #undef MLD_CT_TESTING_SECRET
241
259
  #undef MLD_EMPTY_CU
242
260
  #undef MLD_ERR_FAIL
243
261
  #undef MLD_ERR_INVALID_ARG
@@ -252,6 +270,7 @@
252
270
  #undef MLD_FIPS202X4_HEADER_FILE
253
271
  #undef MLD_FIPS202_HEADER_FILE
254
272
  #undef MLD_FREE
273
+ #undef MLD_HAVE_INLINE_ASM
255
274
  #undef MLD_INTERNAL_API
256
275
  #undef MLD_INTERNAL_DATA_DECLARATION
257
276
  #undef MLD_INTERNAL_DATA_DEFINITION
@@ -267,8 +286,7 @@
267
286
  #undef mld_pack_sig_c
268
287
  #undef mld_pack_sig_h
269
288
  #undef mld_pack_sig_z
270
- #undef mld_pack_sk_rho_key_tr_s2
271
- #undef mld_pack_sk_s1
289
+ #undef mld_pack_sk_rho_key_tr
272
290
  #undef mld_sig_unpack_hints
273
291
  #undef mld_unpack_pk_t1
274
292
  #undef mld_unpack_sk
@@ -294,13 +312,19 @@
294
312
  #undef MLDSA_PK_RHO_OFFSET
295
313
  #undef MLDSA_PK_T1_BYTES
296
314
  #undef MLDSA_PK_T1_OFFSET
315
+ #undef MLDSA_POLYETA_PACKEDBITS
297
316
  #undef MLDSA_POLYETA_PACKEDBYTES
298
317
  #undef MLDSA_POLYT0_PACKEDBYTES
318
+ #undef MLDSA_POLYT1_PACKEDBITS
299
319
  #undef MLDSA_POLYT1_PACKEDBYTES
300
320
  #undef MLDSA_POLYVECH_PACKEDBYTES
321
+ #undef MLDSA_POLYW1_PACKEDBITS
322
+ #undef MLDSA_POLYW1_PACKEDBITS_32
323
+ #undef MLDSA_POLYW1_PACKEDBITS_88
301
324
  #undef MLDSA_POLYW1_PACKEDBYTES
302
325
  #undef MLDSA_POLYW1_PACKEDBYTES_32
303
326
  #undef MLDSA_POLYW1_PACKEDBYTES_88
327
+ #undef MLDSA_POLYZ_PACKEDBITS
304
328
  #undef MLDSA_POLYZ_PACKEDBYTES
305
329
  #undef MLDSA_Q
306
330
  #undef MLDSA_Q_HALF
@@ -343,24 +367,22 @@
343
367
  #undef mld_polyeta_pack
344
368
  #undef mld_polyeta_unpack
345
369
  #undef mld_polyw1_pack
370
+ #undef mld_polyw1_unpack
346
371
  #undef mld_polyz_pack
347
372
  #undef mld_polyz_unpack
348
373
  /* mldsa/src/polyvec.h */
349
374
  #undef MLD_POLYVEC_H
350
375
  #undef mld_polyveck
351
376
  #undef mld_polyveck_caddq
352
- #undef mld_polyveck_chknorm
353
- #undef mld_polyveck_decompose
377
+ #undef mld_polyveck_decompose_pack_w1
354
378
  #undef mld_polyveck_invntt_tomont
355
379
  #undef mld_polyveck_ntt
356
- #undef mld_polyveck_pack_eta
357
- #undef mld_polyveck_pack_w1
358
380
  #undef mld_polyveck_reduce
359
381
  #undef mld_polyveck_unpack_eta
382
+ #undef mld_polyveck_unpack_eta_chknorm
360
383
  #undef mld_polyvecl
361
384
  #undef mld_polyvecl_chknorm
362
385
  #undef mld_polyvecl_ntt
363
- #undef mld_polyvecl_pack_eta
364
386
  #undef mld_polyvecl_pointwise_acc_montgomery
365
387
  #undef mld_polyvecl_uniform_gamma1
366
388
  #undef mld_polyvecl_unpack_eta
@@ -417,6 +439,9 @@
417
439
  #undef mld_yvec_init_eager
418
440
  #undef mld_yvec_init_lazy
419
441
  #undef mld_yvec_lazy
442
+ #undef mld_yvec_scratch
443
+ #undef mld_yvec_scratch_eager
444
+ #undef mld_yvec_scratch_lazy
420
445
  /* mldsa/src/rounding.h */
421
446
  #undef MLD_2_POW_D
422
447
  #undef MLD_ROUNDING_H
@@ -459,6 +484,8 @@
459
484
  /*
460
485
  * Undefine macros from MLD_CONFIG_PARAMETER_SET-generic files
461
486
  */
487
+ /* mldsa/src/capability.h */
488
+ #undef MLD_CAPABILITY_H
462
489
  /* mldsa/src/context.h */
463
490
  #undef MLD_CONTEXT_H
464
491
  #undef MLD_CONTEXT_PARAMETERS_0
@@ -511,10 +538,11 @@
511
538
  #undef mld_polyt1_unpack
512
539
  #undef mld_polyw1_pack_32
513
540
  #undef mld_polyw1_pack_88
541
+ #undef mld_polyw1_unpack_32
542
+ #undef mld_polyw1_unpack_88
514
543
  /* mldsa/src/randombytes.h */
515
544
  #undef MLD_RANDOMBYTES_H
516
545
  /* mldsa/src/reduce.h */
517
- #undef MLD_MONT
518
546
  #undef MLD_REDUCE32_DOMAIN_MAX
519
547
  #undef MLD_REDUCE32_RANGE_MAX
520
548
  #undef MLD_REDUCE_H
@@ -542,38 +570,6 @@
542
570
  #undef mld_xof256_x4_init
543
571
  #undef mld_xof256_x4_release
544
572
  #undef mld_xof256_x4_squeezeblocks
545
- /* mldsa/src/sys.h */
546
- #undef MLD_ALIGN
547
- #undef MLD_ALIGN_UP
548
- #undef MLD_ALWAYS_INLINE
549
- #undef MLD_CET_ENDBR
550
- #undef MLD_CT_TESTING_DECLASSIFY
551
- #undef MLD_CT_TESTING_SECRET
552
- #undef MLD_DEFAULT_ALIGN
553
- #undef MLD_HAVE_INLINE_ASM
554
- #undef MLD_INLINE
555
- #undef MLD_MUST_CHECK_RETURN_VALUE
556
- #undef MLD_NOINLINE
557
- #undef MLD_RESTRICT
558
- #undef MLD_STATIC_TESTABLE
559
- #undef MLD_SYSV_ABI
560
- #undef MLD_SYSV_ABI_SUPPORTED
561
- #undef MLD_SYS_AARCH64
562
- #undef MLD_SYS_AARCH64_EB
563
- #undef MLD_SYS_AARCH64_NEON
564
- #undef MLD_SYS_APPLE
565
- #undef MLD_SYS_ARMV81M_MVE
566
- #undef MLD_SYS_BIG_ENDIAN
567
- #undef MLD_SYS_H
568
- #undef MLD_SYS_LINUX
569
- #undef MLD_SYS_LITTLE_ENDIAN
570
- #undef MLD_SYS_PPC64LE
571
- #undef MLD_SYS_RISCV32
572
- #undef MLD_SYS_RISCV64
573
- #undef MLD_SYS_RISCV64_RVV
574
- #undef MLD_SYS_WINDOWS
575
- #undef MLD_SYS_X86_64
576
- #undef MLD_SYS_X86_64_AVX2
577
573
  /* mldsa/src/cbmc.h */
578
574
  #undef MLD_CBMC_H
579
575
  #undef __contract__
@@ -671,13 +667,25 @@
671
667
  /*
672
668
  * Undefine macros from native code (FIPS202, x86_64)
673
669
  */
670
+ /* mldsa/src/fips202/native/x86_64/auto.h */
671
+ #undef MLD_FIPS202_NATIVE_X86_64_AUTO_H
672
+ /* mldsa/src/fips202/native/x86_64/keccak_f1600_x1_avx512.h */
673
+ #undef MLD_FIPS202_NATIVE_X86_64_KECCAK_F1600_X1_AVX512_H
674
+ #undef MLD_FIPS202_X86_64_NEED_X1_AVX512
675
+ #undef MLD_USE_NATIVE_FIPS202_X1
674
676
  /* mldsa/src/fips202/native/x86_64/keccak_f1600_x4_avx2.h */
675
677
  #undef MLD_FIPS202_NATIVE_X86_64_KECCAK_F1600_X4_AVX2_H
676
678
  #undef MLD_FIPS202_X86_64_NEED_X4_AVX2
677
679
  #undef MLD_USE_NATIVE_FIPS202_X4
680
+ /* mldsa/src/fips202/native/x86_64/keccak_f1600_x4_avx512.h */
681
+ #undef MLD_FIPS202_NATIVE_X86_64_KECCAK_F1600_X4_AVX512_H
682
+ #undef MLD_FIPS202_X86_64_NEED_X4_AVX512
683
+ #undef MLD_USE_NATIVE_FIPS202_X4
678
684
  /* mldsa/src/fips202/native/x86_64/src/fips202_native_x86_64.h */
679
685
  #undef MLD_FIPS202_NATIVE_X86_64_SRC_FIPS202_NATIVE_X86_64_H
686
+ #undef mld_keccak_f1600_x1_avx512_asm
680
687
  #undef mld_keccak_f1600_x4_avx2_asm
688
+ #undef mld_keccak_f1600_x4_avx512_asm
681
689
  #undef mld_keccak_rho56
682
690
  #undef mld_keccak_rho8
683
691
  #undef mld_keccakf1600_round_constants
@@ -826,5 +834,63 @@
826
834
  #undef MLD_NATIVE_X86_64_SRC_CONSTS_H
827
835
  #undef mld_qdata
828
836
  #endif /* MLD_SYS_X86_64 */
837
+ #if defined(MLD_SYS_RISCV32)
838
+ /*
839
+ * Undefine macros from native code (Arith, RV32IM)
840
+ */
841
+ /* mldsa/src/native/rv32im/fastmul.h */
842
+ #undef MLD_ARITH_BACKEND_RV32IM
843
+ #undef MLD_NATIVE_RV32IM_FASTMUL_H
844
+ #undef MLD_RV32IM_NEED_FASTMUL
845
+ #undef MLD_USE_NATIVE_INTT
846
+ #undef MLD_USE_NATIVE_NTT
847
+ #undef MLD_USE_NATIVE_POINTWISE_MONTGOMERY
848
+ /* mldsa/src/native/rv32im/slowmul.h */
849
+ #undef MLD_ARITH_BACKEND_RV32IM
850
+ #undef MLD_NATIVE_RV32IM_SLOWMUL_H
851
+ #undef MLD_RV32IM_NEED_SLOWMUL
852
+ #undef MLD_USE_NATIVE_INTT
853
+ #undef MLD_USE_NATIVE_NTT
854
+ #undef MLD_USE_NATIVE_POINTWISE_MONTGOMERY
855
+ /* mldsa/src/native/rv32im/src/arith_native_rv32im.h */
856
+ #undef MLD_NATIVE_RV32IM_SRC_ARITH_NATIVE_RV32IM_H
857
+ #undef mld_intt_rv32im_fastmul_asm
858
+ #undef mld_intt_rv32im_slowmul_asm
859
+ #undef mld_ntt_rv32im_fastmul_asm
860
+ #undef mld_ntt_rv32im_slowmul_asm
861
+ #undef mld_poly_pointwise_montgomery_rv32im_asm
862
+ #undef mld_rv32im_ntt_zetas
863
+ #endif /* MLD_SYS_RISCV32 */
829
864
  #endif /* MLD_CONFIG_USE_NATIVE_BACKEND_ARITH */
865
+ /* mldsa/src/sys.h */
866
+ #undef MLD_ALIGN
867
+ #undef MLD_ALIGN_UP
868
+ #undef MLD_ALWAYS_INLINE
869
+ #undef MLD_CET_ENDBR
870
+ #undef MLD_DEFAULT_ALIGN
871
+ #undef MLD_INLINE
872
+ #undef MLD_MUST_CHECK_RETURN_VALUE
873
+ #undef MLD_NOINLINE
874
+ #undef MLD_RESTRICT
875
+ #undef MLD_STATIC_TESTABLE
876
+ #undef MLD_SYSV_ABI
877
+ #undef MLD_SYSV_ABI_SUPPORTED
878
+ #undef MLD_SYS_AARCH64
879
+ #undef MLD_SYS_AARCH64_EB
880
+ #undef MLD_SYS_AARCH64_NEON
881
+ #undef MLD_SYS_APPLE
882
+ #undef MLD_SYS_ARMV81M_MVE
883
+ #undef MLD_SYS_BIG_ENDIAN
884
+ #undef MLD_SYS_H
885
+ #undef MLD_SYS_LINUX
886
+ #undef MLD_SYS_LITTLE_ENDIAN
887
+ #undef MLD_SYS_PPC64LE
888
+ #undef MLD_SYS_RISCV32
889
+ #undef MLD_SYS_RISCV32_M
890
+ #undef MLD_SYS_RISCV64
891
+ #undef MLD_SYS_RISCV64_RVV
892
+ #undef MLD_SYS_WINDOWS
893
+ #undef MLD_SYS_X86_64
894
+ #undef MLD_SYS_X86_64_AVX2
895
+ #undef MLD_SYS_X86_64_AVX512
830
896
  #endif /* !MLD_CONFIG_MONOBUILD_KEEP_SHARED_HEADERS */
@@ -184,15 +184,91 @@
184
184
  * the implementation.
185
185
  */
186
186
  /* #define MLD_CONFIG_CONSTANTS_ONLY */
187
+
188
+ /**
189
+ * MLD_CONFIG_KEYGEN_PCT
190
+ *
191
+ * Compliance with @[FIPS140_3_IG, p.87] requires a
192
+ * Pairwise Consistency Test (PCT) to be carried out on a freshly
193
+ * generated keypair before it can be exported.
194
+ *
195
+ * Set this option if such a check should be implemented.
196
+ * In this case, keypair_internal and
197
+ * keypair will return MLD_ERR_PCT_FAIL if the
198
+ * PCT failed.
199
+ *
200
+ * @note This feature will drastically lower the performance of
201
+ * key generation.
202
+ *
203
+ * @note This option is incompatible with MLD_CONFIG_NO_SIGN_API
204
+ * and MLD_CONFIG_NO_VERIFY_API as the current PCT implementation
205
+ * requires signature() and verify().
206
+ */
207
+ /* #define MLD_CONFIG_KEYGEN_PCT */
208
+
209
+ /**
210
+ * MLD_CONFIG_CONTEXT_PARAMETER
211
+ *
212
+ * Set this to add a caller-supplied context parameter to the public API
213
+ * functions, which is then forwarded unchanged to the custom callbacks
214
+ * (allocation, and signing hooks below).
215
+ *
216
+ * When this option is set, every public API function gains a trailing
217
+ * parameter
218
+ *
219
+ * MLD_CONFIG_CONTEXT_PARAMETER_TYPE context
220
+ *
221
+ * as its last argument; its type is configured via
222
+ * MLD_CONFIG_CONTEXT_PARAMETER_TYPE (see below). mldsa-native treats this
223
+ * value as opaque: it never dereferences it and only passes it on to the
224
+ * configurable hook macros. It is meant to carry per-caller state -- e.g. a
225
+ * pointer to a memory pool for the allocation hooks, or the resume state for
226
+ * the signing hooks -- into those hooks.
227
+ *
228
+ * When this option is unset (the default), no extra parameter is added and
229
+ * the hook macros never receive a context argument.
230
+ *
231
+ * The hooks that receive the context are the allocation hooks (see
232
+ * MLD_CONFIG_CUSTOM_ALLOC_FREE) and the signing hooks (see
233
+ * MLD_CONFIG_SIGN_HOOK_RESUME / _ATTEMPT / _FINISH); each is documented with
234
+ * its own option below.
235
+ */
236
+ /* #define MLD_CONFIG_CONTEXT_PARAMETER */
237
+
238
+ /**
239
+ * MLD_CONFIG_CONTEXT_PARAMETER_TYPE
240
+ *
241
+ * Set this to define the type of the context parameter added by
242
+ * MLD_CONFIG_CONTEXT_PARAMETER. It can be any C type usable as a function
243
+ * parameter, e.g. `void *` or a pointer to a caller-defined struct such as
244
+ * `struct my_ctx *`.
245
+ *
246
+ * This option must be defined if and only if MLD_CONFIG_CONTEXT_PARAMETER is
247
+ * defined; defining one without the other is a compile-time error.
248
+ */
249
+ /* #define MLD_CONFIG_CONTEXT_PARAMETER_TYPE void* */
250
+
251
+ /**
252
+ * MLD_CONFIG_REDUCE_RAM
253
+ *
254
+ * Set this to reduce RAM usage. This trades memory for performance.
255
+ *
256
+ * For expected memory usage, see the MLD_TOTAL_ALLOC_* constants defined in
257
+ * mldsa_native.h.
258
+ *
259
+ * This option is useful for embedded systems with tight RAM constraints but
260
+ * relaxed performance requirements.
261
+ *
262
+ */
263
+ /* #define MLD_CONFIG_REDUCE_RAM */
187
264
  /******************************************************************************
188
265
  *
189
266
  * Build-only configuration options
190
267
  *
191
- * The remaining configurations are build-options only.
192
- * They do not affect the API described in mldsa_native.h.
268
+ * The remaining configurations only affect the build, not the API
269
+ * described in mldsa_native.h.
193
270
  *
194
271
  *****************************************************************************/
195
- #if defined(MLD_BUILD_INTERNAL)
196
272
 
197
273
  /**
198
274
  * MLD_CONFIG_MULTILEVEL_WITH_SHARED
@@ -402,7 +478,7 @@
402
478
  /* #define MLD_CONFIG_CUSTOM_ZEROIZE
403
479
  #if !defined(__ASSEMBLER__)
404
480
  #include <stdint.h>
405
- #include "src/src.h"
481
+ #include "src/sys.h"
406
482
  static MLD_INLINE void mld_zeroize(void *ptr, size_t len)
407
483
  {
408
484
  ... your implementation ...
@@ -427,7 +503,7 @@
427
503
  /* #define MLD_CONFIG_CUSTOM_RANDOMBYTES
428
504
  #if !defined(__ASSEMBLER__)
429
505
  #include <stdint.h>
430
- #include "src/src.h"
506
+ #include "src/sys.h"
431
507
  static MLD_INLINE int mld_randombytes(uint8_t *ptr, size_t len)
432
508
  {
433
509
  ... your implementation ...
@@ -461,10 +537,13 @@
461
537
  * will be run on, you must use this option.
462
538
  */
463
539
  /* #define MLD_CONFIG_CUSTOM_CAPABILITY_FUNC
540
+ #if !defined(__ASSEMBLER__)
541
+ #include "src/sys.h"
464
542
  static MLD_INLINE int mld_sys_check_capability(mld_sys_cap cap)
465
543
  {
466
544
  ... your implementation ...
467
545
  }
546
+ #endif
468
547
  */
469
548
 
470
549
  /**
@@ -488,9 +567,10 @@
488
567
  * - T: Type of structure to be freed.
489
568
  * - N: Number of elements to be freed.
490
569
  *
491
- * @warning This option is experimental. Its scope, configuration and
492
- * function/macro signatures may change at any time. We expect a
493
- * stable API in a future version.
570
+ * If MLD_CONFIG_CONTEXT_PARAMETER is set, both macros receive the
571
+ * context as a fourth parameter, e.g. MLD_CUSTOM_ALLOC(v, T, N, context):
572
+ * - context: The context passed to the public API function, of type
573
+ * MLD_CONFIG_CONTEXT_PARAMETER_TYPE.
494
574
  *
495
575
  * @note Even if this option is set, some allocations further down
496
576
  * the call stack will still be made from the stack. Those will
@@ -525,7 +605,7 @@
525
605
  /* #define MLD_CONFIG_CUSTOM_MEMCPY
526
606
  #if !defined(__ASSEMBLER__)
527
607
  #include <stdint.h>
528
- #include "src/src.h"
608
+ #include "src/sys.h"
529
609
  static MLD_INLINE void *mld_memcpy(void *dest, const void *src, size_t n)
530
610
  {
531
611
  ... your implementation ...
@@ -547,7 +627,7 @@
547
627
  /* #define MLD_CONFIG_CUSTOM_MEMSET
548
628
  #if !defined(__ASSEMBLER__)
549
629
  #include <stdint.h>
550
- #include "src/src.h"
630
+ #include "src/sys.h"
551
631
  static MLD_INLINE void *mld_memset(void *s, int c, size_t n)
552
632
  {
553
633
  ... your implementation ...
@@ -612,27 +692,6 @@
612
692
  */
613
693
  /* #define MLD_CONFIG_NO_ASM_VALUE_BARRIER */
614
694
 
615
- /**
616
- * MLD_CONFIG_KEYGEN_PCT
617
- *
618
- * Compliance with @[FIPS140_3_IG, p.87] requires a
619
- * Pairwise Consistency Test (PCT) to be carried out on a freshly
620
- * generated keypair before it can be exported.
621
- *
622
- * Set this option if such a check should be implemented.
623
- * In this case, keypair_internal and
624
- * keypair will return MLD_ERR_PCT_FAIL if the
625
- * PCT failed.
626
- *
627
- * @note This feature will drastically lower the performance of
628
- * key generation.
629
- *
630
- * @note This option is incompatible with MLD_CONFIG_NO_SIGN_API
631
- * and MLD_CONFIG_NO_VERIFY_API as the current PCT implementation
632
- * requires signature() and verify().
633
- */
634
- /* #define MLD_CONFIG_KEYGEN_PCT */
635
-
636
695
  /**
637
696
  * MLD_CONFIG_KEYGEN_PCT_BREAKAGE_TEST
638
697
  *
@@ -644,7 +703,7 @@
644
703
  */
645
704
  /* #define MLD_CONFIG_KEYGEN_PCT_BREAKAGE_TEST
646
705
  #if !defined(__ASSEMBLER__)
647
- #include "src/src.h"
706
+ #include "src/sys.h"
648
707
  static MLD_INLINE int mld_break_pct(void)
649
708
  {
650
709
  ... return 0/1 depending on whether PCT should be broken ...
@@ -697,56 +756,15 @@
697
756
  */
698
757
  /* #define MLD_CONFIG_SERIAL_FIPS202_ONLY */
699
758
 
700
- /**
701
- * MLD_CONFIG_CONTEXT_PARAMETER
702
- *
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.
721
- *
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.
726
- */
727
- /* #define MLD_CONFIG_CONTEXT_PARAMETER */
728
-
729
- /**
730
- * MLD_CONFIG_CONTEXT_PARAMETER_TYPE
731
- *
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 *`.
736
- *
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.
739
- */
740
- /* #define MLD_CONFIG_CONTEXT_PARAMETER_TYPE void* */
741
-
742
759
  /**
743
760
  * Signing hooks: MLD_CONFIG_SIGN_HOOK_RESUME / _ATTEMPT / _FINISH
744
761
  *
745
762
  * Three optional, independent hooks into the ML-DSA signing rejection-sampling
746
763
  * loop. Each is enabled by defining the matching option, in which case the
747
764
  * 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.
765
+ * per-operation state, enable MLD_CONFIG_CONTEXT_PARAMETER; each hook then
766
+ * receives the context passed to the public API function, of type
767
+ * MLD_CONFIG_CONTEXT_PARAMETER_TYPE, as its last argument (`ctxt` below).
750
768
  *
751
769
  * @warning This feature is experimental. Its scope, configuration and
752
770
  * function signatures may change at any time, including after v2.
@@ -810,24 +828,8 @@
810
828
  #endif
811
829
  */
812
830
 
813
- /**
814
- * MLD_CONFIG_REDUCE_RAM
815
- *
816
- * Set this to reduce RAM usage. This trades memory for performance.
817
- *
818
- * For expected memory usage, see the MLD_TOTAL_ALLOC_* constants defined in
819
- * mldsa_native.h.
820
- *
821
- * This option is useful for embedded systems with tight RAM constraints but
822
- * relaxed performance requirements.
823
- *
824
- */
825
- /* #define MLD_CONFIG_REDUCE_RAM */
826
-
827
831
  /************************* Config internals ********************************/
828
832
 
829
- #endif /* MLD_BUILD_INTERNAL */
830
-
831
833
  /* Default namespace
832
834
  *
833
835
  * Don't change this. If you need a different namespace, re-define
@@ -0,0 +1,31 @@
1
+ /*
2
+ * Copyright (c) The mlkem-native project authors
3
+ * Copyright (c) The mldsa-native project authors
4
+ * SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
5
+ */
6
+ #ifndef MLD_CAPABILITY_H
7
+ #define MLD_CAPABILITY_H
8
+
9
+ #include "sys.h"
10
+
11
+ #if !defined(MLD_CONFIG_CUSTOM_CAPABILITY_FUNC) && !defined(__ASSEMBLER__)
12
+ #include "cbmc.h"
13
+
14
+ MLD_MUST_CHECK_RETURN_VALUE
15
+ static MLD_INLINE int mld_sys_check_capability(mld_sys_cap cap)
16
+ __contract__(
17
+ ensures(return_value == 0 || return_value == 1)
18
+ )
19
+ {
20
+ /* By default, we rely on compile-time feature detection/specification:
21
+ * If a feature is enabled at compile-time, we assume it is supported by
22
+ * the host that the resulting library/binary will be built on.
23
+ * If this assumption is not true, you MUST overwrite this function.
24
+ * See the documentation of MLD_CONFIG_CUSTOM_CAPABILITY_FUNC in
25
+ * mldsa_native_config.h for more information. */
26
+ (void)cap;
27
+ return 1;
28
+ }
29
+ #endif /* !MLD_CONFIG_CUSTOM_CAPABILITY_FUNC && !__ASSEMBLER__ */
30
+
31
+ #endif /* !MLD_CAPABILITY_H */
@@ -105,6 +105,15 @@
105
105
  * Note that the range on qvar is _exclusive_ between qvar_lb .. qvar_ub
106
106
  * https://diffblue.github.io/cbmc/contracts-quantifiers.html
107
107
  *
108
+ * forall(qvar, qvar_lb, qvar_ub, predicate) quantifies directly over
109
+ * [qvar_lb, qvar_ub).
110
+ *
111
+ * forall(qvar, qvar_lb, qvar_ub, qvar_max, predicate) additionally takes a
112
+ * compile-time constant qvar_max. It quantifies over [0, qvar_max) and
113
+ * restricts to [qvar_lb, qvar_ub) via an implication. Use this form when
114
+ * qvar_ub is variable, so the propositional backend can expand a constant
115
+ * range. A variable qvar_lb alone does not require this form.
116
+ *
108
117
  * The quantified variable is declared as uint32_t, so these macros
109
118
  * quantify only over indices in [0, UINT32_MAX). Bounds larger than
110
119
  * UINT32_MAX (4 GiB) are NOT supported: the explicit (uint32_t) casts
@@ -122,13 +131,24 @@
122
131
  * Prevent clang-format from corrupting CBMC's special ==> operator
123
132
  */
124
133
  /* clang-format off */
125
- #define forall(qvar, qvar_lb, qvar_ub, predicate) \
134
+ #define CBMC_FORALL(qvar, qvar_lb, qvar_ub, predicate) \
126
135
  __CPROVER_forall \
127
136
  { \
128
137
  uint32_t qvar; \
129
138
  ((uint32_t) (qvar_lb) <= (qvar) && (qvar) < (uint32_t) (qvar_ub)) ==> (predicate) \
130
139
  }
131
140
 
141
+ #define CBMC_FORALL_BOUNDED(qvar, qvar_lb, qvar_ub, qvar_max, predicate) \
142
+ CBMC_FORALL(qvar, 0, qvar_max, \
143
+ ((uint32_t)(qvar_lb) <= (qvar) && \
144
+ (qvar) < (uint32_t)(qvar_ub)) ==> (predicate))
145
+
146
+ /* The final argument keeps the selector's variadic tail nonempty in C99. */
147
+ #define CBMC_FORALL_SELECT(_1, _2, _3, _4, _5, NAME, ...) NAME
148
+ #define forall(...) \
149
+ CBMC_FORALL_SELECT(__VA_ARGS__, CBMC_FORALL_BOUNDED, CBMC_FORALL, \
150
+ unused)(__VA_ARGS__)
151
+
132
152
  #define exists(qvar, qvar_lb, qvar_ub, predicate) \
133
153
  __CPROVER_exists \
134
154
  { \
@@ -157,10 +177,33 @@
157
177
  (((array_var)[(qvar)]) < (int)(value_ub))) \
158
178
  }
159
179
 
160
- #define array_bound(array_var, qvar_lb, qvar_ub, value_lb, value_ub) \
161
- array_bound_core(CBMC_CONCAT(_cbmc_idx, __COUNTER__), (qvar_lb), \
180
+ #define array_bound_bounded_core(qvar, qvar_lb, qvar_ub, qvar_max, \
181
+ array_var, value_lb, value_ub) \
182
+ CBMC_FORALL(qvar, 0, qvar_max, \
183
+ ((uint32_t)(qvar_lb) <= (qvar) && \
184
+ (qvar) < (uint32_t)(qvar_ub)) ==> \
185
+ (((int)(value_lb) <= ((array_var)[(qvar)])) && \
186
+ (((array_var)[(qvar)]) < (int)(value_ub))))
187
+
188
+ /*
189
+ * array_bound(array_var, qvar_lb, qvar_ub, value_lb, value_ub) and
190
+ * array_bound(array_var, qvar_lb, qvar_ub, qvar_max, value_lb, value_ub)
191
+ * mirror the two forms of forall.
192
+ */
193
+ #define CBMC_ARRAY_BOUND(array_var, qvar_lb, qvar_ub, value_lb, value_ub) \
194
+ array_bound_core(CBMC_CONCAT(_cbmc_idx, __COUNTER__), (qvar_lb), \
162
195
  (qvar_ub), (array_var), (value_lb), (value_ub))
163
196
 
197
+ #define CBMC_ARRAY_BOUND_BOUNDED(array_var, qvar_lb, qvar_ub, qvar_max, \
198
+ value_lb, value_ub) \
199
+ array_bound_bounded_core(CBMC_CONCAT(_cbmc_idx, __COUNTER__), (qvar_lb), \
200
+ (qvar_ub), (qvar_max), (array_var), (value_lb), (value_ub))
201
+
202
+ #define CBMC_ARRAY_BOUND_SELECT(_1, _2, _3, _4, _5, _6, NAME, ...) NAME
203
+ #define array_bound(...) \
204
+ CBMC_ARRAY_BOUND_SELECT(__VA_ARGS__, CBMC_ARRAY_BOUND_BOUNDED, \
205
+ CBMC_ARRAY_BOUND, unused)(__VA_ARGS__)
206
+
164
207
  #define array_unchanged_core(qvar, qvar_lb, qvar_ub, array_var) \
165
208
  __CPROVER_forall \
166
209
  { \
@@ -225,9 +268,17 @@
225
268
  * Note that since the lower bound in array_bound is inclusive, we have to
226
269
  * raise it by 1 here.
227
270
  */
228
- #define array_abs_bound(arr, lb, ub, k) \
271
+ #define CBMC_ARRAY_ABS_BOUND(arr, lb, ub, k) \
229
272
  array_bound((arr), (lb), (ub), -((int)(k)) + 1, (k))
230
273
 
274
+ #define CBMC_ARRAY_ABS_BOUND_BOUNDED(arr, lb, ub, max, k) \
275
+ array_bound((arr), (lb), (ub), (max), -((int)(k)) + 1, (k))
276
+
277
+ /* array_abs_bound takes an optional constant max like array_bound. */
278
+ #define array_abs_bound(...) \
279
+ CBMC_FORALL_SELECT(__VA_ARGS__, CBMC_ARRAY_ABS_BOUND_BOUNDED, \
280
+ CBMC_ARRAY_ABS_BOUND, unused)(__VA_ARGS__)
281
+
231
282
  #endif /* CBMC */
232
283
 
233
284
  #endif /* !MLD_CBMC_H */