Skip to content

Commit 54d1c4a

Browse files
jakemasmkannwischer
authored andcommitted
Add MLD_CONFIG_MULTILEVEL_WITH_SHARED and NO_SHARED
This PR removes NAMESPACETOP and implements the NAMESPACE_KL for multilevel functionality. Also added are the config MLD_CONFIG_MULTILEVEL_WITH_SHARED and the no shared option MLD_CONFIG_MULTILEVEL_NO_SHARED. These multilevel guards have been added to ntt.c/polyvec.c/debug.c. The functions within poly.c have been split into shared and parameter- dependent in poly_kl.c. Signed-off-by: Jake Massimo <[email protected]>
1 parent 47831f0 commit 54d1c4a

File tree

37 files changed

+1343
-857
lines changed

37 files changed

+1343
-857
lines changed

BIBLIOGRAPHY.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ source code and documentation.
5050
- [mldsa/fips202/fips202x4.c](mldsa/fips202/fips202x4.c)
5151
- [mldsa/ntt.h](mldsa/ntt.h)
5252
- [mldsa/poly.c](mldsa/poly.c)
53+
- [mldsa/poly_kl.c](mldsa/poly_kl.c)
5354
- [mldsa/polyvec.c](mldsa/polyvec.c)
5455
- [mldsa/rounding.h](mldsa/rounding.h)
5556
- [mldsa/sign.c](mldsa/sign.c)
@@ -127,6 +128,7 @@ source code and documentation.
127128
- [README.md](README.md)
128129
- [mldsa/ntt.c](mldsa/ntt.c)
129130
- [mldsa/poly.c](mldsa/poly.c)
131+
- [mldsa/poly_kl.c](mldsa/poly_kl.c)
130132

131133
### `REF_AVX2`
132134

integration/liboqs/ML-DSA-44_META.yml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ implementations:
3131
sources: integration/liboqs/config_c.h integration/liboqs/fips202_glue.h integration/liboqs/fips202x4_glue.h
3232
mldsa/cbmc.h mldsa/common.h mldsa/ct.c mldsa/ct.h mldsa/debug.c mldsa/debug.h
3333
mldsa/ntt.c mldsa/ntt.h mldsa/packing.c mldsa/packing.h mldsa/params.h mldsa/poly.c
34-
mldsa/poly.h mldsa/polyvec.c mldsa/polyvec.h mldsa/randombytes.h mldsa/reduce.h
35-
mldsa/rounding.h mldsa/sign.c mldsa/sign.h mldsa/symmetric.h mldsa/sys.h mldsa/zetas.inc
34+
mldsa/poly.h mldsa/poly_kl.c mldsa/polyvec.c mldsa/polyvec.h mldsa/randombytes.h
35+
mldsa/reduce.h mldsa/rounding.h mldsa/sign.c mldsa/sign.h mldsa/symmetric.h mldsa/sys.h
36+
mldsa/zetas.inc
3637
- name: x86_64
3738
version: FIPS204
3839
folder_name: .
@@ -44,9 +45,9 @@ implementations:
4445
sources: integration/liboqs/config_x86_64.h integration/liboqs/fips202_glue.h integration/liboqs/fips202x4_glue.h
4546
mldsa/cbmc.h mldsa/common.h mldsa/ct.c mldsa/ct.h mldsa/debug.c mldsa/debug.h
4647
mldsa/native/api.h mldsa/native/meta.h mldsa/ntt.c mldsa/ntt.h mldsa/packing.c
47-
mldsa/packing.h mldsa/params.h mldsa/poly.c mldsa/poly.h mldsa/polyvec.c mldsa/polyvec.h
48-
mldsa/randombytes.h mldsa/reduce.h mldsa/rounding.h mldsa/sign.c mldsa/sign.h
49-
mldsa/symmetric.h mldsa/sys.h mldsa/zetas.inc mldsa/native/x86_64
48+
mldsa/packing.h mldsa/params.h mldsa/poly.c mldsa/poly.h mldsa/poly_kl.c mldsa/polyvec.c
49+
mldsa/polyvec.h mldsa/randombytes.h mldsa/reduce.h mldsa/rounding.h mldsa/sign.c
50+
mldsa/sign.h mldsa/symmetric.h mldsa/sys.h mldsa/zetas.inc mldsa/native/x86_64
5051
supported_platforms:
5152
- architecture: x86_64
5253
operating_systems:
@@ -67,9 +68,9 @@ implementations:
6768
sources: integration/liboqs/config_aarch64.h integration/liboqs/fips202_glue.h integration/liboqs/fips202x4_glue.h
6869
mldsa/cbmc.h mldsa/common.h mldsa/ct.c mldsa/ct.h mldsa/debug.c mldsa/debug.h
6970
mldsa/native/api.h mldsa/native/meta.h mldsa/ntt.c mldsa/ntt.h mldsa/packing.c
70-
mldsa/packing.h mldsa/params.h mldsa/poly.c mldsa/poly.h mldsa/polyvec.c mldsa/polyvec.h
71-
mldsa/randombytes.h mldsa/reduce.h mldsa/rounding.h mldsa/sign.c mldsa/sign.h
72-
mldsa/symmetric.h mldsa/sys.h mldsa/zetas.inc mldsa/native/aarch64
71+
mldsa/packing.h mldsa/params.h mldsa/poly.c mldsa/poly.h mldsa/poly_kl.c mldsa/polyvec.c
72+
mldsa/polyvec.h mldsa/randombytes.h mldsa/reduce.h mldsa/rounding.h mldsa/sign.c
73+
mldsa/sign.h mldsa/symmetric.h mldsa/sys.h mldsa/zetas.inc mldsa/native/aarch64
7374
supported_platforms:
7475
- architecture: arm_8
7576
operating_systems:

