pq_crypto 0.6.0 → 0.6.2

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 (154) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +12 -0
  3. data/SECURITY.md +7 -0
  4. data/ext/pqcrypto/extconf.rb +2 -0
  5. data/ext/pqcrypto/pqcrypto_ruby_secure.c +139 -0
  6. data/ext/pqcrypto/pqcrypto_secure.c +532 -0
  7. data/ext/pqcrypto/pqcrypto_secure.h +20 -0
  8. data/ext/pqcrypto/pqcrypto_version.h +1 -1
  9. data/ext/pqcrypto/vendor/.vendored +4 -4
  10. data/ext/pqcrypto/vendor/mldsa-native/README.md +23 -10
  11. data/ext/pqcrypto/vendor/mldsa-native/mldsa/README.md +23 -0
  12. data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native.c +114 -58
  13. data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native.h +498 -461
  14. data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native_asm.S +145 -85
  15. data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native_config.h +456 -422
  16. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/cbmc.h +47 -25
  17. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/common.h +26 -14
  18. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/ct.h +56 -81
  19. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/debug.h +17 -24
  20. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/fips202.c +33 -40
  21. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/fips202.h +67 -87
  22. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/fips202x4.c +19 -14
  23. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/fips202x4.h +13 -5
  24. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/keccakf1600.c +84 -10
  25. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/keccakf1600.h +10 -5
  26. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/auto.h +6 -0
  27. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/fips202_native_aarch64.h +22 -15
  28. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_scalar_aarch64_asm.S +376 -0
  29. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_v84a_aarch64_asm.S +204 -0
  30. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x2_v84a_aarch64_asm.S +259 -0
  31. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_scalar_hybrid_aarch64_asm.S +1077 -0
  32. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_v84a_scalar_hybrid_aarch64_asm.S +987 -0
  33. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccakf1600_round_constants.c +16 -10
  34. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x1_scalar.h +2 -1
  35. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x1_v84a.h +1 -1
  36. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x2_v84a.h +4 -2
  37. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x4_v8a_scalar.h +2 -2
  38. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x4_v8a_v84a_scalar.h +1 -1
  39. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/api.h +60 -0
  40. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/mve.h +48 -0
  41. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/fips202_native_armv81m.h +18 -1
  42. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.S +658 -582
  43. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.c +5 -100
  44. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccakf1600_round_constants.c +26 -25
  45. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/state_extract_bytes_x4_mve.S +334 -0
  46. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/state_xor_bytes_x4_mve.S +355 -0
  47. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/auto.h +8 -3
  48. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/{xkcp.h → keccak_f1600_x4_avx2.h} +11 -8
  49. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/fips202_native_x86_64.h +44 -0
  50. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/keccak_f1600_x4_avx2_asm.S +454 -0
  51. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/keccakf1600_constants.c +52 -0
  52. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/meta.h +37 -28
  53. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/aarch64_zetas.c +213 -196
  54. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/arith_native_aarch64.h +248 -64
  55. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/intt_aarch64_asm.S +753 -0
  56. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l4_aarch64_asm.S +129 -0
  57. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l5_aarch64_asm.S +145 -0
  58. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l7_aarch64_asm.S +177 -0
  59. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/ntt_aarch64_asm.S +653 -0
  60. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/pointwise_montgomery_aarch64_asm.S +84 -0
  61. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_caddq_aarch64_asm.S +53 -0
  62. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_chknorm_aarch64_asm.S +55 -0
  63. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_decompose_32_aarch64_asm.S +86 -0
  64. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_decompose_88_aarch64_asm.S +86 -0
  65. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_use_hint_32_aarch64_asm.S +103 -0
  66. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_use_hint_88_aarch64_asm.S +111 -0
  67. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/polyz_unpack_17_aarch64_asm.S +75 -0
  68. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/polyz_unpack_19_aarch64_asm.S +72 -0
  69. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/polyz_unpack_table.c +23 -11
  70. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_aarch64_asm.S +189 -0
  71. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_eta2_aarch64_asm.S +137 -0
  72. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_eta4_aarch64_asm.S +130 -0
  73. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_eta_table.c +520 -516
  74. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_table.c +34 -33
  75. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/api.h +202 -242
  76. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/meta.h +25 -17
  77. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/arith_native_x86_64.h +112 -28
  78. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/consts.c +1 -1
  79. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/consts.h +1 -1
  80. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/intt_avx2_asm.S +2311 -0
  81. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/ntt_avx2_asm.S +2383 -0
  82. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/nttunpack_avx2_asm.S +238 -0
  83. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l4_avx2_asm.S +139 -0
  84. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l5_avx2_asm.S +155 -0
  85. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l7_avx2_asm.S +187 -0
  86. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_avx2_asm.S +130 -0
  87. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_caddq_avx2_asm.S +190 -0
  88. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_decompose_32_avx2.c +6 -4
  89. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_decompose_88_avx2.c +6 -4
  90. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_use_hint_32_avx2.c +9 -8
  91. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_use_hint_88_avx2.c +10 -9
  92. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/polyz_unpack_17_avx2.c +8 -5
  93. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/polyz_unpack_19_avx2.c +8 -5
  94. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/rej_uniform_eta2_avx2.c +6 -4
  95. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/rej_uniform_eta4_avx2.c +6 -4
  96. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/rej_uniform_table.c +130 -129
  97. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/packing.c +109 -180
  98. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/packing.h +169 -150
  99. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly.c +56 -40
  100. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly.h +149 -164
  101. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly_kl.c +52 -57
  102. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly_kl.h +132 -167
  103. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec.c +57 -424
  104. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec.h +167 -474
  105. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec_lazy.c +308 -0
  106. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec_lazy.h +653 -0
  107. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/reduce.h +22 -29
  108. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/rounding.h +37 -43
  109. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/sign.c +511 -367
  110. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/sign.h +456 -417
  111. data/lib/pq_crypto/hybrid_kem.rb +1 -1
  112. data/lib/pq_crypto/internal.rb +23 -0
  113. data/lib/pq_crypto/kem.rb +27 -34
  114. data/lib/pq_crypto/pkcs8/der.rb +68 -0
  115. data/lib/pq_crypto/pkcs8/private_key_choice.rb +186 -0
  116. data/lib/pq_crypto/pkcs8.rb +51 -468
  117. data/lib/pq_crypto/serialization.rb +19 -29
  118. data/lib/pq_crypto/signature.rb +28 -35
  119. data/lib/pq_crypto/version.rb +1 -1
  120. data/lib/pq_crypto.rb +10 -0
  121. data/script/vendor_libs.rb +3 -3
  122. metadata +44 -35
  123. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_scalar_asm.S +0 -376
  124. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_v84a_asm.S +0 -204
  125. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x2_v84a_asm.S +0 -259
  126. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_scalar_hybrid_asm.S +0 -1077
  127. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_v84a_scalar_hybrid_asm.S +0 -987
  128. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/KeccakP_1600_times4_SIMD256.c +0 -488
  129. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/KeccakP_1600_times4_SIMD256.h +0 -16
  130. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/intt.S +0 -753
  131. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l4.S +0 -129
  132. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l5.S +0 -145
  133. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l7.S +0 -177
  134. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/ntt.S +0 -653
  135. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/pointwise_montgomery.S +0 -79
  136. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_caddq_asm.S +0 -53
  137. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_chknorm_asm.S +0 -55
  138. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_decompose_32_asm.S +0 -85
  139. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_decompose_88_asm.S +0 -85
  140. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_use_hint_32_asm.S +0 -102
  141. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_use_hint_88_asm.S +0 -110
  142. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/polyz_unpack_17_asm.S +0 -72
  143. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/polyz_unpack_19_asm.S +0 -69
  144. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_asm.S +0 -189
  145. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_eta2_asm.S +0 -135
  146. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_eta4_asm.S +0 -128
  147. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/intt.S +0 -2311
  148. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/ntt.S +0 -2383
  149. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/nttunpack.S +0 -239
  150. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise.S +0 -131
  151. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l4.S +0 -139
  152. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l5.S +0 -155
  153. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l7.S +0 -187
  154. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_caddq_avx2.c +0 -61
