pq_crypto 0.6.1 → 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 (141) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -0
  3. data/SECURITY.md +7 -0
  4. data/ext/pqcrypto/pqcrypto_version.h +1 -1
  5. data/ext/pqcrypto/vendor/.vendored +4 -4
  6. data/ext/pqcrypto/vendor/mldsa-native/README.md +23 -10
  7. data/ext/pqcrypto/vendor/mldsa-native/mldsa/README.md +23 -0
  8. data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native.c +114 -58
  9. data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native.h +498 -461
  10. data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native_asm.S +145 -85
  11. data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native_config.h +456 -422
  12. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/cbmc.h +47 -25
  13. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/common.h +26 -14
  14. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/ct.h +56 -81
  15. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/debug.h +17 -24
  16. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/fips202.c +33 -40
  17. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/fips202.h +67 -87
  18. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/fips202x4.c +19 -14
  19. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/fips202x4.h +13 -5
  20. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/keccakf1600.c +84 -10
  21. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/keccakf1600.h +10 -5
  22. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/auto.h +6 -0
  23. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/fips202_native_aarch64.h +22 -15
  24. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_scalar_aarch64_asm.S +376 -0
  25. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_v84a_aarch64_asm.S +204 -0
  26. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x2_v84a_aarch64_asm.S +259 -0
  27. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_scalar_hybrid_aarch64_asm.S +1077 -0
  28. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_v84a_scalar_hybrid_aarch64_asm.S +987 -0
  29. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccakf1600_round_constants.c +16 -10
  30. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x1_scalar.h +2 -1
  31. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x1_v84a.h +1 -1
  32. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x2_v84a.h +4 -2
  33. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x4_v8a_scalar.h +2 -2
  34. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x4_v8a_v84a_scalar.h +1 -1
  35. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/api.h +60 -0
  36. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/mve.h +48 -0
  37. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/fips202_native_armv81m.h +18 -1
  38. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.S +658 -582
  39. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.c +5 -100
  40. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccakf1600_round_constants.c +26 -25
  41. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/state_extract_bytes_x4_mve.S +334 -0
  42. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/state_xor_bytes_x4_mve.S +355 -0
  43. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/auto.h +8 -3
  44. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/{xkcp.h → keccak_f1600_x4_avx2.h} +11 -8
  45. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/fips202_native_x86_64.h +44 -0
  46. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/keccak_f1600_x4_avx2_asm.S +454 -0
  47. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/keccakf1600_constants.c +52 -0
  48. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/meta.h +37 -28
  49. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/aarch64_zetas.c +213 -196
  50. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/arith_native_aarch64.h +248 -64
  51. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/intt_aarch64_asm.S +753 -0
  52. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l4_aarch64_asm.S +129 -0
  53. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l5_aarch64_asm.S +145 -0
  54. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l7_aarch64_asm.S +177 -0
  55. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/ntt_aarch64_asm.S +653 -0
  56. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/pointwise_montgomery_aarch64_asm.S +84 -0
  57. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_caddq_aarch64_asm.S +53 -0
  58. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_chknorm_aarch64_asm.S +55 -0
  59. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_decompose_32_aarch64_asm.S +86 -0
  60. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_decompose_88_aarch64_asm.S +86 -0
  61. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_use_hint_32_aarch64_asm.S +103 -0
  62. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_use_hint_88_aarch64_asm.S +111 -0
  63. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/polyz_unpack_17_aarch64_asm.S +75 -0
  64. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/polyz_unpack_19_aarch64_asm.S +72 -0
  65. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/polyz_unpack_table.c +23 -11
  66. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_aarch64_asm.S +189 -0
  67. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_eta2_aarch64_asm.S +137 -0
  68. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_eta4_aarch64_asm.S +130 -0
  69. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_eta_table.c +520 -516
  70. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_table.c +34 -33
  71. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/api.h +202 -242
  72. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/meta.h +25 -17
  73. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/arith_native_x86_64.h +112 -28
  74. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/consts.c +1 -1
  75. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/consts.h +1 -1
  76. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/intt_avx2_asm.S +2311 -0
  77. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/ntt_avx2_asm.S +2383 -0
  78. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/nttunpack_avx2_asm.S +238 -0
  79. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l4_avx2_asm.S +139 -0
  80. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l5_avx2_asm.S +155 -0
  81. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l7_avx2_asm.S +187 -0
  82. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_avx2_asm.S +130 -0
  83. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_caddq_avx2_asm.S +190 -0
  84. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_decompose_32_avx2.c +6 -4
  85. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_decompose_88_avx2.c +6 -4
  86. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_use_hint_32_avx2.c +9 -8
  87. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_use_hint_88_avx2.c +10 -9
  88. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/polyz_unpack_17_avx2.c +8 -5
  89. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/polyz_unpack_19_avx2.c +8 -5
  90. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/rej_uniform_eta2_avx2.c +6 -4
  91. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/rej_uniform_eta4_avx2.c +6 -4
  92. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/rej_uniform_table.c +130 -129
  93. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/packing.c +109 -180
  94. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/packing.h +169 -150
  95. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly.c +56 -40
  96. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly.h +149 -164
  97. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly_kl.c +52 -57
  98. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly_kl.h +132 -167
  99. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec.c +57 -424
  100. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec.h +167 -474
  101. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec_lazy.c +308 -0
  102. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec_lazy.h +653 -0
  103. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/reduce.h +22 -29
  104. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/rounding.h +37 -43
  105. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/sign.c +511 -367
  106. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/sign.h +456 -417
  107. data/lib/pq_crypto/version.rb +1 -1
  108. data/script/vendor_libs.rb +3 -3
  109. metadata +41 -35
  110. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_scalar_asm.S +0 -376
  111. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_v84a_asm.S +0 -204
  112. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x2_v84a_asm.S +0 -259
  113. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_scalar_hybrid_asm.S +0 -1077
  114. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_v84a_scalar_hybrid_asm.S +0 -987
  115. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/KeccakP_1600_times4_SIMD256.c +0 -488
  116. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/KeccakP_1600_times4_SIMD256.h +0 -16
  117. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/intt.S +0 -753
  118. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l4.S +0 -129
  119. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l5.S +0 -145
  120. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l7.S +0 -177
  121. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/ntt.S +0 -653
  122. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/pointwise_montgomery.S +0 -79
  123. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_caddq_asm.S +0 -53
  124. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_chknorm_asm.S +0 -55
  125. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_decompose_32_asm.S +0 -85
  126. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_decompose_88_asm.S +0 -85
  127. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_use_hint_32_asm.S +0 -102
  128. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_use_hint_88_asm.S +0 -110
  129. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/polyz_unpack_17_asm.S +0 -72
  130. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/polyz_unpack_19_asm.S +0 -69
  131. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_asm.S +0 -189
  132. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_eta2_asm.S +0 -135
  133. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_eta4_asm.S +0 -128
  134. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/intt.S +0 -2311
  135. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/ntt.S +0 -2383
  136. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/nttunpack.S +0 -239
  137. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise.S +0 -131
  138. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l4.S +0 -139
  139. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l5.S +0 -155
  140. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l7.S +0 -187
  141. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_caddq_avx2.c +0 -61
