| 1 |
[//]: # (SPDX-License-Identifier: CC-BY-4.0) |
| 2 |
|
| 3 |
# Custom FIPS-202 Backend |
| 4 |
|
| 5 |
This directory contains a minimal example for using mldsa-native with a custom FIPS-202 *backend* |
| 6 |
(as opposed to a complete custom FIPS-202 implementation). We use tiny_sha3[^tiny_sha3] as an example. |
| 7 |
|
| 8 |
## Use Case |
| 9 |
|
| 10 |
Use this approach when: |
| 11 |
- You need only one ML-DSA parameter set (44, 65, 87) |
| 12 |
- You want to replace the low-level Keccak-f1600 permutation |
| 13 |
- You want to keep mldsa-native's FIPS-202 frontend (absorb/squeeze logic) |
| 14 |
|
| 15 |
This differs from `bring_your_own_fips202` in that you only replace the *backend* (Keccak permutation), |
| 16 |
not the entire FIPS-202 implementation. |
| 17 |
|
| 18 |
## Components |
| 19 |
|
| 20 |
1. Arithmetic part of mldsa-native: [`mldsa/src/`](../../mldsa/src) |
| 21 |
2. FIPS-202 frontend: [`mldsa/src/fips202/`](../../mldsa/src/fips202) (can remove existing backends) |
| 22 |
3. A secure random number generator implementing [`randombytes.h`](../../mldsa/src/randombytes.h) |
| 23 |
4. Custom FIPS-202 backend (see below) |
| 24 |
5. Your application source code |
| 25 |
|
| 26 |
## Configuration |
| 27 |
|
| 28 |
The configuration file [mldsa_native_config.h](mldsa_native/mldsa_native_config.h) sets: |
| 29 |
- `MLD_CONFIG_USE_NATIVE_BACKEND_FIPS202`: Enables native FIPS-202 backend |
| 30 |
- `MLD_CONFIG_FIPS202_BACKEND_FILE`: Path to your custom backend metadata file |
| 31 |
|
| 32 |
A custom backend consists of: |
| 33 |
1. A metadata header (e.g., [custom.h](mldsa_native/src/fips202/native/custom/custom.h)) that: |
| 34 |
- Sets `MLD_USE_FIPS202_X1_NATIVE` (and/or `X4`) to indicate which functions are replaced |
| 35 |
- Includes the implementation header |
| 36 |
2. An implementation providing `mld_keccakf1600_native()` (and/or batched variants) |
| 37 |
|
| 38 |
Example backend metadata file: |
| 39 |
```c |
| 40 |
#ifndef CUSTOM_FIPS202_BACKEND_H |
| 41 |
#define CUSTOM_FIPS202_BACKEND_H |
| 42 |
|
| 43 |
/* Indicate we're replacing 1-fold Keccak-f1600 */ |
| 44 |
#define MLD_USE_FIPS202_X1_NATIVE |
| 45 |
|
| 46 |
/* Include the implementation */ |
| 47 |
#include "custom/src/keccak_impl.h" |
| 48 |
|
| 49 |
#endif |
| 50 |
``` |
| 51 |
|
| 52 |
## Notes |
| 53 |
|
| 54 |
- The tiny_sha3 code uses byte-reversed Keccak state on big-endian targets; this example removes |
| 55 |
that reversal since mldsa-native's frontend assumes standard byte order |
| 56 |
|
| 57 |
## Usage |
| 58 |
|
| 59 |
```bash |
| 60 |
make build # Build the example |
| 61 |
make run # Run the example |
| 62 |
``` |
| 63 |
|
| 64 |
## Warning |
| 65 |
|
| 66 |
The `randombytes()` implementation in `test_only_rng/` is for TESTING ONLY. |
| 67 |
You MUST provide a cryptographically secure RNG for production use. |
| 68 |
|
| 69 |
<!--- bibliography ---> |
| 70 |
[^tiny_sha3]: Markku-Juhani O. Saarinen: tiny_sha3, [https://github.com/mjosaarinen/tiny_sha3](https://github.com/mjosaarinen/tiny_sha3) |