@@ -15,240 +15,18 @@
15
15
  #include "polyvec.h"
16
16
 
17
17
  #include "debug.h"
18
+ #include "polyvec_lazy.h"
18
19
 
19
20
  /* This namespacing is not done at the top to avoid a naming conflict
20
21
  * with native backends, which are currently not yet namespaced. */
21
- #define mld_polymat_permute_bitrev_to_custom \
22
- MLD_ADD_PARAM_SET(mld_polymat_permute_bitrev_to_custom)
23
- #define mld_polyvecl_permute_bitrev_to_custom \
24
- MLD_ADD_PARAM_SET(mld_polyvecl_permute_bitrev_to_custom)
25
22
  #define mld_polyvecl_pointwise_acc_montgomery_c \
26
23
  MLD_ADD_PARAM_SET(mld_polyvecl_pointwise_acc_montgomery_c)
27
24
 
28
- #if !defined(MLD_CONFIG_REDUCE_RAM)
29
- /* Helper function to ensure that the polynomial entries in the output
30
- * of mld_polyvec_matrix_expand use the standard (bitreversed) ordering
31
- * of coefficients.
32
- * No-op unless a native backend with a custom ordering is used.
33
- */
34
-
35
- static void mld_polyvecl_permute_bitrev_to_custom(mld_polyvecl *v)
36
- __contract__(
37
- /* We don't specify that this should be a permutation, but only
38
- * that it does not change the bound established at the end of
39
- * mld_polyvec_matrix_expand.
40
- */
41
- requires(memory_no_alias(v, sizeof(mld_polyvecl)))
42
- requires(forall(x, 0, MLDSA_L,
43
- array_bound(v->vec[x].coeffs, 0, MLDSA_N, 0, MLDSA_Q)))
44
- assigns(memory_slice(v, sizeof(mld_polyvecl)))
45
- ensures(forall(x, 0, MLDSA_L,
46
- array_bound(v->vec[x].coeffs, 0, MLDSA_N, 0, MLDSA_Q))))
47
- {
48
- #if defined(MLD_USE_NATIVE_NTT_CUSTOM_ORDER)
49
- unsigned i;
50
- for (i = 0; i < MLDSA_L; i++)
51
- __loop__(
52
- assigns(i, memory_slice(v, sizeof(mld_polyvecl)))
53
- invariant(i <= MLDSA_L)
54
- invariant(forall(x, 0, MLDSA_L,
55
- array_bound(v->vec[x].coeffs, 0, MLDSA_N, 0, MLDSA_Q)))
56
- decreases(MLDSA_L - i))
57
- {
58
- mld_poly_permute_bitrev_to_custom(v->vec[i].coeffs);
59
- }
60
- #else /* MLD_USE_NATIVE_NTT_CUSTOM_ORDER */
61
- /* Nothing to do */
62
- (void)v;
63
- #endif /* !MLD_USE_NATIVE_NTT_CUSTOM_ORDER */
64
- }
65
-
66
- static void mld_polymat_permute_bitrev_to_custom(mld_polymat *mat)
67
- __contract__(
68
- /* We don't specify that this should be a permutation, but only
69
- * that it does not change the bound established at the end of
70
- * mld_polyvec_matrix_expand.
71
- */
72
- requires(memory_no_alias(mat, sizeof(mld_polymat)))
73
- requires(forall(k1, 0, MLDSA_K, forall(l1, 0, MLDSA_L,
74
- array_bound(mat->vec[k1].vec[l1].coeffs, 0, MLDSA_N, 0, MLDSA_Q))))
75
- assigns(memory_slice(mat, sizeof(mld_polymat)))
76
- ensures(forall(k1, 0, MLDSA_K, forall(l1, 0, MLDSA_L,
77
- array_bound(mat->vec[k1].vec[l1].coeffs, 0, MLDSA_N, 0, MLDSA_Q))))
78
- )
79
- {
80
- unsigned int i;
81
- for (i = 0; i < MLDSA_K; i++)
82
- __loop__(
83
- assigns(i, memory_slice(mat, sizeof(mld_polymat)))
84
- invariant(i <= MLDSA_K)
85
- invariant(forall(k1, 0, MLDSA_K, forall(l1, 0, MLDSA_L,
86
- array_bound(mat->vec[k1].vec[l1].coeffs, 0, MLDSA_N, 0, MLDSA_Q))))
87
- decreases(MLDSA_K - i))
88
- {
89
- mld_polyvecl_permute_bitrev_to_custom(&mat->vec[i]);
90
- }
91
- }
92
- #endif /* !MLD_CONFIG_REDUCE_RAM */
93
-
94
- MLD_INTERNAL_API
95
- const mld_polyvecl *mld_polymat_get_row(mld_polymat *mat, unsigned int row)
96
- {
97
- #if defined(MLD_CONFIG_REDUCE_RAM)
98
- unsigned int i;
99
- MLD_ALIGN uint8_t seed_ext[MLD_ALIGN_UP(MLDSA_SEEDBYTES + 2)];
100
-
101
- mld_memcpy(seed_ext, mat->rho, MLDSA_SEEDBYTES);
102
-
103
- /* Generate row on-demand */
104
- for (i = 0; i < MLDSA_L; i++)
105
- {
106
- uint8_t x = (uint8_t)row;
107
- uint8_t y = (uint8_t)i;
108
-
109
- seed_ext[MLDSA_SEEDBYTES + 0] = y;
110
- seed_ext[MLDSA_SEEDBYTES + 1] = x;
111
-
112
- mld_poly_uniform(&mat->row_buffer.vec[i], seed_ext);
113
-
114
- #if defined(MLD_USE_NATIVE_NTT_CUSTOM_ORDER)
115
- mld_poly_permute_bitrev_to_custom(mat->row_buffer.vec[i].coeffs);
116
- #endif
117
- }
118
-
119
- /* @[FIPS204, Section 3.6.3] Destruction of intermediate values. */
120
- mld_zeroize(seed_ext, sizeof(seed_ext));
121
-
122
- return &mat->row_buffer;
123
- #else /* MLD_CONFIG_REDUCE_RAM */
124
- return &mat->vec[row];
125
- #endif /* !MLD_CONFIG_REDUCE_RAM */
126
- }
127
-
128
- MLD_INTERNAL_API
129
- void mld_polyvec_matrix_expand(mld_polymat *mat,
130
- const uint8_t rho[MLDSA_SEEDBYTES])
131
- {
132
- #if defined(MLD_CONFIG_REDUCE_RAM)
133
- /* In REDUCE_RAM mode, just copy the seed for later on-demand generation */
134
- mld_memcpy(mat->rho, rho, MLDSA_SEEDBYTES);
135
- #else
136
- unsigned int i, j;
137
- /*
138
- * We generate four separate seed arrays rather than a single one to work
139
- * around limitations in CBMC function contracts dealing with disjoint slices
140
- * of the same parent object.
141
- */
142
-
143
- MLD_ALIGN uint8_t seed_ext[4][MLD_ALIGN_UP(MLDSA_SEEDBYTES + 2)];
144
-
145
- for (j = 0; j < 4; j++)
146
- __loop__(
147
- assigns(j, object_whole(seed_ext))
148
- invariant(j <= 4)
149
- decreases(4 - j)
150
- )
151
- {
152
- mld_memcpy(seed_ext[j], rho, MLDSA_SEEDBYTES);
153
- }
154
-
155
- #if !defined(MLD_CONFIG_SERIAL_FIPS202_ONLY)
156
- /* Sample 4 matrix entries a time. */
157
- for (i = 0; i < (MLDSA_K * MLDSA_L / 4) * 4; i += 4)
158
- __loop__(
159
- assigns(i, j, object_whole(seed_ext), memory_slice(mat, sizeof(mld_polymat)))
160
- invariant(i <= (MLDSA_K * MLDSA_L / 4) * 4 && i % 4 == 0)
161
- /* vectors 0 .. i / MLDSA_L are completely sampled */
162
- invariant(forall(k1, 0, i / MLDSA_L, forall(l1, 0, MLDSA_L,
163
- array_bound(mat->vec[k1].vec[l1].coeffs, 0, MLDSA_N, 0, MLDSA_Q))))
164
- /* last vector is sampled up to i % MLDSA_L */
165
- invariant(forall(k2, i / MLDSA_L, i / MLDSA_L + 1, forall(l2, 0, i % MLDSA_L,
166
- array_bound(mat->vec[k2].vec[l2].coeffs, 0, MLDSA_N, 0, MLDSA_Q))))
167
- decreases((MLDSA_K * MLDSA_L / 4) * 4 - i)
168
- )
169
- {
170
- for (j = 0; j < 4; j++)
171
- __loop__(
172
- assigns(j, object_whole(seed_ext))
173
- invariant(j <= 4)
174
- decreases(4 - j)
175
- )
176
- {
177
- uint8_t x = (uint8_t)((i + j) / MLDSA_L);
178
- uint8_t y = (uint8_t)((i + j) % MLDSA_L);
179
-
180
- seed_ext[j][MLDSA_SEEDBYTES + 0] = y;
181
- seed_ext[j][MLDSA_SEEDBYTES + 1] = x;
182
- }
183
-
184
- mld_poly_uniform_4x(&mat->vec[i / MLDSA_L].vec[i % MLDSA_L],
185
- &mat->vec[(i + 1) / MLDSA_L].vec[(i + 1) % MLDSA_L],
186
- &mat->vec[(i + 2) / MLDSA_L].vec[(i + 2) % MLDSA_L],
187
- &mat->vec[(i + 3) / MLDSA_L].vec[(i + 3) % MLDSA_L],
188
- seed_ext);
189
- }
190
- #else /* !MLD_CONFIG_SERIAL_FIPS202_ONLY */
191
- i = 0;
192
- #endif /* MLD_CONFIG_SERIAL_FIPS202_ONLY */
193
-
194
- /* Entries omitted by the batch-sampling are sampled individually. */
195
- while (i < MLDSA_K * MLDSA_L)
196
- __loop__(
197
- assigns(i, object_whole(seed_ext), memory_slice(mat, sizeof(mld_polymat)))
198
- invariant(i <= MLDSA_K * MLDSA_L)
199
- /* vectors 0 .. i / MLDSA_L are completely sampled */
200
- invariant(forall(k1, 0, i / MLDSA_L, forall(l1, 0, MLDSA_L,
201
- array_bound(mat->vec[k1].vec[l1].coeffs, 0, MLDSA_N, 0, MLDSA_Q))))
202
- /* last vector is sampled up to i % MLDSA_L */
203
- invariant(forall(k2, i / MLDSA_L, i / MLDSA_L + 1, forall(l2, 0, i % MLDSA_L,
204
- array_bound(mat->vec[k2].vec[l2].coeffs, 0, MLDSA_N, 0, MLDSA_Q))))
205
- decreases(MLDSA_K * MLDSA_L - i)
206
- )
207
- {
208
- uint8_t x = (uint8_t)(i / MLDSA_L);
209
- uint8_t y = (uint8_t)(i % MLDSA_L);
210
- mld_poly *this_poly = &mat->vec[i / MLDSA_L].vec[i % MLDSA_L];
211
-
212
- seed_ext[0][MLDSA_SEEDBYTES + 0] = y;
213
- seed_ext[0][MLDSA_SEEDBYTES + 1] = x;
214
-
215
- mld_poly_uniform(this_poly, seed_ext[0]);
216
- i++;
217
- }
218
-
219
- mld_polymat_permute_bitrev_to_custom(mat);
220
-
221
- /* @[FIPS204, Section 3.6.3] Destruction of intermediate values. */
222
- mld_zeroize(seed_ext, sizeof(seed_ext));
223
- #endif /* !MLD_CONFIG_REDUCE_RAM */
224
- }
225
-
226
- MLD_INTERNAL_API
227
- void mld_polyvec_matrix_pointwise_montgomery(mld_polyveck *t, mld_polymat *mat,
228
- const mld_polyvecl *v)
229
- {
230
- unsigned int i;
231
- mld_assert_abs_bound_2d(v->vec, MLDSA_L, MLDSA_N, MLD_NTT_BOUND);
232
-
233
- for (i = 0; i < MLDSA_K; ++i)
234
- __loop__(
235
- assigns(i, memory_slice(t, sizeof(mld_polyveck)))
236
- invariant(i <= MLDSA_K)
237
- invariant(forall(k0, 0, i,
238
- array_abs_bound(t->vec[k0].coeffs, 0, MLDSA_N, MLDSA_Q)))
239
- decreases(MLDSA_K - i)
240
- )
241
- {
242
- const mld_polyvecl *row = mld_polymat_get_row(mat, i);
243
- mld_polyvecl_pointwise_acc_montgomery(&t->vec[i], row, v);
244
- }
245
-
246
- mld_assert_abs_bound_2d(t->vec, MLDSA_K, MLDSA_N, MLDSA_Q);
247
- }
248
-
249
25
  /**************************************************************/