@@ -37,6 +37,7 @@
37
37
  /* End of parameter set namespacing */
38
38
 
39
39
 
40
+ #if !defined(MLD_CONFIG_NO_SIGN_API)
40
41
  MLD_STATIC_TESTABLE
41
42
  void mld_poly_decompose_c(mld_poly *a1, mld_poly *a0)
42
43
  __contract__(
@@ -100,40 +101,17 @@ void mld_poly_decompose(mld_poly *a1, mld_poly *a0)
100
101
  mld_poly_decompose_c(a1, a0);
101
102
  }
102
103
 
103
- MLD_INTERNAL_API
104
- unsigned int mld_poly_make_hint(mld_poly *h, const mld_poly *a0,
105
- const mld_poly *a1)
106
- {
107
- unsigned int i, s = 0;
108
-
109
- for (i = 0; i < MLDSA_N; ++i)
110
- __loop__(
111
- invariant(i <= MLDSA_N)
112
- invariant(s <= i)
113
- invariant(array_bound(h->coeffs, 0, i, 0, 2))
114
- decreases(MLDSA_N - i)
115
- )
116
- {
117
- const unsigned int hint_bit = mld_make_hint(a0->coeffs[i], a1->coeffs[i]);
118
- h->coeffs[i] = (int32_t)hint_bit;
119
- s += hint_bit;
120
- }
104
+ #endif /* !MLD_CONFIG_NO_SIGN_API */
121
105
 
122
- mld_assert(s <= MLDSA_N);
123
- mld_assert_bound(h->coeffs, MLDSA_N, 0, 2);
124
- return s;
125
- }
126
-
127
- MLD_STATIC_TESTABLE void mld_poly_use_hint_c(mld_poly *b, const mld_poly *a,
128
- const mld_poly *h)
106
+ #if !defined(MLD_CONFIG_NO_VERIFY_API)
107
+ MLD_STATIC_TESTABLE void mld_poly_use_hint_c(mld_poly *a, const mld_poly *h)
129
108
  __contract__(
130
- requires(memory_no_alias(a, sizeof(mld_poly)))
131
- requires(memory_no_alias(b, sizeof(mld_poly)))
109
+ requires(memory_no_alias(a, sizeof(mld_poly)))
132
110
  requires(memory_no_alias(h, sizeof(mld_poly)))
133
111
  requires(array_bound(a->coeffs, 0, MLDSA_N, 0, MLDSA_Q))
134
112
  requires(array_bound(h->coeffs, 0, MLDSA_N, 0, 2))
135
- assigns(memory_slice(b, sizeof(mld_poly)))
136
- ensures(array_bound(b->coeffs, 0, MLDSA_N, 0, (MLDSA_Q-1)/(2*MLDSA_GAMMA2)))
113
+ assigns(memory_slice(a, sizeof(mld_poly)))
114
+ ensures(array_bound(a->coeffs, 0, MLDSA_N, 0, (MLDSA_Q-1)/(2*MLDSA_GAMMA2)))
137
115
  )
