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,47 @@
1
+ /*
2
+ * Copyright (c) The mldsa-native project authors
3
+ * SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
4
+ */
5
+
6
+ /*
7
+ * WARNING: This file is auto-generated from scripts/autogen
8
+ * in the mldsa-native repository.
9
+ * Do not modify it directly.
10
+ */
11
+
12
+ #include "../../../../common.h"
13
+
14
+ #if (defined(MLD_FIPS202_AARCH64_NEED_X1_SCALAR) || \
15
+ defined(MLD_FIPS202_AARCH64_NEED_X1_V84A) || \
16
+ defined(MLD_FIPS202_AARCH64_NEED_X2_V84A) || \
17
+ defined(MLD_FIPS202_AARCH64_NEED_X4_V8A_SCALAR_HYBRID) || \
18
+ defined(MLD_FIPS202_AARCH64_NEED_X4_V8A_V84A_SCALAR_HYBRID)) && \
19
+ !defined(MLD_CONFIG_MULTILEVEL_NO_SHARED)
20
+
21
+ #include "fips202_native_aarch64.h"
22
+
23
+ MLD_ALIGN MLD_INTERNAL_DATA_DEFINITION const uint64_t
24
+ mld_keccakf1600_round_constants[24] = {
25
+ 0x0000000000000001, 0x0000000000008082, 0x800000000000808a,
26
+ 0x8000000080008000, 0x000000000000808b, 0x0000000080000001,
27
+ 0x8000000080008081, 0x8000000000008009, 0x000000000000008a,
28
+ 0x0000000000000088, 0x0000000080008009, 0x000000008000000a,
29
+ 0x000000008000808b, 0x800000000000008b, 0x8000000000008089,
30
+ 0x8000000000008003, 0x8000000000008002, 0x8000000000000080,
31
+ 0x000000000000800a, 0x800000008000000a, 0x8000000080008081,
32
+ 0x8000000000008080, 0x0000000080000001, 0x8000000080008008,
33
+ };
34
+
35
+ #else /* (MLD_FIPS202_AARCH64_NEED_X1_SCALAR || \
36
+ MLD_FIPS202_AARCH64_NEED_X1_V84A || MLD_FIPS202_AARCH64_NEED_X2_V84A \
37
+ || MLD_FIPS202_AARCH64_NEED_X4_V8A_SCALAR_HYBRID || \
38
+ MLD_FIPS202_AARCH64_NEED_X4_V8A_V84A_SCALAR_HYBRID) && \
39
+ !MLD_CONFIG_MULTILEVEL_NO_SHARED */
40
+
41
+ MLD_EMPTY_CU(fips202_aarch64_round_constants)
42
+
43
+ #endif /* !((MLD_FIPS202_AARCH64_NEED_X1_SCALAR || \
44
+ MLD_FIPS202_AARCH64_NEED_X1_V84A || MLD_FIPS202_AARCH64_NEED_X2_V84A \
45
+ || MLD_FIPS202_AARCH64_NEED_X4_V8A_SCALAR_HYBRID || \
46
+ MLD_FIPS202_AARCH64_NEED_X4_V8A_V84A_SCALAR_HYBRID) && \
47
+ !MLD_CONFIG_MULTILEVEL_NO_SHARED) */
@@ -0,0 +1,27 @@
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_FIPS202_NATIVE_AARCH64_X1_SCALAR_H
8
+ #define MLD_FIPS202_NATIVE_AARCH64_X1_SCALAR_H
9
+
10
+ /* Part of backend API */
11
+ #define MLD_USE_NATIVE_FIPS202_X1
12
+ /* Guard for assembly file */
13
+ #define MLD_FIPS202_AARCH64_NEED_X1_SCALAR
14
+
15
+ #if !defined(__ASSEMBLER__)
16
+ #include "../api.h"
17
+ #include "src/fips202_native_aarch64.h"
18
+ MLD_MUST_CHECK_RETURN_VALUE
19
+ static MLD_INLINE int mld_keccak_f1600_x1_native(uint64_t *state)
20
+ {
21
+ mld_keccak_f1600_x1_scalar_aarch64_asm(state,
22
+ mld_keccakf1600_round_constants);
23
+ return MLD_NATIVE_FUNC_SUCCESS;
24
+ }
25
+ #endif /* !__ASSEMBLER__ */
26
+
27
+ #endif /* !MLD_FIPS202_NATIVE_AARCH64_X1_SCALAR_H */
@@ -0,0 +1,36 @@
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_FIPS202_NATIVE_AARCH64_X1_V84A_H
8
+ #define MLD_FIPS202_NATIVE_AARCH64_X1_V84A_H
9
+
10
+ #if !defined(__ARM_FEATURE_SHA3)
11
+ #error This backend can only be used if SHA3 extensions are available.
12
+ #endif
13
+
14
+ /* Part of backend API */
15
+ #define MLD_USE_NATIVE_FIPS202_X1
16
+ /* Guard for assembly file */
17
+ #define MLD_FIPS202_AARCH64_NEED_X1_V84A
18
+
19
+ #if !defined(__ASSEMBLER__)
20
+ #include "../api.h"
21
+ #include "src/fips202_native_aarch64.h"
22
+ MLD_MUST_CHECK_RETURN_VALUE
23
+ static MLD_INLINE int mld_keccak_f1600_x1_native(uint64_t *state)
24
+ {
25
+ if (!mld_sys_check_capability(MLD_SYS_CAP_AARCH64_NEON) ||
26
+ !mld_sys_check_capability(MLD_SYS_CAP_AARCH64_SHA3))
27
+ {
28
+ return MLD_NATIVE_FUNC_FALLBACK;
29
+ }
30
+
31
+ mld_keccak_f1600_x1_v84a_aarch64_asm(state, mld_keccakf1600_round_constants);
32
+ return MLD_NATIVE_FUNC_SUCCESS;
33
+ }
34
+ #endif /* !__ASSEMBLER__ */
35
+
36
+ #endif /* !MLD_FIPS202_NATIVE_AARCH64_X1_V84A_H */
@@ -0,0 +1,40 @@
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_FIPS202_NATIVE_AARCH64_X2_V84A_H
8
+ #define MLD_FIPS202_NATIVE_AARCH64_X2_V84A_H
9
+
10
+ #if !defined(__ARM_FEATURE_SHA3)
11
+ #error This backend can only be used if SHA3 extensions are available.
12
+ #endif
13
+
14
+ /* Part of backend API */
15
+ #define MLD_USE_NATIVE_FIPS202_X4
16
+ /* Guard for assembly file */
17
+ #define MLD_FIPS202_AARCH64_NEED_X2_V84A
18
+
19
+ #if !defined(__ASSEMBLER__)
20
+ #include "../api.h"
21
+ #include "src/fips202_native_aarch64.h"
22
+
23
+ MLD_MUST_CHECK_RETURN_VALUE
24
+ static MLD_INLINE int mld_keccak_f1600_x4_native(uint64_t *state)
25
+ {
26
+ if (!mld_sys_check_capability(MLD_SYS_CAP_AARCH64_NEON) ||
27
+ !mld_sys_check_capability(MLD_SYS_CAP_AARCH64_SHA3))
28
+ {
29
+ return MLD_NATIVE_FUNC_FALLBACK;
30
+ }
31
+
32
+ mld_keccak_f1600_x2_v84a_aarch64_asm(state + 0 * 25,
33
+ mld_keccakf1600_round_constants);
34
+ mld_keccak_f1600_x2_v84a_aarch64_asm(state + 2 * 25,
35
+ mld_keccakf1600_round_constants);
36
+ return MLD_NATIVE_FUNC_SUCCESS;
37
+ }
38
+ #endif /* !__ASSEMBLER__ */
39
+
40
+ #endif /* !MLD_FIPS202_NATIVE_AARCH64_X2_V84A_H */
@@ -0,0 +1,32 @@
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_FIPS202_NATIVE_AARCH64_X4_V8A_SCALAR_H
8
+ #define MLD_FIPS202_NATIVE_AARCH64_X4_V8A_SCALAR_H
9
+
10
+ /* Part of backend API */
11
+ #define MLD_USE_NATIVE_FIPS202_X4
12
+ /* Guard for assembly file */
13
+ #define MLD_FIPS202_AARCH64_NEED_X4_V8A_SCALAR_HYBRID
14
+
15
+ #if !defined(__ASSEMBLER__)
16
+ #include "../api.h"
17
+ #include "src/fips202_native_aarch64.h"
18
+ MLD_MUST_CHECK_RETURN_VALUE
19
+ static MLD_INLINE int mld_keccak_f1600_x4_native(uint64_t *state)
20
+ {
21
+ if (!mld_sys_check_capability(MLD_SYS_CAP_AARCH64_NEON))
22
+ {
23
+ return MLD_NATIVE_FUNC_FALLBACK;
24
+ }
25
+
26
+ mld_keccak_f1600_x4_v8a_scalar_hybrid_aarch64_asm(
27
+ state, mld_keccakf1600_round_constants);
28
+ return MLD_NATIVE_FUNC_SUCCESS;
29
+ }
30
+ #endif /* !__ASSEMBLER__ */
31
+
32
+ #endif /* !MLD_FIPS202_NATIVE_AARCH64_X4_V8A_SCALAR_H */
@@ -0,0 +1,37 @@
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_FIPS202_NATIVE_AARCH64_X4_V8A_V84A_SCALAR_H
8
+ #define MLD_FIPS202_NATIVE_AARCH64_X4_V8A_V84A_SCALAR_H
9
+
10
+ #if !defined(__ARM_FEATURE_SHA3)
11
+ #error This backend can only be used if SHA3 extensions are available.
12
+ #endif
13
+
14
+ /* Part of backend API */
15
+ #define MLD_USE_NATIVE_FIPS202_X4
16
+ /* Guard for assembly file */
17
+ #define MLD_FIPS202_AARCH64_NEED_X4_V8A_V84A_SCALAR_HYBRID
18
+
19
+ #if !defined(__ASSEMBLER__)
20
+ #include "../api.h"
21
+ #include "src/fips202_native_aarch64.h"
22
+ MLD_MUST_CHECK_RETURN_VALUE
23
+ static MLD_INLINE int mld_keccak_f1600_x4_native(uint64_t *state)
24
+ {
25
+ if (!mld_sys_check_capability(MLD_SYS_CAP_AARCH64_NEON) ||
26
+ !mld_sys_check_capability(MLD_SYS_CAP_AARCH64_SHA3))
27
+ {
28
+ return MLD_NATIVE_FUNC_FALLBACK;
29
+ }
30
+
31
+ mld_keccak_f1600_x4_v8a_v84a_scalar_hybrid_aarch64_asm(
32
+ state, mld_keccakf1600_round_constants);
33
+ return MLD_NATIVE_FUNC_SUCCESS;
34
+ }
35
+ #endif /* !__ASSEMBLER__ */
36
+
37
+ #endif /* !MLD_FIPS202_NATIVE_AARCH64_X4_V8A_V84A_SCALAR_H */
@@ -0,0 +1,129 @@
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_FIPS202_NATIVE_API_H
8
+ #define MLD_FIPS202_NATIVE_API_H
9
+ /*
10
+ * FIPS-202 native interface
11
+ *
12
+ * This header is primarily for documentation purposes.
13
+ * It should not be included by backend implementations.
14
+ */
15
+
16
+ #include "../../cbmc.h"
17
+ #include "../../common.h"
18
+
19
+ /* Backends must return MLD_NATIVE_FUNC_SUCCESS upon success. */
20
+ #define MLD_NATIVE_FUNC_SUCCESS (0)
21
+ /* Backends may return MLD_NATIVE_FUNC_FALLBACK to signal to the frontend that
22
+ * the target/parameters are unsupported; typically, this would be because of
23
+ * dependencies on CPU features not detected on the host CPU. In this case,
24
+ * the frontend falls back to the default C implementation.
25
+ *
26
+ * IMPORTANT: Backend implementations must ensure that the decision of whether
27
+ * to fallback (return MLD_NATIVE_FUNC_FALLBACK) or not must never depend on
28
+ * the input data itself. Fallback decisions may only depend on system
29
+ * capabilities (e.g., CPU features) and, where present, length information.
30
+ * This requirement applies to all backend functions to maintain constant-time
31
+ * properties.
32
+ */
33
+ #define MLD_NATIVE_FUNC_FALLBACK (-1)
34
+
35
+ /*
36
+ * This is the C<->native interface allowing for the drop-in
37
+ * of custom Keccak-F1600 implementations.
38
+ *
39
+ * A _backend_ is a specific implementation of parts of this interface.
40
+ *
41
+ * You can replace 1-fold or 4-fold batched Keccak-F1600.
42
+ * To enable, set MLD_USE_NATIVE_FIPS202_X1 or MLD_USE_NATIVE_FIPS202_X4
43
+ * in your backend, and define the inline wrappers mld_keccak_f1600_x1_native()
44
+ * and/or mld_keccak_f1600_x4_native(), respectively, to forward to your
45
+ * implementation.
46
+ */
47
+
48
+ #if defined(MLD_USE_NATIVE_FIPS202_X1)
49
+ MLD_MUST_CHECK_RETURN_VALUE
50
+ static MLD_INLINE int mld_keccak_f1600_x1_native(uint64_t *state)
51
+ __contract__(
52
+ requires(memory_no_alias(state, sizeof(uint64_t) * 25 * 1))
53
+ assigns(memory_slice(state, sizeof(uint64_t) * 25 * 1))
54
+ ensures(return_value == MLD_NATIVE_FUNC_FALLBACK || return_value == MLD_NATIVE_FUNC_SUCCESS)
55
+ ensures((return_value == MLD_NATIVE_FUNC_FALLBACK) ==> array_unchanged_u64(state, 25 * 1))
56
+ );
57
+ #endif /* MLD_USE_NATIVE_FIPS202_X1 */
58
+ #if defined(MLD_USE_NATIVE_FIPS202_X4)
59
+ MLD_MUST_CHECK_RETURN_VALUE
60
+ static MLD_INLINE int mld_keccak_f1600_x4_native(uint64_t *state)
61
+ __contract__(
62
+ requires(memory_no_alias(state, sizeof(uint64_t) * 25 * 4))
63
+ assigns(memory_slice(state, sizeof(uint64_t) * 25 * 4))
64
+ ensures(return_value == MLD_NATIVE_FUNC_FALLBACK || return_value == MLD_NATIVE_FUNC_SUCCESS)
65
+ ensures((return_value == MLD_NATIVE_FUNC_FALLBACK) ==> array_unchanged_u64(state, 25 * 4))
66
+ );
67
+ #endif /* MLD_USE_NATIVE_FIPS202_X4 */
68
+
69
+ /*
70
+ * Native x4 XOR bytes and extract bytes interface.
71
+ *
72
+ * These functions allow backends to provide optimized implementations for
73
+ * XORing input data into the state and extracting output data from the state.
74
+ * This is particularly useful for backends that use a different internal state
75
+ * representation (e.g., bit-interleaved), as conversion can happen during
76
+ * XOR/extract rather than before/after each permutation.
77
+ *
78
+ * NOTE: We assume that the custom representation of the zero state is the
79
+ * all-zero state.
80
+ *
81
+ * MLD_USE_NATIVE_FIPS202_X4_XOR_BYTES: Backend provides native XOR bytes
82
+ * MLD_USE_NATIVE_FIPS202_X4_EXTRACT_BYTES: Backend provides native extract
83
+ * bytes
84
+ */
85
+
86
+ #if defined(MLD_USE_NATIVE_FIPS202_X4_XOR_BYTES)
87
+ MLD_MUST_CHECK_RETURN_VALUE
88
+ static MLD_INLINE int mld_keccakf1600_xor_bytes_x4_native(
89
+ uint64_t *state, const unsigned char *data0, const unsigned char *data1,
90
+ const unsigned char *data2, const unsigned char *data3, unsigned offset,
91
+ unsigned length)
92
+ __contract__(
93
+ requires(0 <= offset && offset <= 25 * sizeof(uint64_t) &&
94
+ 0 <= length && length <= 25 * sizeof(uint64_t) - offset)
95
+ requires(memory_no_alias(state, sizeof(uint64_t) * 25 * 4))
96
+ requires(memory_no_alias(data0, length))
97
+ requires((data0 == data1 &&
98
+ data0 == data2 &&
99
+ data0 == data3) ||
100
+ (memory_no_alias(data1, length) &&
101
+ memory_no_alias(data2, length) &&
102
+ memory_no_alias(data3, length)))
103
+ assigns(memory_slice(state, sizeof(uint64_t) * 25 * 4))
104
+ ensures(return_value == MLD_NATIVE_FUNC_FALLBACK || return_value == MLD_NATIVE_FUNC_SUCCESS)
105
+ ensures((return_value == MLD_NATIVE_FUNC_FALLBACK) ==> array_unchanged_u64(state, 25 * 4)));
106
+ #endif /* MLD_USE_NATIVE_FIPS202_X4_XOR_BYTES */
107
+
108
+ #if defined(MLD_USE_NATIVE_FIPS202_X4_EXTRACT_BYTES)
109
+ MLD_MUST_CHECK_RETURN_VALUE
110
+ static MLD_INLINE int mld_keccakf1600_extract_bytes_x4_native(
111
+ uint64_t *state, unsigned char *data0, unsigned char *data1,
112
+ unsigned char *data2, unsigned char *data3, unsigned offset,
113
+ unsigned length)
114
+ __contract__(
115
+ requires(0 <= offset && offset <= 25 * sizeof(uint64_t) &&
116
+ 0 <= length && length <= 25 * sizeof(uint64_t) - offset)
117
+ requires(memory_no_alias(state, sizeof(uint64_t) * 25 * 4))
118
+ requires(memory_no_alias(data0, length))
119
+ requires(memory_no_alias(data1, length))
120
+ requires(memory_no_alias(data2, length))
121
+ requires(memory_no_alias(data3, length))
122
+ assigns(memory_slice(data0, length))
123
+ assigns(memory_slice(data1, length))
124
+ assigns(memory_slice(data2, length))
125
+ assigns(memory_slice(data3, length))
126
+ ensures(return_value == MLD_NATIVE_FUNC_FALLBACK || return_value == MLD_NATIVE_FUNC_SUCCESS));
127
+ #endif /* MLD_USE_NATIVE_FIPS202_X4_EXTRACT_BYTES */
128
+
129
+ #endif /* !MLD_FIPS202_NATIVE_API_H */
@@ -0,0 +1,10 @@
1
+ [//]: # (SPDX-License-Identifier: CC-BY-4.0)
2
+
3
+ # FIPS202 backend for Armv8.1-M + MVE
4
+
5
+ This directory contains the source code for a FIPS202 backend targeting
6
+ the Armv8.1-M + MVE/Helium architecture. It is automatically derived from
7
+ the respective development source in [dev/fips202/armv81m](../../../../../dev/fips202/armv81m).
8
+
9
+ **Warning:** This backend is still in active development and has not yet undergone
10
+ the same level of review as the rest of the code. Use at your own risk!
@@ -0,0 +1,67 @@
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_FIPS202_NATIVE_ARMV81M_MVE_H
8
+ #define MLD_FIPS202_NATIVE_ARMV81M_MVE_H
9
+
10
+ #define MLD_FIPS202_NATIVE_ARMV81M
11
+
12
+ /* Part of backend API */
13
+ #define MLD_USE_NATIVE_FIPS202_X4
14
+ #define MLD_USE_NATIVE_FIPS202_X4_XOR_BYTES
15
+ #define MLD_USE_NATIVE_FIPS202_X4_EXTRACT_BYTES
16
+ /* Guard for assembly file */
17
+ #define MLD_FIPS202_ARMV81M_NEED_X4
18
+
19
+ #if !defined(__ASSEMBLER__)
20
+ #include "../api.h"
21
+ #include "src/fips202_native_armv81m.h"
22
+
23
+ /*
24
+ * Native x4 permutation
25
+ * State is kept in bit-interleaved format.
26
+ */
27
+ #define mld_keccak_f1600_x4_native_impl \
28
+ MLD_NAMESPACE(keccak_f1600_x4_native_impl)
29
+ MLD_INTERNAL_API
30
+ int mld_keccak_f1600_x4_native_impl(uint64_t *state);
31
+
32
+ MLD_MUST_CHECK_RETURN_VALUE
33
+ static MLD_INLINE int mld_keccak_f1600_x4_native(uint64_t *state)
34
+ {
35
+ return mld_keccak_f1600_x4_native_impl(state);
36
+ }
37
+
38
+ /*
39
+ * Native x4 XOR bytes (with on-the-fly bit interleaving)
40
+ */
41
+ MLD_MUST_CHECK_RETURN_VALUE
42
+ static MLD_INLINE int mld_keccakf1600_xor_bytes_x4_native(
43
+ uint64_t *state, const uint8_t *data0, const uint8_t *data1,
44
+ const uint8_t *data2, const uint8_t *data3, unsigned offset,
45
+ unsigned length)
46
+ {
47
+ mld_keccak_f1600_x4_state_xor_bytes_asm(state, data0, data1, data2, data3,
48
+ offset, length);
49
+ return MLD_NATIVE_FUNC_SUCCESS;
50
+ }
51
+
52
+ /*
53
+ * Native x4 extract bytes (with on-the-fly bit de-interleaving)
54
+ */
55
+ MLD_MUST_CHECK_RETURN_VALUE
56
+ static MLD_INLINE int mld_keccakf1600_extract_bytes_x4_native(
57
+ uint64_t *state, uint8_t *data0, uint8_t *data1, uint8_t *data2,
58
+ uint8_t *data3, unsigned offset, unsigned length)
59
+ {
60
+ mld_keccak_f1600_x4_state_extract_bytes_asm(state, data0, data1, data2, data3,
61
+ offset, length);
62
+ return MLD_NATIVE_FUNC_SUCCESS;
63
+ }
64
+
65
+ #endif /* !__ASSEMBLER__ */
66
+
67
+ #endif /* !MLD_FIPS202_NATIVE_ARMV81M_MVE_H */
@@ -0,0 +1,37 @@
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_FIPS202_NATIVE_ARMV81M_SRC_FIPS202_NATIVE_ARMV81M_H
7
+ #define MLD_FIPS202_NATIVE_ARMV81M_SRC_FIPS202_NATIVE_ARMV81M_H
8
+
9
+ #include "../../../../common.h"
10
+
11
+ /* Keccak round constants in bit-interleaved form */
12
+ #define mld_keccakf1600_round_constants \
13
+ MLD_NAMESPACE(keccakf1600_round_constants)
14
+ MLD_INTERNAL_DATA_DECLARATION const uint32_t
15
+ mld_keccakf1600_round_constants[48];
16
+
17
+ #define mld_keccak_f1600_x4_mve_asm MLD_NAMESPACE(keccak_f1600_x4_mve_asm)
18
+ void mld_keccak_f1600_x4_mve_asm(uint64_t state[100], uint64_t tmpstate[100],
19
+ const uint32_t rc[48]);
20
+
21
+ #define mld_keccak_f1600_x4_state_xor_bytes_asm \
22
+ MLD_NAMESPACE(keccak_f1600_x4_state_xor_bytes_asm)
23
+ void mld_keccak_f1600_x4_state_xor_bytes_asm(void *state, const uint8_t *d0,
24
+ const uint8_t *d1,
25
+ const uint8_t *d2,
26
+ const uint8_t *d3, unsigned offset,
27
+ unsigned length);
28
+
29
+ #define mld_keccak_f1600_x4_state_extract_bytes_asm \
30
+ MLD_NAMESPACE(keccak_f1600_x4_state_extract_bytes_asm)
31
+ void mld_keccak_f1600_x4_state_extract_bytes_asm(void *state, uint8_t *data0,
32
+ uint8_t *data1, uint8_t *data2,
33
+ uint8_t *data3,
34
+ unsigned offset,
35
+ unsigned length);
36
+
37
+ #endif /* !MLD_FIPS202_NATIVE_ARMV81M_SRC_FIPS202_NATIVE_ARMV81M_H */