pq_crypto 0.6.8 → 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 (206) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +11 -0
  3. data/README.md +1 -3
  4. data/ext/pqcrypto/pqcrypto_version.h +1 -1
  5. data/ext/pqcrypto/vendor/.vendored +7 -7
  6. data/ext/pqcrypto/vendor/mldsa-native/BUILDING.md +71 -0
  7. data/ext/pqcrypto/vendor/mldsa-native/README.md +26 -11
  8. data/ext/pqcrypto/vendor/mldsa-native/RELEASE.md +77 -150
  9. data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native.c +93 -40
  10. data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native.h +74 -59
  11. data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native_asm.S +106 -40
  12. data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native_config.h +94 -92
  13. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/capability.h +31 -0
  14. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/cbmc.h +55 -4
  15. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/common.h +30 -0
  16. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/context.h +1 -0
  17. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/debug.c +1 -0
  18. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/fips202.h +1 -0
  19. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_scalar_aarch64_asm.S +5 -2
  20. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_v84a_aarch64_asm.S +4 -4
  21. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x2_v84a_aarch64_asm.S +4 -4
  22. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_scalar_hybrid_aarch64_asm.S +8 -3
  23. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_v84a_scalar_hybrid_aarch64_asm.S +8 -4
  24. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/mve.h +12 -0
  25. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.S +4 -2
  26. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccak_f1600_x4_state_extract_bytes_mve.S +37 -19
  27. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccak_f1600_x4_state_xor_bytes_mve.S +37 -19
  28. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/auto.h +3 -8
  29. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/auto.h +53 -0
  30. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/keccak_f1600_x1_avx512.h +38 -0
  31. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/keccak_f1600_x4_avx512.h +38 -0
  32. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/fips202_native_x86_64.h +24 -0
  33. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/keccak_f1600_x1_avx512_asm.S +574 -0
  34. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/keccak_f1600_x4_avx2_asm.S +46 -18
  35. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/keccak_f1600_x4_avx512_asm.S +679 -0
  36. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/keccakf1600_constants.c +13 -4
  37. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/meta.h +6 -4
  38. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/arith_native_aarch64.h +5 -6
  39. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_intt_aarch64_asm.S +4 -2
  40. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_ntt_aarch64_asm.S +4 -2
  41. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_pointwise_montgomery_aarch64_asm.S +6 -4
  42. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_poly_caddq_aarch64_asm.S +4 -2
  43. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_poly_chknorm_aarch64_asm.S +6 -4
  44. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_poly_decompose_32_aarch64_asm.S +4 -3
  45. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_poly_decompose_88_aarch64_asm.S +4 -3
  46. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_poly_use_hint_32_aarch64_asm.S +4 -3
  47. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_poly_use_hint_88_aarch64_asm.S +4 -3
  48. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_polyvecl_pointwise_acc_montgomery_l4_aarch64_asm.S +4 -2
  49. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_polyvecl_pointwise_acc_montgomery_l5_aarch64_asm.S +4 -2
  50. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_polyvecl_pointwise_acc_montgomery_l7_aarch64_asm.S +4 -2
  51. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_polyz_unpack_17_aarch64_asm.S +5 -3
  52. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_polyz_unpack_19_aarch64_asm.S +5 -3
  53. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_rej_uniform_aarch64_asm.S +110 -120
  54. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_rej_uniform_eta2_aarch64_asm.S +109 -101
  55. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_rej_uniform_eta4_aarch64_asm.S +97 -93
  56. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/api.h +1 -9
  57. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/meta.h +4 -0
  58. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/rv32im/fastmul.h +74 -0
  59. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/rv32im/slowmul.h +77 -0
  60. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/rv32im/src/arith_native_rv32im.h +124 -0
  61. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/rv32im/src/mldsa_intt_rv32im_asm.S +331 -0
  62. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/rv32im/src/mldsa_intt_rv32im_slowmul_asm.S +381 -0
  63. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/rv32im/src/mldsa_ntt_rv32im_asm.S +304 -0
  64. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/rv32im/src/mldsa_ntt_rv32im_slowmul_asm.S +351 -0
  65. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/rv32im/src/mldsa_poly_pointwise_montgomery_rv32im_asm.S +139 -0
  66. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/rv32im/src/rv32im_zetas.c +118 -0
  67. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/meta.h +6 -5
  68. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/arith_native_x86_64.h +2 -3
  69. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_intt_avx2_asm.S +5 -3
  70. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_ntt_avx2_asm.S +5 -3
  71. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_nttunpack_avx2_asm.S +5 -3
  72. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_pointwise_acc_l4_avx2_asm.S +6 -3
  73. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_pointwise_acc_l5_avx2_asm.S +6 -3
  74. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_pointwise_acc_l7_avx2_asm.S +6 -3
  75. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_pointwise_avx2_asm.S +5 -3
  76. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_poly_caddq_avx2_asm.S +5 -3
  77. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_poly_chknorm_avx2_asm.S +7 -5
  78. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_poly_decompose_32_avx2_asm.S +69 -67
  79. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_poly_decompose_88_avx2_asm.S +69 -67
  80. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_poly_use_hint_32_avx2_asm.S +12 -16
  81. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_poly_use_hint_88_avx2_asm.S +14 -18
  82. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_polyz_unpack_17_avx2_asm.S +6 -3
  83. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_polyz_unpack_19_avx2_asm.S +6 -3
  84. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_rej_uniform_avx2_asm.S +5 -3
  85. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_rej_uniform_eta2_avx2_asm.S +5 -3
  86. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_rej_uniform_eta4_avx2_asm.S +5 -3
  87. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/packing.c +23 -27
  88. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/packing.h +21 -42
  89. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/params.h +28 -1
  90. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly.c +87 -28
  91. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly.h +61 -3
  92. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly_kl.c +23 -19
  93. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly_kl.h +30 -0
  94. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec.c +55 -107
  95. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec.h +67 -107
  96. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec_lazy.c +16 -24
  97. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec_lazy.h +27 -21
  98. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/reduce.h +8 -8
  99. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/sign.c +191 -119
  100. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/sign.h +6 -3
  101. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/sys.h +16 -42
  102. data/ext/pqcrypto/vendor/mlkem-native/BUILDING.md +72 -0
  103. data/ext/pqcrypto/vendor/mlkem-native/README.md +9 -5
  104. data/ext/pqcrypto/vendor/mlkem-native/RELEASE.md +64 -312
  105. data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native.c +77 -34
  106. data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native.h +41 -13
  107. data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native_asm.S +89 -33
  108. data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native_config.h +50 -46
  109. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/capability.h +30 -0
  110. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/common.h +30 -0
  111. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/compress.c +1 -0
  112. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/compress.h +4 -5
  113. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/debug.c +1 -0
  114. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/fips202.c +15 -0
  115. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/fips202.h +23 -8
  116. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/fips202x4.c +11 -3
  117. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/fips202x4.h +7 -1
  118. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/keccakf1600.c +8 -0
  119. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/keccakf1600.h +8 -0
  120. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccak_f1600_x1_scalar_aarch64_asm.S +5 -2
  121. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccak_f1600_x1_v84a_aarch64_asm.S +4 -4
  122. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccak_f1600_x2_v84a_aarch64_asm.S +4 -4
  123. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_scalar_hybrid_aarch64_asm.S +8 -3
  124. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_v84a_scalar_hybrid_aarch64_asm.S +8 -4
  125. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.S +4 -2
  126. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/keccak_f1600_x4_state_extract_bytes_mve.S +37 -19
  127. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/keccak_f1600_x4_state_xor_bytes_mve.S +37 -19
  128. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/auto.h +2 -2
  129. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/auto.h +47 -0
  130. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/keccak_f1600_x1_avx512.h +37 -0
  131. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/keccak_f1600_x4_avx512.h +37 -0
  132. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/src/fips202_native_x86_64.h +24 -0
  133. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/src/keccak_f1600_x1_avx512_asm.S +573 -0
  134. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/src/keccak_f1600_x4_avx2_asm.S +46 -18
  135. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/src/keccak_f1600_x4_avx512_asm.S +678 -0
  136. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/src/keccakf1600_constants.c +13 -4
  137. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/indcpa.c +1 -2
  138. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/kem.c +7 -5
  139. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/kem.h +29 -5
  140. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/meta.h +156 -0
  141. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/arith_native_aarch64.h +137 -3
  142. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/compress_d5_table.c +43 -0
  143. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/decompress_d10_table.c +50 -0
  144. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/decompress_d11_table.c +53 -0
  145. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/decompress_d4_table.c +44 -0
  146. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/decompress_d5_table.c +53 -0
  147. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_intt_aarch64_asm.S +5 -3
  148. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_ntt_aarch64_asm.S +4 -2
  149. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_poly_compress_d10_aarch64_asm.S +439 -0
  150. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_poly_compress_d11_aarch64_asm.S +452 -0
  151. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_poly_compress_d4_aarch64_asm.S +106 -0
  152. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_poly_compress_d5_aarch64_asm.S +124 -0
  153. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_poly_decompress_d10_aarch64_asm.S +108 -0
  154. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_poly_decompress_d11_aarch64_asm.S +116 -0
  155. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_poly_decompress_d4_aarch64_asm.S +93 -0
  156. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_poly_decompress_d5_aarch64_asm.S +104 -0
  157. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_poly_frombytes_aarch64_asm.S +84 -0
  158. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_poly_mulcache_compute_aarch64_asm.S +4 -2
  159. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_poly_reduce_aarch64_asm.S +4 -2
  160. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_poly_tobytes_aarch64_asm.S +5 -3
  161. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_poly_tomont_aarch64_asm.S +4 -3
  162. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_polyvec_basemul_acc_montgomery_cached_k2_aarch64_asm.S +4 -2
  163. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_polyvec_basemul_acc_montgomery_cached_k3_aarch64_asm.S +4 -2
  164. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_polyvec_basemul_acc_montgomery_cached_k4_aarch64_asm.S +4 -2
  165. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_rej_uniform_aarch64_asm.S +112 -104
  166. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/api.h +0 -1
  167. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/meta.h +2 -2
  168. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/README.md +2 -2
  169. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/meta.h +16 -21
  170. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/arith_native_ppc64le.h +1 -0
  171. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/consts.c +2 -2
  172. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/mlkem_intt_ppc_asm.S +6 -5
  173. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/mlkem_ntt_ppc_asm.S +6 -5
  174. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/mlkem_poly_tomont_ppc_asm.S +6 -5
  175. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/mlkem_reduce_ppc_asm.S +6 -5
  176. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/rv64v_debug.c +5 -4
  177. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/rv64v_debug.h +2 -2
  178. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/rv64v_poly.c +1 -1
  179. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/arith_native_x86_64.h +5 -5
  180. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_intt_avx2_asm.S +36 -33
  181. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_ntt_avx2_asm.S +67 -65
  182. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_nttfrombytes_avx2_asm.S +8 -5
  183. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_ntttobytes_avx2_asm.S +6 -3
  184. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_nttunpack_avx2_asm.S +5 -3
  185. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_poly_compress_d10_avx2_asm.S +7 -5
  186. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_poly_compress_d11_avx2_asm.S +7 -4
  187. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_poly_compress_d4_avx2_asm.S +7 -5
  188. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_poly_compress_d5_avx2_asm.S +7 -4
  189. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_poly_decompress_d10_avx2_asm.S +7 -4
  190. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_poly_decompress_d11_avx2_asm.S +6 -4
  191. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_poly_decompress_d4_avx2_asm.S +7 -4
  192. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_poly_decompress_d5_avx2_asm.S +6 -4
  193. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_poly_mulcache_compute_avx2_asm.S +5 -3
  194. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_polyvec_basemul_acc_montgomery_cached_k2_avx2_asm.S +118 -115
  195. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_polyvec_basemul_acc_montgomery_cached_k3_avx2_asm.S +174 -171
  196. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_polyvec_basemul_acc_montgomery_cached_k4_avx2_asm.S +230 -227
  197. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_reduce_avx2_asm.S +17 -15
  198. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_rej_uniform_avx2_asm.S +7 -6
  199. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_tomont_avx2_asm.S +5 -3
  200. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/poly_k.c +4 -9
  201. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/poly_k.h +1 -1
  202. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/sys.h +31 -44
  203. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/verify.h +1 -1
  204. data/lib/pq_crypto/version.rb +1 -1
  205. data/script/vendor_libs.rb +6 -6
  206. metadata +36 -1