250
26
  /************ Vectors of polynomials of length MLDSA_L **************/
251
27
  /**************************************************************/
28
+ #if !defined(MLD_CONFIG_NO_SIGN_API) && \
29
+ (!defined(MLD_CONFIG_REDUCE_RAM) || defined(MLD_UNIT_TEST))
252
30
  MLD_INTERNAL_API
253
31
  void mld_polyvecl_uniform_gamma1(mld_polyvecl *v,
254
32
  const uint8_t seed[MLDSA_CRHBYTES],
@@ -291,7 +69,13 @@ void mld_polyvecl_uniform_gamma1(mld_polyvecl *v,
291
69
  mld_assert_bound_2d(v->vec, MLDSA_L, MLDSA_N, -(MLDSA_GAMMA1 - 1),
292
70
  MLDSA_GAMMA1 + 1);
293
71
  }
72
+ #endif /* !MLD_CONFIG_NO_SIGN_API && (!MLD_CONFIG_REDUCE_RAM || MLD_UNIT_TEST) \
73
+ */
294
74
 
75
+ #if !defined(MLD_CONFIG_NO_KEYPAIR_API) || \
76
+ !defined(MLD_CONFIG_NO_VERIFY_API) || \
77
+ (!defined(MLD_CONFIG_NO_SIGN_API) && \
78
+ (!defined(MLD_CONFIG_REDUCE_RAM) || defined(MLD_UNIT_TEST)))
295
79
  MLD_INTERNAL_API
296
80
  void mld_polyvecl_ntt(mld_polyvecl *v)
297
81
  {
@@ -311,7 +95,11 @@ void mld_polyvecl_ntt(mld_polyvecl *v)
311
95
 
312
96
  mld_assert_abs_bound_2d(v->vec, MLDSA_L, MLDSA_N, MLD_NTT_BOUND);
313
97
  }
98
+ #endif /* !MLD_CONFIG_NO_KEYPAIR_API || !MLD_CONFIG_NO_VERIFY_API || \
99
+ (!MLD_CONFIG_NO_SIGN_API && (!MLD_CONFIG_REDUCE_RAM || \
100
+ MLD_UNIT_TEST)) */
314
101
 
102
+ #if !defined(MLD_CONFIG_REDUCE_RAM) || defined(MLD_UNIT_TEST)
315
103
  MLD_STATIC_TESTABLE void mld_polyvecl_pointwise_acc_montgomery_c(
316
104
  mld_poly *w, const mld_polyvecl *u, const mld_polyvecl *v)
317
105
  __contract__(
@@ -407,17 +195,20 @@ void mld_polyvecl_pointwise_acc_montgomery(mld_poly *w, const mld_polyvecl *u,
407
195
  MLD_CONFIG_PARAMETER_SET == 65) && \
408
196
  MLD_USE_NATIVE_POLYVECL_POINTWISE_ACC_MONTGOMERY_L7 && \
409
197
  MLD_CONFIG_PARAMETER_SET == 87 */
410
- /* The first input is bounded by [0, Q-1] inclusive
411
- * The second input is bounded by [-9Q+1, 9Q-1] inclusive . Hence, we can
412
- * safely accumulate in 64-bits without intermediate reductions as
413
- * MLDSA_L * (MLD_NTT_BOUND-1) * (Q-1) < INT64_MAX
198
+ /* The first input is bounded by [0, MLDSA_Q-1] inclusive.
199
+ * The second input is bounded by [-(9*MLDSA_Q-1), 9*MLDSA_Q-1] inclusive.
200
+ * Hence, we can safely accumulate in 64-bits without intermediate reductions
201
+ * as MLDSA_L * (MLD_NTT_BOUND-1) * (MLDSA_Q-1) < INT64_MAX.
414
202
  *
415
- * The worst case is ML-DSA-87: 7 * (9Q-1) * (Q-1) < 2**52
416
- * (and likewise for negative values)
203
+ * The worst case is ML-DSA-87: 7 * (9*MLDSA_Q-1) * (MLDSA_Q-1) < 2**52
204
+ * (and likewise for negative values).
417
205
  */
418
206
  mld_polyvecl_pointwise_acc_montgomery_c(w, u, v);
419
207
  }
208
+ #endif /* !MLD_CONFIG_REDUCE_RAM || MLD_UNIT_TEST */
420
209
 
210
+ #if !defined(MLD_CONFIG_NO_KEYPAIR_API) || !defined(MLD_CONFIG_NO_VERIFY_API) || \
211
+ defined(MLD_UNIT_TEST)
421
212
  MLD_INTERNAL_API
422
213
  uint32_t mld_polyvecl_chknorm(const mld_polyvecl *v, int32_t bound)
423
214
  {
@@ -442,10 +233,15 @@ uint32_t mld_polyvecl_chknorm(const mld_polyvecl *v, int32_t bound)
442
233
  }
443
234
  return t;
444
235
  }
