Skip to content

Commit 07b1aba

Browse files
authored
Merge branch 'main' into mld_polyz_unpack-debug
Signed-off-by: Matthias J. Kannwischer <matthias@kannwischer.eu>
2 parents 58e5c5e + 2227d0b commit 07b1aba

File tree

220 files changed

+4756
-3104
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

220 files changed

+4756
-3104
lines changed

.github/actions/config-variations/action.yml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ runs:
3737
shell: bash
3838
run: |
3939
make clean
40-
CFLAGS='-DMLD_CONFIG_FILE=\"../../test/break_pct_config.h\"' make func -j4
40+
CFLAGS='-Itest -DMLD_CONFIG_FILE=\"break_pct_config.h\"' make func -j4
4141
# PCT breakage is done at runtime via MLD_BREAK_PCT
4242
make run_func # Should be OK
4343
MLD_BREAK_PCT=0 make run_func # Should be OK
@@ -53,7 +53,7 @@ runs:
5353
with:
5454
gh_token: ${{ inputs.gh_token }}
5555
compile_mode: native
56-
cflags: "-std=c11 -D_GNU_SOURCE -DMLD_CONFIG_FILE=\\\\\\\"../../test/custom_zeroize_config.h\\\\\\\" -fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all"
56+
cflags: "-std=c11 -D_GNU_SOURCE -Itest -DMLD_CONFIG_FILE=\\\\\\\"custom_zeroize_config.h\\\\\\\" -fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all"
5757
ldflags: "-fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all"
5858
func: true
5959
kat: true
@@ -66,7 +66,7 @@ runs:
6666
with:
6767
gh_token: ${{ inputs.gh_token }}
6868
compile_mode: native
69-
cflags: "-std=c11 -D_GNU_SOURCE -DMLD_CONFIG_FILE=\\\\\\\"../../test/custom_native_capability_config_1.h\\\\\\\" -fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all"
69+
cflags: "-std=c11 -D_GNU_SOURCE -Itest -DMLD_CONFIG_FILE=\\\\\\\"custom_native_capability_config_1.h\\\\\\\" -fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all"
7070
ldflags: "-fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all"
7171
func: true
7272
kat: true
@@ -79,7 +79,7 @@ runs:
7979
with:
8080
gh_token: ${{ inputs.gh_token }}
8181
compile_mode: native
82-
cflags: "-std=c11 -D_GNU_SOURCE -DMLD_CONFIG_FILE=\\\\\\\"../../test/custom_native_capability_config_0.h\\\\\\\" -fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all"
82+
cflags: "-std=c11 -D_GNU_SOURCE -Itest -DMLD_CONFIG_FILE=\\\\\\\"custom_native_capability_config_0.h\\\\\\\" -fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all"
8383
ldflags: "-fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all"
8484
func: true
8585
kat: true
@@ -92,7 +92,7 @@ runs:
9292
with:
9393
gh_token: ${{ inputs.gh_token }}
9494
compile_mode: native
95-
cflags: "-std=c11 -march=armv8.4-a+sha3 -D_GNU_SOURCE -DMLD_CONFIG_FILE=\\\\\\\"../../test/custom_native_capability_config_ID_AA64PFR1_EL1.h\\\\\\\" -fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all"
95+
cflags: "-std=c11 -march=armv8.4-a+sha3 -D_GNU_SOURCE -Itest -DMLD_CONFIG_FILE=\\\\\\\"custom_native_capability_config_ID_AA64PFR1_EL1.h\\\\\\\" -fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all"
9696
ldflags: "-fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all"
9797
func: true
9898
kat: true
@@ -105,7 +105,7 @@ runs:
105105
with:
106106
gh_token: ${{ inputs.gh_token }}
107107
compile_mode: native
108-
cflags: "-std=c11 -mavx2 -mbmi2 -mpopcnt -D_GNU_SOURCE -DMLD_CONFIG_FILE=\\\\\\\"../../test/custom_native_capability_config_CPUID_AVX2.h\\\\\\\" -fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all"
108+
cflags: "-std=c11 -mavx2 -mbmi2 -mpopcnt -D_GNU_SOURCE -Itest -DMLD_CONFIG_FILE=\\\\\\\"custom_native_capability_config_CPUID_AVX2.h\\\\\\\" -fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all"
109109
ldflags: "-fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all"
110110
func: true
111111
kat: true
@@ -118,7 +118,7 @@ runs:
118118
with:
119119
gh_token: ${{ inputs.gh_token }}
120120
compile_mode: native
121-
cflags: "-std=c11 -D_GNU_SOURCE -DMLD_CONFIG_FILE=\\\\\\\"../../test/no_asm_config.h\\\\\\\" -fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all"
121+
cflags: "-std=c11 -D_GNU_SOURCE -Itest -DMLD_CONFIG_FILE=\\\\\\\"no_asm_config.h\\\\\\\" -fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all"
122122
ldflags: "-fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all"
123123
func: true
124124
kat: true
@@ -131,7 +131,7 @@ runs:
131131
with:
132132
gh_token: ${{ inputs.gh_token }}
133133
compile_mode: native
134-
cflags: "-std=c11 -D_GNU_SOURCE -DMLD_CONFIG_FILE=\\\\\\\"../../test/serial_fips202_config.h\\\\\\\" -fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all"
134+
cflags: "-std=c11 -D_GNU_SOURCE -Itest -DMLD_CONFIG_FILE=\\\\\\\"serial_fips202_config.h\\\\\\\" -fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all"
135135
ldflags: "-fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all"
136136
func: true
137137
kat: true
@@ -144,7 +144,7 @@ runs:
144144
with:
145145
gh_token: ${{ inputs.gh_token }}
146146
compile_mode: native
147-
cflags: "-std=c11 -D_GNU_SOURCE -DMLD_CONFIG_FILE=\\\\\\\"../../test/custom_randombytes_config.h\\\\\\\" -fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all"
147+
cflags: "-std=c11 -D_GNU_SOURCE -Itest -DMLD_CONFIG_FILE=\\\\\\\"custom_randombytes_config.h\\\\\\\" -fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all"
148148
ldflags: "-fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all"
149149
func: true
150150
kat: true
@@ -157,7 +157,7 @@ runs:
157157
with:
158158
gh_token: ${{ inputs.gh_token }}
159159
compile_mode: native
160-
cflags: "-std=c11 -D_GNU_SOURCE -DMLD_CONFIG_FILE=\\\\\\\"../../test/custom_memcpy_config.h\\\\\\\" -fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all"
160+
cflags: "-std=c11 -D_GNU_SOURCE -Itest -DMLD_CONFIG_FILE=\\\\\\\"custom_memcpy_config.h\\\\\\\" -fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all"
161161
ldflags: "-fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all"
162162
func: true
163163
kat: true
@@ -170,7 +170,7 @@ runs:
170170
with:
171171
gh_token: ${{ inputs.gh_token }}
172172
compile_mode: native
173-
cflags: "-std=c11 -D_GNU_SOURCE -DMLD_CONFIG_FILE=\\\\\\\"../../test/custom_memset_config.h\\\\\\\" -fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all"
173+
cflags: "-std=c11 -D_GNU_SOURCE -Itest -DMLD_CONFIG_FILE=\\\\\\\"custom_memset_config.h\\\\\\\" -fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all"
174174
ldflags: "-fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all"
175175
func: true
176176
kat: true
@@ -183,7 +183,7 @@ runs:
183183
with:
184184
gh_token: ${{ inputs.gh_token }}
185185
compile_mode: native
186-
cflags: "-std=c11 -D_GNU_SOURCE -DMLD_CONFIG_FILE=\\\\\\\"../../test/custom_stdlib_config.h\\\\\\\" -fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all"
186+
cflags: "-std=c11 -D_GNU_SOURCE -Itest -DMLD_CONFIG_FILE=\\\\\\\"custom_stdlib_config.h\\\\\\\" -fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all"
187187
ldflags: "-fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all"
188188
func: true
189189
kat: true