138
116
  {
139
117
  unsigned int i;
@@ -143,26 +121,27 @@ __contract__(
143
121
  for (i = 0; i < MLDSA_N; ++i)
144
122
  __loop__(
145
123
  invariant(i <= MLDSA_N)
146
- invariant(array_bound(b->coeffs, 0, i, 0, (MLDSA_Q-1)/(2*MLDSA_GAMMA2)))
124
+ invariant(array_bound(a->coeffs, 0, i, 0, (MLDSA_Q-1)/(2*MLDSA_GAMMA2)))
125
+ invariant(array_bound(a->coeffs, i, MLDSA_N, 0, MLDSA_Q))
147
126
  decreases(MLDSA_N - i)
148
127
  )
149
128
  {
150
- b->coeffs[i] = mld_use_hint(a->coeffs[i], h->coeffs[i]);
129
+ a->coeffs[i] = mld_use_hint(a->coeffs[i], h->coeffs[i]);
151
130
  }
152
- mld_assert_bound(b->coeffs, MLDSA_N, 0, (MLDSA_Q - 1) / (2 * MLDSA_GAMMA2));
131
+ mld_assert_bound(a->coeffs, MLDSA_N, 0, (MLDSA_Q - 1) / (2 * MLDSA_GAMMA2));
153
132
  }
154
133
 
155
134
  MLD_INTERNAL_API
156
- void mld_poly_use_hint(mld_poly *b, const mld_poly *a, const mld_poly *h)
135
+ void mld_poly_use_hint(mld_poly *a, const mld_poly *h)
157
136
  {
158
137
  #if defined(MLD_USE_NATIVE_POLY_USE_HINT_88) && MLD_CONFIG_PARAMETER_SET == 44
159
138
  int ret;
160
139
  mld_assert_bound(a->coeffs, MLDSA_N, 0, MLDSA_Q);
161
140
  mld_assert_bound(h->coeffs, MLDSA_N, 0, 2);
162
- ret = mld_poly_use_hint_88_native(b->coeffs, a->coeffs, h->coeffs);
141
+ ret = mld_poly_use_hint_88_native(a->coeffs, h->coeffs);
163
142
  if (ret == MLD_NATIVE_FUNC_SUCCESS)
164
143
  {
165
- mld_assert_bound(b->coeffs, MLDSA_N, 0, (MLDSA_Q - 1) / (2 * MLDSA_GAMMA2));
144
+ mld_assert_bound(a->coeffs, MLDSA_N, 0, (MLDSA_Q - 1) / (2 * MLDSA_GAMMA2));
166
145
  return;
167
146
  }
168
147
  #elif defined(MLD_USE_NATIVE_POLY_USE_HINT_32) && \
@@ -170,34 +149,33 @@ void mld_poly_use_hint(mld_poly *b, const mld_poly *a, const mld_poly *h)
170
149
  int ret;
171
150
  mld_assert_bound(a->coeffs, MLDSA_N, 0, MLDSA_Q);
172
151
  mld_assert_bound(h->coeffs, MLDSA_N, 0, 2);
173
- ret = mld_poly_use_hint_32_native(b->coeffs, a->coeffs, h->coeffs);
152
+ ret = mld_poly_use_hint_32_native(a->coeffs, h->coeffs);
174
153
  if (ret == MLD_NATIVE_FUNC_SUCCESS)
175
154
  {
176
- mld_assert_bound(b->coeffs, MLDSA_N, 0, (MLDSA_Q - 1) / (2 * MLDSA_GAMMA2));
155
+ mld_assert_bound(a->coeffs, MLDSA_N, 0, (MLDSA_Q - 1) / (2 * MLDSA_GAMMA2));
177
156
  return;
178
157
  }
179
158
  #endif /* !(MLD_USE_NATIVE_POLY_USE_HINT_88 && MLD_CONFIG_PARAMETER_SET == 44) \
180
159
  && MLD_USE_NATIVE_POLY_USE_HINT_32 && (MLD_CONFIG_PARAMETER_SET == \
181
160
  65 || MLD_CONFIG_PARAMETER_SET == 87) */
182
- mld_poly_use_hint_c(b, a, h);
161
+ mld_poly_use_hint_c(a, h);
183
162
  }
163
+ #endif /* !MLD_CONFIG_NO_VERIFY_API */
184
164
 
185
- /*************************************************
186
- * Name: mld_rej_eta
165
+ #if !defined(MLD_CONFIG_NO_KEYPAIR_API)
166
+ /**
167
+ * Sample uniformly random coefficients in [-MLDSA_ETA, MLDSA_ETA] by
168
+ * performing rejection sampling on an array of random bytes.
187
169
  *
188
- * Description: Sample uniformly random coefficients in [-MLDSA_ETA, MLDSA_ETA]
189
- *by performing rejection sampling on array of random bytes.
170
+ * @param[out] a Pointer to output array (allocated).
171
+ * @param target Requested number of coefficients to sample.
172
+ * @param offset Number of coefficients already sampled.
173
+ * @param[in] buf Array of random bytes to sample from.
174
+ * @param buflen Length of array of random bytes.
190
175
  *
191
- * Arguments: - int32_t *a: pointer to output array (allocated)
192
- * - unsigned int target: requested number of coefficients to
193
- *sample
194
- * - unsigned int offset: number of coefficients already sampled
195
- * - const uint8_t *buf: array of random bytes to sample from
196
- * - unsigned int buflen: length of array of random bytes
197
- *
198
- * Returns number of sampled coefficients. Can be smaller than target if not
199
- *enough random bytes were given.
200
- **************************************************/
176
+ * @return Number of sampled coefficients. Can be smaller than target if not
177
+ * enough random bytes were given.
178
+ */
201
179
 
202
180
  /* Reference: `mld_rej_eta()` in the reference implementation @[REF].
203
181
  * - Our signature differs from the reference implementation
@@ -485,12 +463,16 @@ void mld_poly_uniform_eta(mld_poly *r, const uint8_t seed[MLDSA_CRHBYTES],
485
463
  mld_zeroize(extseed, sizeof(extseed));
486
464
  }
487
465
  #endif /* MLD_CONFIG_SERIAL_FIPS202_ONLY */
466
+ #endif /* !MLD_CONFIG_NO_KEYPAIR_API */
488
467
 
468
+ #if !defined(MLD_CONFIG_NO_SIGN_API)
489
469
  #define MLD_POLY_UNIFORM_GAMMA1_NBLOCKS \
490
470
  ((MLDSA_POLYZ_PACKEDBYTES + MLD_STREAM256_BLOCKBYTES - 1) / \
491
471
  MLD_STREAM256_BLOCKBYTES)
492
472
 
493
- #if MLD_CONFIG_PARAMETER_SET == 65 || defined(MLD_CONFIG_SERIAL_FIPS202_ONLY)
473
+ #if MLD_CONFIG_PARAMETER_SET == 65 || \
474
+ defined(MLD_CONFIG_SERIAL_FIPS202_ONLY) || \
475
+ defined(MLD_CONFIG_REDUCE_RAM) || defined(MLD_UNIT_TEST)
494
476
  MLD_INTERNAL_API
495
477
  void mld_poly_uniform_gamma1(mld_poly *a, const uint8_t seed[MLDSA_CRHBYTES],
496
478
  uint16_t nonce)
@@ -518,10 +500,12 @@ void mld_poly_uniform_gamma1(mld_poly *a, const uint8_t seed[MLDSA_CRHBYTES],
518
500
  mld_zeroize(buf, sizeof(buf));
519
501
  mld_zeroize(extseed, sizeof(extseed));
520
502
  }
521
- #endif /* MLD_CONFIG_PARAMETER_SET == 65 || MLD_CONFIG_SERIAL_FIPS202_ONLY */
503
+ #endif /* MLD_CONFIG_PARAMETER_SET == 65 || MLD_CONFIG_SERIAL_FIPS202_ONLY || \
504
+ MLD_CONFIG_REDUCE_RAM || MLD_UNIT_TEST */
522
505
 
523
506
 
524
- #if !defined(MLD_CONFIG_SERIAL_FIPS202_ONLY)
507
+ #if !defined(MLD_CONFIG_SERIAL_FIPS202_ONLY) && \
508
+ (!defined(MLD_CONFIG_REDUCE_RAM) || defined(MLD_UNIT_TEST))
525
509
  MLD_INTERNAL_API
526
510
  void mld_poly_uniform_gamma1_4x(mld_poly *r0, mld_poly *r1, mld_poly *r2,
527
511
  mld_poly *r3,
@@ -570,8 +554,11 @@ void mld_poly_uniform_gamma1_4x(mld_poly *r0, mld_poly *r1, mld_poly *r2,
570
554
  mld_zeroize(buf, sizeof(buf));
571
555
  mld_zeroize(extseed, sizeof(extseed));
572
556
  }
573
- #endif /* !MLD_CONFIG_SERIAL_FIPS202_ONLY */
557
+ #endif /* !MLD_CONFIG_SERIAL_FIPS202_ONLY && (!MLD_CONFIG_REDUCE_RAM || \
558
+ MLD_UNIT_TEST) */
559
+ #endif /* !MLD_CONFIG_NO_SIGN_API */
574
560
 
561
+ #if !defined(MLD_CONFIG_NO_SIGN_API) || !defined(MLD_CONFIG_NO_VERIFY_API)
575
562
  MLD_INTERNAL_API
576
563
  void mld_poly_challenge(mld_poly *c, const uint8_t seed[MLDSA_CTILDEBYTES])
577
564
  {
@@ -654,7 +641,9 @@ void mld_poly_challenge(mld_poly *c, const uint8_t seed[MLDSA_CTILDEBYTES])
654
641
  mld_zeroize(buf, sizeof(buf));
655
642
  mld_zeroize(&signs, sizeof(signs));
656
643
  }
644
+ #endif /* !MLD_CONFIG_NO_SIGN_API || !MLD_CONFIG_NO_VERIFY_API */
657
645
 
646
+ #if !defined(MLD_CONFIG_NO_KEYPAIR_API)
658
647
  MLD_INTERNAL_API
659
648
  void mld_polyeta_pack(uint8_t r[MLDSA_POLYETA_PACKEDBYTES], const mld_poly *a)
660
649
  {
@@ -702,7 +691,9 @@ void mld_polyeta_pack(uint8_t r[MLDSA_POLYETA_PACKEDBYTES], const mld_poly *a)
702
691
  #error "Invalid value of MLDSA_ETA"
703
692
  #endif /* MLDSA_ETA != 2 && MLDSA_ETA != 4 */
704
693
  }
694
+ #endif /* !MLD_CONFIG_NO_KEYPAIR_API */
705
695
 
696
+ #if !defined(MLD_CONFIG_NO_KEYPAIR_API) || !defined(MLD_CONFIG_NO_SIGN_API)
706
697
  void mld_polyeta_unpack(mld_poly *r, const uint8_t a[MLDSA_POLYETA_PACKEDBYTES])
707
698
  {
708
699
  unsigned int i;
@@ -751,8 +742,9 @@ void mld_polyeta_unpack(mld_poly *r, const uint8_t a[MLDSA_POLYETA_PACKEDBYTES])
751
742
  mld_assert_bound(r->coeffs, MLDSA_N, MLD_POLYETA_UNPACK_LOWER_BOUND,
752
743
  MLDSA_ETA + 1);
753
744
  }
745
+ #endif /* !MLD_CONFIG_NO_KEYPAIR_API || !MLD_CONFIG_NO_SIGN_API */
754
746
 
755
-
747
+ #if !defined(MLD_CONFIG_NO_SIGN_API)
756
748
  MLD_INTERNAL_API
757
749
  void mld_polyz_pack(uint8_t r[MLDSA_POLYZ_PACKEDBYTES], const mld_poly *a)
758
750
  {
@@ -805,7 +797,9 @@ void mld_polyz_pack(uint8_t r[MLDSA_POLYZ_PACKEDBYTES], const mld_poly *a)
805
797
  }
806
798
  #endif /* MLD_CONFIG_PARAMETER_SET != 44 */
807
799
  }