integration/liboqs/ML-DSA-65_META.yml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ implementations:
3131
sources: integration/liboqs/config_c.h integration/liboqs/fips202_glue.h integration/liboqs/fips202x4_glue.h
3232
mldsa/cbmc.h mldsa/common.h mldsa/ct.c mldsa/ct.h mldsa/debug.c mldsa/debug.h
3333
mldsa/ntt.c mldsa/ntt.h mldsa/packing.c mldsa/packing.h mldsa/params.h mldsa/poly.c
34-
mldsa/poly.h mldsa/polyvec.c mldsa/polyvec.h mldsa/randombytes.h mldsa/reduce.h
35-
mldsa/rounding.h mldsa/sign.c mldsa/sign.h mldsa/symmetric.h mldsa/sys.h mldsa/zetas.inc
34+
mldsa/poly.h mldsa/poly_kl.c mldsa/polyvec.c mldsa/polyvec.h mldsa/randombytes.h
35+
mldsa/reduce.h mldsa/rounding.h mldsa/sign.c mldsa/sign.h mldsa/symmetric.h mldsa/sys.h
36+
mldsa/zetas.inc
3637
- name: x86_64
3738
version: FIPS204
3839
folder_name: .
@@ -44,9 +45,9 @@ implementations:
4445
sources: integration/liboqs/config_x86_64.h integration/liboqs/fips202_glue.h integration/liboqs/fips202x4_glue.h
4546
mldsa/cbmc.h mldsa/common.h mldsa/ct.c mldsa/ct.h mldsa/debug.c mldsa/debug.h
4647
mldsa/native/api.h mldsa/native/meta.h mldsa/ntt.c mldsa/ntt.h mldsa/packing.c
47-
mldsa/packing.h mldsa/params.h mldsa/poly.c mldsa/poly.h mldsa/polyvec.c mldsa/polyvec.h
48-
mldsa/randombytes.h mldsa/reduce.h mldsa/rounding.h mldsa/sign.c mldsa/sign.h
49-
mldsa/symmetric.h mldsa/sys.h mldsa/zetas.inc mldsa/native/x86_64
48+
mldsa/packing.h mldsa/params.h mldsa/poly.c mldsa/poly.h mldsa/poly_kl.c mldsa/polyvec.c
49+
mldsa/polyvec.h mldsa/randombytes.h mldsa/reduce.h mldsa/rounding.h mldsa/sign.c
50+
mldsa/sign.h mldsa/symmetric.h mldsa/sys.h mldsa/zetas.inc mldsa/native/x86_64
5051
supported_platforms:
5152
- architecture: x86_64
5253
operating_systems:
@@ -67,9 +68,9 @@ implementations:
6768
sources: integration/liboqs/config_aarch64.h integration/liboqs/fips202_glue.h integration/liboqs/fips202x4_glue.h
6869
mldsa/cbmc.h mldsa/common.h mldsa/ct.c mldsa/ct.h mldsa/debug.c mldsa/debug.h
6970
mldsa/native/api.h mldsa/native/meta.h mldsa/ntt.c mldsa/ntt.h mldsa/packing.c
70-
mldsa/packing.h mldsa/params.h mldsa/poly.c mldsa/poly.h mldsa/polyvec.c mldsa/polyvec.h
71-
mldsa/randombytes.h mldsa/reduce.h mldsa/rounding.h mldsa/sign.c mldsa/sign.h
72-
mldsa/symmetric.h mldsa/sys.h mldsa/zetas.inc mldsa/native/aarch64
71+
mldsa/packing.h mldsa/params.h mldsa/poly.c mldsa/poly.h mldsa/poly_kl.c mldsa/polyvec.c
72+
mldsa/polyvec.h mldsa/randombytes.h mldsa/reduce.h mldsa/rounding.h mldsa/sign.c
73+
mldsa/sign.h mldsa/symmetric.h mldsa/sys.h mldsa/zetas.inc mldsa/native/aarch64
7374
supported_platforms:
7475
- architecture: arm_8
7576
operating_systems:

integration/liboqs/ML-DSA-87_META.yml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ implementations:
3131
sources: integration/liboqs/config_c.h integration/liboqs/fips202_glue.h integration/liboqs/fips202x4_glue.h
3232
mldsa/cbmc.h mldsa/common.h mldsa/ct.c mldsa/ct.h mldsa/debug.c mldsa/debug.h
3333
mldsa/ntt.c mldsa/ntt.h mldsa/packing.c mldsa/packing.h mldsa/params.h mldsa/poly.c
34-
mldsa/poly.h mldsa/polyvec.c mldsa/polyvec.h mldsa/randombytes.h mldsa/reduce.h
35-
mldsa/rounding.h mldsa/sign.c mldsa/sign.h mldsa/symmetric.h mldsa/sys.h mldsa/zetas.inc
34+
mldsa/poly.h mldsa/poly_kl.c mldsa/polyvec.c mldsa/polyvec.h mldsa/randombytes.h
35+
mldsa/reduce.h mldsa/rounding.h mldsa/sign.c mldsa/sign.h mldsa/symmetric.h mldsa/sys.h
36+
mldsa/zetas.inc
3637
- name: x86_64
3738
version: FIPS204
3839
folder_name: .
@@ -44,9 +45,9 @@ implementations:
4445
sources: integration/liboqs/config_x86_64.h integration/liboqs/fips202_glue.h integration/liboqs/fips202x4_glue.h
4546
mldsa/cbmc.h mldsa/common.h mldsa/ct.c mldsa/ct.h mldsa/debug.c mldsa/debug.h
4647
mldsa/native/api.h mldsa/native/meta.h mldsa/ntt.c mldsa/ntt.h mldsa/packing.c
47-
mldsa/packing.h mldsa/params.h mldsa/poly.c mldsa/poly.h mldsa/polyvec.c mldsa/polyvec.h
48-
mldsa/randombytes.h mldsa/reduce.h mldsa/rounding.h mldsa/sign.c mldsa/sign.h
49-
mldsa/symmetric.h mldsa/sys.h mldsa/zetas.inc mldsa/native/x86_64
48+
mldsa/packing.h mldsa/params.h mldsa/poly.c mldsa/poly.h mldsa/poly_kl.c mldsa/polyvec.c
49+
mldsa/polyvec.h mldsa/randombytes.h mldsa/reduce.h mldsa/rounding.h mldsa/sign.c
50+
mldsa/sign.h mldsa/symmetric.h mldsa/sys.h mldsa/zetas.inc mldsa/native/x86_64
5051
supported_platforms:
5152
- architecture: x86_64
5253
operating_systems:
@@ -66,9 +67,9 @@ implementations:
6667
sources: integration/liboqs/config_aarch64.h integration/liboqs/fips202_glue.h integration/liboqs/fips202x4_glue.h
6768
mldsa/cbmc.h mldsa/common.h mldsa/ct.c mldsa/ct.h mldsa/debug.c mldsa/debug.h
6869
mldsa/native/api.h mldsa/native/meta.h mldsa/ntt.c mldsa/ntt.h mldsa/packing.c
69-
mldsa/packing.h mldsa/params.h mldsa/poly.c mldsa/poly.h mldsa/polyvec.c mldsa/polyvec.h
70-
mldsa/randombytes.h mldsa/reduce.h mldsa/rounding.h mldsa/sign.c mldsa/sign.h
71-
mldsa/symmetric.h mldsa/sys.h mldsa/zetas.inc mldsa/native/aarch64
70+
mldsa/packing.h mldsa/params.h mldsa/poly.c mldsa/poly.h mldsa/poly_kl.c mldsa/polyvec.c
71+
mldsa/polyvec.h mldsa/randombytes.h mldsa/reduce.h mldsa/rounding.h mldsa/sign.c
72+
mldsa/sign.h mldsa/symmetric.h mldsa/sys.h mldsa/zetas.inc mldsa/native/aarch64
7273
supported_platforms:
7374
- architecture: arm_8
7475
operating_systems:

mldsa/common.h

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,32 @@
4949
#define MLD_CONCAT_(x1, x2) x1##x2
5050
#define MLD_CONCAT(x1, x2) MLD_CONCAT_(x1, x2)
5151

52+
#if defined(MLD_CONFIG_MULTILEVEL_NO_SHARED) || \
53+
defined(MLD_CONFIG_MULTILEVEL_WITH_SHARED)
54+
#define MLD_MULTILEVEL_BUILD
55+
#endif
56+
57+
#if defined(MLD_MULTILEVEL_BUILD)
58+
#define MLD_ADD_PARAM_SET(s) MLD_CONCAT(s, MLD_CONFIG_PARAMETER_SET)
59+
#else
60+
#define MLD_ADD_PARAM_SET(s) s
61+
#endif
62+
5263
#define MLD_NAMESPACE_PREFIX MLD_CONCAT(MLD_CONFIG_NAMESPACE_PREFIX, _)
64+
#define MLD_NAMESPACE_PREFIX_KL \
65+
MLD_CONCAT(MLD_ADD_PARAM_SET(MLD_CONFIG_NAMESPACE_PREFIX), _)
5366

5467
/* Functions are prefixed by MLD_CONFIG_NAMESPACE_PREFIX.
5568
*
56-
* Example: If MLD_CONFIG_NAMESPACE_PREFIX is PQCP_MLDSA_NATIVE_MLDSA44, then
57-
* MLD_NAMESPACE(sign) becomes PQCP_MLDSA_NATIVE_MLDSA44_sign.
69+
* If multiple parameter sets are used, functions depending on the parameter
70+
* set are additionally prefixed with 44/65/87. See config.h.
71+
*
72+
* Example: If MLD_CONFIG_NAMESPACE_PREFIX is PQCP_MLDSA_NATIVE, then
73+
* MLD_NAMESPACE_KL(keypair) becomes PQCP_MLDSA_NATIVE44_keypair/
74+
* PQCP_MLDSA_NATIVE65_keypair/PQCP_MLDSA_NATIVE87_keypair.
5875
*/
5976
#define MLD_NAMESPACE(s) MLD_CONCAT(MLD_NAMESPACE_PREFIX, s)
60-
#define MLD_NAMESPACETOP MLD_CONFIG_NAMESPACE_PREFIX
77+
#define MLD_NAMESPACE_KL(s) MLD_CONCAT(MLD_NAMESPACE_PREFIX_KL, s)
6178