BIBLIOGRAPHY.md

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,20 @@ source code and documentation.
2323
- National Institute of Standards and Technology
2424
* URL: https://csrc.nist.gov/projects/cryptographic-module-validation-program/fips-140-3-ig-announcements
2525
* Referenced from:
26-
- [examples/basic_deterministic/mldsa_native/custom_no_randomized_config.h](examples/basic_deterministic/mldsa_native/custom_no_randomized_config.h)
27-
- [examples/custom_backend/mldsa_native/custom_config.h](examples/custom_backend/mldsa_native/custom_config.h)
28-
- [examples/monolithic_build/config_44.h](examples/monolithic_build/config_44.h)
29-
- [examples/monolithic_build/config_65.h](examples/monolithic_build/config_65.h)
30-
- [examples/monolithic_build/config_87.h](examples/monolithic_build/config_87.h)
31-
- [examples/monolithic_build_multilevel/multilevel_config.h](examples/monolithic_build_multilevel/multilevel_config.h)
32-
- [examples/monolithic_build_multilevel_native/multilevel_config.h](examples/monolithic_build_multilevel_native/multilevel_config.h)
33-
- [examples/monolithic_build_native/config_44.h](examples/monolithic_build_native/config_44.h)
34-
- [examples/monolithic_build_native/config_65.h](examples/monolithic_build_native/config_65.h)
35-
- [examples/monolithic_build_native/config_87.h](examples/monolithic_build_native/config_87.h)
26+
- [examples/basic_deterministic/mldsa_native/mldsa_native_config.h](examples/basic_deterministic/mldsa_native/mldsa_native_config.h)
27+
- [examples/bring_your_own_fips202/mldsa_native/mldsa_native_config.h](examples/bring_your_own_fips202/mldsa_native/mldsa_native_config.h)
28+
- [examples/bring_your_own_fips202_static/mldsa_native/mldsa_native_config.h](examples/bring_your_own_fips202_static/mldsa_native/mldsa_native_config.h)
29+
- [examples/custom_backend/mldsa_native/mldsa_native_config.h](examples/custom_backend/mldsa_native/mldsa_native_config.h)
30+
- [examples/monolithic_build/mldsa_native/mldsa_native_config.h](examples/monolithic_build/mldsa_native/mldsa_native_config.h)
31+
- [examples/monolithic_build_multilevel/mldsa_native/mldsa_native_config.h](examples/monolithic_build_multilevel/mldsa_native/mldsa_native_config.h)
32+
- [examples/monolithic_build_multilevel_native/mldsa_native/mldsa_native_config.h](examples/monolithic_build_multilevel_native/mldsa_native/mldsa_native_config.h)
33+
- [examples/monolithic_build_native/mldsa_native/mldsa_native_config.h](examples/monolithic_build_native/mldsa_native/mldsa_native_config.h)
34+
- [examples/multilevel_build/mldsa_native/mldsa_native_config.h](examples/multilevel_build/mldsa_native/mldsa_native_config.h)
35+
- [examples/multilevel_build_native/mldsa_native/mldsa_native_config.h](examples/multilevel_build_native/mldsa_native/mldsa_native_config.h)
3636
- [integration/liboqs/config_aarch64.h](integration/liboqs/config_aarch64.h)
3737
- [integration/liboqs/config_c.h](integration/liboqs/config_c.h)
3838
- [integration/liboqs/config_x86_64.h](integration/liboqs/config_x86_64.h)
39-
- [mldsa/src/config.h](mldsa/src/config.h)
39+
- [mldsa/mldsa_native_config.h](mldsa/mldsa_native_config.h)
4040
- [mldsa/src/sign.c](mldsa/src/sign.c)
4141
- [test/break_pct_config.h](test/break_pct_config.h)
4242
- [test/custom_memcpy_config.h](test/custom_memcpy_config.h)
@@ -69,18 +69,18 @@ source code and documentation.
6969
* URL: https://csrc.nist.gov/pubs/fips/204/final
7070
* Referenced from:
7171
- [README.md](README.md)
72-
- [examples/basic_deterministic/mldsa_native/custom_no_randomized_config.h](examples/basic_deterministic/mldsa_native/custom_no_randomized_config.h)
73-
- [examples/custom_backend/mldsa_native/custom_config.h](examples/custom_backend/mldsa_native/custom_config.h)
74-
- [examples/monolithic_build/config_44.h](examples/monolithic_build/config_44.h)
75-
- [examples/monolithic_build/config_65.h](examples/monolithic_build/config_65.h)
76-
- [examples/monolithic_build/config_87.h](examples/monolithic_build/config_87.h)
77-
- [examples/monolithic_build_multilevel/multilevel_config.h](examples/monolithic_build_multilevel/multilevel_config.h)
78-
- [examples/monolithic_build_multilevel_native/multilevel_config.h](examples/monolithic_build_multilevel_native/multilevel_config.h)
79-
- [examples/monolithic_build_native/config_44.h](examples/monolithic_build_native/config_44.h)
80-
- [examples/monolithic_build_native/config_65.h](examples/monolithic_build_native/config_65.h)
81-
- [examples/monolithic_build_native/config_87.h](examples/monolithic_build_native/config_87.h)
72+
- [examples/basic_deterministic/mldsa_native/mldsa_native_config.h](examples/basic_deterministic/mldsa_native/mldsa_native_config.h)
73+
- [examples/bring_your_own_fips202/mldsa_native/mldsa_native_config.h](examples/bring_your_own_fips202/mldsa_native/mldsa_native_config.h)
74+
- [examples/bring_your_own_fips202_static/mldsa_native/mldsa_native_config.h](examples/bring_your_own_fips202_static/mldsa_native/mldsa_native_config.h)
75+
- [examples/custom_backend/mldsa_native/mldsa_native_config.h](examples/custom_backend/mldsa_native/mldsa_native_config.h)
76+
- [examples/monolithic_build/mldsa_native/mldsa_native_config.h](examples/monolithic_build/mldsa_native/mldsa_native_config.h)
77+
- [examples/monolithic_build_multilevel/mldsa_native/mldsa_native_config.h](examples/monolithic_build_multilevel/mldsa_native/mldsa_native_config.h)
78+
- [examples/monolithic_build_multilevel_native/mldsa_native/mldsa_native_config.h](examples/monolithic_build_multilevel_native/mldsa_native/mldsa_native_config.h)
79+
- [examples/monolithic_build_native/mldsa_native/mldsa_native_config.h](examples/monolithic_build_native/mldsa_native/mldsa_native_config.h)
80+
- [examples/multilevel_build/mldsa_native/mldsa_native_config.h](examples/multilevel_build/mldsa_native/mldsa_native_config.h)
81+
- [examples/multilevel_build_native/mldsa_native/mldsa_native_config.h](examples/multilevel_build_native/mldsa_native/mldsa_native_config.h)
8282
- [mldsa/mldsa_native.h](mldsa/mldsa_native.h)
83-
- [mldsa/src/config.h](mldsa/src/config.h)
83+
- [mldsa/mldsa_native_config.h](mldsa/mldsa_native_config.h)
8484
- [mldsa/src/ct.h](mldsa/src/ct.h)
8585
- [mldsa/src/fips202/fips202.c](mldsa/src/fips202/fips202.c)
8686
- [mldsa/src/fips202/fips202x4.c](mldsa/src/fips202/fips202x4.c)