800
+ #endif /* !MLD_CONFIG_NO_SIGN_API */
808
801
 
802
+ #if !defined(MLD_CONFIG_NO_SIGN_API) || !defined(MLD_CONFIG_NO_VERIFY_API)
809
803
  MLD_STATIC_TESTABLE void mld_polyz_unpack_c(
810
804
  mld_poly *r, const uint8_t a[MLDSA_POLYZ_PACKEDBYTES])
811
805
  __contract__(
@@ -931,6 +925,7 @@ void mld_polyw1_pack(uint8_t r[MLDSA_POLYW1_PACKEDBYTES], const mld_poly *a)
931
925
  }
932
926
  #endif /* MLD_CONFIG_PARAMETER_SET != 44 */
933
927
  }
928
+ #endif /* !MLD_CONFIG_NO_SIGN_API || !MLD_CONFIG_NO_VERIFY_API */
934
929
 
935
930
  /* To facilitate single-compilation-unit (SCU) builds, undefine all macros. */
936
931
 
@@ -9,27 +9,23 @@
9
9
  #include "common.h"
10
10
  #include "poly.h"
11
11
 
12
+ #if !defined(MLD_CONFIG_NO_SIGN_API)
12
13
  #define mld_poly_decompose MLD_NAMESPACE_KL(poly_decompose)
13
- /*************************************************
14
- * Name: mld_poly_decompose
14
+ /**
15
+ * For all coefficients c of the input polynomial, compute high and low bits
16
+ * c0, c1 such c mod MLDSA_Q = c1*ALPHA + c0 with -ALPHA/2 < c0 <= ALPHA/2
17
+ * except c1 = (MLDSA_Q-1)/ALPHA where we set c1 = 0 and
18
+ * -ALPHA/2 <= c0 = c mod MLDSA_Q - MLDSA_Q < 0. Assumes coefficients to be
19
+ * standard representatives.
15
20
  *
16
- * Description: For all coefficients c of the input polynomial,
17
- * compute high and low bits c0, c1 such c mod MLDSA_Q = c1*ALPHA +
18
- * c0 with -ALPHA/2 < c0 <= ALPHA/2 except
19
- * c1 = (MLDSA_Q-1)/ALPHA where we set
20
- * c1 = 0 and -ALPHA/2 <= c0 = c mod MLDSA_Q - MLDSA_Q < 0.
21
- * Assumes coefficients to be standard representatives.
21
+ * @reference{The reference implementation has the input polynomial as a
22
+ * separate argument that may be aliased with either of the outputs. Removing
23
+ * the aliasing eases CBMC proofs.}
22
24
  *
23
- * Arguments: - mld_poly *a1: pointer to output polynomial with coefficients
24
- * c1
25
- * - mld_poly *a0: pointer to input/output polynomial. Output
26
- * polynomial has coefficients c0
27
- *
28
- * Reference: The reference implementation has the input polynomial as a
29
- * separate argument that may be aliased with either of the outputs.
30
- * Removing the aliasing eases CBMC proofs.
31
- *
32
- **************************************************/
25
+ * @param[out] a1 Pointer to output polynomial with coefficients c1.
26
+ * @param[in,out] a0 Pointer to input/output polynomial. Output polynomial has
27
+ * coefficients c0.
28
+ */
33
29
  MLD_INTERNAL_API
