|
1 | 1 | [//]: # (SPDX-License-Identifier: CC-BY-4.0) |
2 | 2 |
|
3 | | -# Bring your own FIPS-202 (Static State Variant) |
| 3 | +# Bring Your Own FIPS-202 (Static State Variant) |
4 | 4 |
|
5 | | -This directory contains a minimal example for how to use mldsa-native with external FIPS-202 |
6 | | -HW/SW-implementations that use a single global state (for example, some hardware accelerators). |
7 | | -Specifically, this example demonstrates the use of the serial-only FIPS-202 configuration |
8 | | -`MLD_CONFIG_SERIAL_FIPS202_ONLY`. |
| 5 | +This directory contains a minimal example for using mldsa-native with a custom FIPS-202 implementation |
| 6 | +that uses a single global state. This is common for hardware accelerators that can only hold one |
| 7 | +Keccak state at a time. |
9 | 8 |
|
10 | | -**WARNING:** This example is EXPECTED TO PRODUCE INCORRECT RESULTS because ML-DSA requires |
11 | | -multiple independent FIPS-202 contexts to be active simultaneously. This example demonstrates |
12 | | -what happens when only a single global state is available. |
| 9 | +## Use Case |
| 10 | + |
| 11 | +Use this approach when: |
| 12 | +- You need only one ML-DSA parameter set (44, 65, or 87) |
| 13 | +- Your application already has a FIPS-202 software/hardware implementation you want to reuse |
| 14 | +- Your FIPS-202 implementation does not support multiple active SHA3/SHAKE computations. |
13 | 15 |
|
14 | 16 | ## Components |
15 | 17 |
|
16 | | -An application using mldsa-native with a custom FIPS-202 implementation needs the following: |
| 18 | +1. Arithmetic part of mldsa-native: [`mldsa/src/`](../../mldsa/src) (excluding `fips202/`) |
| 19 | +2. A secure random number generator implementing [`randombytes.h`](../../mldsa/src/randombytes.h) |
| 20 | +3. Custom FIPS-202 implementation with headers compatible with [`fips202.h`](../../mldsa/src/fips202/fips202.h) |
| 21 | +4. Your application source code |
| 22 | + |
| 23 | +## Configuration |
| 24 | + |
| 25 | +The configuration file [mldsa_native_config.h](mldsa_native/mldsa_native_config.h) sets: |
| 26 | +- `MLD_CONFIG_SERIAL_FIPS202_ONLY`: Disables batched Keccak; matrix entries generated one at a time |
| 27 | +- `MLD_CONFIG_FIPS202_CUSTOM_HEADER`: Path to your custom `fips202.h` |
17 | 28 |
|
18 | | -1. Arithmetic part of the mldsa-native source tree: [`mldsa/src/`](../../mldsa/src) |
19 | | -2. A secure pseudo random number generator, implementing [`randombytes.h`](../../mldsa/src/randombytes.h). |
20 | | -3. A custom FIPS-202 with `fips202.h` header compatible with [`mldsa/fips202/fips202.h`](../../mldsa/src/fips202/fips202.h). |
21 | | - With `MLD_CONFIG_SERIAL_FIPS202_ONLY`, the FIPS-202x4 parallel API is not used. |
22 | | -4. The application source code |
| 29 | +Your custom FIPS-202 implementation must provide: |
| 30 | +- `mld_shake128_init()`, `mld_shake128_absorb()`, `mld_shake128_finalize()`, `mld_shake128_squeeze()`, `mld_shake128_release()` |
| 31 | +- `mld_shake256_init()`, `mld_shake256_absorb()`, `mld_shake256_finalize()`, `mld_shake256_squeeze()`, `mld_shake256_release()` |
| 32 | +- `mld_shake256` |
| 33 | +- Structure definitions for `mld_shake128ctx` and `mld_shake256ctx` |
23 | 34 |
|
24 | | -**WARNING:** The `randombytes()` implementation used here is for TESTING ONLY. You MUST NOT use this implementation |
25 | | -outside of testing. |
| 35 | +## Notes |
| 36 | + |
| 37 | +- `MLD_CONFIG_SERIAL_FIPS202_ONLY` may reduce performance on CPUs with SIMD support |
| 38 | +- Matrix and vector generation becomes sequential instead of batched (4 entries at a time) |
| 39 | +- Only enable this when your hardware requires it |
26 | 40 |
|
27 | 41 | ## Usage |
28 | 42 |
|
29 | | -Build this example with `make build`, run with `make run`. |
| 43 | +```bash |
| 44 | +make build # Build the example |
| 45 | +make run # Run the example |
| 46 | +``` |
| 47 | + |
| 48 | +## Warning |
30 | 49 |
|
31 | | -You should see verification failures, which is the expected behavior demonstrating that a single |
32 | | -global FIPS-202 state is insufficient for ML-DSA. |
| 50 | +The `randombytes()` implementation in `test_only_rng/` is for TESTING ONLY. |
| 51 | +You MUST provide a cryptographically secure RNG for production use. |
33 | 52 |
|
34 | 53 | <!--- bibliography ---> |
35 | 54 | [^tiny_sha3]: Markku-Juhani O. Saarinen: tiny_sha3, [https://github.com/mjosaarinen/tiny_sha3](https://github.com/mjosaarinen/tiny_sha3) |
0 commit comments