examples/README.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
[//]: # (SPDX-License-Identifier: CC-BY-4.0)
2+
3+
# Usage examples
4+
5+
This directory contains minimal examples demonstrating how you can use mldsa-native.
6+
7+
## Basic
8+
9+
See [basic](basic) for a basic example of how to build a single instance of mldsa-native.
10+
11+
## Basic_deterministic
12+
13+
See [basic_deterministic](basic_deterministic) for a basic example of how to build a single instance of mldsa-native without `randombytes()` implementation. This allows users to build mldsa-native using only the deterministic API when randomized functions are not required.
14+
## Multi-level build (C only)
15+
16+
See [multilevel_build](multilevel_build) for an example of how to build one instance of mldsa-native per security level,
17+
in such a way that level-independent code is shared.
18+
19+
## Multi-level build (with native code)
20+
21+
See [multilevel_build_native](multilevel_build_native) for an example of how to build one instance of mldsa-native per
22+
security level, in such a way that level-independent code is shared, and leveraging the native backends.
23+
24+
## Custom FIPS202 implementation
25+
26+
See [bring_your_own_fips202](bring_your_own_fips202) for an example of how to use mldsa-native with your own FIPS-202
27+
implementation.
28+
29+
## Custom FIPS202 implementation (static state variant)
30+
31+
See [bring_your_own_fips202_static](bring_your_own_fips202_static) for an example of how to use mldsa-native with a
32+
custom FIPS-202 implementation using a static state. This variant demonstrates the serial-only FIPS-202 configuration
33+
(`MLD_CONFIG_SERIAL_FIPS202_ONLY`).
34+
35+
## Custom config + custom FIPS-202 backend
36+
37+
See [custom_backend](custom_backend) for an example of how to use mldsa-native with a custom configuration file and a
38+
custom FIPS-202 backend.
39+
40+
## Monobuild (C only)
41+
42+
See [monolithic_build](monolithic_build) for an example of how to build mldsa-native (with C backend) from a single
43+
auto-generated compilation unit.
44+
45+
## Multi-level monobuild (C only)
46+
47+
See [monolithic_build_multilevel](monolithic_build_multilevel) for an example of how to build all security levels of
48+
mldsa-native (with C backend) inside a single compilation unit, sharing the level-independent code.
49+
50+
## Multi-level monobuild (with native code)
51+
52+
See [monolithic_build_multilevel_native](monolithic_build_multilevel_native) for an example of how to build all security
53+
levels of mldsa-native inside a single compilation unit, sharing the level-independent code, while also linking in assembly
54+
from the native backends.

examples/basic/Makefile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@ endif
5555
# In this example, we compile the individual mldsa-native source files directly.
5656
# Alternatively, you can compile the 'monobuild' source file mldsa_native.c.
5757
# See examples/monolithic_build for that.
58-
MLD_SOURCE=$(wildcard \
59-
mldsa_native/mldsa/src/*.c \
60-
mldsa_native/mldsa/src/**/*.c \
61-
mldsa_native/mldsa/src/**/**/*.c \
62-
mldsa_native/mldsa/src/**/**/**/*.c)
58+
MLD_SOURCE=$(wildcard \
59+
mldsa_native/src/*.c \
60+
mldsa_native/src/**/*.c \
61+
mldsa_native/src/**/**/*.c \
62+
mldsa_native/src/**/**/**/*.c)
6363

64-
INC=-Imldsa_native/mldsa/
64+
INC=-Imldsa_native
6565

6666
# Part B:
6767
#

examples/basic/README.md

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,38 @@
11
[//]: # (SPDX-License-Identifier: CC-BY-4.0)
22

3-
# Building mldsa-native
3+
# Basic build
44

5-
This directory contains a minimal example for how to build mldsa-native.
5+
This directory contains a minimal example for how to build mldsa-native for a single security level.
66

7-
## Components
8-
9-
An application using mldsa-native as-is needs to include the following components:
10-
11-
1. mldsa-native source tree, including [`mldsa/src/`](../../mldsa/src) and [`mldsa/src/fips202/`](../../mldsa/src/fips202).
12-
2. A secure pseudo random number generator, implementing [`randombytes.h`](../../mldsa/src/randombytes.h).
13-
3. The application source code
7+
## Use Case
148

15-
**WARNING:** The `randombytes()` implementation used here is for TESTING ONLY. You MUST NOT use this implementation
16-
outside of testing.
9+
Use this approach when:
10+
- You need only one ML-DSA parameter set (44, 65, or 87)
11+
- You want to build the mldsa-native C files separately, not as a single compilation unit.
12+
- You're using C only, no native backends.
1713

18-
## Usage
14+
## Components
1915

20-
Build this example with `make build`, run with `make run`.
16+
1. mldsa-native source tree: [`mldsa/src/`](../../mldsa/src) and [`mldsa/src/fips202/`](../../mldsa/src/fips202)
17+
2. A secure random number generator implementing [`randombytes.h`](../../mldsa/src/randombytes.h)
18+
3. Your application source code
2119

22-
## What this example demonstrates
20+
## Configuration
2321

24-
This basic example shows how to use the ML-DSA (Module-Lattice-Based Digital Signature Algorithm) for:
22+
The configuration file [mldsa_native_config.h](mldsa_native/mldsa_native_config.h) sets:
23+
- `MLD_CONFIG_PARAMETER_SET`: Security level (44, 65, or 87). Default is 65.
24+
- `MLD_CONFIG_NAMESPACE_PREFIX`: Symbol prefix for the API. Set to `mldsa` in this example.
2525

26-
1. **Key Generation**: Generate a public/private key pair
27-
2. **Signing**: Sign a message with a private key and optional context
28-
3. **Signature Verification**: Verify a signature using the public key
29-
4. **Signed Messages**: Create and open signed messages (signature + message combined)
26+
To change the security level, modify `MLD_CONFIG_PARAMETER_SET` in the config file or pass it via CFLAGS.
3027

31-
The example demonstrates both the detached signature API (`crypto_sign_signature`/`crypto_sign_verify`) and the combined signature API (`crypto_sign`/`crypto_sign_open`).
28+
## Usage
3229

33-
## Parameter Sets
30+
```bash
31+
make build # Build the example
32+
make run # Run the example
33+
```
3434

35-
ML-DSA supports three parameter sets:
36-
- **ML-DSA-44**
37-
- **ML-DSA-65**
38-
- **ML-DSA-87**
35+
## Warning
3936

40-
The example builds and runs all three parameter sets to demonstrate the different security levels and their corresponding key/signature sizes.
37+
The `randombytes()` implementation in `test_only_rng/` is for TESTING ONLY.
38+
You MUST provide a cryptographically secure RNG for production use.

0 commit comments

Comments
 (0)