34
30
  void mld_poly_decompose(mld_poly *a1, mld_poly *a0)
35
31
  __contract__(
@@ -42,77 +38,46 @@ __contract__(
42
38
  ensures(array_abs_bound(a0->coeffs, 0, MLDSA_N, MLDSA_GAMMA2+1))
43
39
  );
44
40
 
41
+ #endif /* !MLD_CONFIG_NO_SIGN_API */
45
42
 
46
- #define mld_poly_make_hint MLD_NAMESPACE_KL(poly_make_hint)
47
- /*************************************************
48
- * Name: mld_poly_make_hint
49
- *
50
- * Description: Compute hint polynomial. The coefficients of which indicate
51
- * whether the low bits of the corresponding coefficient of
52
- * the input polynomial overflow into the high bits.
53
- *
54
- * Arguments: - mld_poly *h: pointer to output hint polynomial
55
- * - const mld_poly *a0: pointer to low part of input polynomial
56
- * - const mld_poly *a1: pointer to high part of input polynomial
57
- *
58
- * Returns number of 1 bits.
59
- **************************************************/
60
- MLD_INTERNAL_API
61
- MLD_MUST_CHECK_RETURN_VALUE
62
- unsigned int mld_poly_make_hint(mld_poly *h, const mld_poly *a0,
63
- const mld_poly *a1)
64
- __contract__(
65
- requires(memory_no_alias(h, sizeof(mld_poly)))
66
- requires(memory_no_alias(a0, sizeof(mld_poly)))
67
- requires(memory_no_alias(a1, sizeof(mld_poly)))
68
- assigns(memory_slice(h, sizeof(mld_poly)))
69
- ensures(return_value <= MLDSA_N)
70
- ensures(array_bound(h->coeffs, 0, MLDSA_N, 0, 2))
71
- );
72
-
43
+ #if !defined(MLD_CONFIG_NO_VERIFY_API)
73
44
  #define mld_poly_use_hint MLD_NAMESPACE_KL(poly_use_hint)
74
- /*************************************************
75
- * Name: mld_poly_use_hint
76
- *
77
- * Description: Use hint polynomial to correct the high bits of a polynomial.
45
+ /**
46
+ * Use hint polynomial h to correct the high bits of a in-place.
78
47
  *
79
- * Arguments: - mld_poly *b: pointer to output polynomial with corrected high
80
- *bits
81
- * - const mld_poly *a: pointer to input polynomial
82
- * - const mld_poly *h: pointer to input hint polynomial
83
- **************************************************/
48
+ * @param[in,out] a Input/output polynomial.
49
+ * @param[in] h Hint polynomial.
50
+ */
84
51
  MLD_INTERNAL_API
85
- void mld_poly_use_hint(mld_poly *b, const mld_poly *a, const mld_poly *h)
52
+ void mld_poly_use_hint(mld_poly *a, const mld_poly *h)
86
53
  __contract__(
87
- requires(memory_no_alias(a, sizeof(mld_poly)))
88
- requires(memory_no_alias(b, sizeof(mld_poly)))
54
+ requires(memory_no_alias(a, sizeof(mld_poly)))
89
55
  requires(memory_no_alias(h, sizeof(mld_poly)))
90
56
  requires(array_bound(a->coeffs, 0, MLDSA_N, 0, MLDSA_Q))
91
57
  requires(array_bound(h->coeffs, 0, MLDSA_N, 0, 2))
92
- assigns(memory_slice(b, sizeof(mld_poly)))
93
- ensures(array_bound(b->coeffs, 0, MLDSA_N, 0, (MLDSA_Q-1)/(2*MLDSA_GAMMA2)))
58
+ assigns(memory_slice(a, sizeof(mld_poly)))
59
+ ensures(array_bound(a->coeffs, 0, MLDSA_N, 0, (MLDSA_Q-1)/(2*MLDSA_GAMMA2)))
94
60
  );
61
+ #endif /* !MLD_CONFIG_NO_VERIFY_API */
95
62
 
63
+ #if !defined(MLD_CONFIG_NO_KEYPAIR_API)
96
64
  #if !defined(MLD_CONFIG_SERIAL_FIPS202_ONLY)
97
65
  #define mld_poly_uniform_eta_4x MLD_NAMESPACE_KL(poly_uniform_eta_4x)
98
- /*************************************************
99
- * Name: mld_poly_uniform_eta
66
+ /**
67
+ * Sample four polynomials with uniformly random coefficients in
68
+ * [-MLDSA_ETA, MLDSA_ETA] by performing rejection sampling on the output
69
+ * stream from SHAKE256(seed|nonce_i).
100
70
  *
101
- * Description: Sample four polynomials with uniformly random coefficients
102
- * in [-MLDSA_ETA,MLDSA_ETA] by performing rejection sampling on
103
- * the output stream from SHAKE256(seed|nonce_i)
104
- *
105
- * Arguments: - mld_poly *r0: pointer to first output polynomial
106
- * - mld_poly *r1: pointer to second output polynomial
107
- * - mld_poly *r2: pointer to third output polynomial
108
- * - mld_poly *r3: pointer to fourth output polynomial
109
- * - const uint8_t seed[]: byte array with seed of length
110
- * MLDSA_CRHBYTES
111
- * - uint8_t nonce0: first nonce
112
- * - uint8_t nonce1: second nonce
113
- * - uint8_t nonce2: third nonce
114
- * - uint8_t nonce3: fourth nonce
115
- **************************************************/
71
+ * @param[out] r0 Pointer to first output polynomial.
72
+ * @param[out] r1 Pointer to second output polynomial.
73
+ * @param[out] r2 Pointer to third output polynomial.
74
+ * @param[out] r3 Pointer to fourth output polynomial.
75
+ * @param[in] seed Byte array with seed of length MLDSA_CRHBYTES.
76
+ * @param nonce0 First nonce.
77
+ * @param nonce1 Second nonce.
78
+ * @param nonce2 Third nonce.
79
+ * @param nonce3 Fourth nonce.
80
+ */
116
81
  MLD_INTERNAL_API
117
82
  void mld_poly_uniform_eta_4x(mld_poly *r0, mld_poly *r1, mld_poly *r2,
118
83
  mld_poly *r3, const uint8_t seed[MLDSA_CRHBYTES],
@@ -137,18 +102,15 @@ __contract__(
137
102
 
138
103
  #if defined(MLD_CONFIG_SERIAL_FIPS202_ONLY)
139
104
  #define mld_poly_uniform_eta MLD_NAMESPACE_KL(poly_uniform_eta)
140
- /*************************************************
141
- * Name: mld_poly_uniform_eta
105
+ /**
106
+ * Sample polynomial with uniformly random coefficients in
107
+ * [-MLDSA_ETA, MLDSA_ETA] by performing rejection sampling on the output
108
+ * stream from SHAKE256(seed|nonce).
142
109
  *
143
- * Description: Sample polynomial with uniformly random coefficients
144
- * in [-MLDSA_ETA,MLDSA_ETA] by performing rejection sampling on
145
- * the output stream from SHAKE256(seed|nonce)
146
- *
147
- * Arguments: - mld_poly *r: pointer to output polynomial
148
- * - const uint8_t seed[]: byte array with seed of length
149
- * MLDSA_CRHBYTES
150
- * - uint8_t nonce: nonce
151
- **************************************************/
110
+ * @param[out] r Pointer to output polynomial.
111
+ * @param[in] seed Byte array with seed of length MLDSA_CRHBYTES.
112
+ * @param nonce Nonce.
113
+ */
152
114
  MLD_INTERNAL_API
153
115
  void mld_poly_uniform_eta(mld_poly *r, const uint8_t seed[MLDSA_CRHBYTES],
154
116
  uint8_t nonce)
@@ -159,21 +121,22 @@ __contract__(
159
121
  ensures(array_abs_bound(r->coeffs, 0, MLDSA_N, MLDSA_ETA + 1))
160
122
  );
161
123
  #endif /* MLD_CONFIG_SERIAL_FIPS202_ONLY */
124
+ #endif /* !MLD_CONFIG_NO_KEYPAIR_API */
162
125
 
163
- #if MLD_CONFIG_PARAMETER_SET == 65 || defined(MLD_CONFIG_SERIAL_FIPS202_ONLY)
126
+ #if !defined(MLD_CONFIG_NO_SIGN_API)
127
+ #if MLD_CONFIG_PARAMETER_SET == 65 || \
128
+ defined(MLD_CONFIG_SERIAL_FIPS202_ONLY) || \
129
+ defined(MLD_CONFIG_REDUCE_RAM) || defined(MLD_UNIT_TEST)
164
130
  #define mld_poly_uniform_gamma1 MLD_NAMESPACE_KL(poly_uniform_gamma1)
165
- /*************************************************
166
- * Name: mld_poly_uniform_gamma1
131
+ /**
132
+ * Sample polynomial with uniformly random coefficients in
133
+ * [-(MLDSA_GAMMA1 - 1), MLDSA_GAMMA1] by unpacking output stream of
134
+ * SHAKE256(seed|nonce).
167
135
  *
168
- * Description: Sample polynomial with uniformly random coefficients
169
- * in [-(MLDSA_GAMMA1 - 1), MLDSA_GAMMA1] by unpacking output
170
- * stream of SHAKE256(seed|nonce)
171
- *
172
- * Arguments: - mld_poly *a: pointer to output polynomial
173
- * - const uint8_t seed[]: byte array with seed of length
174
- * MLDSA_CRHBYTES
175
- * - uint16_t nonce: 16-bit nonce
176
- **************************************************/
136
+ * @param[out] a Pointer to output polynomial.
137
+ * @param[in] seed Byte array with seed of length MLDSA_CRHBYTES.
138
+ * @param nonce 16-bit nonce.
139
+ */
177
140
  MLD_INTERNAL_API
178
141
  void mld_poly_uniform_gamma1(mld_poly *a, const uint8_t seed[MLDSA_CRHBYTES],
179
142
  uint16_t nonce)
@@ -183,22 +146,27 @@ __contract__(
183
146
  assigns(memory_slice(a, sizeof(mld_poly)))
184
147
  ensures(array_bound(a->coeffs, 0, MLDSA_N, -(MLDSA_GAMMA1 - 1), MLDSA_GAMMA1 + 1))
185
148
  );
186
- #endif /* MLD_CONFIG_PARAMETER_SET == 65 || MLD_CONFIG_SERIAL_FIPS202_ONLY */
149
+ #endif /* MLD_CONFIG_PARAMETER_SET == 65 || MLD_CONFIG_SERIAL_FIPS202_ONLY || \
150
+ MLD_CONFIG_REDUCE_RAM || MLD_UNIT_TEST */
187
151
 
188
- #if !defined(MLD_CONFIG_SERIAL_FIPS202_ONLY)
152
+ #if !defined(MLD_CONFIG_SERIAL_FIPS202_ONLY) && \
153
+ (!defined(MLD_CONFIG_REDUCE_RAM) || defined(MLD_UNIT_TEST))
189
154
  #define mld_poly_uniform_gamma1_4x MLD_NAMESPACE_KL(poly_uniform_gamma1_4x)
190
- /*************************************************
191
- * Name: mld_poly_uniform_gamma1_4x
155
+ /**
156
+ * Sample four polynomials with uniformly random coefficients in
157
+ * [-(MLDSA_GAMMA1 - 1), MLDSA_GAMMA1] by unpacking output streams of
158
+ * SHAKE256(seed|nonce_i).
192
159
  *
193
- * Description: Sample polynomial with uniformly random coefficients
194
- * in [-(MLDSA_GAMMA1 - 1), MLDSA_GAMMA1] by unpacking output
195
- * stream of SHAKE256(seed|nonce)
196
- *
197
- * Arguments: - mld_poly *a: pointer to output polynomial
198
- * - const uint8_t seed[]: byte array with seed of length
199
- * MLDSA_CRHBYTES
200
- * - uint16_t nonce: 16-bit nonce
201
- **************************************************/
160
+ * @param[out] r0 Pointer to first output polynomial.
161
+ * @param[out] r1 Pointer to second output polynomial.
162
+ * @param[out] r2 Pointer to third output polynomial.
163
+ * @param[out] r3 Pointer to fourth output polynomial.
164
+ * @param[in] seed Byte array with seed of length MLDSA_CRHBYTES.
165
+ * @param nonce0 First 16-bit nonce.
166
+ * @param nonce1 Second 16-bit nonce.
167
+ * @param nonce2 Third 16-bit nonce.
168
+ * @param nonce3 Fourth 16-bit nonce.
169
+ */
202
170
  MLD_INTERNAL_API
203
171
  void mld_poly_uniform_gamma1_4x(mld_poly *r0, mld_poly *r1, mld_poly *r2,
204
172
  mld_poly *r3,
@@ -220,20 +188,19 @@ __contract__(
220
188
  ensures(array_bound(r2->coeffs, 0, MLDSA_N, -(MLDSA_GAMMA1 - 1), MLDSA_GAMMA1 + 1))
221
189
  ensures(array_bound(r3->coeffs, 0, MLDSA_N, -(MLDSA_GAMMA1 - 1), MLDSA_GAMMA1 + 1))
222
190
  );
223
- #endif /* !MLD_CONFIG_SERIAL_FIPS202_ONLY */
191
+ #endif /* !MLD_CONFIG_SERIAL_FIPS202_ONLY && (!MLD_CONFIG_REDUCE_RAM || \
192
+ MLD_UNIT_TEST) */
193
+ #endif /* !MLD_CONFIG_NO_SIGN_API */
224
194
 
195
+ #if !defined(MLD_CONFIG_NO_SIGN_API) || !defined(MLD_CONFIG_NO_VERIFY_API)
225
196
  #define mld_poly_challenge MLD_NAMESPACE_KL(poly_challenge)
226
- /*************************************************
227
- * Name: mld_poly_challenge
228
- *
229
- * Description: Implementation of H. Samples polynomial with MLDSA_TAU nonzero
230
- * coefficients in {-1,1} using the output stream of
231
- * SHAKE256(seed).
197
+ /**
198
+ * Implementation of H. Samples polynomial with MLDSA_TAU nonzero coefficients
199
+ * in {-1, 1} using the output stream of SHAKE256(seed).
232
200
  *
233
- * Arguments: - mld_poly *c: pointer to output polynomial
234
- * - const uint8_t mu[]: byte array containing seed of length
235
- * MLDSA_CTILDEBYTES
236
- **************************************************/
201
+ * @param[out] c Pointer to output polynomial.
202
+ * @param[in] seed Byte array containing seed of length MLDSA_CTILDEBYTES.
203
+ */
237
204
  MLD_INTERNAL_API
238
205
  void mld_poly_challenge(mld_poly *c, const uint8_t seed[MLDSA_CTILDEBYTES])
239
206
  __contract__(
@@ -243,17 +210,17 @@ __contract__(
243
210
  /* All coefficients of c are -1, 0 or +1 */
244
211
  ensures(array_bound(c->coeffs, 0, MLDSA_N, -1, 2))
245
212
  );
213
+ #endif /* !MLD_CONFIG_NO_SIGN_API || !MLD_CONFIG_NO_VERIFY_API */
246
214
 
215
+ #if !defined(MLD_CONFIG_NO_KEYPAIR_API)
247
216
  #define mld_polyeta_pack MLD_NAMESPACE_KL(polyeta_pack)
248
- /*************************************************
249
- * Name: mld_polyeta_pack
217
+ /**
218
+ * Bit-pack polynomial with coefficients in [-MLDSA_ETA, MLDSA_ETA].
250
219
  *
251
- * Description: Bit-pack polynomial with coefficients in [-MLDSA_ETA,MLDSA_ETA].
252
- *
253
- * Arguments: - uint8_t *r: pointer to output byte array with at least
254
- * MLDSA_POLYETA_PACKEDBYTES bytes
255
- * - const mld_poly *a: pointer to input polynomial
256
- **************************************************/
220
+ * @param[out] r Pointer to output byte array with at least
221
+ * MLDSA_POLYETA_PACKEDBYTES bytes.
222
+ * @param[in] a Pointer to input polynomial.
223
+ */
257
224
  MLD_INTERNAL_API
258
225
  void mld_polyeta_pack(uint8_t r[MLDSA_POLYETA_PACKEDBYTES], const mld_poly *a)
259
226
  __contract__(
@@ -262,12 +229,14 @@ __contract__(
262
229
  requires(array_abs_bound(a->coeffs, 0, MLDSA_N, MLDSA_ETA + 1))
263
230
  assigns(memory_slice(r, MLDSA_POLYETA_PACKEDBYTES))
264
231
  );
232
+ #endif /* !MLD_CONFIG_NO_KEYPAIR_API */
265
233
 
234
+ #if !defined(MLD_CONFIG_NO_KEYPAIR_API) || !defined(MLD_CONFIG_NO_SIGN_API)
266
235
  /*
267
- * polyeta_unpack produces coefficients in [-MLDSA_ETA,MLDSA_ETA] for
236
+ * polyeta_unpack produces coefficients in [-MLDSA_ETA, MLDSA_ETA] for
268
237
  * well-formed inputs (i.e., those produced by polyeta_pack).
269
238
  * However, when passed an arbitrary byte array, it may produce smaller values,
270
- * i.e, values in [MLD_POLYETA_UNPACK_LOWER_BOUND,MLDSA_ETA]
239
+ * i.e., values in [MLD_POLYETA_UNPACK_LOWER_BOUND, MLDSA_ETA].
271
240
  * Even though this should never happen, we use use the bound for arbitrary
272
241
  * inputs in the CBMC proofs.
273
242
  */
@@ -280,14 +249,12 @@ __contract__(
280
249
  #endif
281
250
 
282
251
  #define mld_polyeta_unpack MLD_NAMESPACE_KL(polyeta_unpack)
283
- /*************************************************
284
- * Name: mld_polyeta_unpack
252
+ /**
253
+ * Unpack polynomial with coefficients in [-MLDSA_ETA, MLDSA_ETA].
285
254
  *
286
- * Description: Unpack polynomial with coefficients in [-MLDSA_ETA,MLDSA_ETA].
287
- *
288
- * Arguments: - mld_poly *r: pointer to output polynomial
289
- * - const uint8_t *a: byte array with bit-packed polynomial
290
- **************************************************/
255
+ * @param[out] r Pointer to output polynomial.
256
+ * @param[in] a Byte array with bit-packed polynomial.
257
+ */
291
258
  MLD_INTERNAL_API
292
259
  void mld_polyeta_unpack(mld_poly *r, const uint8_t a[MLDSA_POLYETA_PACKEDBYTES])
293
260
  __contract__(
@@ -296,18 +263,18 @@ __contract__(
296
263
  assigns(memory_slice(r, sizeof(mld_poly)))
297
264
  ensures(array_bound(r->coeffs, 0, MLDSA_N, MLD_POLYETA_UNPACK_LOWER_BOUND, MLDSA_ETA + 1))
298
265
  );
266
+ #endif /* !MLD_CONFIG_NO_KEYPAIR_API || !MLD_CONFIG_NO_SIGN_API */
299
267
 
268
+ #if !defined(MLD_CONFIG_NO_SIGN_API)
300
269
  #define mld_polyz_pack MLD_NAMESPACE_KL(polyz_pack)
301
- /*************************************************
302
- * Name: mld_polyz_pack
303
- *
304
- * Description: Bit-pack polynomial with coefficients
305
- * in [-(MLDSA_GAMMA1 - 1), MLDSA_GAMMA1].
270
+ /**
271
+ * Bit-pack polynomial with coefficients in
272
+ * [-(MLDSA_GAMMA1 - 1), MLDSA_GAMMA1].
306
273
  *
307
- * Arguments: - uint8_t *r: pointer to output byte array with at least
308
- * MLDSA_POLYZ_PACKEDBYTES bytes
309
- * - const mld_poly *a: pointer to input polynomial
310
- **************************************************/
274
+ * @param[out] r Pointer to output byte array with at least
275
+ * MLDSA_POLYZ_PACKEDBYTES bytes.
276
+ * @param[in] a Pointer to input polynomial.
277
+ */
311
278
  MLD_INTERNAL_API
312
279
  void mld_polyz_pack(uint8_t r[MLDSA_POLYZ_PACKEDBYTES], const mld_poly *a)
313
280
  __contract__(
@@ -316,18 +283,17 @@ __contract__(
316
283
  requires(array_bound(a->coeffs, 0, MLDSA_N, -(MLDSA_GAMMA1 - 1), MLDSA_GAMMA1 + 1))
317
284
  assigns(memory_slice(r, MLDSA_POLYZ_PACKEDBYTES))
318
285
  );
286
+ #endif /* !MLD_CONFIG_NO_SIGN_API */
319
287
 
320
-
288
+ #if !defined(MLD_CONFIG_NO_SIGN_API) || !defined(MLD_CONFIG_NO_VERIFY_API)
321
289
  #define mld_polyz_unpack MLD_NAMESPACE_KL(polyz_unpack)
322
- /*************************************************
323
- * Name: mld_polyz_unpack
290
+ /**
291
+ * Unpack polynomial z with coefficients in
292
+ * [-(MLDSA_GAMMA1 - 1), MLDSA_GAMMA1].
324
293
  *
325
- * Description: Unpack polynomial z with coefficients
326
- * in [-(MLDSA_GAMMA1 - 1), MLDSA_GAMMA1].
327
- *
328
- * Arguments: - mld_poly *r: pointer to output polynomial
329
- * - const uint8_t *a: byte array with bit-packed polynomial
330
- **************************************************/
294
+ * @param[out] r Pointer to output polynomial.
295
+ * @param[in] a Byte array with bit-packed polynomial.
296
+ */
331
297
  MLD_INTERNAL_API
332
298
  void mld_polyz_unpack(mld_poly *r, const uint8_t a[MLDSA_POLYZ_PACKEDBYTES])
333
299
  __contract__(
@@ -338,16 +304,14 @@ __contract__(
338
304
  );
339
305
 
340
306
  #define mld_polyw1_pack MLD_NAMESPACE_KL(polyw1_pack)
341
- /*************************************************
342
- * Name: mld_polyw1_pack
307
+ /**
308
+ * Bit-pack polynomial w1 with coefficients in [0, 15] or [0, 43]. Input
309
+ * coefficients are assumed to be standard representatives.
343
310
  *
344
- * Description: Bit-pack polynomial w1 with coefficients in [0,15] or [0,43].
345
- * Input coefficients are assumed to be standard representatives.
346
- *
347
- * Arguments: - uint8_t *r: pointer to output byte array with at least
348
- * MLDSA_POLYW1_PACKEDBYTES bytes
349
- * - const mld_poly *a: pointer to input polynomial
350
- **************************************************/
311
+ * @param[out] r Pointer to output byte array with at least
312
+ * MLDSA_POLYW1_PACKEDBYTES bytes.
313
+ * @param[in] a Pointer to input polynomial.
314
+ */
351
315
  MLD_INTERNAL_API
352
316
  void mld_polyw1_pack(uint8_t r[MLDSA_POLYW1_PACKEDBYTES], const mld_poly *a)
353
317
  __contract__(
@@ -356,5 +320,6 @@ __contract__(
356
320
  requires(array_bound(a->coeffs, 0, MLDSA_N, 0, (MLDSA_Q-1)/(2*MLDSA_GAMMA2)))
357
321
  assigns(memory_slice(r, MLDSA_POLYW1_PACKEDBYTES))
358
322
  );
323
+ #endif /* !MLD_CONFIG_NO_SIGN_API || !MLD_CONFIG_NO_VERIFY_API */
359
324
 
360
325
  #endif /* !MLD_POLY_KL_H */