@@ -6,6 +6,11 @@
6
6
  /* References
7
7
  * ==========
8
8
  *
9
+ * - [DilithiumMemory]
10
+ * Dilithium for Memory Constrained Devices
11
+ * Bos, Renes, Sprenkels
12
+ * https://eprint.iacr.org/2022/323
13
+ *
9
14
  * - [FIPS140_3_IG]
10
15
  * Implementation Guidance for FIPS 140-3 and the Cryptographic Module
11
16
  * Validation Program
@@ -22,6 +27,12 @@
22
27
  * National Institute of Standards and Technology
23
28
  * https://csrc.nist.gov/files/pubs/fips/204/final/docs/fips-204-potential-updates.xlsx
24
29
  *
30
+ * - [KLS17]
31
+ * A Concrete Treatment of Fiat-Shamir Signatures in the Quantum Random-Oracle
32
+ * Model
33
+ * Kiltz, Lyubashevsky, Schaffner
34
+ * https://eprint.iacr.org/2017/916
35
+ *
25
36
  * - [Round3_Spec]
26
37
  * CRYSTALS-Dilithium Algorithm Specifications and Supporting Documentation
27
38
  * (Version 3.1)
@@ -30,7 +41,6 @@
30
41
  */
31
42
 
32
43
  #include "sign.h"
33
-
34
44
  #include "cbmc.h"
35
45
  #include "ct.h"
36
46
  #include "debug.h"
@@ -46,7 +56,7 @@
46
56
  * of mldsa-native (e.g. with varying parameter sets)
47
57
  * within a single compilation unit. */
48
58
  #define mld_check_pct MLD_ADD_PARAM_SET(mld_check_pct) MLD_CONTEXT_PARAMETERS_2
49
- #define mld_sample_s1_s2 MLD_ADD_PARAM_SET(mld_sample_s1_s2)
59
+ #define mld_sample_pack_s1_s2 MLD_ADD_PARAM_SET(mld_sample_pack_s1_s2)
50
60
  #define mld_validate_hash_length MLD_ADD_PARAM_SET(mld_validate_hash_length)
51
61
  #define mld_get_hash_oid MLD_ADD_PARAM_SET(mld_get_hash_oid)
52
62
  #define mld_H MLD_ADD_PARAM_SET(mld_H)