236
+ #endif /* !MLD_CONFIG_NO_KEYPAIR_API || !MLD_CONFIG_NO_VERIFY_API || \
237
+ MLD_UNIT_TEST */
445
238
 
446
239
  /**************************************************************/
447
240
  /************ Vectors of polynomials of length MLDSA_K **************/
448
241
  /**************************************************************/
242
+ #if (!defined(MLD_CONFIG_NO_SIGN_API) && \
243
+ defined(MLD_CONFIG_REDUCE_RAM)) || \
244
+ defined(MLD_UNIT_TEST)
449
245
  MLD_INTERNAL_API
450
246
  void mld_polyveck_reduce(mld_polyveck *v)
451
247
  {
@@ -469,7 +265,10 @@ void mld_polyveck_reduce(mld_polyveck *v)
469
265
  mld_assert_bound_2d(v->vec, MLDSA_K, MLDSA_N, -MLD_REDUCE32_RANGE_MAX,
470
266
  MLD_REDUCE32_RANGE_MAX);
471
267
  }
268
+ #endif /* (!MLD_CONFIG_NO_SIGN_API && MLD_CONFIG_REDUCE_RAM) || MLD_UNIT_TEST \
269
+ */
472
270
 
271
+ #if !defined(MLD_CONFIG_NO_SIGN_API) || defined(MLD_UNIT_TEST)
473
272
  MLD_INTERNAL_API
