Skip to content

Commit e9954fb

Browse files
committed
Use ad-hoc matrix generation for reduced RAM usage
Signed-off-by: Hanno Becker <beckphan@amazon.co.uk>
1 parent 4e0d1bd commit e9954fb

File tree

31 files changed

+190
-217
lines changed

31 files changed

+190
-217
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,15 @@ 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**: 16 KB (ML-DSA-44), 30 KB (ML-DSA-65), 56 KB (ML-DSA-87)
161+
- **Performance cost**: Matrix generation is no longer batched, resulting in slower signing and verification
162+
163+
To enable this mode, define `MLD_CONFIG_REDUCE_RAM` in [mldsa_config.h](mldsa/mldsa_config.h) or pass `-DMLD_CONFIG_REDUCE_RAM` as a compiler flag.
164+
156165
### Does mldsa-native use hedged or deterministic signing?
157166

158167
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: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -671,13 +671,11 @@
671671
*
672672
* Description: Set this to reduce RAM usage.
673673
*
674-
* This configuration option is work in progress.
675-
*
676-
* At present it results the following memory saving in signing
677-
* with no impact on performance:
678-
* - ML-DSA-44: 4 KiB
679-
* - ML-DSA-65: 5 KiB
680-
* - ML-DSA-87: 7 KiB
674+
* This trades memory for performance:
675+
* - Memory savings: 16 KB (ML-DSA-44), 30 KB (ML-DSA-65),
676+
* 56 KB (ML-DSA-87)
677+
* - Performance cost: Matrix generation is no longer batched,
678+
* resulting in slower signing and verification
681679
*
682680
* This option is useful for embedded systems with tight RAM
683681
* constraints but relaxed performance requirements.
@@ -689,7 +687,6 @@
689687
*****************************************************************************/
690688
/* #define MLD_CONFIG_REDUCE_RAM */
691689

692-
693690
/************************* Config internals ********************************/
694691

695692
#endif /* MLD_BUILD_INTERNAL */

examples/basic_lowram/mldsa_native/mldsa_native_config.h

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -670,13 +670,11 @@
670670
*
671671
* Description: Set this to reduce RAM usage.
672672
*
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
673+
* This trades memory for performance:
674+
* - Memory savings: 16 KB (ML-DSA-44), 30 KB (ML-DSA-65),
675+
* 56 KB (ML-DSA-87)
676+
* - Performance cost: Matrix generation is no longer batched,
677+
* resulting in slower signing and verification
680678
*
681679
* This option is useful for embedded systems with tight RAM
682680
* constraints but relaxed performance requirements.
@@ -688,7 +686,6 @@
688686
*****************************************************************************/
689687
#define MLD_CONFIG_REDUCE_RAM
690688

691-
692689
/************************* Config internals ********************************/
693690

694691
#endif /* MLD_BUILD_INTERNAL */

examples/bring_your_own_fips202/mldsa_native/mldsa_native_config.h

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -671,13 +671,11 @@
671671
*
672672
* Description: Set this to reduce RAM usage.
673673
*
674-
* This configuration option is work in progress.
675-
*
676-
* At present it results the following memory saving in signing
677-
* with no impact on performance:
678-
* - ML-DSA-44: 4 KiB
679-
* - ML-DSA-65: 5 KiB
680-
* - ML-DSA-87: 7 KiB
674+
* This trades memory for performance:
675+
* - Memory savings: 16 KB (ML-DSA-44), 30 KB (ML-DSA-65),
676+
* 56 KB (ML-DSA-87)
677+
* - Performance cost: Matrix generation is no longer batched,
678+
* resulting in slower signing and verification
681679
*
682680
* This option is useful for embedded systems with tight RAM
683681
* constraints but relaxed performance requirements.
@@ -689,7 +687,6 @@
689687
*****************************************************************************/
690688
/* #define MLD_CONFIG_REDUCE_RAM */
691689

692-
693690
/************************* Config internals ********************************/
694691

695692
#endif /* MLD_BUILD_INTERNAL */

examples/bring_your_own_fips202_static/mldsa_native/mldsa_native_config.h

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -672,13 +672,11 @@
672672
*
673673
* Description: Set this to reduce RAM usage.
674674
*
675-
* This configuration option is work in progress.
676-
*
677-
* At present it results the following memory saving in signing
678-
* with no impact on performance:
679-
* - ML-DSA-44: 4 KiB
680-
* - ML-DSA-65: 5 KiB
681-
* - ML-DSA-87: 7 KiB
675+
* This trades memory for performance:
676+
* - Memory savings: 16 KB (ML-DSA-44), 30 KB (ML-DSA-65),
677+
* 56 KB (ML-DSA-87)
678+
* - Performance cost: Matrix generation is no longer batched,
679+
* resulting in slower signing and verification
682680
*
683681
* This option is useful for embedded systems with tight RAM
684682
* constraints but relaxed performance requirements.
@@ -690,7 +688,6 @@
690688
*****************************************************************************/
691689
/* #define MLD_CONFIG_REDUCE_RAM */
692690

693-
694691
/************************* Config internals ********************************/
695692

696693
#endif /* MLD_BUILD_INTERNAL */

