Skip to content

Commit b6269a2

Browse files
committed
Align common.h with mlkem-native
The common.h in mldsa-native diverged slightly from the mlkem-native one even though by now they are implementing the same features. The primary difference was ordering. Two minor things have been resolved: 1) There was a bad configuration warning missing when MLD_CONFIG_USE_NATIVE_BACKEND_FIPS202 is set, but MLD_CONFIG_FIPS202_BACKEND_FILE is not set. 2) We did not correctly handle when MLD_CONFIG_NO_ASM is set, and MLD_CONFIG_USE_NATIVE_BACKEND_ARITH or MLD_CONFIG_USE_NATIVE_BACKEND_FIPS202 are also set (MLD_CONFIG_NO_ASM should take precedence). Resolves #684 Signed-off-by: Matthias J. Kannwischer <matthias@kannwischer.eu>
1 parent a91e007 commit b6269a2

File tree

1 file changed

+36
-26
lines changed

1 file changed

+36
-26
lines changed

mldsa/src/common.h

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/*
22
* Copyright (c) The mldsa-native project authors
3+
* Copyright (c) The mlkem-native project authors
34
* SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
45
*/
5-
66
#ifndef MLD_COMMON_H
77
#define MLD_COMMON_H
88

@@ -30,24 +30,14 @@
3030
#define MLD_EXTERNAL_API MLD_CONFIG_EXTERNAL_API_QUALIFIER
3131
#endif
3232

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-
4633
#if defined(MLD_CONFIG_MULTILEVEL_NO_SHARED) || \
4734
defined(MLD_CONFIG_MULTILEVEL_WITH_SHARED)
4835
#define MLD_MULTILEVEL_BUILD
4936
#endif
5037

38+
#define MLD_CONCAT_(x1, x2) x1##x2
39+
#define MLD_CONCAT(x1, x2) MLD_CONCAT_(x1, x2)
40+
5141
#if defined(MLD_MULTILEVEL_BUILD)
5242
#define MLD_ADD_PARAM_SET(s) MLD_CONCAT(s, MLD_CONFIG_PARAMETER_SET)
5343
#else
@@ -70,18 +60,6 @@
7060
#define MLD_NAMESPACE(s) MLD_CONCAT(MLD_NAMESPACE_PREFIX, s)
7161
#define MLD_NAMESPACE_KL(s) MLD_CONCAT(MLD_NAMESPACE_PREFIX_KL, s)
7262

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-
8563
/* On Apple platforms, we need to emit leading underscore
8664
* in front of assembly symbols. We thus introducee a separate
8765
* namespace wrapper for ASM symbols. */
@@ -108,6 +86,38 @@
10886
* The following is to avoid compilers complaining about this. */
10987
#define MLD_EMPTY_CU(s) extern int MLD_NAMESPACE_KL(empty_cu_##s);
11088

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+
111121
#if defined(MLD_CONFIG_USE_NATIVE_BACKEND_FIPS202)
112122
#include MLD_CONFIG_FIPS202_BACKEND_FILE
113123
/* Include to enforce consistency of API and implementation,

0 commit comments

Comments
 (0)