474
273
  void mld_polyveck_caddq(mld_polyveck *v)
475
274
  {
@@ -489,76 +288,10 @@ void mld_polyveck_caddq(mld_polyveck *v)
489
288
 
490
289
  mld_assert_bound_2d(v->vec, MLDSA_K, MLDSA_N, 0, MLDSA_Q);
491
290
  }
291
+ #endif /* !MLD_CONFIG_NO_SIGN_API || MLD_UNIT_TEST */
492
292
 
493
- /* Reference: We use destructive version (output=first input) to avoid
494
- * reasoning about aliasing in the CBMC specification */
495
- MLD_INTERNAL_API
496
- void mld_polyveck_add(mld_polyveck *u, const mld_polyveck *v)
497
- {
498
- unsigned int i;
499
-
500
- for (i = 0; i < MLDSA_K; ++i)
501
- __loop__(
502
- assigns(i, memory_slice(u, sizeof(mld_polyveck)))
503
- invariant(i <= MLDSA_K)
504
- invariant(forall(k0, i, MLDSA_K,
505
- forall(k1, 0, MLDSA_N, u->vec[k0].coeffs[k1] == loop_entry(*u).vec[k0].coeffs[k1])))
506
- invariant(forall(k6, 0, i, array_bound(u->vec[k6].coeffs, 0, MLDSA_N, INT32_MIN, MLD_REDUCE32_DOMAIN_MAX)))
507
- decreases(MLDSA_K - i)
508
- )
509
- {
510
- mld_poly_add(&u->vec[i], &v->vec[i]);
511
- }
512
- mld_assert_bound_2d(u->vec, MLDSA_K, MLDSA_N, INT32_MIN,
513
- MLD_REDUCE32_DOMAIN_MAX);
514
- }
515
-
516
- MLD_INTERNAL_API
517
- void mld_polyveck_sub(mld_polyveck *u, const mld_polyveck *v)
518
- {
519
- unsigned int i;
520
- mld_assert_abs_bound_2d(u->vec, MLDSA_K, MLDSA_N, MLDSA_Q);
521
- mld_assert_abs_bound_2d(v->vec, MLDSA_K, MLDSA_N, MLDSA_Q);
522
-
523
- for (i = 0; i < MLDSA_K; ++i)
524
- __loop__(
525
- assigns(i, memory_slice(u, sizeof(mld_polyveck)))
526
- invariant(i <= MLDSA_K)
527
- invariant(forall(k0, 0, i,
528
- array_bound(u->vec[k0].coeffs, 0, MLDSA_N, INT32_MIN, MLD_REDUCE32_DOMAIN_MAX)))
529
- invariant(forall(k1, i, MLDSA_K,
530
- forall(n1, 0, MLDSA_N, u->vec[k1].coeffs[n1] == loop_entry(*u).vec[k1].coeffs[n1])))
531
- decreases(MLDSA_K - i))
532
- {
533
- mld_poly_sub(&u->vec[i], &v->vec[i]);
534
- }
535
-
536
- mld_assert_bound_2d(u->vec, MLDSA_K, MLDSA_N, INT32_MIN,
537
- MLD_REDUCE32_DOMAIN_MAX);
538
- }
539
-
540
- MLD_INTERNAL_API
541
- void mld_polyveck_shiftl(mld_polyveck *v)
542
- {
543
- unsigned int i;
544
- mld_assert_bound_2d(v->vec, MLDSA_K, MLDSA_N, 0, 1 << 10);
545
-
546
- for (i = 0; i < MLDSA_K; ++i)
547
- __loop__(
548
- assigns(i, memory_slice(v, sizeof(mld_polyveck)))
549
- invariant(i <= MLDSA_K)
550
- invariant(forall(k1, 0, i, array_bound(v->vec[k1].coeffs, 0, MLDSA_N, 0, MLDSA_Q)))
551
- invariant(forall(k1, i, MLDSA_K,
552
- forall(n1, 0, MLDSA_N, v->vec[k1].coeffs[n1] == loop_entry(*v).vec[k1].coeffs[n1])))
553
- decreases(MLDSA_K - i)
554
- )
555
- {
556
- mld_poly_shiftl(&v->vec[i]);
557
- }
558
-
559
- mld_assert_bound_2d(v->vec, MLDSA_K, MLDSA_N, 0, MLDSA_Q);
560
- }
561
-
293
+ #if (!defined(MLD_CONFIG_NO_SIGN_API) || defined(MLD_UNIT_TEST)) && \
294
+ (!defined(MLD_CONFIG_REDUCE_RAM) || defined(MLD_UNIT_TEST))
562
295
  MLD_INTERNAL_API
