mldsa_gh 0.1.0

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 (128) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +21 -0
  3. data/README.md +88 -0
  4. data/ext/mldsa_gh_native/extconf.rb +14 -0
  5. data/ext/mldsa_gh_native/mldsa_gh_native.c +222 -0
  6. data/ext/mldsa_gh_native/mldsa_gh_native_all.c +24 -0
  7. data/ext/mldsa_gh_native/mldsa_gh_native_all.h +26 -0
  8. data/ext/mldsa_gh_native/vendor/mldsa-native/BUILDING.md +108 -0
  9. data/ext/mldsa_gh_native/vendor/mldsa-native/LICENSE +305 -0
  10. data/ext/mldsa_gh_native/vendor/mldsa-native/README.md +247 -0
  11. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/README.md +23 -0
  12. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/mldsa_native.c +803 -0
  13. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/mldsa_native.h +956 -0
  14. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/mldsa_native_asm.S +830 -0
  15. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/mldsa_native_config.h +855 -0
  16. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/cbmc.h +233 -0
  17. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/common.h +301 -0
  18. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/context.h +152 -0
  19. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/ct.c +21 -0
  20. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/ct.h +373 -0
  21. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/debug.c +75 -0
  22. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/debug.h +125 -0
  23. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/fips202.c +270 -0
  24. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/fips202.h +224 -0
  25. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/fips202x4.c +187 -0
  26. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/fips202x4.h +125 -0
  27. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/keccakf1600.c +510 -0
  28. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/keccakf1600.h +110 -0
  29. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/auto.h +85 -0
  30. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/fips202_native_aarch64.h +69 -0
  31. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_scalar_aarch64_asm.S +378 -0
  32. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_v84a_aarch64_asm.S +207 -0
  33. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x2_v84a_aarch64_asm.S +262 -0
  34. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_scalar_hybrid_aarch64_asm.S +1080 -0
  35. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_v84a_scalar_hybrid_aarch64_asm.S +990 -0
  36. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccakf1600_round_constants.c +47 -0
  37. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x1_scalar.h +27 -0
  38. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x1_v84a.h +36 -0
  39. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x2_v84a.h +40 -0
  40. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x4_v8a_scalar.h +32 -0
  41. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x4_v8a_v84a_scalar.h +37 -0
  42. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/api.h +129 -0
  43. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/README.md +10 -0
  44. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/mve.h +67 -0
  45. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/fips202_native_armv81m.h +37 -0
  46. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.S +717 -0
  47. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.c +42 -0
  48. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccak_f1600_x4_state_extract_bytes_mve.S +334 -0
  49. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccak_f1600_x4_state_xor_bytes_mve.S +355 -0
  50. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccakf1600_round_constants.c +53 -0
  51. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/auto.h +35 -0
  52. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/keccak_f1600_x4_avx2.h +34 -0
  53. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/fips202_native_x86_64.h +45 -0
  54. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/keccak_f1600_x4_avx2_asm.S +488 -0
  55. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/keccakf1600_constants.c +52 -0
  56. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/meta.h +314 -0
  57. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/aarch64_zetas.c +248 -0
  58. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/arith_native_aarch64.h +367 -0
  59. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_intt_aarch64_asm.S +786 -0
  60. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_ntt_aarch64_asm.S +686 -0
  61. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_pointwise_montgomery_aarch64_asm.S +106 -0
  62. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_poly_caddq_aarch64_asm.S +69 -0
  63. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_poly_chknorm_aarch64_asm.S +76 -0
  64. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_poly_decompose_32_aarch64_asm.S +108 -0
  65. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_poly_decompose_88_aarch64_asm.S +108 -0
  66. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_poly_use_hint_32_aarch64_asm.S +125 -0
  67. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_poly_use_hint_88_aarch64_asm.S +133 -0
  68. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_polyvecl_pointwise_acc_montgomery_l4_aarch64_asm.S +157 -0
  69. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_polyvecl_pointwise_acc_montgomery_l5_aarch64_asm.S +173 -0
  70. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_polyvecl_pointwise_acc_montgomery_l7_aarch64_asm.S +205 -0
  71. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_polyz_unpack_17_aarch64_asm.S +103 -0
  72. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_polyz_unpack_19_aarch64_asm.S +100 -0
  73. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_rej_uniform_aarch64_asm.S +222 -0
  74. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_rej_uniform_eta2_aarch64_asm.S +170 -0
  75. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_rej_uniform_eta4_aarch64_asm.S +163 -0
  76. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/polyz_unpack_table.c +52 -0
  77. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_eta_table.c +547 -0
  78. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_table.c +63 -0
  79. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/api.h +617 -0
  80. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/meta.h +24 -0
  81. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/meta.h +323 -0
  82. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/arith_native_x86_64.h +330 -0
  83. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/consts.c +157 -0
  84. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/consts.h +27 -0
  85. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_intt_avx2_asm.S +2333 -0
  86. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_ntt_avx2_asm.S +2405 -0
  87. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_nttunpack_avx2_asm.S +254 -0
  88. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_pointwise_acc_l4_avx2_asm.S +173 -0
  89. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_pointwise_acc_l5_avx2_asm.S +189 -0
  90. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_pointwise_acc_l7_avx2_asm.S +221 -0
  91. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_pointwise_avx2_asm.S +158 -0
  92. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_poly_caddq_avx2_asm.S +199 -0
  93. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_poly_chknorm_avx2_asm.S +176 -0
  94. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_poly_decompose_32_avx2_asm.S +490 -0
  95. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_poly_decompose_88_avx2_asm.S +489 -0
  96. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_poly_use_hint_32_avx2_asm.S +123 -0
  97. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_poly_use_hint_88_avx2_asm.S +125 -0
  98. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_polyz_unpack_17_avx2_asm.S +355 -0
  99. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_polyz_unpack_19_avx2_asm.S +355 -0
  100. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_rej_uniform_avx2_asm.S +132 -0
  101. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_rej_uniform_eta2_avx2_asm.S +205 -0
  102. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_rej_uniform_eta4_avx2_asm.S +176 -0
  103. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/rej_uniform_table.c +161 -0
  104. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/packing.c +213 -0
  105. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/packing.h +277 -0
  106. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/params.h +153 -0
  107. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/poly.c +1066 -0
  108. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/poly.h +464 -0
  109. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/poly_kl.c +910 -0
  110. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/poly_kl.h +367 -0
  111. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/polyvec.c +509 -0
  112. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/polyvec.h +435 -0
  113. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/polyvec_lazy.c +311 -0
  114. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/polyvec_lazy.h +652 -0
  115. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/randombytes.h +26 -0
  116. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/reduce.h +144 -0
  117. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/rounding.h +265 -0
  118. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/sign.c +1720 -0
  119. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/sign.h +850 -0
  120. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/symmetric.h +68 -0
  121. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/sys.h +327 -0
  122. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/zetas.inc +55 -0
  123. data/lib/mldsa/parameter_set.rb +82 -0
  124. data/lib/mldsa/signing_key.rb +147 -0
  125. data/lib/mldsa/verify_key.rb +72 -0
  126. data/lib/mldsa/version.rb +7 -0
  127. data/lib/mldsa_gh.rb +93 -0
  128. metadata +225 -0
