Skip to content

Commit 40ff385

Browse files
hanno-beckermkannwischer
authored andcommitted
Use ad-hoc matrix generation for reduced RAM usage
Signed-off-by: Hanno Becker <beckphan@amazon.co.uk>
1 parent 3f327b7 commit 40ff385

File tree

31 files changed

+141
-217
lines changed

31 files changed

+141
-217
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,16 @@ contracts and loop invariants from the code; they will be ignored unless `CBMC`
153153

154154
Yes. mldsa-native supports all three ML-DSA security levels (ML-DSA-44, ML-DSA-65, ML-DSA-87) as defined in FIPS 204. The security level is a compile-time parameter configured by setting `MLD_CONFIG_PARAMETER_SET=44/65/87` in [mldsa_native_config.h](mldsa/mldsa_native_config.h).
155155

156+
### Can I reduce RAM usage for embedded systems?
157+
158+
Yes. mldsa-native provides a compile-time option `MLD_CONFIG_REDUCE_RAM` that reduces RAM usage. This trades memory for performance:
159+
160+
- **Memory savings**: 12 KB (ML-DSA-44), 25 KB (ML-DSA-65), 49 KB (ML-DSA-87) for each of key generation, signing, and verification.
161+
For signing, additional 4 KB (ML-DSA-44), 5 KB (ML-DSA-65), and 7 KB (ML-DSA-87) are saved.
162+
- **Performance cost**: Matrix generation is no longer batched, resulting in slower signing and verification
163+
164+
To enable this mode, define `MLD_CONFIG_REDUCE_RAM` in [mldsa_native_config.h](mldsa/mldsa_native_config.h) or pass `-DMLD_CONFIG_REDUCE_RAM` as a compiler flag.
165+
156166
### Does mldsa-native use hedged or deterministic signing?
157167

158168
By default, mldsa-native uses the randomized "hedged" signing variant as specified in FIPS 204 Section 3.4. The hedged variant uses both fresh randomness at signing time and precomputed randomness from the private key. This helps mitigate fault injection attacks and side-channel attacks while protecting against potential flaws in the random number generator.

examples/basic_deterministic/mldsa_native/mldsa_native_config.h

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -673,14 +673,10 @@
673673
* Name: MLD_CONFIG_REDUCE_RAM [EXPERIMENTAL]
674674
*
675675
* Description: Set this to reduce RAM usage.
676+
* This trades memory for performance.
676677
*
677-
* This configuration option is work in progress.
678-
*
679-
* At present it results the following memory saving in signing
680-
* with no impact on performance:
681-
* - ML-DSA-44: 4 KiB
682-
* - ML-DSA-65: 5 KiB
683-
* - ML-DSA-87: 7 KiB
678+
* For detailed expected memory savings, see the
679+
* mldsa-native README.
684680
*
685681
* This option is useful for embedded systems with tight RAM
686682
* constraints but relaxed performance requirements.
@@ -692,7 +688,6 @@
692688
*****************************************************************************/
693689
/* #define MLD_CONFIG_REDUCE_RAM */
694690

695-
696691
/************************* Config internals ********************************/
697692

698693
#endif /* MLD_BUILD_INTERNAL */

examples/basic_lowram/mldsa_native/mldsa_native_config.h

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -672,14 +672,10 @@
672672
* Name: MLD_CONFIG_REDUCE_RAM [EXPERIMENTAL]
673673
*
674674
* Description: Set this to reduce RAM usage.
675+
* This trades memory for performance.
675676
*
676-
* This configuration option is work in progress.
677-
*
678-
* At present it results the following memory saving in signing
679-
* with no impact on performance:
680-
* - ML-DSA-44: 4 KiB
681-
* - ML-DSA-65: 5 KiB
682-
* - ML-DSA-87: 7 KiB
677+
* For detailed expected memory savings, see the
678+
* mldsa-native README.
683679
*
684680
* This option is useful for embedded systems with tight RAM
685681
* constraints but relaxed performance requirements.
@@ -691,7 +687,6 @@
691687
*****************************************************************************/
692688
#define MLD_CONFIG_REDUCE_RAM
693689