563
296
  void mld_polyveck_ntt(mld_polyveck *v)
564
297
  {
@@ -577,7 +310,10 @@ void mld_polyveck_ntt(mld_polyveck *v)
577
310
  }
578
311
  mld_assert_abs_bound_2d(v->vec, MLDSA_K, MLDSA_N, MLD_NTT_BOUND);
579
312
  }
313
+ #endif /* (!MLD_CONFIG_NO_SIGN_API || MLD_UNIT_TEST) && \
314
+ (!MLD_CONFIG_REDUCE_RAM || MLD_UNIT_TEST) */
580
315
 
316
+ #if !defined(MLD_CONFIG_NO_SIGN_API) || defined(MLD_UNIT_TEST)
581
317
  MLD_INTERNAL_API
582
318
  void mld_polyveck_invntt_tomont(mld_polyveck *v)
583
319
  {
@@ -597,27 +333,9 @@ void mld_polyveck_invntt_tomont(mld_polyveck *v)
597
333
 
598
334
  mld_assert_abs_bound_2d(v->vec, MLDSA_K, MLDSA_N, MLD_INTT_BOUND);
599
335
  }
336
+ #endif /* !MLD_CONFIG_NO_SIGN_API || MLD_UNIT_TEST */
600
337
 
601
- MLD_INTERNAL_API
602
- void mld_polyveck_pointwise_poly_montgomery(mld_polyveck *r, const mld_poly *a,
603
- const mld_polyveck *v)
604
- {
605
- unsigned int i;
606
- mld_assert_abs_bound_2d(v->vec, MLDSA_K, MLDSA_N, MLD_NTT_BOUND);
607
-
608
- for (i = 0; i < MLDSA_K; ++i)
609
- __loop__(
610
- assigns(i, memory_slice(r, sizeof(mld_polyveck)))
611
- invariant(i <= MLDSA_K)
612
- invariant(forall(k2, 0, i, array_abs_bound(r->vec[k2].coeffs, 0, MLDSA_N, MLDSA_Q)))
613
- decreases(MLDSA_K - i)
614
- )
615
- {
616
- mld_poly_pointwise_montgomery(&r->vec[i], a, &v->vec[i]);
617
- }
618
- mld_assert_abs_bound_2d(r->vec, MLDSA_K, MLDSA_N, MLDSA_Q);
619
- }
620
-
338
+ #if !defined(MLD_CONFIG_NO_KEYPAIR_API)
621
339
  MLD_INTERNAL_API