@@ -0,0 +1,323 @@
1
+ /*
2
+ * Copyright (c) The mlkem-native project authors
3
+ * Copyright (c) The mldsa-native project authors
4
+ * SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
5
+ */
6
+
7
+ #ifndef MLD_NATIVE_X86_64_META_H
8
+ #define MLD_NATIVE_X86_64_META_H
9
+
10
+ /* Identifier for this backend so that source and assembly files
11
+ * in the build can be appropriately guarded. */
12
+ #define MLD_ARITH_BACKEND_X86_64_DEFAULT
13
+
14
+ #define MLD_USE_NATIVE_NTT_CUSTOM_ORDER
15
+ #define MLD_USE_NATIVE_NTT
16
+ #define MLD_USE_NATIVE_INTT
17
+ #define MLD_USE_NATIVE_REJ_UNIFORM
18
+ #define MLD_USE_NATIVE_REJ_UNIFORM_ETA2
19
+ #define MLD_USE_NATIVE_REJ_UNIFORM_ETA4
20
+ #define MLD_USE_NATIVE_POLY_DECOMPOSE_32
21
+ #define MLD_USE_NATIVE_POLY_DECOMPOSE_88
22
+ #define MLD_USE_NATIVE_POLY_CADDQ
23
+ #define MLD_USE_NATIVE_POLY_USE_HINT_32
24
+ #define MLD_USE_NATIVE_POLY_USE_HINT_88
25
+ #define MLD_USE_NATIVE_POLY_CHKNORM
26
+ #define MLD_USE_NATIVE_POLYZ_UNPACK_17
27
+ #define MLD_USE_NATIVE_POLYZ_UNPACK_19
28
+ #define MLD_USE_NATIVE_POINTWISE_MONTGOMERY
29
+ #define MLD_USE_NATIVE_POLYVECL_POINTWISE_ACC_MONTGOMERY_L4
30
+ #define MLD_USE_NATIVE_POLYVECL_POINTWISE_ACC_MONTGOMERY_L5
31
+ #define MLD_USE_NATIVE_POLYVECL_POINTWISE_ACC_MONTGOMERY_L7
32
+
33
+ #if !defined(__ASSEMBLER__)
34
+ #include <string.h>
35
+ #include "../../common.h"
36
+ #include "../api.h"
37
+ #include "src/arith_native_x86_64.h"
38
+
39
+ static MLD_INLINE void mld_poly_permute_bitrev_to_custom(int32_t data[MLDSA_N])
40
+ {
41
+ if (mld_sys_check_capability(MLD_SYS_CAP_X86_64_AVX2))
42
+ {
43
+ mld_nttunpack_avx2_asm(data);
44
+ }
45
+ }
46
+
47
+ MLD_MUST_CHECK_RETURN_VALUE
48
+ static MLD_INLINE int mld_ntt_native(int32_t data[MLDSA_N])
49
+ {
50
+ if (!mld_sys_check_capability(MLD_SYS_CAP_X86_64_AVX2))
51
+ {
52
+ return MLD_NATIVE_FUNC_FALLBACK;
53
+ }
54
+
55
+ mld_ntt_avx2_asm(data, mld_qdata);
56
+ return MLD_NATIVE_FUNC_SUCCESS;
57
+ }
58
+
59
+ MLD_MUST_CHECK_RETURN_VALUE
60
+ static MLD_INLINE int mld_intt_native(int32_t data[MLDSA_N])
61
+ {
62
+ if (!mld_sys_check_capability(MLD_SYS_CAP_X86_64_AVX2))
63
+ {
64
+ return MLD_NATIVE_FUNC_FALLBACK;
65
+ }
66
+ mld_invntt_avx2_asm(data, mld_qdata);
67
+ return MLD_NATIVE_FUNC_SUCCESS;
68
+ }
69
+
70
+ MLD_MUST_CHECK_RETURN_VALUE
71
+ static MLD_INLINE int mld_rej_uniform_native(int32_t *r, unsigned len,
72
+ const uint8_t *buf,
73
+ unsigned buflen)
74
+ {
75
+ /* AVX2 implementation assumes specific buffer lengths */
76
+ if (!mld_sys_check_capability(MLD_SYS_CAP_X86_64_AVX2) || len != MLDSA_N ||
77
+ buflen != MLD_AVX2_REJ_UNIFORM_BUFLEN)
78
+ {
79
+ return MLD_NATIVE_FUNC_FALLBACK;
80
+ }
81
+
82
+ /* Safety: outlen is at most MLDSA_N and, hence, this cast is safe. */
83
+ return (int)mld_rej_uniform_avx2_asm(r, buf, mld_rej_uniform_table);
84
+ }
85
+
86
+ #if !defined(MLD_CONFIG_NO_KEYPAIR_API)
87
+ #if defined(MLD_CONFIG_MULTILEVEL_WITH_SHARED) || MLDSA_ETA == 2
88
+ MLD_MUST_CHECK_RETURN_VALUE
89
+ static MLD_INLINE int mld_rej_uniform_eta2_native(int32_t *r, unsigned len,
90
+ const uint8_t *buf,
91
+ unsigned buflen)
92
+ {
93
+ unsigned int outlen;
94
+ /* AVX2 implementation assumes specific buffer lengths */
95
+ if (!mld_sys_check_capability(MLD_SYS_CAP_X86_64_AVX2) || len != MLDSA_N ||
96
+ buflen != MLD_AVX2_REJ_UNIFORM_ETA2_BUFLEN)
97
+ {
98
+ return MLD_NATIVE_FUNC_FALLBACK;
99
+ }
100
+
101
+ /* Constant time: Inputs and outputs to this function are secret.
102
+ * It is safe to leak which coefficients are accepted/rejected.
103
+ * The assembly implementation must not leak any other information about the
104
+ * accepted coefficients. Constant-time testing cannot cover this, and we
105
+ * hence have to manually verify the assembly.
106
+ * We declassify prior the input data and mark the outputs as secret.
107
+ */
108
+ MLD_CT_TESTING_DECLASSIFY(buf, buflen);
109
+ outlen = mld_rej_uniform_eta2_avx2_asm(r, buf, mld_rej_uniform_table);
110
+ MLD_CT_TESTING_SECRET(r, sizeof(int32_t) * outlen);
111
+ /* Safety: outlen is at most MLDSA_N and, hence, this cast is safe. */
112
+ return (int)outlen;
113
+ }
114
+ #endif /* MLD_CONFIG_MULTILEVEL_WITH_SHARED || MLDSA_ETA == 2 */
115
+
116
+ #if defined(MLD_CONFIG_MULTILEVEL_WITH_SHARED) || MLDSA_ETA == 4
117
+ MLD_MUST_CHECK_RETURN_VALUE
118
+ static MLD_INLINE int mld_rej_uniform_eta4_native(int32_t *r, unsigned len,
119
+ const uint8_t *buf,
120
+ unsigned buflen)
121
+ {
122
+ unsigned int outlen;
123
+ /* AVX2 implementation assumes specific buffer lengths */
124
+ if (!mld_sys_check_capability(MLD_SYS_CAP_X86_64_AVX2) || len != MLDSA_N ||
125
+ buflen != MLD_AVX2_REJ_UNIFORM_ETA4_BUFLEN)
126
+ {
127
+ return MLD_NATIVE_FUNC_FALLBACK;
128
+ }
129
+
130
+ /* Constant time: Inputs and outputs to this function are secret.
131
+ * It is safe to leak which coefficients are accepted/rejected.
132
+ * The assembly implementation must not leak any other information about the
133
+ * accepted coefficients. Constant-time testing cannot cover this, and we
134
+ * hence have to manually verify the assembly.
135
+ * We declassify prior the input data and mark the outputs as secret.
136
+ */
137
+ MLD_CT_TESTING_DECLASSIFY(buf, buflen);
138
+ outlen = mld_rej_uniform_eta4_avx2_asm(r, buf, mld_rej_uniform_table);
139
+ MLD_CT_TESTING_SECRET(r, sizeof(int32_t) * outlen);
140
+ /* Safety: outlen is at most MLDSA_N and, hence, this cast is safe. */
141
+ return (int)outlen;
142
+ }
143
+ #endif /* MLD_CONFIG_MULTILEVEL_WITH_SHARED || MLDSA_ETA == 4 */
144
+ #endif /* !MLD_CONFIG_NO_KEYPAIR_API */
145
+
146
+ #if !defined(MLD_CONFIG_NO_SIGN_API)
147
+ #if defined(MLD_CONFIG_MULTILEVEL_WITH_SHARED) || \
148
+ (MLD_CONFIG_PARAMETER_SET == 65 || MLD_CONFIG_PARAMETER_SET == 87)
149
+ MLD_MUST_CHECK_RETURN_VALUE
150
+ static MLD_INLINE int mld_poly_decompose_32_native(int32_t *a1, int32_t *a0)
151
+ {
152
+ if (!mld_sys_check_capability(MLD_SYS_CAP_X86_64_AVX2))
153
+ {
154
+ return MLD_NATIVE_FUNC_FALLBACK;
155
+ }
156
+ mld_poly_decompose_32_avx2_asm(a1, a0);
157
+ return MLD_NATIVE_FUNC_SUCCESS;
158
+ }
159
+ #endif /* MLD_CONFIG_MULTILEVEL_WITH_SHARED || MLD_CONFIG_PARAMETER_SET == 65 \
160
+ || MLD_CONFIG_PARAMETER_SET == 87 */
161
+
162
+ #if defined(MLD_CONFIG_MULTILEVEL_WITH_SHARED) || MLD_CONFIG_PARAMETER_SET == 44
163
+ MLD_MUST_CHECK_RETURN_VALUE
164
+ static MLD_INLINE int mld_poly_decompose_88_native(int32_t *a1, int32_t *a0)
165
+ {
166
+ if (!mld_sys_check_capability(MLD_SYS_CAP_X86_64_AVX2))
167
+ {
168
+ return MLD_NATIVE_FUNC_FALLBACK;
169
+ }
170
+ mld_poly_decompose_88_avx2_asm(a1, a0);
171
+ return MLD_NATIVE_FUNC_SUCCESS;
172
+ }
173
+ #endif /* MLD_CONFIG_MULTILEVEL_WITH_SHARED || MLD_CONFIG_PARAMETER_SET == 44 \
174
+ */
175
+ #endif /* !MLD_CONFIG_NO_SIGN_API */
176
+
177
+ MLD_MUST_CHECK_RETURN_VALUE
178
+ static MLD_INLINE int mld_poly_caddq_native(int32_t a[MLDSA_N])
179
+ {
180
+ if (!mld_sys_check_capability(MLD_SYS_CAP_X86_64_AVX2))
181
+ {
182
+ return MLD_NATIVE_FUNC_FALLBACK;
183
+ }
184
+ mld_poly_caddq_avx2_asm(a);
185
+ return MLD_NATIVE_FUNC_SUCCESS;
186
+ }
187
+
188
+ #if !defined(MLD_CONFIG_NO_VERIFY_API)
189
+ #if defined(MLD_CONFIG_MULTILEVEL_WITH_SHARED) || \
190
+ (MLD_CONFIG_PARAMETER_SET == 65 || MLD_CONFIG_PARAMETER_SET == 87)
191
+ MLD_MUST_CHECK_RETURN_VALUE
192
+ static MLD_INLINE int mld_poly_use_hint_32_native(int32_t *a, const int32_t *h)
193
+ {
194
+ if (!mld_sys_check_capability(MLD_SYS_CAP_X86_64_AVX2))
195
+ {
196
+ return MLD_NATIVE_FUNC_FALLBACK;
197
+ }
198
+ mld_poly_use_hint_32_avx2_asm(a, h);
199
+ return MLD_NATIVE_FUNC_SUCCESS;
200
+ }
201
+ #endif /* MLD_CONFIG_MULTILEVEL_WITH_SHARED || MLD_CONFIG_PARAMETER_SET == 65 \
202
+ || MLD_CONFIG_PARAMETER_SET == 87 */
203
+
204
+ #if defined(MLD_CONFIG_MULTILEVEL_WITH_SHARED) || MLD_CONFIG_PARAMETER_SET == 44
205
+ MLD_MUST_CHECK_RETURN_VALUE
206
+ static MLD_INLINE int mld_poly_use_hint_88_native(int32_t *a, const int32_t *h)
207
+ {
208
+ if (!mld_sys_check_capability(MLD_SYS_CAP_X86_64_AVX2))
209
+ {
210
+ return MLD_NATIVE_FUNC_FALLBACK;
211
+ }
212
+ mld_poly_use_hint_88_avx2_asm(a, h);
213
+ return MLD_NATIVE_FUNC_SUCCESS;
214
+ }
215
+ #endif /* MLD_CONFIG_MULTILEVEL_WITH_SHARED || MLD_CONFIG_PARAMETER_SET == 44 \
216
+ */
217
+ #endif /* !MLD_CONFIG_NO_VERIFY_API */
218
+
219
+ MLD_MUST_CHECK_RETURN_VALUE
220
+ static MLD_INLINE int mld_poly_chknorm_native(const int32_t *a, int32_t B)
221
+ {
222
+ if (!mld_sys_check_capability(MLD_SYS_CAP_X86_64_AVX2))
223
+ {
224
+ return MLD_NATIVE_FUNC_FALLBACK;
225
+ }
226
+ return mld_poly_chknorm_avx2_asm(a, B);
227
+ }
228
+
229
+ #if !defined(MLD_CONFIG_NO_SIGN_API) || !defined(MLD_CONFIG_NO_VERIFY_API)
230
+ #if defined(MLD_CONFIG_MULTILEVEL_WITH_SHARED) || MLD_CONFIG_PARAMETER_SET == 44
231
+ MLD_MUST_CHECK_RETURN_VALUE
232
+ static MLD_INLINE int mld_polyz_unpack_17_native(int32_t *r, const uint8_t *a)
233
+ {
234
+ if (!mld_sys_check_capability(MLD_SYS_CAP_X86_64_AVX2))
235
+ {
236
+ return MLD_NATIVE_FUNC_FALLBACK;
237
+ }
238
+ mld_polyz_unpack_17_avx2_asm(r, a);
239
+ return MLD_NATIVE_FUNC_SUCCESS;
240
+ }
241
+ #endif /* MLD_CONFIG_MULTILEVEL_WITH_SHARED || MLD_CONFIG_PARAMETER_SET == 44 \
242
+ */
243
+
244
+ #if defined(MLD_CONFIG_MULTILEVEL_WITH_SHARED) || \
245
+ (MLD_CONFIG_PARAMETER_SET == 65 || MLD_CONFIG_PARAMETER_SET == 87)
246
+ MLD_MUST_CHECK_RETURN_VALUE
247
+ static MLD_INLINE int mld_polyz_unpack_19_native(int32_t *r, const uint8_t *a)
248
+ {
249
+ if (!mld_sys_check_capability(MLD_SYS_CAP_X86_64_AVX2))
250
+ {
251
+ return MLD_NATIVE_FUNC_FALLBACK;
252
+ }
253
+ mld_polyz_unpack_19_avx2_asm(r, a);
254
+ return MLD_NATIVE_FUNC_SUCCESS;
255
+ }
256
+ #endif /* MLD_CONFIG_MULTILEVEL_WITH_SHARED || MLD_CONFIG_PARAMETER_SET == 65 \
257
+ || MLD_CONFIG_PARAMETER_SET == 87 */
258
+ #endif /* !MLD_CONFIG_NO_SIGN_API || !MLD_CONFIG_NO_VERIFY_API */
259
+
260
+ #if !defined(MLD_CONFIG_NO_SIGN_API) || !defined(MLD_CONFIG_NO_VERIFY_API) || \
261
+ defined(MLD_CONFIG_REDUCE_RAM) || defined(MLD_UNIT_TEST)
262
+ MLD_MUST_CHECK_RETURN_VALUE
263
+ static MLD_INLINE int mld_poly_pointwise_montgomery_native(
264
+ int32_t a[MLDSA_N], const int32_t b[MLDSA_N])
265
+ {
266
+ if (!mld_sys_check_capability(MLD_SYS_CAP_X86_64_AVX2))
267
+ {
268
+ return MLD_NATIVE_FUNC_FALLBACK;
269
+ }
270
+ mld_pointwise_avx2_asm(a, b, mld_qdata);
271
+ return MLD_NATIVE_FUNC_SUCCESS;
272
+ }
273
+ #endif /* !MLD_CONFIG_NO_SIGN_API || !MLD_CONFIG_NO_VERIFY_API || \
274
+ MLD_CONFIG_REDUCE_RAM || MLD_UNIT_TEST */
275
+
276
+ #if defined(MLD_CONFIG_MULTILEVEL_WITH_SHARED) || MLDSA_L == 4
277
+ MLD_MUST_CHECK_RETURN_VALUE
278
+ static MLD_INLINE int mld_polyvecl_pointwise_acc_montgomery_l4_native(
279
+ int32_t w[MLDSA_N], const int32_t u[4][MLDSA_N],
280
+ const int32_t v[4][MLDSA_N])
281
+ {
282
+ if (!mld_sys_check_capability(MLD_SYS_CAP_X86_64_AVX2))
283
+ {
284
+ return MLD_NATIVE_FUNC_FALLBACK;
285
+ }
286
+ mld_pointwise_acc_l4_avx2_asm(w, u, v, mld_qdata);
287
+ return MLD_NATIVE_FUNC_SUCCESS;
288
+ }
289
+ #endif /* MLD_CONFIG_MULTILEVEL_WITH_SHARED || MLDSA_L == 4 */
290
+
291
+ #if defined(MLD_CONFIG_MULTILEVEL_WITH_SHARED) || MLDSA_L == 5
292
+ MLD_MUST_CHECK_RETURN_VALUE
293
+ static MLD_INLINE int mld_polyvecl_pointwise_acc_montgomery_l5_native(
294
+ int32_t w[MLDSA_N], const int32_t u[5][MLDSA_N],
295
+ const int32_t v[5][MLDSA_N])
296
+ {
297
+ if (!mld_sys_check_capability(MLD_SYS_CAP_X86_64_AVX2))
298
+ {
299
+ return MLD_NATIVE_FUNC_FALLBACK;
300
+ }
301
+ mld_pointwise_acc_l5_avx2_asm(w, u, v, mld_qdata);
302
+ return MLD_NATIVE_FUNC_SUCCESS;
303
+ }
304
+ #endif /* MLD_CONFIG_MULTILEVEL_WITH_SHARED || MLDSA_L == 5 */
305
+
306
+ #if defined(MLD_CONFIG_MULTILEVEL_WITH_SHARED) || MLDSA_L == 7
307
+ MLD_MUST_CHECK_RETURN_VALUE
308
+ static MLD_INLINE int mld_polyvecl_pointwise_acc_montgomery_l7_native(
309
+ int32_t w[MLDSA_N], const int32_t u[7][MLDSA_N],
310
+ const int32_t v[7][MLDSA_N])
311
+ {
312
+ if (!mld_sys_check_capability(MLD_SYS_CAP_X86_64_AVX2))
313
+ {
314
+ return MLD_NATIVE_FUNC_FALLBACK;
315
+ }
316
+ mld_pointwise_acc_l7_avx2_asm(w, u, v, mld_qdata);
317
+ return MLD_NATIVE_FUNC_SUCCESS;
318
+ }
319
+ #endif /* MLD_CONFIG_MULTILEVEL_WITH_SHARED || MLDSA_L == 7 */
320
+
321
+ #endif /* !__ASSEMBLER__ */
322
+
323
+ #endif /* !MLD_NATIVE_X86_64_META_H */
@@ -0,0 +1,330 @@
1
+ /*
2
+ * Copyright (c) The mlkem-native project authors
3
+ * Copyright (c) The mldsa-native project authors
4
+ * SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
5
+ */
6
+ #ifndef MLD_NATIVE_X86_64_SRC_ARITH_NATIVE_X86_64_H
7
+ #define MLD_NATIVE_X86_64_SRC_ARITH_NATIVE_X86_64_H
8
+ #include "../../../common.h"
9
+
10
+ #include "consts.h"
11
+
12
+ #define MLD_AVX2_REJ_UNIFORM_BUFLEN \
13
+ (5 * 168) /* REJ_UNIFORM_NBLOCKS * SHAKE128_RATE */
14
+
15
+
16
+ /*
17
+ * Sampling 256 coefficients mod 15 using rejection sampling from 4 bits.
18
+ * Expected number of required bytes: (256 * (16/15))/2 = 136.5 bytes.
19
+ * We sample 1 block (=136 bytes) of SHAKE256_RATE output initially.
20
+ * Sampling 2 blocks initially results in slightly worse performance.
21
+ */
22
+ #define MLD_AVX2_REJ_UNIFORM_ETA2_BUFLEN (1 * 136)
23
+
24
+ /*
25
+ * Sampling 256 coefficients mod 9 using rejection sampling from 4 bits.
26
+ * Expected number of required bytes: (256 * (16/9))/2 = 227.5 bytes.
27
+ * We sample 2 blocks (=272 bytes) of SHAKE256_RATE output initially.
28
+ */
29
+ #define MLD_AVX2_REJ_UNIFORM_ETA4_BUFLEN (2 * 136)
30
+
31
+ #define mld_rej_uniform_table MLD_NAMESPACE(mld_rej_uniform_table)
32
+ MLD_INTERNAL_DATA_DECLARATION const uint8_t mld_rej_uniform_table[256][8];
33
+
34
+ #define mld_ntt_avx2_asm MLD_NAMESPACE(ntt_avx2_asm)
35
+ MLD_SYSV_ABI
36
+ void mld_ntt_avx2_asm(int32_t *r, const int32_t *qdata)
37
+ /* This must be kept in sync with the HOL-Light specification
38
+ * in proofs/hol_light/x86_64/proofs/mldsa_ntt_avx2_asm.ml */
39
+ __contract__(
40
+ requires(memory_no_alias(r, sizeof(int32_t) * MLDSA_N))
41
+ /* check-magic: 8380417 == MLDSA_Q */
42
+ requires(array_abs_bound(r, 0, MLDSA_N, 8380417))
43
+ requires(qdata == mld_qdata)
44
+ assigns(memory_slice(r, sizeof(int32_t) * MLDSA_N))
45
+ /* check-magic: off */
46
+ ensures(array_abs_bound(r, 0, MLDSA_N, 42035262))
47
+ /* check-magic: on */
48
+ );
49
+
50
+ #define mld_invntt_avx2_asm MLD_NAMESPACE(invntt_avx2_asm)
51
+ MLD_SYSV_ABI
52
+ void mld_invntt_avx2_asm(int32_t *r, const int32_t *qdata)
53
+ /* This must be kept in sync with the HOL-Light specification
54
+ * in proofs/hol_light/x86_64/proofs/mldsa_intt_avx2_asm.ml */
55
+ __contract__(
56
+ requires(memory_no_alias(r, sizeof(int32_t) * MLDSA_N))
57
+ requires(array_abs_bound(r, 0, MLDSA_N, 8380417))
58
+ requires(qdata == mld_qdata)
59
+ assigns(memory_slice(r, sizeof(int32_t) * MLDSA_N))
60
+ /* check-magic: off */
61
+ ensures(array_abs_bound(r, 0, MLDSA_N, 6285313))
62
+ /* check-magic: on */
63
+ );
64
+
65
+ #define mld_nttunpack_avx2_asm MLD_NAMESPACE(nttunpack_avx2_asm)
66
+ MLD_SYSV_ABI
67
+ void mld_nttunpack_avx2_asm(int32_t *r)
68
+ /* This must be kept in sync with the HOL-Light specification
69
+ * in proofs/hol_light/x86_64/proofs/mldsa_nttunpack_avx2_asm.ml */
70
+ __contract__(
71
+ requires(memory_no_alias(r, sizeof(int32_t) * MLDSA_N))
72
+ requires(array_abs_bound(r, 0, MLDSA_N, 8380417))
73
+ assigns(memory_slice(r, sizeof(int32_t) * MLDSA_N))
74
+ /* Output is a permutation of input: every output coefficient
75
+ * is some input coefficient */
76
+ ensures(forall(i, 0, MLDSA_N, exists(j, 0, MLDSA_N,
77
+ r[i] == old(*(int32_t (*)[MLDSA_N])r)[j])))
78
+ );
79
+
80
+ #define mld_rej_uniform_avx2_asm MLD_NAMESPACE(rej_uniform_avx2_asm)
81
+ /* This contract must be kept in sync with the HOL-Light specification
82
+ * in proofs/hol_light/x86_64/proofs/mldsa_rej_uniform_avx2_asm.ml */
83
+ MLD_MUST_CHECK_RETURN_VALUE MLD_SYSV_ABI
84
+ unsigned mld_rej_uniform_avx2_asm(
85
+ int32_t *r, const uint8_t buf[MLD_AVX2_REJ_UNIFORM_BUFLEN],
86
+ const uint8_t table[256][8])
87
+ __contract__(
88
+ requires(memory_no_alias(r, sizeof(int32_t) * MLDSA_N))
89
+ requires(memory_no_alias(buf, 840))
90
+ requires(table == mld_rej_uniform_table)
91
+ assigns(memory_slice(r, sizeof(int32_t) * MLDSA_N))
92
+ ensures(return_value <= MLDSA_N)
93
+ ensures(array_bound(r, 0, return_value, 0, MLDSA_Q))
94
+ );
95
+
96
+ #if !defined(MLD_CONFIG_NO_KEYPAIR_API)
97
+ #define mld_rej_uniform_eta2_avx2_asm MLD_NAMESPACE(rej_uniform_eta2_avx2_asm)
98
+ /* This contract must be kept in sync with the HOL-Light specification
99
+ * in proofs/hol_light/x86_64/proofs/mldsa_rej_uniform_eta2_avx2_asm.ml */
100
+ MLD_MUST_CHECK_RETURN_VALUE MLD_SYSV_ABI
101
+ unsigned mld_rej_uniform_eta2_avx2_asm(
102
+ int32_t *r, const uint8_t buf[MLD_AVX2_REJ_UNIFORM_ETA2_BUFLEN],
103
+ const uint8_t table[256][8])
104
+ __contract__(
105
+ requires(memory_no_alias(r, sizeof(int32_t) * MLDSA_N))
106
+ requires(memory_no_alias(buf, MLD_AVX2_REJ_UNIFORM_ETA2_BUFLEN))
107
+ requires(table == mld_rej_uniform_table)
108
+ assigns(memory_slice(r, sizeof(int32_t) * MLDSA_N))
109
+ ensures(return_value <= MLDSA_N)
110
+ ensures(array_abs_bound(r, 0, return_value, 3))
111
+ );
112
+
113
+ #define mld_rej_uniform_eta4_avx2_asm MLD_NAMESPACE(rej_uniform_eta4_avx2_asm)
114
+ /* This contract must be kept in sync with the HOL-Light specification
115
+ * in proofs/hol_light/x86_64/proofs/mldsa_rej_uniform_eta4_avx2_asm.ml */
116
+ MLD_MUST_CHECK_RETURN_VALUE MLD_SYSV_ABI
117
+ unsigned mld_rej_uniform_eta4_avx2_asm(
118
+ int32_t *r, const uint8_t buf[MLD_AVX2_REJ_UNIFORM_ETA4_BUFLEN],
119
+ const uint8_t table[256][8])
120
+ __contract__(
121
+ requires(memory_no_alias(r, sizeof(int32_t) * MLDSA_N))
122
+ requires(memory_no_alias(buf, MLD_AVX2_REJ_UNIFORM_ETA4_BUFLEN))
123
+ requires(table == mld_rej_uniform_table)
124
+ assigns(memory_slice(r, sizeof(int32_t) * MLDSA_N))
125
+ ensures(return_value <= MLDSA_N)
126
+ ensures(array_abs_bound(r, 0, return_value, 5))
127
+ );
128
+ #endif /* !MLD_CONFIG_NO_KEYPAIR_API */
129
+
130
+ #if !defined(MLD_CONFIG_NO_SIGN_API)
131
+ #define mld_poly_decompose_32_avx2_asm MLD_NAMESPACE(poly_decompose_32_avx2_asm)
132
+ MLD_SYSV_ABI
133
+ void mld_poly_decompose_32_avx2_asm(int32_t *a1, int32_t *a0)
134
+ /* This must be kept in sync with the HOL-Light specification
135
+ * in proofs/hol_light/x86_64/proofs/mldsa_poly_decompose_32_avx2_asm.ml */
136
+ __contract__(
137
+ requires(memory_no_alias(a1, sizeof(int32_t) * MLDSA_N))
138
+ requires(memory_no_alias(a0, sizeof(int32_t) * MLDSA_N))
139
+ requires(array_bound(a0, 0, MLDSA_N, 0, MLDSA_Q))
140
+ assigns(memory_slice(a1, sizeof(int32_t) * MLDSA_N))
141
+ assigns(memory_slice(a0, sizeof(int32_t) * MLDSA_N))
142
+ /* check-magic: 16 == (MLDSA_Q - 1) / (2 * ((MLDSA_Q - 1) / 32)) */
143
+ ensures(array_bound(a1, 0, MLDSA_N, 0, 16))
144
+ /* check-magic: 261889 == (MLDSA_Q - 1) / 32 + 1 */
145
+ ensures(array_abs_bound(a0, 0, MLDSA_N, 261889))
146
+ );
147
+
148
+ #define mld_poly_decompose_88_avx2_asm MLD_NAMESPACE(poly_decompose_88_avx2_asm)
149
+ MLD_SYSV_ABI
150
+ void mld_poly_decompose_88_avx2_asm(int32_t *a1, int32_t *a0)
151
+ /* This must be kept in sync with the HOL-Light specification
152
+ * in proofs/hol_light/x86_64/proofs/mldsa_poly_decompose_88_avx2_asm.ml */
153
+ __contract__(
154
+ requires(memory_no_alias(a1, sizeof(int32_t) * MLDSA_N))
155
+ requires(memory_no_alias(a0, sizeof(int32_t) * MLDSA_N))
156
+ requires(array_bound(a0, 0, MLDSA_N, 0, MLDSA_Q))
157
+ assigns(memory_slice(a1, sizeof(int32_t) * MLDSA_N))
158
+ assigns(memory_slice(a0, sizeof(int32_t) * MLDSA_N))
159
+ /* check-magic: 44 == (MLDSA_Q - 1) / (2 * ((MLDSA_Q - 1) / 88)) */
160
+ ensures(array_bound(a1, 0, MLDSA_N, 0, 44))
161
+ /* check-magic: 95233 == (MLDSA_Q - 1) / 88 + 1 */
162
+ ensures(array_abs_bound(a0, 0, MLDSA_N, 95233))
163
+ );
164
+ #endif /* !MLD_CONFIG_NO_SIGN_API */
165
+
166
+ #define mld_poly_caddq_avx2_asm MLD_NAMESPACE(poly_caddq_avx2_asm)
167
+ MLD_SYSV_ABI
168
+ void mld_poly_caddq_avx2_asm(int32_t *r)
169
+ /* This must be kept in sync with the HOL-Light specification
170
+ * in proofs/hol_light/x86_64/proofs/mldsa_poly_caddq_avx2_asm.ml */
171
+ __contract__(
172
+ requires(memory_no_alias(r, sizeof(int32_t) * MLDSA_N))
173
+ requires(array_abs_bound(r, 0, MLDSA_N, MLDSA_Q))
174
+ assigns(memory_slice(r, sizeof(int32_t) * MLDSA_N))
175
+ ensures(array_bound(r, 0, MLDSA_N, 0, MLDSA_Q))
176
+ );
177
+
178
+ #if !defined(MLD_CONFIG_NO_VERIFY_API)
179
+ #define mld_poly_use_hint_32_avx2_asm MLD_NAMESPACE(poly_use_hint_32_avx2_asm)
180
+ MLD_SYSV_ABI
181
+ void mld_poly_use_hint_32_avx2_asm(int32_t *a, const int32_t *h)
182
+ /* This must be kept in sync with the HOL-Light specification
183
+ * in proofs/hol_light/x86_64/proofs/mldsa_poly_use_hint_32_avx2_asm.ml */
184
+ __contract__(
185
+ requires(memory_no_alias(a, sizeof(int32_t) * MLDSA_N))
186
+ requires(memory_no_alias(h, sizeof(int32_t) * MLDSA_N))
187
+ requires(array_bound(a, 0, MLDSA_N, 0, MLDSA_Q))
188
+ requires(array_bound(h, 0, MLDSA_N, 0, 2))
189
+ assigns(memory_slice(a, sizeof(int32_t) * MLDSA_N))
190
+ /* check-magic: 16 == (MLDSA_Q - 1) / (2 * ((MLDSA_Q - 1) / 32)) */
191
+ ensures(array_bound(a, 0, MLDSA_N, 0, 16))
192
+ );
193
+
194
+ #define mld_poly_use_hint_88_avx2_asm MLD_NAMESPACE(poly_use_hint_88_avx2_asm)
195
+ MLD_SYSV_ABI
196
+ void mld_poly_use_hint_88_avx2_asm(int32_t *a, const int32_t *h)
197
+ /* This must be kept in sync with the HOL-Light specification
198
+ * in proofs/hol_light/x86_64/proofs/mldsa_poly_use_hint_88_avx2_asm.ml */
199
+ __contract__(
200
+ requires(memory_no_alias(a, sizeof(int32_t) * MLDSA_N))
201
+ requires(memory_no_alias(h, sizeof(int32_t) * MLDSA_N))
202
+ requires(array_bound(a, 0, MLDSA_N, 0, MLDSA_Q))
203
+ requires(array_bound(h, 0, MLDSA_N, 0, 2))
204
+ assigns(memory_slice(a, sizeof(int32_t) * MLDSA_N))
205
+ /* check-magic: 44 == (MLDSA_Q - 1) / (2 * ((MLDSA_Q - 1) / 88)) */
206
+ ensures(array_bound(a, 0, MLDSA_N, 0, 44))
207
+ );
208
+ #endif /* !MLD_CONFIG_NO_VERIFY_API */
209
+
210
+ #define mld_poly_chknorm_avx2_asm MLD_NAMESPACE(poly_chknorm_avx2_asm)
211
+ MLD_MUST_CHECK_RETURN_VALUE MLD_SYSV_ABI
212
+ int mld_poly_chknorm_avx2_asm(const int32_t *a, int32_t B)
213
+ /* This must be kept in sync with the HOL-Light specification
214
+ * in proofs/hol_light/x86_64/proofs/mldsa_poly_chknorm_avx2_asm.ml */
215
+ __contract__(
216
+ requires(memory_no_alias(a, sizeof(int32_t) * MLDSA_N))
217
+ /* HOL Light precondition: abs(ival(x i)) < 2^31, i.e., a[i] != INT32_MIN */
218
+ requires(forall(k0, 0, MLDSA_N, a[k0] > INT32_MIN))
219
+ /* HOL Light precondition: 0 <= ival bound (asm computes B-1 internally) */
220
+ requires(B >= 0)
221
+ ensures(return_value == 0 || return_value == 1)
222
+ ensures((return_value == 0) == array_abs_bound(a, 0, MLDSA_N, B))
223
+ );
224
+
225
+ #if !defined(MLD_CONFIG_NO_SIGN_API) || !defined(MLD_CONFIG_NO_VERIFY_API)
226
+ #define mld_polyz_unpack_17_avx2_asm MLD_NAMESPACE(polyz_unpack_17_avx2_asm)
227
+ MLD_SYSV_ABI
228
+ void mld_polyz_unpack_17_avx2_asm(int32_t *r, const uint8_t *a)
229
+ /* This must be kept in sync with the HOL-Light specification
230
+ * in proofs/hol_light/x86_64/proofs/mldsa_polyz_unpack_17_avx2_asm.ml */
231
+ __contract__(
232
+ requires(memory_no_alias(r, sizeof(int32_t) * MLDSA_N))
233
+ requires(memory_no_alias(a, 576))
234
+ assigns(memory_slice(r, sizeof(int32_t) * MLDSA_N))
235
+ ensures(array_bound(r, 0, MLDSA_N, -((1 << 17) - 1), (1 << 17) + 1))
236
+ );
237
+
238
+ #define mld_polyz_unpack_19_avx2_asm MLD_NAMESPACE(polyz_unpack_19_avx2_asm)
239
+ MLD_SYSV_ABI
240
+ void mld_polyz_unpack_19_avx2_asm(int32_t *r, const uint8_t *a)
241
+ /* This must be kept in sync with the HOL-Light specification
242
+ * in proofs/hol_light/x86_64/proofs/mldsa_polyz_unpack_19_avx2_asm.ml */
243
+ __contract__(
244
+ requires(memory_no_alias(r, sizeof(int32_t) * MLDSA_N))
245
+ requires(memory_no_alias(a, 640))
246
+ assigns(memory_slice(r, sizeof(int32_t) * MLDSA_N))
247
+ ensures(array_bound(r, 0, MLDSA_N, -((1 << 19) - 1), (1 << 19) + 1))
248
+ );
249
+ #endif /* !MLD_CONFIG_NO_SIGN_API || !MLD_CONFIG_NO_VERIFY_API */
250
+
251
+ #define mld_pointwise_avx2_asm MLD_NAMESPACE(pointwise_avx2_asm)
252
+ MLD_SYSV_ABI
253
+ void mld_pointwise_avx2_asm(int32_t *a, const int32_t *b, const int32_t *qdata)
254
+ /* This must be kept in sync with the HOL-Light specification
255
+ * in proofs/hol_light/x86_64/proofs/mldsa_pointwise_avx2_asm.ml */
256
+ __contract__(
257
+ requires(memory_no_alias(a, sizeof(int32_t) * MLDSA_N))
258
+ requires(memory_no_alias(b, sizeof(int32_t) * MLDSA_N))
259
+ /* Input bound MLD_NTT_BOUND = 9 * MLD_FQMUL_BOUND, the guaranteed bound of
260
+ * any forward NTT implementation. Hardcoded here to keep this header free
261
+ * of poly.h. */
262
+ /* check-magic: 94279698 == 9 * ((5 * MLDSA_Q + 3) / 4) */
263
+ requires(array_abs_bound(a, 0, MLDSA_N, 94279698))
264
+ requires(array_abs_bound(b, 0, MLDSA_N, 94279698))
265
+ requires(qdata == mld_qdata)
266
+ assigns(memory_slice(a, sizeof(int32_t) * MLDSA_N))
267
+ ensures(array_abs_bound(a, 0, MLDSA_N, 8380417))
268
+ );
269
+
270
+ #define mld_pointwise_acc_l4_avx2_asm MLD_NAMESPACE(pointwise_acc_l4_avx2_asm)
271
+ MLD_SYSV_ABI
272
+ void mld_pointwise_acc_l4_avx2_asm(int32_t c[MLDSA_N],
273
+ const int32_t a[4][MLDSA_N],
274
+ const int32_t b[4][MLDSA_N],
275
+ const int32_t *qdata)
276
+ /* This must be kept in sync with the HOL-Light specification
277
+ * in proofs/hol_light/x86_64/proofs/mldsa_pointwise_acc_l4_avx2_asm.ml */
278
+ __contract__(
279
+ requires(memory_no_alias(c, sizeof(int32_t) * MLDSA_N))
280
+ requires(memory_no_alias(a, sizeof(int32_t) * 4 * MLDSA_N))
281
+ requires(memory_no_alias(b, sizeof(int32_t) * 4 * MLDSA_N))
282
+ requires(forall(l0, 0, 4, array_abs_bound(a[l0], 0, MLDSA_N, 8380417)))
283
+ /* check-magic: 94279698 == 9 * ((5 * MLDSA_Q + 3) / 4) */
284
+ requires(forall(l1, 0, 4, array_abs_bound(b[l1], 0, MLDSA_N, 94279698)))
285
+ requires(qdata == mld_qdata)
286
+ assigns(memory_slice(c, sizeof(int32_t) * MLDSA_N))
287
+ ensures(array_abs_bound(c, 0, MLDSA_N, 8380417))
288
+ );
289
+
290
+ #define mld_pointwise_acc_l5_avx2_asm MLD_NAMESPACE(pointwise_acc_l5_avx2_asm)
291
+ MLD_SYSV_ABI
292
+ void mld_pointwise_acc_l5_avx2_asm(int32_t c[MLDSA_N],
293
+ const int32_t a[5][MLDSA_N],
294
+ const int32_t b[5][MLDSA_N],
295
+ const int32_t *qdata)
296
+ /* This must be kept in sync with the HOL-Light specification
297
+ * in proofs/hol_light/x86_64/proofs/mldsa_pointwise_acc_l5_avx2_asm.ml */
298
+ __contract__(
299
+ requires(memory_no_alias(c, sizeof(int32_t) * MLDSA_N))
300
+ requires(memory_no_alias(a, sizeof(int32_t) * 5 * MLDSA_N))
301
+ requires(memory_no_alias(b, sizeof(int32_t) * 5 * MLDSA_N))
302
+ requires(forall(l0, 0, 5, array_abs_bound(a[l0], 0, MLDSA_N, 8380417)))
303
+ /* check-magic: 94279698 == 9 * ((5 * MLDSA_Q + 3) / 4) */
304
+ requires(forall(l1, 0, 5, array_abs_bound(b[l1], 0, MLDSA_N, 94279698)))
305
+ requires(qdata == mld_qdata)
306
+ assigns(memory_slice(c, sizeof(int32_t) * MLDSA_N))
307
+ ensures(array_abs_bound(c, 0, MLDSA_N, 8380417))
308
+ );
309
+
310
+ #define mld_pointwise_acc_l7_avx2_asm MLD_NAMESPACE(pointwise_acc_l7_avx2_asm)
311
+ MLD_SYSV_ABI
312
+ void mld_pointwise_acc_l7_avx2_asm(int32_t c[MLDSA_N],
313
+ const int32_t a[7][MLDSA_N],
314
+ const int32_t b[7][MLDSA_N],
315
+ const int32_t *qdata)
316
+ /* This must be kept in sync with the HOL-Light specification
317
+ * in proofs/hol_light/x86_64/proofs/mldsa_pointwise_acc_l7_avx2_asm.ml */
318
+ __contract__(
319
+ requires(memory_no_alias(c, sizeof(int32_t) * MLDSA_N))
320
+ requires(memory_no_alias(a, sizeof(int32_t) * 7 * MLDSA_N))
321
+ requires(memory_no_alias(b, sizeof(int32_t) * 7 * MLDSA_N))
322
+ requires(forall(l0, 0, 7, array_abs_bound(a[l0], 0, MLDSA_N, 8380417)))
323
+ /* check-magic: 94279698 == 9 * ((5 * MLDSA_Q + 3) / 4) */
324
+ requires(forall(l1, 0, 7, array_abs_bound(b[l1], 0, MLDSA_N, 94279698)))
325
+ requires(qdata == mld_qdata)
326
+ assigns(memory_slice(c, sizeof(int32_t) * MLDSA_N))
327
+ ensures(array_abs_bound(c, 0, MLDSA_N, 8380417))
328
+ );
329
+
330
+ #endif /* !MLD_NATIVE_X86_64_SRC_ARITH_NATIVE_X86_64_H */