|
1 | 1 | /* |
2 | 2 | * Copyright (c) The mldsa-native project authors |
| 3 | + * Copyright (c) The mlkem-native project authors |
3 | 4 | * SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT |
4 | 5 | */ |
5 | | - |
6 | 6 | #ifndef MLD_COMMON_H |
7 | 7 | #define MLD_COMMON_H |
8 | 8 |
|
|
30 | 30 | #define MLD_EXTERNAL_API MLD_CONFIG_EXTERNAL_API_QUALIFIER |
31 | 31 | #endif |
32 | 32 |
|
33 | | - |
34 | | -#if defined(MLD_CONFIG_USE_NATIVE_BACKEND_ARITH) && \ |
35 | | - !defined(MLD_CONFIG_ARITH_BACKEND_FILE) |
36 | | -#error Bad configuration: MLD_CONFIG_USE_NATIVE_BACKEND_ARITH is set, but MLD_CONFIG_ARITH_BACKEND_FILE is not. |
37 | | -#endif |
38 | | - |
39 | | -#if defined(MLD_CONFIG_NO_RANDOMIZED_API) && defined(MLD_CONFIG_KEYGEN_PCT) |
40 | | -#error Bad configuration: MLD_CONFIG_NO_RANDOMIZED_API is incompatible with MLD_CONFIG_KEYGEN_PCT as the current PCT implementation requires crypto_sign_signature() |
41 | | -#endif |
42 | | - |
43 | | -#define MLD_CONCAT_(x1, x2) x1##x2 |
44 | | -#define MLD_CONCAT(x1, x2) MLD_CONCAT_(x1, x2) |
45 | | - |
46 | 33 | #if defined(MLD_CONFIG_MULTILEVEL_NO_SHARED) || \ |
47 | 34 | defined(MLD_CONFIG_MULTILEVEL_WITH_SHARED) |
48 | 35 | #define MLD_MULTILEVEL_BUILD |
49 | 36 | #endif |
50 | 37 |
|
| 38 | +#define MLD_CONCAT_(x1, x2) x1##x2 |
| 39 | +#define MLD_CONCAT(x1, x2) MLD_CONCAT_(x1, x2) |
| 40 | + |
51 | 41 | #if defined(MLD_MULTILEVEL_BUILD) |
52 | 42 | #define MLD_ADD_PARAM_SET(s) MLD_CONCAT(s, MLD_CONFIG_PARAMETER_SET) |
53 | 43 | #else |
|
70 | 60 | #define MLD_NAMESPACE(s) MLD_CONCAT(MLD_NAMESPACE_PREFIX, s) |
71 | 61 | #define MLD_NAMESPACE_KL(s) MLD_CONCAT(MLD_NAMESPACE_PREFIX_KL, s) |
72 | 62 |
|
73 | | -#if defined(MLD_CONFIG_USE_NATIVE_BACKEND_ARITH) |
74 | | -#include MLD_CONFIG_ARITH_BACKEND_FILE |
75 | | -/* Include to enforce consistency of API and implementation, |
76 | | - * and conduct sanity checks on the backend. |
77 | | - * |
78 | | - * Keep this _after_ the inclusion of the backend; otherwise, |
79 | | - * the sanity checks won't have an effect. */ |
80 | | -#if defined(MLD_CHECK_APIS) && !defined(__ASSEMBLER__) |
81 | | -#include "native/api.h" |
82 | | -#endif |
83 | | -#endif /* MLD_CONFIG_USE_NATIVE_BACKEND_ARITH */ |
84 | | - |
85 | 63 | /* On Apple platforms, we need to emit leading underscore |
86 | 64 | * in front of assembly symbols. We thus introducee a separate |
87 | 65 | * namespace wrapper for ASM symbols. */ |
|
108 | 86 | * The following is to avoid compilers complaining about this. */ |
109 | 87 | #define MLD_EMPTY_CU(s) extern int MLD_NAMESPACE_KL(empty_cu_##s); |
110 | 88 |
|
| 89 | +/* MLD_CONFIG_NO_ASM takes precedence over MLD_USE_NATIVE_XXX */ |
| 90 | +#if defined(MLD_CONFIG_NO_ASM) |
| 91 | +#undef MLD_CONFIG_USE_NATIVE_BACKEND_ARITH |
| 92 | +#undef MLD_CONFIG_USE_NATIVE_BACKEND_FIPS202 |
| 93 | +#endif |
| 94 | + |
| 95 | +#if defined(MLD_CONFIG_USE_NATIVE_BACKEND_ARITH) && \ |
| 96 | + !defined(MLD_CONFIG_ARITH_BACKEND_FILE) |
| 97 | +#error Bad configuration: MLD_CONFIG_USE_NATIVE_BACKEND_ARITH is set, but MLD_CONFIG_ARITH_BACKEND_FILE is not. |
| 98 | +#endif |
| 99 | + |
| 100 | +#if defined(MLD_CONFIG_USE_NATIVE_BACKEND_FIPS202) && \ |
| 101 | + !defined(MLD_CONFIG_FIPS202_BACKEND_FILE) |
| 102 | +#error Bad configuration: MLD_CONFIG_USE_NATIVE_BACKEND_FIPS202 is set, but MLD_CONFIG_FIPS202_BACKEND_FILE is not. |
| 103 | +#endif |
| 104 | + |
| 105 | +#if defined(MLD_CONFIG_NO_RANDOMIZED_API) && defined(MLD_CONFIG_KEYGEN_PCT) |
| 106 | +#error Bad configuration: MLD_CONFIG_NO_RANDOMIZED_API is incompatible with MLD_CONFIG_KEYGEN_PCT as the current PCT implementation requires crypto_sign_signature() |
| 107 | +#endif |
| 108 | + |
| 109 | +#if defined(MLD_CONFIG_USE_NATIVE_BACKEND_ARITH) |
| 110 | +#include MLD_CONFIG_ARITH_BACKEND_FILE |
| 111 | +/* Include to enforce consistency of API and implementation, |
| 112 | + * and conduct sanity checks on the backend. |
| 113 | + * |
| 114 | + * Keep this _after_ the inclusion of the backend; otherwise, |
| 115 | + * the sanity checks won't have an effect. */ |
| 116 | +#if defined(MLD_CHECK_APIS) && !defined(__ASSEMBLER__) |
| 117 | +#include "native/api.h" |
| 118 | +#endif |
| 119 | +#endif /* MLD_CONFIG_USE_NATIVE_BACKEND_ARITH */ |
| 120 | + |
111 | 121 | #if defined(MLD_CONFIG_USE_NATIVE_BACKEND_FIPS202) |
112 | 122 | #include MLD_CONFIG_FIPS202_BACKEND_FILE |
113 | 123 | /* Include to enforce consistency of API and implementation, |
|
0 commit comments