examples/custom_backend/mldsa_native/mldsa_native_config.h

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -667,13 +667,11 @@
667667
*
668668
* Description: Set this to reduce RAM usage.
669669
*
670-
* This configuration option is work in progress.
671-
*
672-
* At present it results the following memory saving in signing
673-
* with no impact on performance:
674-
* - ML-DSA-44: 4 KiB
675-
* - ML-DSA-65: 5 KiB
676-
* - ML-DSA-87: 7 KiB
670+
* This trades memory for performance:
671+
* - Memory savings: 16 KB (ML-DSA-44), 30 KB (ML-DSA-65),
672+
* 56 KB (ML-DSA-87)
673+
* - Performance cost: Matrix generation is no longer batched,
674+
* resulting in slower signing and verification
677675
*
678676
* This option is useful for embedded systems with tight RAM
679677
* constraints but relaxed performance requirements.
@@ -685,7 +683,6 @@
685683
*****************************************************************************/
686684
/* #define MLD_CONFIG_REDUCE_RAM */
687685

688-
689686
/************************* Config internals ********************************/
690687

691688
#endif /* MLD_BUILD_INTERNAL */

examples/monolithic_build/mldsa_native/mldsa_native_config.h

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -670,13 +670,11 @@
670670
*
671671
* Description: Set this to reduce RAM usage.
672672
*
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
673+
* This trades memory for performance:
674+
* - Memory savings: 16 KB (ML-DSA-44), 30 KB (ML-DSA-65),
675+
* 56 KB (ML-DSA-87)
676+
* - Performance cost: Matrix generation is no longer batched,
677+
* resulting in slower signing and verification
680678
*
681679
* This option is useful for embedded systems with tight RAM
682680
* constraints but relaxed performance requirements.
@@ -688,7 +686,6 @@
688686
*****************************************************************************/
689687
/* #define MLD_CONFIG_REDUCE_RAM */
690688

691-
692689
/************************* Config internals ********************************/
693690

694691
#endif /* MLD_BUILD_INTERNAL */

examples/monolithic_build_multilevel/mldsa_native/mldsa_native_config.h

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -671,13 +671,11 @@
671671
*
672672
* Description: Set this to reduce RAM usage.
673673
*
674-
* This configuration option is work in progress.
675-
*
676-
* At present it results the following memory saving in signing
677-
* with no impact on performance:
678-
* - ML-DSA-44: 4 KiB
679-
* - ML-DSA-65: 5 KiB
680-
* - ML-DSA-87: 7 KiB
674+
* This trades memory for performance:
675+
* - Memory savings: 16 KB (ML-DSA-44), 30 KB (ML-DSA-65),
676+
* 56 KB (ML-DSA-87)
677+
* - Performance cost: Matrix generation is no longer batched,
678+
* resulting in slower signing and verification
681679
*
682680
* This option is useful for embedded systems with tight RAM
683681
* constraints but relaxed performance requirements.
@@ -689,7 +687,6 @@
689687
*****************************************************************************/
690688
/* #define MLD_CONFIG_REDUCE_RAM */
691689

692-
693690
/************************* Config internals ********************************/
694691

695692
#endif /* MLD_BUILD_INTERNAL */

examples/monolithic_build_multilevel_native/mldsa_native/mldsa_native_config.h

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -678,13 +678,11 @@ static MLD_INLINE void mld_randombytes(uint8_t *ptr, size_t len)
678678
*
679679
* Description: Set this to reduce RAM usage.
680680
*
681-
* This configuration option is work in progress.
682-
*
683-
* At present it results the following memory saving in signing
684-
* with no impact on performance:
685-
* - ML-DSA-44: 4 KiB
686-
* - ML-DSA-65: 5 KiB
687-
* - ML-DSA-87: 7 KiB
681+
* This trades memory for performance:
682+
* - Memory savings: 16 KB (ML-DSA-44), 30 KB (ML-DSA-65),
683+
* 56 KB (ML-DSA-87)
684+
* - Performance cost: Matrix generation is no longer batched,
685+
* resulting in slower signing and verification
688686
*
689687
* This option is useful for embedded systems with tight RAM
690688
* constraints but relaxed performance requirements.
@@ -696,7 +694,6 @@ static MLD_INLINE void mld_randombytes(uint8_t *ptr, size_t len)
696694
*****************************************************************************/
697695
/* #define MLD_CONFIG_REDUCE_RAM */
698696

699-
700697
/************************* Config internals ********************************/
701698

702699
#endif /* MLD_BUILD_INTERNAL */

examples/monolithic_build_native/mldsa_native/mldsa_native_config.h

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -670,13 +670,11 @@
670670
*
671671
* Description: Set this to reduce RAM usage.
672672
*
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
673+
* This trades memory for performance:
674+
* - Memory savings: 16 KB (ML-DSA-44), 30 KB (ML-DSA-65),
675+
* 56 KB (ML-DSA-87)
676+
* - Performance cost: Matrix generation is no longer batched,
677+
* resulting in slower signing and verification
680678
*
681679
* This option is useful for embedded systems with tight RAM
682680
* constraints but relaxed performance requirements.
@@ -688,7 +686,6 @@
688686
*****************************************************************************/
689687
/* #define MLD_CONFIG_REDUCE_RAM */
690688

691-
692689
/************************* Config internals ********************************/
693690

694691
#endif /* MLD_BUILD_INTERNAL */

0 commit comments

Comments
 (0)