@@ -129,7 +139,7 @@ static int mld_check_pct(uint8_t const pk[MLDSA_CRYPTO_PUBLICKEYBYTES],
129
139
  /* Deliberately break public key for testing purposes */
130
140
  if (mld_break_pct())
131
141
  {
132
- pk_test[0] = ~pk_test[0];
142
+ pk_test[0] ^= 0xFF;
133
143
  }
134
144
  #endif /* MLD_CONFIG_KEYGEN_PCT_BREAKAGE_TEST */
135
145
 
@@ -173,64 +183,115 @@ static int mld_check_pct(uint8_t const pk[MLDSA_CRYPTO_PUBLICKEYBYTES],
173
183
  #endif /* !MLD_CONFIG_KEYGEN_PCT */
174
184
 
175
185
  /**
176
- * Sample the short secret vectors s1 (length MLDSA_L) and s2 (length MLDSA_K)
177
- * with coefficients in [-MLDSA_ETA, MLDSA_ETA] from the seed.
186
+ * Sample s1 and s2 with coefficients in [-MLDSA_ETA, MLDSA_ETA] from the seed
187
+ * and bit-pack them into s1_packed and s2_packed.
178
188
  *
179
- * @spec{Implements @[FIPS204, Algorithm 33, ExpandS].}
189
+ * s2 is sampled first, using s1 as scratch, and packed directly, so
190
+ * it is never held in memory as a whole. s1 is then sampled, packed, and
191
+ * also returned unpacked.
180
192
  *
181
- * @param[out] s1 Output vector s1.
182
- * @param[out] s2 Output vector s2.
183
- * @param[in] seed Byte array with seed of length MLDSA_CRHBYTES.
193
+ * @spec{Implements @[FIPS204, Algorithm 33, ExpandS], followed by the s1 and
194
+ * s2 parts of @[FIPS204, Algorithm 24, skEncode].}
195
+ *
196
+ * @param[out] s1_packed Output buffer for packed s1 (size
197
+ * MLDSA_L * MLDSA_POLYETA_PACKEDBYTES; i.e. the s1
198
+ * region of sk).
199
+ * @param[out] s2_packed Output buffer for packed s2 (size
200
+ * MLDSA_K * MLDSA_POLYETA_PACKEDBYTES; i.e. the s2
201
+ * region of sk).
202
+ * @param[out] s1 Unpacked s1.
203
+ * @param[in] seed Byte array with seed of length MLDSA_CRHBYTES.
184
204
  */
185
- static void mld_sample_s1_s2(mld_polyvecl *s1, mld_polyveck *s2,
186
- const uint8_t seed[MLDSA_CRHBYTES])
205
+ static void mld_sample_pack_s1_s2(
206
+ uint8_t s1_packed[MLDSA_L * MLDSA_POLYETA_PACKEDBYTES],
207
+ uint8_t s2_packed[MLDSA_K * MLDSA_POLYETA_PACKEDBYTES], mld_polyvecl *s1,
208
+ const uint8_t seed[MLDSA_CRHBYTES])
187
209
  __contract__(
210
+ requires(memory_no_alias(s1_packed, MLDSA_L * MLDSA_POLYETA_PACKEDBYTES))
211
+ requires(memory_no_alias(s2_packed, MLDSA_K * MLDSA_POLYETA_PACKEDBYTES))
188
212
  requires(memory_no_alias(s1, sizeof(mld_polyvecl)))
189
- requires(memory_no_alias(s2, sizeof(mld_polyveck)))
190
213
  requires(memory_no_alias(seed, MLDSA_CRHBYTES))
191
- assigns(object_whole(s1), object_whole(s2))
214
+ assigns(memory_slice(s1_packed, MLDSA_L * MLDSA_POLYETA_PACKEDBYTES))
215
+ assigns(memory_slice(s2_packed, MLDSA_K * MLDSA_POLYETA_PACKEDBYTES))
216
+ assigns(memory_slice(s1, sizeof(mld_polyvecl)))
192
217
  ensures(forall(l0, 0, MLDSA_L, array_abs_bound(s1->vec[l0].coeffs, 0, MLDSA_N, MLDSA_ETA + 1)))
193
- ensures(forall(k0, 0, MLDSA_K, array_abs_bound(s2->vec[k0].coeffs, 0, MLDSA_N, MLDSA_ETA + 1)))
194
218
  )
195
219
  {
196
- /* Sample short vectors s1 and s2 */
220
+ /* Polynomial i of s1 || s2 uses nonce i.
221
+ * Safety: The nonces are at most 14 (MLDSA_L + MLDSA_K - 1), and, hence, the
222
+ * casts are safe. */
197
223
  #if defined(MLD_CONFIG_SERIAL_FIPS202_ONLY)
198
- int i;
199
- uint16_t nonce = 0;
200
- /* Safety: The nonces are at most 14 (MLDSA_L + MLDSA_K - 1), and, hence, the
201
- * casts are safe. */
202
- for (i = 0; i < MLDSA_L; i++)
224
+ unsigned int i;
225
+ for (i = 0; i < MLDSA_K; i++)
203
226
  {
204
- mld_poly_uniform_eta(&s1->vec[i], seed, (uint8_t)(nonce + i));
227
+ mld_poly_uniform_eta(&s1->vec[0], seed, (uint8_t)(MLDSA_L + i));
228
+ mld_polyeta_pack(s2_packed + i * MLDSA_POLYETA_PACKEDBYTES, &s1->vec[0]);
205
229
  }
206
- for (i = 0; i < MLDSA_K; i++)
230
+ for (i = 0; i < MLDSA_L; i++)
207
231
  {
208
- mld_poly_uniform_eta(&s2->vec[i], seed, (uint8_t)(nonce + MLDSA_L + i));
232
+ mld_poly_uniform_eta(&s1->vec[i], seed, (uint8_t)i);
233
+ mld_polyeta_pack(s1_packed + i * MLDSA_POLYETA_PACKEDBYTES, &s1->vec[i]);
209
234
  }
210
235
  #else /* MLD_CONFIG_SERIAL_FIPS202_ONLY */
236
+ /* Batches keep the nonce grouping of the serial path; s2 and don't-care
237
+ * outputs go to s1 slots that are yet to be sampled. */
211
238
  #if MLD_CONFIG_PARAMETER_SET == 44
212
239
  mld_poly_uniform_eta_4x(&s1->vec[0], &s1->vec[1], &s1->vec[2], &s1->vec[3],
213
- seed, 0, 1, 2, 3);
214
- mld_poly_uniform_eta_4x(&s2->vec[0], &s2->vec[1], &s2->vec[2], &s2->vec[3],
215
240
  seed, 4, 5, 6, 7);
216
- #elif MLD_CONFIG_PARAMETER_SET == 65
241
+ mld_polyeta_pack(s2_packed + 0 * MLDSA_POLYETA_PACKEDBYTES, &s1->vec[0]);
242
+ mld_polyeta_pack(s2_packed + 1 * MLDSA_POLYETA_PACKEDBYTES, &s1->vec[1]);
243
+ mld_polyeta_pack(s2_packed + 2 * MLDSA_POLYETA_PACKEDBYTES, &s1->vec[2]);
244
+ mld_polyeta_pack(s2_packed + 3 * MLDSA_POLYETA_PACKEDBYTES, &s1->vec[3]);
217
245
  mld_poly_uniform_eta_4x(&s1->vec[0], &s1->vec[1], &s1->vec[2], &s1->vec[3],
218
246
  seed, 0, 1, 2, 3);
219
- mld_poly_uniform_eta_4x(&s1->vec[4], &s2->vec[0], &s2->vec[1],
220
- &s2->vec[2] /* irrelevant */, seed, 4, 5, 6,
221
- 0xFF /* irrelevant */);
222
- mld_poly_uniform_eta_4x(&s2->vec[2], &s2->vec[3], &s2->vec[4], &s2->vec[5],
247
+ mld_polyeta_pack(s1_packed + 0 * MLDSA_POLYETA_PACKEDBYTES, &s1->vec[0]);
248
+ mld_polyeta_pack(s1_packed + 1 * MLDSA_POLYETA_PACKEDBYTES, &s1->vec[1]);
249
+ mld_polyeta_pack(s1_packed + 2 * MLDSA_POLYETA_PACKEDBYTES, &s1->vec[2]);
250
+ mld_polyeta_pack(s1_packed + 3 * MLDSA_POLYETA_PACKEDBYTES, &s1->vec[3]);
251
+ #elif MLD_CONFIG_PARAMETER_SET == 65
252
+ mld_poly_uniform_eta_4x(&s1->vec[0], &s1->vec[1], &s1->vec[2], &s1->vec[3],
223
253
  seed, 7, 8, 9, 10);
224
- #elif MLD_CONFIG_PARAMETER_SET == 87
254
+ mld_polyeta_pack(s2_packed + 2 * MLDSA_POLYETA_PACKEDBYTES, &s1->vec[0]);
255
+ mld_polyeta_pack(s2_packed + 3 * MLDSA_POLYETA_PACKEDBYTES, &s1->vec[1]);
256
+ mld_polyeta_pack(s2_packed + 4 * MLDSA_POLYETA_PACKEDBYTES, &s1->vec[2]);
257
+ mld_polyeta_pack(s2_packed + 5 * MLDSA_POLYETA_PACKEDBYTES, &s1->vec[3]);
258
+ mld_poly_uniform_eta_4x(&s1->vec[4], &s1->vec[0], &s1->vec[1],
259
+ &s1->vec[2] /* irrelevant */, seed, 4, 5, 6,
260
+ 0xFF /* irrelevant */);
261
+ mld_polyeta_pack(s1_packed + 4 * MLDSA_POLYETA_PACKEDBYTES, &s1->vec[4]);
262
+ mld_polyeta_pack(s2_packed + 0 * MLDSA_POLYETA_PACKEDBYTES, &s1->vec[0]);
263
+ mld_polyeta_pack(s2_packed + 1 * MLDSA_POLYETA_PACKEDBYTES, &s1->vec[1]);
225
264
  mld_poly_uniform_eta_4x(&s1->vec[0], &s1->vec[1], &s1->vec[2], &s1->vec[3],
226
265
  seed, 0, 1, 2, 3);
266
+ mld_polyeta_pack(s1_packed + 0 * MLDSA_POLYETA_PACKEDBYTES, &s1->vec[0]);
267
+ mld_polyeta_pack(s1_packed + 1 * MLDSA_POLYETA_PACKEDBYTES, &s1->vec[1]);
268
+ mld_polyeta_pack(s1_packed + 2 * MLDSA_POLYETA_PACKEDBYTES, &s1->vec[2]);
269
+ mld_polyeta_pack(s1_packed + 3 * MLDSA_POLYETA_PACKEDBYTES, &s1->vec[3]);
270
+ #elif MLD_CONFIG_PARAMETER_SET == 87
271
+ mld_poly_uniform_eta_4x(&s1->vec[0], &s1->vec[1], &s1->vec[2], &s1->vec[3],
272
+ seed, 11, 12, 13, 14);
273
+ mld_polyeta_pack(s2_packed + 4 * MLDSA_POLYETA_PACKEDBYTES, &s1->vec[0]);
274
+ mld_polyeta_pack(s2_packed + 5 * MLDSA_POLYETA_PACKEDBYTES, &s1->vec[1]);
275
+ mld_polyeta_pack(s2_packed + 6 * MLDSA_POLYETA_PACKEDBYTES, &s1->vec[2]);
276
+ mld_polyeta_pack(s2_packed + 7 * MLDSA_POLYETA_PACKEDBYTES, &s1->vec[3]);
277
+ mld_poly_uniform_eta_4x(&s1->vec[0], &s1->vec[1], &s1->vec[2], &s1->vec[3],
278
+ seed, 7, 8, 9, 10);
279
+ mld_polyeta_pack(s2_packed + 0 * MLDSA_POLYETA_PACKEDBYTES, &s1->vec[0]);
280
+ mld_polyeta_pack(s2_packed + 1 * MLDSA_POLYETA_PACKEDBYTES, &s1->vec[1]);
281
+ mld_polyeta_pack(s2_packed + 2 * MLDSA_POLYETA_PACKEDBYTES, &s1->vec[2]);
282
+ mld_polyeta_pack(s2_packed + 3 * MLDSA_POLYETA_PACKEDBYTES, &s1->vec[3]);
227
283
  mld_poly_uniform_eta_4x(&s1->vec[4], &s1->vec[5], &s1->vec[6],
228
- &s2->vec[0] /* irrelevant */, seed, 4, 5, 6,
284
+ &s1->vec[0] /* irrelevant */, seed, 4, 5, 6,
229
285
  0xFF /* irrelevant */);
230
- mld_poly_uniform_eta_4x(&s2->vec[0], &s2->vec[1], &s2->vec[2], &s2->vec[3],
231
- seed, 7, 8, 9, 10);
232
- mld_poly_uniform_eta_4x(&s2->vec[4], &s2->vec[5], &s2->vec[6], &s2->vec[7],
233
- seed, 11, 12, 13, 14);
286
+ mld_polyeta_pack(s1_packed + 4 * MLDSA_POLYETA_PACKEDBYTES, &s1->vec[4]);
287
+ mld_polyeta_pack(s1_packed + 5 * MLDSA_POLYETA_PACKEDBYTES, &s1->vec[5]);
288
+ mld_polyeta_pack(s1_packed + 6 * MLDSA_POLYETA_PACKEDBYTES, &s1->vec[6]);
289
+ mld_poly_uniform_eta_4x(&s1->vec[0], &s1->vec[1], &s1->vec[2], &s1->vec[3],
290
+ seed, 0, 1, 2, 3);
291
+ mld_polyeta_pack(s1_packed + 0 * MLDSA_POLYETA_PACKEDBYTES, &s1->vec[0]);
292
+ mld_polyeta_pack(s1_packed + 1 * MLDSA_POLYETA_PACKEDBYTES, &s1->vec[1]);
293
+ mld_polyeta_pack(s1_packed + 2 * MLDSA_POLYETA_PACKEDBYTES, &s1->vec[2]);
294
+ mld_polyeta_pack(s1_packed + 3 * MLDSA_POLYETA_PACKEDBYTES, &s1->vec[3]);
234
295
  #endif /* MLD_CONFIG_PARAMETER_SET == 87 */
235
296
  #endif /* !MLD_CONFIG_SERIAL_FIPS202_ONLY */
236
297
  }
@@ -240,16 +301,24 @@ __contract__(
240
301
  * t1[k] via power2round, and bit-pack t1[k] into pk_t1 and t0[k] into the
241
302
  * t0_packed buffer. Used by both keygen and pk_from_sk.
242
303
  *
243
- * @spec{Partially implements @[FIPS204, Algorithm 22, pkEncode] (t1) and
304
+ * @spec{Implements @[FIPS204, Algorithm 6, ML-DSA.KeyGen_internal, L5-L6]
305
+ * using @[FIPS204, Algorithm 35, Power2Round], and partially implements
306
+ * @[FIPS204, Algorithm 22, pkEncode] (t1) and
244
307
  * @[FIPS204, Algorithm 24, skEncode] (t0).}
245
308
  *
309
+ * s2 is provided in component-wise bit-packed form as per
310
+ * @[FIPS204, Algorithm 17, BitPack] and
311
+ * @[FIPS204, Algorithm 24, skEncode, L2-L7].
312
+ *
246
313
  * @param[out] pk_t1 Output buffer for packed t1 (size
247
314
  * MLDSA_K * MLDSA_POLYT1_PACKEDBYTES; i.e. the t1
248
315
  * region of pk).
249
316
  * @param[out] t0_packed Output buffer for packed t0 (size
250
317
  * MLDSA_K * MLDSA_POLYT0_PACKEDBYTES).
251
318
  * @param[in] s1hat s1 in NTT domain.
252
- * @param[in] s2 s2.
319
+ * @param[in] s2_packed Bit-packed s2 (size
320
+ * MLDSA_K * MLDSA_POLYETA_PACKEDBYTES; i.e. the s2
321
+ * region of sk).
253
322
  * @param[in] rho Byte array containing seed rho.
254
323
  * @param context Application context. Only present when
255
324
  * MLD_CONFIG_CONTEXT_PARAMETER is defined; type set by
@@ -263,20 +332,18 @@ MLD_MUST_CHECK_RETURN_VALUE
263
332
  static int mld_compute_pack_t0_t1(
264
333
  uint8_t pk_t1[MLDSA_K * MLDSA_POLYT1_PACKEDBYTES],
265
334
  uint8_t t0_packed[MLDSA_K * MLDSA_POLYT0_PACKEDBYTES],
266
- const mld_polyvecl *s1hat, const mld_polyveck *s2,
335
+ const mld_polyvecl *s1hat,
336
+ const uint8_t s2_packed[MLDSA_K * MLDSA_POLYETA_PACKEDBYTES],
267
337
  const uint8_t rho[MLDSA_SEEDBYTES],
268
338
  MLD_CONFIG_CONTEXT_PARAMETER_TYPE context)
269
339
  __contract__(
270
340
  requires(memory_no_alias(pk_t1, MLDSA_K * MLDSA_POLYT1_PACKEDBYTES))
271
341
  requires(memory_no_alias(t0_packed, MLDSA_K * MLDSA_POLYT0_PACKEDBYTES))
272
342
  requires(memory_no_alias(s1hat, sizeof(mld_polyvecl)))
273
- requires(memory_no_alias(s2, sizeof(mld_polyveck)))
343
+ requires(memory_no_alias(s2_packed, MLDSA_K * MLDSA_POLYETA_PACKEDBYTES))
274
344
  requires(memory_no_alias(rho, MLDSA_SEEDBYTES))
275
345
  requires(forall(l1, 0, MLDSA_L,
276
346
  array_abs_bound(s1hat->vec[l1].coeffs, 0, MLDSA_N, MLD_NTT_BOUND)))
277
- requires(forall(k2, 0, MLDSA_K,
278
- array_bound(s2->vec[k2].coeffs, 0, MLDSA_N,
279
- MLD_POLYETA_UNPACK_LOWER_BOUND, MLDSA_ETA + 1)))
280
347
  assigns(memory_slice(pk_t1, MLDSA_K * MLDSA_POLYT1_PACKEDBYTES))
281
348
  assigns(memory_slice(t0_packed, MLDSA_K * MLDSA_POLYT0_PACKEDBYTES))
282
349
  ensures(return_value == 0 || return_value == MLD_ERR_OUT_OF_MEMORY))
@@ -313,8 +380,9 @@ __contract__(
313
380
  /* t0k = invNTT(t0k) */
314
381
  mld_poly_invntt_tomont(t0k);
315
382
 
316
- /* t0k += s2[k] */
317
- mld_poly_add(t0k, &s2->vec[k]);
383
+ /* t0k += s2[k], unpacked on demand into the (still unused) t1k. */
384
+ mld_polyeta_unpack(t1k, s2_packed + k * MLDSA_POLYETA_PACKEDBYTES);
385
+ mld_poly_add(t0k, t1k);
318
386
 
319
387
  /* Reference: The following reduction is not present in the reference
320
388
  * implementation. Omitting this reduction requires the output
@@ -360,10 +428,8 @@ int mld_sign_keypair_internal(uint8_t pk[MLDSA_CRYPTO_PUBLICKEYBYTES],
360
428
  MLD_ALLOC(inbuf, uint8_t, MLDSA_SEEDBYTES + 2, context);
361
429
  MLD_ALLOC(tr, uint8_t, MLDSA_TRBYTES, context);
362
430
  MLD_ALLOC(s1, mld_polyvecl, 1, context);
363
- MLD_ALLOC(s2, mld_polyveck, 1, context);
364
431
 
365
- if (seedbuf == NULL || inbuf == NULL || tr == NULL || s1 == NULL ||
366
- s2 == NULL)
432
+ if (seedbuf == NULL || inbuf == NULL || tr == NULL || s1 == NULL)
367
433
  {
368
434
  ret = MLD_ERR_OUT_OF_MEMORY;
369
435
  goto cleanup;
@@ -382,11 +448,9 @@ int mld_sign_keypair_internal(uint8_t pk[MLDSA_CRYPTO_PUBLICKEYBYTES],
382
448
  /* Constant time: rho is part of the public key and, hence, public. */
383
449
  MLD_CT_TESTING_DECLASSIFY(rho, MLDSA_SEEDBYTES);
384
450
 
385
- /* Sample s1 and s2 */
386
- mld_sample_s1_s2(s1, s2, rhoprime);
387
-
388
- /* Pack s1 into sk before NTT */
389
- mld_pack_sk_s1(sk, s1);
451
+ /* Sample s1 and s2 into their packed regions of sk, keeping s1 unpacked. */
452
+ mld_sample_pack_s1_s2(sk + MLDSA_SK_S1_OFFSET, sk + MLDSA_SK_S2_OFFSET, s1,
453
+ rhoprime);
390
454
 
391
455
  /* NTT s1 in place to use as s1hat */
392
456
  mld_polyvecl_ntt(s1);
@@ -395,9 +459,9 @@ int mld_sign_keypair_internal(uint8_t pk[MLDSA_CRYPTO_PUBLICKEYBYTES],
395
459
  mld_memcpy(pk + MLDSA_PK_RHO_OFFSET, rho, MLDSA_SEEDBYTES);
396
460
 
397
461
  /* Compute t = A*s1hat + s2 row by row, decompose into t1/t0, and pack
398
- * t1 into pk and t0 directly into the t0 region of sk. */
462
+ * t1 into pk and t0 into the t0 region of sk; s2 is read back from sk. */
399
463
  ret = mld_compute_pack_t0_t1(pk + MLDSA_PK_T1_OFFSET, sk + MLDSA_SK_T0_OFFSET,
400
- s1, s2, rho, context);
464
+ s1, sk + MLDSA_SK_S2_OFFSET, rho, context);
401
465
  if (ret != 0)
402
466
  {
403
467
  goto cleanup;
@@ -406,15 +470,14 @@ int mld_sign_keypair_internal(uint8_t pk[MLDSA_CRYPTO_PUBLICKEYBYTES],
406
470
  /* Compute tr = H(pk) */
407
471
  mld_shake256(tr, MLDSA_TRBYTES, pk, MLDSA_CRYPTO_PUBLICKEYBYTES);
408
472
 
409
- /* Pack remaining secret key components (s1 and t0 already packed) */
410
- mld_pack_sk_rho_key_tr_s2(sk, rho, tr, key, s2);
473
+ /* Pack remaining secret key components (s1, s2 and t0 already packed) */
474
+ mld_pack_sk_rho_key_tr(sk, rho, tr, key);
411
475
 
412
476
  /* Constant time: pk is the public key, inherently public data */
413
477
  MLD_CT_TESTING_DECLASSIFY(pk, MLDSA_CRYPTO_PUBLICKEYBYTES);
414
478
 
415
479
  cleanup:
416
480
  /* @[FIPS204, Section 3.6.3] Destruction of intermediate values. */
417
- MLD_FREE(s2, mld_polyveck, 1, context);
418
481
  MLD_FREE(s1, mld_polyvecl, 1, context);
419
482
  MLD_FREE(tr, uint8_t, MLDSA_TRBYTES, context);
420
483
  MLD_FREE(inbuf, uint8_t, MLDSA_SEEDBYTES + 2, context);
@@ -731,28 +794,28 @@ __contract__(
731
794
 
732
795
  typedef union
733
796
  {
734
- mld_polyveck w1;
735
- mld_polyvecl tmp;
736
- } w1tmp_u;
737
- mld_polyveck *w1;
738
- mld_polyvecl *tmp;
797
+ mld_yvec_scratch y;
798
+ mld_poly w;
799
+ } scratch_u;
800
+ mld_yvec_scratch *scratch_yvec;
801
+ mld_poly *scratch_w;
739
802
 
740
803
  MLD_ALLOC(challenge_bytes, uint8_t, MLDSA_CTILDEBYTES, context);
741
804
  MLD_ALLOC(y, mld_yvec, 1, context);
742
- MLD_ALLOC(z, mld_poly, 1, context);
743
- MLD_ALLOC(w1tmp, w1tmp_u, 1, context);
805
+ MLD_ALLOC(scratch, scratch_u, 1, context);
806
+ MLD_ALLOC(w1_packed, uint8_t, (MLDSA_K * MLDSA_POLYW1_PACKEDBYTES), context);
744
807
  MLD_ALLOC(w0, mld_polyveck, 1, context);
745
808
  MLD_ALLOC(cp, mld_poly, 1, context);
746
809
  MLD_ALLOC(t, mld_poly, 1, context);
747
810
 
748
- if (challenge_bytes == NULL || y == NULL || z == NULL || w1tmp == NULL ||
749
- w0 == NULL || cp == NULL || t == NULL)
811
+ if (challenge_bytes == NULL || y == NULL || scratch == NULL ||
812
+ w1_packed == NULL || w0 == NULL || cp == NULL || t == NULL)
750
813
  {
751
814
  ret = MLD_ERR_OUT_OF_MEMORY;
752
815
  goto cleanup;
753
816
  }
754
- w1 = &w1tmp->w1;
755
- tmp = &w1tmp->tmp;
817
+ scratch_yvec = &scratch->y;
818
+ scratch_w = &scratch->w;
756
819
 
757
820
  /* @[FIPS204, Algorithm 7, line 11] y <- ExpandMask(rhoprime, kappa). */
758
821
  mld_yvec_init(y, rhoprime, kappa);
@@ -761,20 +824,19 @@ __contract__(
761
824
  * performs the whole line: it NTTs y, accumulates the pointwise product with
762
825
  * A_hat, and applies the inverse NTT. In REDUCE_RAM mode the y sampling is
763
826
  * fused into the same pass. */
764
- mld_polyvec_matrix_pointwise_montgomery_yvec(w0, mat, y, tmp);
827
+ mld_polyvec_matrix_pointwise_montgomery_yvec(w0, mat, y, scratch_yvec);
765
828
 
766
829
  /* @[FIPS204, Algorithm 7, line 13] w1 <- HighBits(w), here together with the
767
- * low part: Decompose yields w = 2*GAMMA2*w1 + w0, keeping both w1 and w0
768
- * (w0 is reused below in the line-21/26 alternative, see further down). */
830
+ * low part: Decompose yields w = 2*GAMMA2*w1 + w0. w0 is kept in full for
831
+ * the line-21/26 alternative below; w1 is kept only in its w1Encode form,
832
+ * from which the hint computation decodes single rows on demand. Keeping w1
833
+ * packed for the whole signing attempt is also done in @[DilithiumMemory]. */
769
834
  mld_polyveck_caddq(w0);
770
- mld_polyveck_decompose(w1, w0);
835
+ mld_polyveck_decompose_pack_w1(w1_packed, w0, scratch_w);
771
836
 
772
- /* @[FIPS204, Algorithm 7, line 15] ctilde <- H(mu || w1Encode(w1), lambda/4).
773
- * w1Encode(w1) is packed into the w1 region of sig (mld_polyveck_pack_w1),
774
- * then absorbed by H together with mu. */
775
- mld_polyveck_pack_w1(sig, w1);
776
-
777
- mld_H(challenge_bytes, MLDSA_CTILDEBYTES, mu, MLDSA_CRHBYTES, sig,
837
+ /* @[FIPS204, Algorithm 7, line 15] ctilde <- H(mu || w1Encode(w1),
838
+ * lambda/4). */
839
+ mld_H(challenge_bytes, MLDSA_CTILDEBYTES, mu, MLDSA_CRHBYTES, w1_packed,
778
840
  MLDSA_K * MLDSA_POLYW1_PACKEDBYTES, NULL, 0);
779
841
  /* Constant time: Leaking challenge_bytes does not reveal any information
780
842
  * about the secret key as H() is modelled as random oracle.
@@ -789,8 +851,14 @@ __contract__(
789
851
  /* @[FIPS204, Algorithm 7, lines 18+20] cs1 <- invNTT(c_hat o s1_hat) and
790
852
  * z <- y + cs1, followed by the line-23 norm check ||z||_inf >= GAMMA1 -
791
853
  * BETA. mld_compute_pack_z fuses all three per polynomial and, on success,
792
- * packs z into sig; it returns MLD_ERR_FAIL if the norm check rejects z. */
793
- ret = mld_compute_pack_z(sig, cp, s1hat, y, t, z);
854
+ * packs z into sig; it returns MLD_ERR_FAIL if the norm check rejects z.
855
+ *
856
+ * Order: z is checked before the remaining checks. Once z is accepted,
857
+ * w - cs2 = Az - ct is a function of public data, so the results of the
858
+ * remaining checks can be revealed @[KLS17, Lemma 4.3]
859
+ * @[Round3_Spec, Appendix B]. That argument does not cover revealing them
860
+ * for attempts whose z is rejected. */
861
+ ret = mld_compute_pack_z(sig, cp, s1hat, y, t, scratch_w);
794
862
  if (ret != 0)
795
863
  {
796
864
  goto cleanup;
@@ -803,9 +871,9 @@ __contract__(
803
871
  * computation of h may instead be implemented "as described in Section 5.1 of
804
872
  * [6]", and that reference is @[Round3_Spec, Section 5.1].
805
873
  *
806
- * The loop below builds w0 - cs2 + ct0 in place in w0; w1 is unmodified, and
807
- * is HighBits(w) from line 13. Those are the inputs to the streamlined
808
- * computation of MakeHint explained below.
874
+ * The loop below builds w0 - cs2 + ct0 in place in w0; w1_packed is
875
+ * unmodified, and holds w1Encode(HighBits(w)) from line 13. Those are the
876
+ * inputs to the streamlined computation of MakeHint explained below.
809
877
  *
810
878
  * Low-bits norm check:
811
879
  * @[FIPS204, Algorithm 7, line 21] computes r0 = LowBits(w - cs2) and line
@@ -825,16 +893,16 @@ __contract__(
825
893
  * (-GAMMA2, GAMMA2], or equals -GAMMA2 while the matching w1 coefficient is
826
894
  * zero (the Decompose border case), and is set otherwise. This equivalence
827
895
  * is precisely what mld_pack_sig_h -> mld_make_hint compute from w0
828
- * (= w0 - cs2 + ct0) and w1. The line-28 ||ct0||_inf >= GAMMA2 check is the
829
- * mld_poly_chknorm(z, GAMMA2) call on ct0 below; the weight bound is
830
- * enforced by mld_pack_sig_h.
896
+ * (= w0 - cs2 + ct0) and the w1 row decoded from w1_packed. The line-28
897
+ * ||ct0||_inf >= GAMMA2 check is the mld_poly_chknorm(scratch_w, GAMMA2)
898
+ * call on ct0 below; the weight bound is enforced by mld_pack_sig_h.
831
899
  *
832
900
  * Building w0 per-component and checking norms incrementally also avoids
833
901
  * allocating a full polyveck for h. */
834
902
  for (k = 0; k < MLDSA_K; k++)
835
903
  __loop__(
836
904
  assigns(k,
837
- object_whole(z),
905
+ object_whole(scratch_w),
838
906
  object_whole(w0))
839
907
  invariant(k <= MLDSA_K)
840
908
  invariant(forall(k0, k, MLDSA_K,
@@ -844,17 +912,18 @@ __contract__(
844
912
  {
845
913
  /* @[FIPS204, Algorithm 7, line 19] cs2[k] <- invNTT(c_hat o s2_hat)[k],
846
914
  * then subtract from w0[k] to form (w0 - cs2)[k]. */
847
- mld_sk_s2hat_get_poly(z, s2hat, k);
848
- mld_poly_pointwise_montgomery(z, cp);
849
- mld_poly_invntt_tomont(z);
915
+ mld_sk_s2hat_get_poly(scratch_w, s2hat, k);
916
+ mld_poly_pointwise_montgomery(scratch_w, cp);
917
+ mld_poly_invntt_tomont(scratch_w);
850
918
 
851
- mld_poly_sub(&w0->vec[k], z);
919
+ mld_poly_sub(&w0->vec[k], scratch_w);
852
920
  mld_poly_reduce(&w0->vec[k]);
853
921
 
854
922
  /* Low-bits norm check (see block comment above): the line-23 check on
855
923
  * r0 = LowBits(w - cs2) holds via ||w0 - cs2||_inf < GAMMA2 - BETA. */
856
924
  w0_invalid = mld_poly_chknorm(&w0->vec[k], MLDSA_GAMMA2 - MLDSA_BETA);
857
- /* Constant time: w0_invalid may be leaked - see comment for z_invalid. */
925
+ /* Constant time: w0_invalid may be leaked, as z has been accepted (see
926
+ * the ordering comment above). */
858
927
  MLD_CT_TESTING_DECLASSIFY(&w0_invalid, sizeof(uint32_t));
859
928
  if (w0_invalid)
860
929
  {
@@ -863,15 +932,16 @@ __contract__(
863
932
  }
864
933
 
865
934
  /* @[FIPS204, Algorithm 7, line 25] ct0[k] <- invNTT(c_hat o t0_hat)[k]. */
866
- mld_sk_t0hat_get_poly(z, t0hat, k);
867
- mld_poly_pointwise_montgomery(z, cp);
868
- mld_poly_invntt_tomont(z);
869
- mld_poly_reduce(z);
935
+ mld_sk_t0hat_get_poly(scratch_w, t0hat, k);
936
+ mld_poly_pointwise_montgomery(scratch_w, cp);
937
+ mld_poly_invntt_tomont(scratch_w);
938
+ mld_poly_reduce(scratch_w);
870
939
 
871
940
  /* @[FIPS204, Algorithm 7, line 28] reject when ||ct0||_inf >= GAMMA2 (the
872
941
  * second part, the OMEGA weight bound, is enforced by mld_pack_sig_h). */
873
- h_invalid = mld_poly_chknorm(z, MLDSA_GAMMA2);
874
- /* Constant time: h_invalid may be leaked - see comment for z_invalid. */
942
+ h_invalid = mld_poly_chknorm(scratch_w, MLDSA_GAMMA2);
943
+ /* Constant time: h_invalid may be leaked, as z has been accepted (see
944
+ * the ordering comment above). */
875
945
  MLD_CT_TESTING_DECLASSIFY(&h_invalid, sizeof(uint32_t));
876
946
  if (h_invalid)
877
947
  {
@@ -881,7 +951,7 @@ __contract__(
881
951
 
882
952
  /* Add ct0[k] to (w0 - cs2)[k], leaving (w0 - cs2 + ct0)[k] in w0[k] -- the
883
953
  * MakeHint input prepared for mld_pack_sig_h (see block comment above). */
884
- mld_poly_add(&w0->vec[k], z);
954
+ mld_poly_add(&w0->vec[k], scratch_w);
885
955
  }
886
956
 
887
957
  /* Constant time: At this point all norm checks have passed and we, hence,
@@ -895,7 +965,7 @@ __contract__(
895
965
  * (see @[FIPS204, Section 6.1]).
896
966
  */
897
967
  MLD_CT_TESTING_DECLASSIFY(w0, sizeof(*w0));
898
- MLD_CT_TESTING_DECLASSIFY(w1, sizeof(*w1));
968
+ MLD_CT_TESTING_DECLASSIFY(w1_packed, MLDSA_K * MLDSA_POLYW1_PACKEDBYTES);
899
969
 
900
970
  /* @[FIPS204, Algorithm 7, line 33] sigEncode(ctilde, z mod+/- q, h) is split
901
971
  * across three calls: z was already packed by mld_compute_pack_z, this call
@@ -904,10 +974,11 @@ __contract__(
904
974
 
905
975
  /* @[FIPS204, Algorithm 7, line 26] h <- MakeHint(-ct0, w - cs2 + ct0),
906
976
  * computed from (w0 = w0 - cs2 + ct0, w1) as described in the block comment
907
- * above, and packed as the h component of the line-33 sigEncode. Returns
908
- * MLD_ERR_FAIL if h would exceed OMEGA nonzero coefficients (the remaining
909
- * part of the line-28 check), in which case we reject. */
910
- ret = mld_pack_sig_h(sig, w0, w1);
977
+ * above, and packed as the h component of the line-33 sigEncode. w1 is
978
+ * recovered from its encoding one polynomial at a time into scratch_w.
979
+ * Returns MLD_ERR_FAIL if h would exceed OMEGA nonzero coefficients (the
980
+ * remaining part of the line-28 check), in which case we reject. */
981
+ ret = mld_pack_sig_h(sig, w0, w1_packed, scratch_w);
911
982
  if (ret != 0)
912
983
  {
913
984
  goto cleanup;
@@ -923,8 +994,8 @@ cleanup:
923
994
  MLD_FREE(t, mld_poly, 1, context);
924
995
  MLD_FREE(cp, mld_poly, 1, context);
925
996
  MLD_FREE(w0, mld_polyveck, 1, context);
926
- MLD_FREE(w1tmp, w1tmp_u, 1, context);
927
- MLD_FREE(z, mld_poly, 1, context);
997
+ MLD_FREE(w1_packed, uint8_t, (MLDSA_K * MLDSA_POLYW1_PACKEDBYTES), context);
998
+ MLD_FREE(scratch, scratch_u, 1, context);
928
999
  MLD_FREE(y, mld_yvec, 1, context);
929
1000
  MLD_FREE(challenge_bytes, uint8_t, MLDSA_CTILDEBYTES, context);
930
1001
 
@@ -1257,7 +1328,7 @@ int mld_sign_verify_internal(const uint8_t sig[MLDSA_CRYPTO_BYTES],
1257
1328
  mld_poly_challenge(cp, c);
1258
1329
  mld_poly_ntt(cp);
1259
1330
 
1260
- for (i = 0; i < MLDSA_K; ++i)
1331
+ for (i = 0; i < MLDSA_K; i++)
1261
1332
  __loop__(
1262
1333
  assigns(MLD_IF_REDUCE_RAM(memory_slice(mat, sizeof(mld_polymat)),)
1263
1334
  i, ret,
@@ -1590,7 +1661,7 @@ size_t mld_prepare_domain_separation_prefix(
1590
1661
 
1591
1662
  if (hashalg != MLD_PREHASH_NONE)
1592
1663
  {
1593
- if (ph == NULL || mld_validate_hash_length(hashalg, phlen) != 0)
1664
+ if (mld_validate_hash_length(hashalg, phlen) != 0)
1594
1665
  {
1595
1666
  return 0;
1596
1667
  }
@@ -1629,28 +1700,29 @@ int mld_sign_pk_from_sk(uint8_t pk[MLDSA_CRYPTO_PUBLICKEYBYTES],
1629
1700
  MLD_ALLOC(tr_computed, uint8_t, MLDSA_TRBYTES, context);
1630
1701
  MLD_ALLOC(key, uint8_t, MLDSA_SEEDBYTES, context);
1631
1702
  MLD_ALLOC(s1, mld_polyvecl, 1, context);
1632
- MLD_ALLOC(s2, mld_polyveck, 1, context);
1703
+ MLD_ALLOC(s2k, mld_poly, 1, context);
1633
1704
  MLD_ALLOC(t0_packed, uint8_t, MLDSA_K *MLDSA_POLYT0_PACKEDBYTES, context);
1634
1705
 
1635
1706
  if (rho == NULL || tr == NULL || tr_computed == NULL || key == NULL ||
1636
- s1 == NULL || s2 == NULL || t0_packed == NULL)
1707
+ s1 == NULL || s2k == NULL || t0_packed == NULL)
1637
1708
  {
1638
1709
  ret = MLD_ERR_OUT_OF_MEMORY;
1639
1710
  goto cleanup;
1640
1711
  }
1641
1712
 
1642
1713
  /* Inline unpack_sk: mld_unpack_sk uses lazy types for s1/s2/t0 which
1643
- * we cannot use here. t0 stays in packed form -- we compare it against
1644
- * the recomputed value below. */
1714
+ * we cannot use here. t0 and s2 stay packed; t0 is compared against the
1715
+ * recomputed value below. */
1645
1716
  mld_memcpy(rho, sk + MLDSA_SK_RHO_OFFSET, MLDSA_SEEDBYTES);
1646
1717
  mld_memcpy(key, sk + MLDSA_SK_KEY_OFFSET, MLDSA_SEEDBYTES);
1647
1718
  mld_memcpy(tr, sk + MLDSA_SK_TR_OFFSET, MLDSA_TRBYTES);
1648
1719
  mld_polyvecl_unpack_eta(s1, sk + MLDSA_SK_S1_OFFSET);
1649
- mld_polyveck_unpack_eta(s2, sk + MLDSA_SK_S2_OFFSET);
1650
1720
 
1651
1721
  /* Validate s1 and s2 coefficients are within [-MLDSA_ETA, MLDSA_ETA] */
1652
1722
  chk1 = mld_polyvecl_chknorm(s1, MLDSA_ETA + 1) & 0xFF;
1653
- chk2 = mld_polyveck_chknorm(s2, MLDSA_ETA + 1) & 0xFF;
1723
+ chk2 = mld_polyveck_unpack_eta_chknorm(sk + MLDSA_SK_S2_OFFSET, MLDSA_ETA + 1,
1724
+ s2k) &
1725
+ 0xFF;
1654
1726
 
1655
1727
  /* NTT s1 in place to use as s1hat */
1656
1728
  mld_polyvecl_ntt(s1);
@@ -1660,8 +1732,8 @@ int mld_sign_pk_from_sk(uint8_t pk[MLDSA_CRYPTO_PUBLICKEYBYTES],
1660
1732
 
1661
1733
  /* Recompute t row by row, decompose, and pack t1 into pk and t0 into
1662
1734
  * t0_packed. */
1663
- ret = mld_compute_pack_t0_t1(pk + MLDSA_PK_T1_OFFSET, t0_packed, s1, s2, rho,
1664
- context);
1735
+ ret = mld_compute_pack_t0_t1(pk + MLDSA_PK_T1_OFFSET, t0_packed, s1,
1736
+ sk + MLDSA_SK_S2_OFFSET, rho, context);
1665
1737
  if (ret != 0)
1666
1738
  {
1667
1739
  goto cleanup;
@@ -1693,7 +1765,7 @@ cleanup:
1693
1765
 
1694
1766
  /* @[FIPS204, Section 3.6.3] Destruction of intermediate values. */
1695
1767
  MLD_FREE(t0_packed, uint8_t, MLDSA_K *MLDSA_POLYT0_PACKEDBYTES, context);
1696
- MLD_FREE(s2, mld_polyveck, 1, context);
1768
+ MLD_FREE(s2k, mld_poly, 1, context);
1697
1769
  MLD_FREE(s1, mld_polyvecl, 1, context);
1698
1770
  MLD_FREE(key, uint8_t, MLDSA_SEEDBYTES, context);
1699
1771
  MLD_FREE(tr_computed, uint8_t, MLDSA_TRBYTES, context);
@@ -1708,7 +1780,7 @@ cleanup:
1708
1780
  /* To facilitate single-compilation-unit (SCU) builds, undefine all macros.
1709
1781
  * Don't modify by hand -- this is auto-generated by scripts/autogen. */
1710
1782
  #undef mld_check_pct
1711
- #undef mld_sample_s1_s2
1783
+ #undef mld_sample_pack_s1_s2
1712
1784
  #undef mld_validate_hash_length
1713
1785
  #undef mld_get_hash_oid
1714
1786
  #undef mld_H
@@ -16,6 +16,7 @@
16
16
  #define MLD_SIGN_H
17
17
 
18
18
  #include <stddef.h>
19
+
19
20
  #include "cbmc.h"
20
21
  #include "common.h"
21
22
  #include "poly.h"
@@ -787,8 +788,8 @@ __contract__(
787
788
  * @return The total length of the formatted prefix, or 0 on error.
788
789
  * Errors are:
789
790
  * - The context string exceeded 255 bytes.
790
- * - For HashML-DSA: hashalg was unsupported, ph was NULL, or phlen
791
- * did not match the output length of hashalg.
791
+ * - For HashML-DSA: hashalg was unsupported, or phlen did not match
792
+ * the output length of hashalg.
792
793
  */
793
794
  MLD_MUST_CHECK_RETURN_VALUE
794
795
  MLD_EXTERNAL_API
@@ -796,13 +797,15 @@ size_t mld_prepare_domain_separation_prefix(
796
797
  uint8_t prefix[MLD_DOMAIN_SEPARATION_MAX_BYTES], const uint8_t *ph,
797
798
  size_t phlen, const uint8_t *ctx, size_t ctxlen, int hashalg)
798
799
  __contract__(
799
- requires(ctxlen <= 255)
800
+ requires(ctxlen <= MLD_MAX_BUFFER_SIZE)
800
801
  requires(phlen <= MLD_MAX_BUFFER_SIZE)
801
802
  requires(ctxlen == 0 || memory_no_alias(ctx, ctxlen))
802
803
  requires(hashalg == MLD_PREHASH_NONE || memory_no_alias(ph, phlen))
803
804
  requires(memory_no_alias(prefix, MLD_DOMAIN_SEPARATION_MAX_BYTES))
804
805
  assigns(memory_slice(prefix, MLD_DOMAIN_SEPARATION_MAX_BYTES))
805
806
  ensures(return_value <= MLD_DOMAIN_SEPARATION_MAX_BYTES)
807
+ ensures(ctxlen > 255 ==> return_value == 0)
808
+ ensures((hashalg == MLD_PREHASH_NONE && ctxlen <= 255) ==> return_value != 0)
806
809
  );
807
810
  #endif /* !MLD_CONFIG_NO_SIGN_API || !MLD_CONFIG_NO_VERIFY_API */
808
811