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
@@ -15,21 +15,22 @@
15
15
  /* Absolute exclusive upper bound for the output of the inverse NTT*/
16
16
  #define MLD_INTT_BOUND MLDSA_Q
17
17
 
18
+ /**
19
+ * Element of R_q = Z_q[X]/(X^n + 1). Represents polynomial
20
+ * coeffs[0] + X*coeffs[1] + X^2*coeffs[2] + ... + X^{n-1}*coeffs[n-1].
21
+ */
18
22
  typedef struct
19
23
  {
20
- int32_t coeffs[MLDSA_N];
24
+ int32_t coeffs[MLDSA_N]; /**< Polynomial coefficients. */
21
25
  } MLD_ALIGN mld_poly;
22
26
 
23
27
  #define mld_poly_reduce MLD_NAMESPACE(poly_reduce)
24
- /*************************************************
25
- * Name: mld_poly_reduce
26
- *
27
- * Description: Inplace reduction of all coefficients of polynomial to
28
- * representative in
29
- *[-MLD_REDUCE32_RANGE_MAX,MLD_REDUCE32_RANGE_MAX].
28
+ /**
29
+ * In-place reduction of all coefficients of polynomial to representative in
30
+ * [-MLD_REDUCE32_RANGE_MAX, MLD_REDUCE32_RANGE_MAX].
30
31
  *
31
- * Arguments: - mld_poly *a: pointer to input/output polynomial
32
- **************************************************/
32
+ * @param[in,out] a Pointer to input/output polynomial.
33
+ */
33
34
  MLD_INTERNAL_API
34
35
  void mld_poly_reduce(mld_poly *a)