694-
695690
/************************* Config internals ********************************/
696691

697692
#endif /* MLD_BUILD_INTERNAL */

examples/bring_your_own_fips202/mldsa_native/mldsa_native_config.h

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -673,14 +673,10 @@
673673
* Name: MLD_CONFIG_REDUCE_RAM [EXPERIMENTAL]
674674
*
675675
* Description: Set this to reduce RAM usage.
676+
* This trades memory for performance.
676677
*
677-
* This configuration option is work in progress.
678-
*
679-
* At present it results the following memory saving in signing
680-
* with no impact on performance:
681-
* - ML-DSA-44: 4 KiB
682-
* - ML-DSA-65: 5 KiB
683-
* - ML-DSA-87: 7 KiB
678+
* For detailed expected memory savings, see the
679+
* mldsa-native README.
684680
*
685681
* This option is useful for embedded systems with tight RAM
686682
* constraints but relaxed performance requirements.
@@ -692,7 +688,6 @@
692688
*****************************************************************************/
693689
/* #define MLD_CONFIG_REDUCE_RAM */
694690

695-
696691
/************************* Config internals ********************************/
697692

698693
#endif /* MLD_BUILD_INTERNAL */

examples/bring_your_own_fips202_static/mldsa_native/mldsa_native_config.h

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -674,14 +674,10 @@
674674
* Name: MLD_CONFIG_REDUCE_RAM [EXPERIMENTAL]
675675
*
676676
* Description: Set this to reduce RAM usage.
677+
* This trades memory for performance.
677678
*
678-
* This configuration option is work in progress.
679-
*
680-
* At present it results the following memory saving in signing
681-
* with no impact on performance:
682-
* - ML-DSA-44: 4 KiB
683-
* - ML-DSA-65: 5 KiB
684-
* - ML-DSA-87: 7 KiB
679+
* For detailed expected memory savings, see the
680+
* mldsa-native README.
685681
*
686682
* This option is useful for embedded systems with tight RAM
687683
* constraints but relaxed performance requirements.
@@ -693,7 +689,6 @@
693689
*****************************************************************************/
694690
/* #define MLD_CONFIG_REDUCE_RAM */
695691

696-
697692
/************************* Config internals ********************************/
698693

699694
#endif /* MLD_BUILD_INTERNAL */

examples/custom_backend/mldsa_native/mldsa_native_config.h

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -669,14 +669,10 @@
669669
* Name: MLD_CONFIG_REDUCE_RAM [EXPERIMENTAL]
670670
*
671671
* Description: Set this to reduce RAM usage.
672+
* This trades memory for performance.
672673
*
673-
* This configuration option is work in progress.
674-
*
675-
* At present it results the following memory saving in signing
676-
* with no impact on performance:
677-
* - ML-DSA-44: 4 KiB
678-
* - ML-DSA-65: 5 KiB
679-
* - ML-DSA-87: 7 KiB
674+
* For detailed expected memory savings, see the
675+
* mldsa-native README.
680676
*
681677
* This option is useful for embedded systems with tight RAM
682678
* constraints but relaxed performance requirements.
@@ -688,7 +684,6 @@
688684
*****************************************************************************/
689685
/* #define MLD_CONFIG_REDUCE_RAM */
690686

691-
692687
/************************* Config internals ********************************/
693688

694689
#endif /* MLD_BUILD_INTERNAL */

examples/monolithic_build/mldsa_native/mldsa_native_config.h

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -672,14 +672,10 @@
672672
* Name: MLD_CONFIG_REDUCE_RAM [EXPERIMENTAL]
673673
*
674674
* Description: Set this to reduce RAM usage.
675+
* This trades memory for performance.
675676
*
676-
* This configuration option is work in progress.
677-
*
678-
* At present it results the following memory saving in signing
679-
* with no impact on performance:
680-
* - ML-DSA-44: 4 KiB
681-
* - ML-DSA-65: 5 KiB
682-
* - ML-DSA-87: 7 KiB
677+
* For detailed expected memory savings, see the
678+
* mldsa-native README.
683679
*
684680
* This option is useful for embedded systems with tight RAM
685681
* constraints but relaxed performance requirements.
@@ -691,7 +687,6 @@
691687
*****************************************************************************/
692688
/* #define MLD_CONFIG_REDUCE_RAM */
693689