622
340
  uint32_t mld_polyveck_chknorm(const mld_polyveck *v, int32_t bound)
623
341
  {
@@ -644,31 +362,9 @@ uint32_t mld_polyveck_chknorm(const mld_polyveck *v, int32_t bound)
644
362
  return t;
645
363
  }
646
364
 
647
- MLD_INTERNAL_API
648
- void mld_polyveck_power2round(mld_polyveck *v1, mld_polyveck *v0,
649
- const mld_polyveck *v)
650
- {
651
- unsigned int i;
652
- mld_assert_bound_2d(v->vec, MLDSA_K, MLDSA_N, 0, MLDSA_Q);
653
-
654
- for (i = 0; i < MLDSA_K; ++i)
655
- __loop__(
656
- assigns(i, memory_slice(v0, sizeof(mld_polyveck)), memory_slice(v1, sizeof(mld_polyveck)))
657
- invariant(i <= MLDSA_K)
658
- invariant(forall(k1, 0, i, array_bound(v0->vec[k1].coeffs, 0, MLDSA_N, -(MLD_2_POW_D/2)+1, (MLD_2_POW_D/2)+1)))
659
- invariant(forall(k2, 0, i, array_bound(v1->vec[k2].coeffs, 0, MLDSA_N, 0, ((MLDSA_Q - 1) / MLD_2_POW_D) + 1)))
660
- decreases(MLDSA_K - i)
661
- )
662
- {
663
- mld_poly_power2round(&v1->vec[i], &v0->vec[i], &v->vec[i]);
664
- }
665
-
666
- mld_assert_bound_2d(v0->vec, MLDSA_K, MLDSA_N, -(MLD_2_POW_D / 2) + 1,
667
- (MLD_2_POW_D / 2) + 1);
668
- mld_assert_bound_2d(v1->vec, MLDSA_K, MLDSA_N, 0,
669
- ((MLDSA_Q - 1) / MLD_2_POW_D) + 1);
670
- }
365
+ #endif /* !MLD_CONFIG_NO_KEYPAIR_API */
671
366
 
367
+ #if !defined(MLD_CONFIG_NO_SIGN_API)
672
368
  MLD_INTERNAL_API
673
369
  void mld_polyveck_decompose(mld_polyveck *v1, mld_polyveck *v0)
674
370
  {
@@ -695,54 +391,9 @@ void mld_polyveck_decompose(mld_polyveck *v1, mld_polyveck *v0)
695
391
  (MLDSA_Q - 1) / (2 * MLDSA_GAMMA2));
696
392
  mld_assert_abs_bound_2d(v0->vec, MLDSA_K, MLDSA_N, MLDSA_GAMMA2 + 1);
697
393
  }
394
+ #endif /* !MLD_CONFIG_NO_SIGN_API */
698
395
 
699
- MLD_INTERNAL_API
700
- unsigned int mld_polyveck_make_hint(mld_polyveck *h, const mld_polyveck *v0,
701
- const mld_polyveck *v1)
702
- {
703
- unsigned int i, s = 0;
704
-
705
- for (i = 0; i < MLDSA_K; ++i)
706
- __loop__(
707
- assigns(i, s, memory_slice(h, sizeof(mld_polyveck)))
708
- invariant(i <= MLDSA_K)
709
- invariant(s <= i * MLDSA_N)
710
- invariant(forall(k1, 0, i, array_bound(h->vec[k1].coeffs, 0, MLDSA_N, 0, 2)))
711
- decreases(MLDSA_K - i)
712
- )
713
- {
714
- s += mld_poly_make_hint(&h->vec[i], &v0->vec[i], &v1->vec[i]);
715
- }
716
-
717
- mld_assert_bound_2d(h->vec, MLDSA_K, MLDSA_N, 0, 2);
718
- return s;
719
- }
720
-
721
- MLD_INTERNAL_API
722
- void mld_polyveck_use_hint(mld_polyveck *w, const mld_polyveck *u,
723
- const mld_polyveck *h)
724
- {
725
- unsigned int i;
726
- mld_assert_bound_2d(u->vec, MLDSA_K, MLDSA_N, 0, MLDSA_Q);
727
- mld_assert_bound_2d(h->vec, MLDSA_K, MLDSA_N, 0, 2);
728
-
729
- for (i = 0; i < MLDSA_K; ++i)
730
- __loop__(
731
- assigns(i, memory_slice(w, sizeof(mld_polyveck)))
732
- invariant(i <= MLDSA_K)
733
- invariant(forall(k2, 0, i,
734
- array_bound(w->vec[k2].coeffs, 0, MLDSA_N, 0,
735
- (MLDSA_Q - 1) / (2 * MLDSA_GAMMA2))))
736
- decreases(MLDSA_K - i)
737
- )
738
- {
739
- mld_poly_use_hint(&w->vec[i], &u->vec[i], &h->vec[i]);
740
- }
741
-
742
- mld_assert_bound_2d(w->vec, MLDSA_K, MLDSA_N, 0,
743
- (MLDSA_Q - 1) / (2 * MLDSA_GAMMA2));
744
- }
745
-
396
+ #if !defined(MLD_CONFIG_NO_SIGN_API)
746
397
  MLD_INTERNAL_API
747
398
  void mld_polyveck_pack_w1(uint8_t r[MLDSA_K * MLDSA_POLYW1_PACKEDBYTES],
748
399
  const mld_polyveck *w1)
@@ -761,7 +412,9 @@ void mld_polyveck_pack_w1(uint8_t r[MLDSA_K * MLDSA_POLYW1_PACKEDBYTES],
761
412
  mld_polyw1_pack(&r[i * MLDSA_POLYW1_PACKEDBYTES], &w1->vec[i]);
762
413
  }
