This directory contains a minimal example for building all three ML-DSA security levels in a single compilation unit with native assembly backends, with shared code deduplicated.
Use this approach when:
- You need all ML-DSA security levels in one application
- You want optimal performance via native assembly
- You want the simplest possible multi-level native integration
- Source tree mldsa_native/*, including top-level compilation unit mldsa_native.c (gathering all C sources), mldsa_native_asm.S (gathering all assembly sources), and the mldsa-native API mldsa_native.h.
- Manually provided wrapper file mldsa_native_all.c,
including
mldsa_native.cthree times (in this example, we don't use a wrapper header since we directly includemldsa_native_all.cintomain.c). - A secure random number generator implementing
randombytes.h - Your application source code
The configuration file mldsa_native_config.h sets:
MLD_CONFIG_MULTILEVEL_BUILD: Enables multi-level modeMLD_CONFIG_NAMESPACE_PREFIX=mldsa: Base prefixMLD_CONFIG_USE_NATIVE_BACKEND_ARITH: Enables native arithmetic backendMLD_CONFIG_USE_NATIVE_BACKEND_FIPS202: Enables native FIPS-202 backend
The wrapper mldsa_native_all.c includes mldsa_native.c three times:
#define MLD_CONFIG_FILE "multilevel_config.h"
/* Include level-independent code with first level */
#define MLD_CONFIG_MULTILEVEL_WITH_SHARED 1
#define MLD_CONFIG_MONOBUILD_KEEP_SHARED_HEADERS
#define MLD_CONFIG_PARAMETER_SET 44
#include "mldsa_native.c"
#undef MLD_CONFIG_MULTILEVEL_WITH_SHARED
#undef MLD_CONFIG_PARAMETER_SET
/* Exclude level-independent code for subsequent levels */
#define MLD_CONFIG_MULTILEVEL_NO_SHARED
#define MLD_CONFIG_PARAMETER_SET 65
#include "mldsa_native.c"
#undef MLD_CONFIG_MONOBUILD_KEEP_SHARED_HEADERS
#undef MLD_CONFIG_PARAMETER_SET
#define MLD_CONFIG_PARAMETER_SET 87
#include "mldsa_native.c"
#undef MLD_CONFIG_PARAMETER_SETThe application main.c embeds the wrapper and imports constants:
#include "mldsa_native_all.c"
#define MLD_CONFIG_CONSTANTS_ONLY
#include <mldsa_native.h>- Both
mldsa_native_all.candmldsa_native_asm.Smust be compiled and linked MLD_CONFIG_MULTILEVEL_WITH_SHAREDmust be set for exactly ONE levelMLD_CONFIG_CONSTANTS_ONLYimports size constants without function declarations- Native backends are auto-selected based on target architecture
make build # Build the example
make run # Run the exampleThe randombytes() implementation in test_only_rng/ is for TESTING ONLY.
You MUST provide a cryptographically secure RNG for production use.