694-
695690
/************************* Config internals ********************************/
696691

697692
#endif /* MLD_BUILD_INTERNAL */

examples/monolithic_build_multilevel/mldsa_native/mldsa_native_config.h

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -673,14 +673,10 @@
673673
* Name: MLD_CONFIG_REDUCE_RAM [EXPERIMENTAL]
674674
*
675675
* Description: Set this to reduce RAM usage.
676+
* This trades memory for performance.
676677
*
677-
* This configuration option is work in progress.
678-
*
679-
* At present it results the following memory saving in signing
680-
* with no impact on performance:
681-
* - ML-DSA-44: 4 KiB
682-
* - ML-DSA-65: 5 KiB
683-
* - ML-DSA-87: 7 KiB
678+
* For detailed expected memory savings, see the
679+
* mldsa-native README.
684680
*
685681
* This option is useful for embedded systems with tight RAM
686682
* constraints but relaxed performance requirements.
@@ -692,7 +688,6 @@
692688
*****************************************************************************/
693689
/* #define MLD_CONFIG_REDUCE_RAM */
694690

695-
696691
/************************* Config internals ********************************/
697692

698693
#endif /* MLD_BUILD_INTERNAL */

examples/monolithic_build_multilevel_native/mldsa_native/mldsa_native_config.h

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -680,14 +680,10 @@ static MLD_INLINE void mld_randombytes(uint8_t *ptr, size_t len)
680680
* Name: MLD_CONFIG_REDUCE_RAM [EXPERIMENTAL]
681681
*
682682
* Description: Set this to reduce RAM usage.
683+
* This trades memory for performance.
683684
*
684-
* This configuration option is work in progress.
685-
*
686-
* At present it results the following memory saving in signing
687-
* with no impact on performance:
688-
* - ML-DSA-44: 4 KiB
689-
* - ML-DSA-65: 5 KiB
690-
* - ML-DSA-87: 7 KiB
685+
* For detailed expected memory savings, see the
686+
* mldsa-native README.
691687
*
692688
* This option is useful for embedded systems with tight RAM
693689
* constraints but relaxed performance requirements.
@@ -699,7 +695,6 @@ static MLD_INLINE void mld_randombytes(uint8_t *ptr, size_t len)
699695
*****************************************************************************/
700696
/* #define MLD_CONFIG_REDUCE_RAM */
701697

702-
703698
/************************* Config internals ********************************/
704699

705700
#endif /* MLD_BUILD_INTERNAL */

examples/monolithic_build_native/mldsa_native/mldsa_native_config.h

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -672,14 +672,10 @@
672672
* Name: MLD_CONFIG_REDUCE_RAM [EXPERIMENTAL]
673673
*
674674
* Description: Set this to reduce RAM usage.
675+
* This trades memory for performance.
675676
*
676-
* This configuration option is work in progress.
677-
*
678-
* At present it results the following memory saving in signing
679-
* with no impact on performance:
680-
* - ML-DSA-44: 4 KiB
681-
* - ML-DSA-65: 5 KiB
682-
* - ML-DSA-87: 7 KiB
677+
* For detailed expected memory savings, see the
678+
* mldsa-native README.
683679
*
684680
* This option is useful for embedded systems with tight RAM
685681
* constraints but relaxed performance requirements.
@@ -691,7 +687,6 @@
691687
*****************************************************************************/
692688
/* #define MLD_CONFIG_REDUCE_RAM */
693689

694-
695690
/************************* Config internals ********************************/
696691

697692
#endif /* MLD_BUILD_INTERNAL */

0 commit comments

Comments
 (0)