763
414
  }
415
+ #endif /* !MLD_CONFIG_NO_SIGN_API */
764
416
 
417
+ #if !defined(MLD_CONFIG_NO_KEYPAIR_API)
765
418
  MLD_INTERNAL_API
766
419
  void mld_polyveck_pack_eta(uint8_t r[MLDSA_K * MLDSA_POLYETA_PACKEDBYTES],
767
420
  const mld_polyveck *p)
@@ -796,24 +449,11 @@ void mld_polyvecl_pack_eta(uint8_t r[MLDSA_L * MLDSA_POLYETA_PACKEDBYTES],
796
449
  }
797
450
  }
798
451
 
799
- MLD_INTERNAL_API
800
- void mld_polyveck_pack_t0(uint8_t r[MLDSA_K * MLDSA_POLYT0_PACKEDBYTES],
801
- const mld_polyveck *p)
802
- {
803
- unsigned int i;
804
- mld_assert_bound_2d(p->vec, MLDSA_K, MLDSA_N, -(1 << (MLDSA_D - 1)) + 1,
805
- (1 << (MLDSA_D - 1)) + 1);
806
- for (i = 0; i < MLDSA_K; ++i)
807
- __loop__(
808
- assigns(i, memory_slice(r, MLDSA_K * MLDSA_POLYT0_PACKEDBYTES))
809
- invariant(i <= MLDSA_K)
810
- decreases(MLDSA_K - i)
811
- )
812
- {
813
- mld_polyt0_pack(&r[i * MLDSA_POLYT0_PACKEDBYTES], &p->vec[i]);
814
- }
815
- }
452
+ #endif /* !MLD_CONFIG_NO_KEYPAIR_API */
816
453
 
454
+ #if !defined(MLD_CONFIG_NO_KEYPAIR_API) || \
455
+ (!defined(MLD_CONFIG_NO_SIGN_API) && \
456
+ (!defined(MLD_CONFIG_REDUCE_RAM) || defined(MLD_UNIT_TEST)))
817
457
  MLD_INTERNAL_API
818
458
  void mld_polyvecl_unpack_eta(
819
459
  mld_polyvecl *p, const uint8_t r[MLDSA_L * MLDSA_POLYETA_PACKEDBYTES])
@@ -827,7 +467,10 @@ void mld_polyvecl_unpack_eta(
827
467
  mld_assert_bound_2d(p->vec, MLDSA_L, MLDSA_N, MLD_POLYETA_UNPACK_LOWER_BOUND,
828
468
  MLDSA_ETA + 1);
829
469
  }
470
+ #endif /* !MLD_CONFIG_NO_KEYPAIR_API || (!MLD_CONFIG_NO_SIGN_API && \
471
+ (!MLD_CONFIG_REDUCE_RAM || MLD_UNIT_TEST)) */
830
472
 
473
+ #if !defined(MLD_CONFIG_NO_VERIFY_API)
831
474
  MLD_INTERNAL_API
832
475
  void mld_polyvecl_unpack_z(mld_polyvecl *z,
833
476
  const uint8_t r[MLDSA_L * MLDSA_POLYZ_PACKEDBYTES])
@@ -841,7 +484,11 @@ void mld_polyvecl_unpack_z(mld_polyvecl *z,
841
484
  mld_assert_bound_2d(z->vec, MLDSA_L, MLDSA_N, -(MLDSA_GAMMA1 - 1),
842
485
  MLDSA_GAMMA1 + 1);
843
486
  }
487
+ #endif /* !MLD_CONFIG_NO_VERIFY_API */
844
488
 
489
+ #if !defined(MLD_CONFIG_NO_KEYPAIR_API) || \
490
+ (!defined(MLD_CONFIG_NO_SIGN_API) && \
491
+ (!defined(MLD_CONFIG_REDUCE_RAM) || defined(MLD_UNIT_TEST)))
845
492
  MLD_INTERNAL_API
846
493
  void mld_polyveck_unpack_eta(
847
494
  mld_polyveck *p, const uint8_t r[MLDSA_K * MLDSA_POLYETA_PACKEDBYTES])
@@ -855,23 +502,9 @@ void mld_polyveck_unpack_eta(
855
502
  mld_assert_bound_2d(p->vec, MLDSA_K, MLDSA_N, MLD_POLYETA_UNPACK_LOWER_BOUND,
856
503
  MLDSA_ETA + 1);
857
504
  }
858
-
859
- MLD_INTERNAL_API
860
- void mld_polyveck_unpack_t0(mld_polyveck *p,
861
- const uint8_t r[MLDSA_K * MLDSA_POLYT0_PACKEDBYTES])
862
- {
863
- unsigned int i;
864
- for (i = 0; i < MLDSA_K; ++i)
865
- {
866
- mld_polyt0_unpack(&p->vec[i], r + i * MLDSA_POLYT0_PACKEDBYTES);
867
- }
868
-
869
- mld_assert_bound_2d(p->vec, MLDSA_K, MLDSA_N, -(1 << (MLDSA_D - 1)) + 1,
870
- (1 << (MLDSA_D - 1)) + 1);
871
- }
505
+ #endif /* !MLD_CONFIG_NO_KEYPAIR_API || (!MLD_CONFIG_NO_SIGN_API && \
506
+ (!MLD_CONFIG_REDUCE_RAM || MLD_UNIT_TEST)) */
872
507
 
873
508
  /* To facilitate single-compilation-unit (SCU) builds, undefine all macros.
874
509
  * Don't modify by hand -- this is auto-generated by scripts/autogen. */
875
- #undef mld_polymat_permute_bitrev_to_custom
876
- #undef mld_polyvecl_permute_bitrev_to_custom
877
510
  #undef mld_polyvecl_pointwise_acc_montgomery_c