6279
#if defined(MLD_CONFIG_USE_NATIVE_BACKEND_ARITH)
6380
#include MLD_CONFIG_ARITH_BACKEND_FILE

mldsa/config.h

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,64 @@
4343
*
4444
* Description: The prefix to use to namespace global symbols from mldsa/.
4545
*
46+
* In a multi-level build (that is, if either
47+
* - MLD_CONFIG_MULTILEVEL_WITH_SHARED, or
48+
* - MLD_CONFIG_MULTILEVEL_NO_SHARED,
49+
* are set, level-dependent symbols will additionally be prefixed
50+
* with the parameter set (44/65/87).
51+
*
4652
* This can also be set using CFLAGS.
4753
*
4854
*****************************************************************************/
4955
#if !defined(MLD_CONFIG_NAMESPACE_PREFIX)
5056
#define MLD_CONFIG_NAMESPACE_PREFIX MLD_DEFAULT_NAMESPACE_PREFIX
5157
#endif
5258

59+
/******************************************************************************
60+
* Name: MLD_CONFIG_MULTILEVEL_WITH_SHARED
61+
*
62+
* Description: This is for multi-level builds of mldsa-native only. If you
63+
* need only a single parameter set, keep this unset.
64+
*
65+
* If this is set, all MLD_CONFIG_PARAMETER_SET-independent
66+
* code will be included in the build, including code needed only
67+
* for other parameter sets.
68+
*
69+
* Example: TODO: add example
70+
*
71+
* To build mldsa-native with support for all parameter sets,
72+
* build it three times -- once per parameter set -- and set the
73+
* option MLD_CONFIG_MULTILEVEL_WITH_SHARED for exactly one of
74+
* them, and MLD_CONFIG_MULTILEVEL_NO_SHARED for the others.
75+
*
76+
* See examples/multilevel_build_mldsa for an example.
77+
*
78+
* This can also be set using CFLAGS.
79+
*
80+
*****************************************************************************/
81+
/* #define MLD_CONFIG_MULTILEVEL_WITH_SHARED */
82+
83+
/******************************************************************************
84+
* Name: MLD_CONFIG_MULTILEVEL_NO_SHARED
85+
*
86+
* Description: This is for multi-level builds of mldsa-native only. If you
87+
* need only a single parameter set, keep this unset.
88+
*
89+
* If this is set, no MLD_CONFIG_PARAMETER_SET-independent code
90+
* will be included in the build.
91+
*
92+
* To build mldsa-native with support for all parameter sets,
93+
* build it three times -- once per parameter set -- and set the
94+
* option MLD_CONFIG_MULTILEVEL_WITH_SHARED for exactly one of
95+
* them, and MLD_CONFIG_MULTILEVEL_NO_SHARED for the others.
96+
*
97+
* See examples/multilevel_build_mldsa for an example.
98+
*
99+
* This can also be set using CFLAGS.
100+
*
101+
*****************************************************************************/
102+
/* #define MLD_CONFIG_MULTILEVEL_NO_SHARED */
103+
53104
/******************************************************************************
54105
* Name: MLD_CONFIG_FILE
55106
*

mldsa/debug.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
#include "common.h"
1010

11+
#if !defined(MLD_CONFIG_MULTILEVEL_NO_SHARED)
12+
1113
#if defined(MLDSA_DEBUG)
1214

1315
#include <inttypes.h>
@@ -60,6 +62,12 @@ MLD_EMPTY_CU(debug)
6062

6163
#endif /* !MLDSA_DEBUG */
6264

65+
#else /* !MLD_CONFIG_MULTILEVEL_NO_SHARED */
66+
67+
MLD_EMPTY_CU(debug)
68+
69+
#endif /* MLD_CONFIG_MULTILEVEL_NO_SHARED */
70+
6371
/* To facilitate single-compilation-unit (SCU) builds, undefine all macros.
6472
* Don't modify by hand -- this is auto-generated by scripts/autogen. */
6573
#undef MLD_DEBUG_ERROR_HEADER

mldsa/ntt.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
* https://github.com/pq-crystals/dilithium/tree/master/ref
1313
*/
1414

15+
#include "common.h"
16+
17+
#if !defined(MLD_CONFIG_MULTILEVEL_NO_SHARED)
18+
1519
#include <stdint.h>
1620

1721
#include "ntt.h"
@@ -244,3 +248,7 @@ void mld_invntt_tomont(int32_t a[MLDSA_N])
244248
a[j] = mld_fqscale(a[j]);
245249
}
246250
}
251+
252+
#else /* !MLD_CONFIG_MULTILEVEL_NO_SHARED */
253+
MLD_EMPTY_CU(mld_ntt)
254+
#endif /* MLD_CONFIG_MULTILEVEL_NO_SHARED */

