Debian Codegraph @

others/mbedtls/tf-psa-crypto/drivers/pqcp/mldsa-native/examples/multilevel_build_native/README.md

raw
1 [//]: # (SPDX-License-Identifier: CC-BY-4.0)
2
3 # Multi-Level Build (Native Backend)
4
5 This directory contains a minimal example for building mldsa-native with support for all three security levels
6 (ML-DSA-44, ML-DSA-65, ML-DSA-87), using native backends for optimal performance, with level-independent
7 code shared to reduce binary size.
8
9 ## Use Case
10
11 Use this approach when:
12 - You need multiple ML-DSA security levels in the same application
13 - You want optimal performance via native assembly (AArch64/AVX2)
14 - You want to build the mldsa-native C files separately, not as a single compilation unit.
15 - You want to minimize code duplication across levels
16
17 ## Components
18
19 1. mldsa-native source tree: [`mldsa/src/`](../../mldsa/src), [`mldsa/src/fips202/`](../../mldsa/src/fips202),
20 and [`mldsa/src/native/`](../../mldsa/src/native)
21 2. A secure random number generator implementing [`randombytes.h`](../../mldsa/src/randombytes.h)
22 3. Your application source code
23
24 ## Configuration
25
26 The library is built 3 times into separate directories (`build/mldsa44`, `build/mldsa65`, `build/mldsa87`).
27
28 The configuration file [mldsa_native_config.h](mldsa_native/mldsa_native_config.h) sets:
29 - `MLD_CONFIG_MULTILEVEL_BUILD`: Enables multi-level build mode
30 - `MLD_CONFIG_NAMESPACE_PREFIX=mldsa`: Base prefix; level suffix added automatically
31 - `MLD_CONFIG_USE_NATIVE_BACKEND_ARITH`: Enables native arithmetic backend
32 - `MLD_CONFIG_USE_NATIVE_BACKEND_FIPS202`: Enables native FIPS-202 backend
33 - `MLD_CONFIG_NO_SUPERCOP`: Disables the SUPERCOP API (crypto_sign*)
34
35 Build-time flags passed via CFLAGS:
36 - `MLD_CONFIG_PARAMETER_SET=44/65/87`: Selects the security level
37 - `MLD_CONFIG_MULTILEVEL_WITH_SHARED`: Set for ONE build to include shared code
38 - `MLD_CONFIG_MULTILEVEL_NO_SHARED`: Set for OTHER builds to exclude shared code
39
40 The resulting API functions are namespaced as:
41 - `mldsa44_keypair()`, `mldsa44_signature()`, `mldsa44_verify()`, ...
42 - `mldsa65_keypair()`, `mldsa65_signature()`, `mldsa65_verify()`, ...
43 - `mldsa87_keypair()`, `mldsa87_signature()`, `mldsa87_verify()`, ...
44
45 ## Notes
46
47 - Native backends are auto-selected based on the target architecture
48 - On unsupported platforms, the build falls back to the C backend
49
50 ## Usage
51
52 ```bash
53 make build # Build all three security levels
54 make run # Run the example
55 ```
56
57 ## Warning
58
59 The `randombytes()` implementation in `test_only_rng/` is for TESTING ONLY.
60 You MUST provide a cryptographically secure RNG for production use.