35
36
  __contract__(
@@ -40,14 +41,12 @@ __contract__(
40
41
  );
41
42
 
42
43
  #define mld_poly_caddq MLD_NAMESPACE(poly_caddq)
43
- /*************************************************
44
- * Name: mld_poly_caddq
44
+ /**
45
+ * For all coefficients of in/out polynomial add MLDSA_Q if coefficient is
46
+ * negative.
45
47
  *
46
- * Description: For all coefficients of in/out polynomial add MLDSA_Q if
47
- * coefficient is negative.
48
- *
49
- * Arguments: - mld_poly *a: pointer to input/output polynomial
50
- **************************************************/
48
+ * @param[in,out] a Pointer to input/output polynomial.
49
+ */
51
50
  MLD_INTERNAL_API
52
51
  void mld_poly_caddq(mld_poly *a)
53
52
  __contract__(
@@ -57,16 +56,16 @@ __contract__(
57
56
  ensures(array_bound(a->coeffs, 0, MLDSA_N, 0, MLDSA_Q))
58
57
  );
59
58
 
59
+ #if !defined(MLD_CONFIG_NO_KEYPAIR_API) || !defined(MLD_CONFIG_NO_SIGN_API) || \
60
+ defined(MLD_CONFIG_REDUCE_RAM) || defined(MLD_UNIT_TEST)
60
61
  #define mld_poly_add MLD_NAMESPACE(poly_add)
61
- /*************************************************
62
- * Name: mld_poly_add
62
+ /**
63
+ * Add polynomials. No modular reduction is performed.
63
64
  *
64
- * Description: Add polynomials. No modular reduction is performed.
65
- *
66
- * Arguments: - r: Pointer to input-output polynomial to be added to.
67
- * - b: Pointer to input polynomial that should be added
68
- * to r. Must be disjoint from r.
69
- **************************************************/
65
+ * @param[in,out] r Pointer to input-output polynomial to be added to.
66
+ * @param[in] b Pointer to input polynomial that should be added to r.
67
+ * Must be disjoint from r.
68
+ */
70
69
 
71
70
  /*
72
71
  * NOTE: The reference implementation uses a 3-argument poly_add.
@@ -84,18 +83,18 @@ __contract__(
84
83
  ensures(forall(k3, 0, MLDSA_N, r->coeffs[k3] < MLD_REDUCE32_DOMAIN_MAX))
85
84
  ensures(forall(k4, 0, MLDSA_N, r->coeffs[k4] >= INT32_MIN))
86
85
  );
86
+ #endif /* !MLD_CONFIG_NO_KEYPAIR_API || !MLD_CONFIG_NO_SIGN_API || \
87
+ MLD_CONFIG_REDUCE_RAM || MLD_UNIT_TEST */
87
88
 
89
+ #if !defined(MLD_CONFIG_NO_SIGN_API) || !defined(MLD_CONFIG_NO_VERIFY_API)
88
90
  #define mld_poly_sub MLD_NAMESPACE(poly_sub)
89
- /*************************************************
90
- * Name: mld_poly_sub
91
- *
92
- * Description: Subtract polynomials. No modular reduction is
93
- * performed.
91
+ /**
92
+ * Subtract polynomials. No modular reduction is performed.
94
93
  *
95
- * Arguments: - mld_poly *r: Pointer to input-output polynomial.
96
- * - const mld_poly *b: Pointer to input polynomial that should be
97
- * subtracted from r. Must be disjoint from r.
98
- **************************************************/
94
+ * @param[in,out] r Pointer to input-output polynomial.
95
+ * @param[in] b Pointer to input polynomial that should be subtracted from
96
+ * r. Must be disjoint from r.
97
+ */
99
98
  /*
100
99
  * NOTE: The reference implementation uses a 3-argument poly_sub.
101
100
  * We specialize to the accumulator form to avoid reasoning about aliasing.
@@ -110,16 +109,16 @@ __contract__(
110
109
  assigns(memory_slice(r, sizeof(mld_poly)))
111
110
  ensures(array_bound(r->coeffs, 0, MLDSA_N, INT32_MIN, MLD_REDUCE32_DOMAIN_MAX))
112
111
  );
112
+ #endif /* !MLD_CONFIG_NO_SIGN_API || !MLD_CONFIG_NO_VERIFY_API */
113
113
 
114
+ #if !defined(MLD_CONFIG_NO_VERIFY_API)
114
115
  #define mld_poly_shiftl MLD_NAMESPACE(poly_shiftl)
115
- /*************************************************
116
- * Name: mld_poly_shiftl
117
- *
118
- * Description: Multiply polynomial by 2^MLDSA_D without modular reduction.
119
- *Assumes input coefficients to be less than 2^{31-MLDSA_D} in absolute value.
116
+ /**
117
+ * Multiply polynomial by 2^MLDSA_D without modular reduction. Assumes input
118
+ * coefficients to be less than 2^{31-MLDSA_D} in absolute value.
120
119
  *
121
- * Arguments: - mld_poly *a: pointer to input/output polynomial
122
- **************************************************/
120
+ * @param[in,out] a Pointer to input/output polynomial.
121
+ */
123
122
  MLD_INTERNAL_API
124
123
  void mld_poly_shiftl(mld_poly *a)
125
124
  __contract__(
@@ -128,16 +127,14 @@ __contract__(
128
127
  assigns(memory_slice(a, sizeof(mld_poly)))
129
128
  ensures(array_bound(a->coeffs, 0, MLDSA_N, 0, MLDSA_Q))
130
129
  );
130
+ #endif /* !MLD_CONFIG_NO_VERIFY_API */
131
131
 
132
132
  #define mld_poly_ntt MLD_NAMESPACE(poly_ntt)
133
- /*************************************************
134
- * Name: mld_poly_ntt
135
- *
136
- * Description: Inplace forward NTT. Coefficients can grow by
137
- * 8*MLDSA_Q in absolute value.
133
+ /**
134
+ * In-place forward NTT. Coefficients can grow by 8*MLDSA_Q in absolute value.
138
135
  *
139
- * Arguments: - mld_poly *a: pointer to input/output polynomial
140
- **************************************************/
136
+ * @param[in,out] a Pointer to input/output polynomial.
137
+ */
141
138
  MLD_INTERNAL_API
142
139
  void mld_poly_ntt(mld_poly *a)
143
140
  __contract__(
@@ -149,16 +146,14 @@ __contract__(
149
146
 
150
147
 
151
148
  #define mld_poly_invntt_tomont MLD_NAMESPACE(poly_invntt_tomont)
152
- /*************************************************
153
- * Name: mld_poly_invntt_tomont
149
+ /**
150
+ * In-place inverse NTT and multiplication by 2^{32}.
154
151
  *
155
- * Description: Inplace inverse NTT and multiplication by 2^{32}.
156
- * Input coefficients need to be less than MLDSA_Q in absolute
157
- * value and output coefficients are bounded by
158
- * MLD_INTT_BOUND.
152
+ * Input coefficients need to be less than MLDSA_Q in absolute value and
153
+ * output coefficients are bounded by MLD_INTT_BOUND.
159
154
  *
160
- * Arguments: - mld_poly *a: pointer to input/output polynomial
161
- **************************************************/
155
+ * @param[in,out] a Pointer to input/output polynomial.
156
+ */
162
157
  MLD_INTERNAL_API
163
158
  void mld_poly_invntt_tomont(mld_poly *a)
164
159
  __contract__(
@@ -168,71 +163,69 @@ __contract__(
168
163
  ensures(array_abs_bound(a->coeffs, 0, MLDSA_N, MLD_INTT_BOUND))
169
164
  );
170
165
 
166
+ #if !defined(MLD_CONFIG_NO_SIGN_API) || !defined(MLD_CONFIG_NO_VERIFY_API) || \
167
+ defined(MLD_CONFIG_REDUCE_RAM) || defined(MLD_UNIT_TEST)
171
168
  #define mld_poly_pointwise_montgomery MLD_NAMESPACE(poly_pointwise_montgomery)
172
- /*************************************************
173
- * Name: mld_poly_pointwise_montgomery
174
- *
175
- * Description: Pointwise multiplication of polynomials in NTT domain
176
- * representation and multiplication of resulting polynomial
177
- * by 2^{-32}.
178
- *
179
- * Arguments: - mld_poly *c: pointer to output polynomial
180
- * - const mld_poly *a: pointer to first input polynomial
181
- * - const mld_poly *b: pointer to second input polynomial
182
- **************************************************/
169
+ /**
170
+ * Pointwise multiplication of polynomials in NTT domain representation and
171
+ * multiplication of resulting polynomial by 2^{-32}. Destructive in the first
172
+ * argument.
173
+ *
174
+ * @param[in,out] a Pointer to first input/output polynomial. On entry, holds
175
+ * the first multiplicand; on exit, holds the product
176
+ * a * b * 2^{-32}.
177
+ * @param[in] b Pointer to second input polynomial.
178
+ */
183
179
  MLD_INTERNAL_API
184
- void mld_poly_pointwise_montgomery(mld_poly *c, const mld_poly *a,
185
- const mld_poly *b)
180
+ void mld_poly_pointwise_montgomery(mld_poly *a, const mld_poly *b)
186
181
  __contract__(
187
182
  requires(memory_no_alias(a, sizeof(mld_poly)))
188
183
  requires(memory_no_alias(b, sizeof(mld_poly)))
189
- requires(memory_no_alias(c, sizeof(mld_poly)))
190
184
  requires(array_abs_bound(a->coeffs, 0, MLDSA_N, MLD_NTT_BOUND))
191
185
  requires(array_abs_bound(b->coeffs, 0, MLDSA_N, MLD_NTT_BOUND))
192
- assigns(memory_slice(c, sizeof(mld_poly)))
193
- ensures(array_abs_bound(c->coeffs, 0, MLDSA_N, MLDSA_Q))
186
+ assigns(memory_slice(a, sizeof(mld_poly)))
187
+ ensures(array_abs_bound(a->coeffs, 0, MLDSA_N, MLDSA_Q))
194
188
  );
189
+ #endif /* !MLD_CONFIG_NO_SIGN_API || !MLD_CONFIG_NO_VERIFY_API || \
190
+ MLD_CONFIG_REDUCE_RAM || MLD_UNIT_TEST */
195
191
 
192
+ #if !defined(MLD_CONFIG_NO_KEYPAIR_API)
196
193
  #define mld_poly_power2round MLD_NAMESPACE(poly_power2round)
197
- /*************************************************
198
- * Name: mld_poly_power2round
199
- *
200
- * Description: For all coefficients c of the input polynomial,
201
- * compute c0, c1 such that c mod MLDSA_Q = c1*2^MLDSA_D + c0
202
- * with -2^{MLDSA_D-1} < c0 <= 2^{MLDSA_D-1}. Assumes coefficients
203
- *to be standard representatives.
204
- *
205
- * Arguments: - mld_poly *a1: pointer to output polynomial with coefficients
206
- *c1
207
- * - mld_poly *a0: pointer to output polynomial with coefficients
208
- *c0
209
- * - const mld_poly *a: pointer to input polynomial
210
- **************************************************/
194
+ /**
195
+ * For all coefficients c of the input polynomial, compute c0, c1 such that
196
+ * c mod MLDSA_Q = c1*2^MLDSA_D + c0 with -2^{MLDSA_D-1} < c0 <= 2^{MLDSA_D-1}.
197
+ * Assumes coefficients to be standard representatives.
198
+ *
199
+ * @param[out] a1 Pointer to output polynomial with coefficients c1.
200
+ * @param[out] a0 Pointer to output polynomial with coefficients c0; may alias
201
+ * the input polynomial a.
202
+ * @param[in] a Pointer to input polynomial.
203
+ */
211
204
  MLD_INTERNAL_API
212
205
  void mld_poly_power2round(mld_poly *a1, mld_poly *a0, const mld_poly *a)
213
206
  __contract__(
214
207
  requires(memory_no_alias(a0, sizeof(mld_poly)))
215
208
  requires(memory_no_alias(a1, sizeof(mld_poly)))
216
- requires(memory_no_alias(a, sizeof(mld_poly)))
209
+ /* The implementation does not require a0 == a, but the single call site
210
+ * aliases them and asserting equality simplifies the proof. */
211
+ requires(a0 == a)
217
212
  requires(array_bound(a->coeffs, 0, MLDSA_N, 0, MLDSA_Q))
218
213
  assigns(memory_slice(a1, sizeof(mld_poly)))
219
214
  assigns(memory_slice(a0, sizeof(mld_poly)))
220
215
  ensures(array_bound(a0->coeffs, 0, MLDSA_N, -(MLD_2_POW_D/2)+1, (MLD_2_POW_D/2)+1))
221
216
  ensures(array_bound(a1->coeffs, 0, MLDSA_N, 0, ((MLDSA_Q - 1) / MLD_2_POW_D) + 1))
222
217
  );
218
+ #endif /* !MLD_CONFIG_NO_KEYPAIR_API */
223
219
 
224
220
  #define mld_poly_uniform MLD_NAMESPACE(poly_uniform)
225
- /*************************************************
226
- * Name: mld_poly_uniform
227
- *
228
- * Description: Sample polynomial with uniformly random coefficients
229
- * in [0,MLDSA_Q-1] by performing rejection sampling on the
230
- * output stream of SHAKE128(seed|nonce)
221
+ /**
222
+ * Sample polynomial with uniformly random coefficients in [0, MLDSA_Q-1] by
223
+ * performing rejection sampling on the output stream of SHAKE128(seed|nonce).
231
224
  *
232
- * Arguments: - mld_poly *a: pointer to output polynomial
233
- * - const uint8_t seed[]: byte array with seed of length
234
- * MLDSA_SEEDBYTES and the packed 2-byte nonce
235
- **************************************************/
225
+ * @param[out] a Pointer to output polynomial.
226
+ * @param[in] seed Byte array with seed of length MLDSA_SEEDBYTES and the
227
+ * packed 2-byte nonce.
228
+ */
236
229
  MLD_INTERNAL_API
237
230
  void mld_poly_uniform(mld_poly *a, const uint8_t seed[MLDSA_SEEDBYTES + 2])
238
231
  __contract__(
@@ -242,21 +235,20 @@ __contract__(
242
235
  ensures(array_bound(a->coeffs, 0, MLDSA_N, 0, MLDSA_Q))
243
236
  );
244
237
 
245
- #if !defined(MLD_CONFIG_SERIAL_FIPS202_ONLY) && !defined(MLD_CONFIG_REDUCE_RAM)
238
+ #if !defined(MLD_CONFIG_SERIAL_FIPS202_ONLY) && \
239
+ (!defined(MLD_CONFIG_REDUCE_RAM) || defined(MLD_UNIT_TEST))
246
240
  #define mld_poly_uniform_4x MLD_NAMESPACE(poly_uniform_4x)
247
- /*************************************************
248
- * Name: mld_poly_uniform_x4
249
- *
250
- * Description: Generate four polynomials using rejection sampling
251
- * on (pseudo-)uniformly random bytes sampled from a seed.
252
- *
253
- * Arguments: - mld_poly *vec0, *vec1, *vec2, *vec3:
254
- * Pointers to 4 polynomials to be sampled.
255
- * - uint8_t seed[4][MLD_ALIGN_UP(MLDSA_SEEDBYTES + 2)]:
256
- * Pointer consecutive array of seed buffers of size
257
- * MLDSA_SEEDBYTES + 2 each, plus padding for alignment.
258
- *
259
- **************************************************/
241
+ /**
242
+ * Generate four polynomials using rejection sampling on (pseudo-)uniformly
243
+ * random bytes sampled from a seed.
244
+ *
245
+ * @param[out] vec0 Pointer to first polynomial to be sampled.
246
+ * @param[out] vec1 Pointer to second polynomial to be sampled.
247
+ * @param[out] vec2 Pointer to third polynomial to be sampled.
248
+ * @param[out] vec3 Pointer to fourth polynomial to be sampled.
249
+ * @param[in] seed Pointer to consecutive array of seed buffers of size
250
+ * MLDSA_SEEDBYTES + 2 each, plus padding for alignment.
251
+ */
260
252
  MLD_INTERNAL_API
261
253
  void mld_poly_uniform_4x(mld_poly *vec0, mld_poly *vec1, mld_poly *vec2,
262
254
  mld_poly *vec3,
@@ -276,19 +268,19 @@ __contract__(
276
268
  ensures(array_bound(vec2->coeffs, 0, MLDSA_N, 0, MLDSA_Q))
277
269
  ensures(array_bound(vec3->coeffs, 0, MLDSA_N, 0, MLDSA_Q))
278
270
  );
279
- #endif /* !MLD_CONFIG_SERIAL_FIPS202_ONLY && !MLD_CONFIG_REDUCE_RAM */
271
+ #endif /* !MLD_CONFIG_SERIAL_FIPS202_ONLY && (!MLD_CONFIG_REDUCE_RAM || \
272
+ MLD_UNIT_TEST) */
280
273
 
274
+ #if !defined(MLD_CONFIG_NO_KEYPAIR_API)
281
275
  #define mld_polyt1_pack MLD_NAMESPACE(polyt1_pack)
282
- /*************************************************
283
- * Name: mld_polyt1_pack
276
+ /**
277
+ * Bit-pack polynomial t1 with coefficients fitting in 10 bits. Input
278
+ * coefficients are assumed to be standard representatives.
284
279
  *
285
- * Description: Bit-pack polynomial t1 with coefficients fitting in 10 bits.
286
- * Input coefficients are assumed to be standard representatives.
287
- *
288
- * Arguments: - uint8_t *r: pointer to output byte array with at least
289
- * MLDSA_POLYT1_PACKEDBYTES bytes
290
- * - const mld_poly *a: pointer to input polynomial
291
- **************************************************/
280
+ * @param[out] r Pointer to output byte array with at least
281
+ * MLDSA_POLYT1_PACKEDBYTES bytes.
282
+ * @param[in] a Pointer to input polynomial.
283
+ */
292
284
  MLD_INTERNAL_API
293
285
  void mld_polyt1_pack(uint8_t r[MLDSA_POLYT1_PACKEDBYTES], const mld_poly *a)
294
286
  __contract__(
@@ -297,17 +289,17 @@ __contract__(
297
289
  requires(array_bound(a->coeffs, 0, MLDSA_N, 0, 1 << 10))
298
290
  assigns(memory_slice(r, MLDSA_POLYT1_PACKEDBYTES))
299
291
  );
292
+ #endif /* !MLD_CONFIG_NO_KEYPAIR_API */
300
293
 
294
+ #if !defined(MLD_CONFIG_NO_VERIFY_API)
301
295
  #define mld_polyt1_unpack MLD_NAMESPACE(polyt1_unpack)
302
- /*************************************************
303
- * Name: mld_polyt1_unpack
296
+ /**
297
+ * Unpack polynomial t1 with 10-bit coefficients. Output coefficients are
298
+ * standard representatives.
304
299
  *
305
- * Description: Unpack polynomial t1 with 10-bit coefficients.
306
- * Output coefficients are standard representatives.
307
- *
308
- * Arguments: - mld_poly *r: pointer to output polynomial
309
- * - const uint8_t *a: byte array with bit-packed polynomial
310
- **************************************************/
300
+ * @param[out] r Pointer to output polynomial.
301
+ * @param[in] a Byte array with bit-packed polynomial.
302
+ */
311
303
  MLD_INTERNAL_API
312
304
  void mld_polyt1_unpack(mld_poly *r, const uint8_t a[MLDSA_POLYT1_PACKEDBYTES])
313
305
  __contract__(
@@ -316,18 +308,17 @@ __contract__(
316
308
  assigns(memory_slice(r, sizeof(mld_poly)))
317
309
  ensures(array_bound(r->coeffs, 0, MLDSA_N, 0, 1 << 10))
318
310
  );
311
+ #endif /* !MLD_CONFIG_NO_VERIFY_API */
319
312
 
313
+ #if !defined(MLD_CONFIG_NO_KEYPAIR_API)
320
314
  #define mld_polyt0_pack MLD_NAMESPACE(polyt0_pack)
321
- /*************************************************
322
- * Name: mld_polyt0_pack
323
- *
324
- * Description: Bit-pack polynomial t0 with coefficients in ]-2^{MLDSA_D-1},
325
- * 2^{MLDSA_D-1}].
315
+ /**
316
+ * Bit-pack polynomial t0 with coefficients in ]-2^{MLDSA_D-1}, 2^{MLDSA_D-1}].
326
317
  *
327
- * Arguments: - uint8_t *r: pointer to output byte array with at least
328
- * MLDSA_POLYT0_PACKEDBYTES bytes
329
- * - const mld_poly *a: pointer to input polynomial
330
- **************************************************/
318
+ * @param[out] r Pointer to output byte array with at least
319
+ * MLDSA_POLYT0_PACKEDBYTES bytes.
320
+ * @param[in] a Pointer to input polynomial.
321
+ */
331
322
  MLD_INTERNAL_API
332
323
  void mld_polyt0_pack(uint8_t r[MLDSA_POLYT0_PACKEDBYTES], const mld_poly *a)
333
324
  __contract__(
@@ -336,18 +327,16 @@ __contract__(
336
327
  requires(array_bound(a->coeffs, 0, MLDSA_N, -(1<<(MLDSA_D-1)) + 1, (1<<(MLDSA_D-1)) + 1))
337
328
  assigns(memory_slice(r, MLDSA_POLYT0_PACKEDBYTES))
338
329
  );
330
+ #endif /* !MLD_CONFIG_NO_KEYPAIR_API */
339
331
 
340
-
332
+ #if !defined(MLD_CONFIG_NO_SIGN_API) || defined(MLD_UNIT_TEST)
341
333
  #define mld_polyt0_unpack MLD_NAMESPACE(polyt0_unpack)
342
- /*************************************************
343
- * Name: mld_polyt0_unpack
334
+ /**
335
+ * Unpack polynomial t0 with coefficients in ]-2^{MLDSA_D-1}, 2^{MLDSA_D-1}].
344
336
  *
345
- * Description: Unpack polynomial t0 with coefficients in ]-2^{MLDSA_D-1},
346
- *2^{MLDSA_D-1}].
347
- *
348
- * Arguments: - mld_poly *r: pointer to output polynomial
349
- * - const uint8_t *a: byte array with bit-packed polynomial
350
- **************************************************/
337
+ * @param[out] r Pointer to output polynomial.
338
+ * @param[in] a Byte array with bit-packed polynomial.
339
+ */
351
340
  MLD_INTERNAL_API
352
341
  void mld_polyt0_unpack(mld_poly *r, const uint8_t a[MLDSA_POLYT0_PACKEDBYTES])
353
342
  __contract__(
@@ -356,29 +345,25 @@ __contract__(
356
345
  assigns(memory_slice(r, sizeof(mld_poly)))
357
346
  ensures(array_bound(r->coeffs, 0, MLDSA_N, -(1<<(MLDSA_D-1)) + 1, (1<<(MLDSA_D-1)) + 1))
358
347
  );
348
+ #endif /* !MLD_CONFIG_NO_SIGN_API || MLD_UNIT_TEST */
359
349
 
360
350
  #define mld_poly_chknorm MLD_NAMESPACE(poly_chknorm)
361
- /*************************************************
362
- * Name: mld_poly_chknorm
363
- *
364
- * Description: Check infinity norm of polynomial against given bound.
365
- * Assumes input coefficients were reduced by mld_reduce32().
351
+ /**
352
+ * Check infinity norm of polynomial against given bound. Assumes input
353
+ * coefficients were reduced by mld_reduce32().
366
354
  *
367
- * Arguments: - const mld_poly *a: pointer to polynomial
368
- * - int32_t B: norm bound
355
+ * @spec{The definition in FIPS-204 requires signed canonical reduction prior
356
+ * to applying the bounds check. However, `-B < (a mod± MLDSA_Q) < B` is
357
+ * equivalent to `-B < a < B` under the assumption that
358
+ * `B <= MLDSA_Q - MLD_REDUCE32_RANGE_MAX` (cf. the assertion in the code).
359
+ * Hence, the present spec and implementation are correct without reduction.}
369
360
  *
370
- * Returns 0 if norm is strictly smaller than
371
- * B <= (MLDSA_Q - MLD_REDUCE32_RANGE_MAX) and 0xFFFFFFFF otherwise.
361
+ * @param[in] a Pointer to polynomial.
362
+ * @param B Norm bound.
372
363
  *
373
- * Specification: The definition of this FIPS-204 requires signed canonical
374
- * reduction prior to applying the bounds check.
375
- * However, `-B < (a mod± MLDSA_Q) < B` is equivalent to
376
- * `-B < a < B` under the assumption that
377
- * `B <= MLDSA_Q - MLD_REDUCE32_RANGE_MAX` (cf. the assertion in
378
- * the code). Hence, the present spec and implementation are
379
- * correct without reduction.
380
- *
381
- **************************************************/
364
+ * @return 0 if norm is strictly smaller than
365
+ * B <= (MLDSA_Q - MLD_REDUCE32_RANGE_MAX) and 0xFFFFFFFF otherwise.
366
+ */
382
367
  MLD_INTERNAL_API
383
368
  MLD_MUST_CHECK_RETURN_VALUE
384
369
  uint32_t mld_poly_chknorm(const mld_poly *a, int32_t B)