mldsa/packing.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include <stdint.h>
99
#include "polyvec.h"
1010

11-
#define mld_pack_pk MLD_NAMESPACE(pack_pk)
11+
#define mld_pack_pk MLD_NAMESPACE_KL(pack_pk)
1212
/*************************************************
1313
* Name: mld_pack_pk
1414
*
@@ -31,7 +31,7 @@ __contract__(
3131
);
3232

3333

34-
#define mld_pack_sk MLD_NAMESPACE(pack_sk)
34+
#define mld_pack_sk MLD_NAMESPACE_KL(pack_sk)
3535
/*************************************************
3636
* Name: mld_pack_sk
3737
*
@@ -69,7 +69,7 @@ __contract__(
6969
);
7070

7171

72-
#define mld_pack_sig MLD_NAMESPACE(pack_sig)
72+
#define mld_pack_sig MLD_NAMESPACE_KL(pack_sig)
7373
/*************************************************
7474
* Name: mld_pack_sig
7575
*
@@ -104,7 +104,7 @@ __contract__(
104104
assigns(memory_slice(sig, CRYPTO_BYTES))
105105
);
106106

107-
#define mld_unpack_pk MLD_NAMESPACE(unpack_pk)
107+
#define mld_unpack_pk MLD_NAMESPACE_KL(unpack_pk)
108108
/*************************************************
109109
* Name: mld_unpack_pk
110110
*
@@ -128,7 +128,7 @@ __contract__(
128128
);
129129

130130

131-
#define mld_unpack_sk MLD_NAMESPACE(unpack_sk)
131+
#define mld_unpack_sk MLD_NAMESPACE_KL(unpack_sk)
132132
/*************************************************
133133
* Name: mld_unpack_sk
134134
*
@@ -169,7 +169,7 @@ __contract__(
169169
array_bound(s2->vec[k2].coeffs, 0, MLDSA_N, MLD_POLYETA_UNPACK_LOWER_BOUND, MLDSA_ETA + 1)))
170170
);
171171

172-
#define mld_unpack_sig MLD_NAMESPACE(unpack_sig)
172+
#define mld_unpack_sig MLD_NAMESPACE_KL(unpack_sig)
173173
/*************************************************
174174
* Name: mld_unpack_sig
175175
*

0 commit comments

Comments
 (0)