Skip to content

Commit 8767dc5

Browse files
committed
Add MLD_CONFIG_SERIAL_FIPS202_ONLY option
Currently, in 3 places in mldsa-native (mld_poly_uniform_4x, mld_poly_uniform_eta_4x, mld_poly_uniform_gamma1_4x) we make use of 4-way batched Keccak. That approach requires to keep around 4 Keccak states in memory. This approach is incompatible with using a Keccak accelerator where there is only a single state and it lives inside of the accelerator. This commit adds an option MLD_CONFIG_SERIAL_FIPS202_ONLY that (once fully implemented) switches to serial processing for the 3 functions above. The functions above are not yet modified in this commit, but instead we do it in subsequent commits. Signed-off-by: Matthias J. Kannwischer <[email protected]>
1 parent f3bc6ca commit 8767dc5

File tree

15 files changed

+333
-12
lines changed

15 files changed

+333
-12
lines changed

examples/monolithic_build/config_44.h

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,28 @@
426426
*****************************************************************************/
427427
/* #define MLD_CONFIG_NO_ASM_VALUE_BARRIER */
428428

429-
429+
/******************************************************************************
430+
* Name: MLD_CONFIG_SERIAL_FIPS202_ONLY
431+
*
432+
* Description: Set this to use a FIPS202 implementation with global state
433+
* that supports only one active Keccak computation at a time
434+
* (e.g. some hardware accelerators).
435+
*
436+
* If this option is set, ML-DSA will use FIPS202 operations
437+
* serially, ensuring that only one SHAKE context is active
438+
* at any given time.
439+
*
440+
* This allows offloading Keccak computations to a hardware
441+
* accelerator that holds only a single Keccak state locally,
442+
* rather than requiring support for multiple concurrent
443+
* Keccak states.
444+
*
445+
* NOTE: Depending on the target CPU, this may reduce
446+
* performance when using software FIPS202 implementations.
447+
* Only enable this when you have to.
448+
*
449+
*****************************************************************************/
450+
/* #define MLD_CONFIG_SERIAL_FIPS202_ONLY */
430451

431452
/************************* Config internals ********************************/
432453

examples/monolithic_build/config_65.h

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,28 @@
426426
*****************************************************************************/
427427
/* #define MLD_CONFIG_NO_ASM_VALUE_BARRIER */
428428

429-
429+
/******************************************************************************
430+
* Name: MLD_CONFIG_SERIAL_FIPS202_ONLY
431+
*
432+
* Description: Set this to use a FIPS202 implementation with global state
433+
* that supports only one active Keccak computation at a time
434+
* (e.g. some hardware accelerators).
435+
*
436+
* If this option is set, ML-DSA will use FIPS202 operations
437+
* serially, ensuring that only one SHAKE context is active
438+
* at any given time.
439+
*
440+
* This allows offloading Keccak computations to a hardware
441+
* accelerator that holds only a single Keccak state locally,
442+
* rather than requiring support for multiple concurrent
443+
* Keccak states.
444+
*
445+
* NOTE: Depending on the target CPU, this may reduce
446+
* performance when using software FIPS202 implementations.
447+
* Only enable this when you have to.
448+
*
449+
*****************************************************************************/
450+
/* #define MLD_CONFIG_SERIAL_FIPS202_ONLY */
430451

431452
/************************* Config internals ********************************/
432453

examples/monolithic_build/config_87.h

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,28 @@
426426
*****************************************************************************/
427427
/* #define MLD_CONFIG_NO_ASM_VALUE_BARRIER */
428428

429-
429+
/******************************************************************************
430+
* Name: MLD_CONFIG_SERIAL_FIPS202_ONLY
431+
*
432+
* Description: Set this to use a FIPS202 implementation with global state
433+
* that supports only one active Keccak computation at a time
434+
* (e.g. some hardware accelerators).
435+
*
436+
* If this option is set, ML-DSA will use FIPS202 operations
437+
* serially, ensuring that only one SHAKE context is active
438+
* at any given time.
439+
*
440+
* This allows offloading Keccak computations to a hardware
441+
* accelerator that holds only a single Keccak state locally,
442+
* rather than requiring support for multiple concurrent
443+
* Keccak states.
444+
*
445+
* NOTE: Depending on the target CPU, this may reduce
446+
* performance when using software FIPS202 implementations.
447+
* Only enable this when you have to.
448+
*
449+
*****************************************************************************/
450+
/* #define MLD_CONFIG_SERIAL_FIPS202_ONLY */
430451

431452
/************************* Config internals ********************************/
432453

examples/monolithic_build_multilevel/multilevel_config.h

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,28 @@
427427
*****************************************************************************/
428428
/* #define MLD_CONFIG_NO_ASM_VALUE_BARRIER */
429429

430-
430+
/******************************************************************************
431+
* Name: MLD_CONFIG_SERIAL_FIPS202_ONLY
432+
*
433+
* Description: Set this to use a FIPS202 implementation with global state
434+
* that supports only one active Keccak computation at a time
435+
* (e.g. some hardware accelerators).
436+
*
437+
* If this option is set, ML-DSA will use FIPS202 operations
438+
* serially, ensuring that only one SHAKE context is active
439+
* at any given time.
440+
*
441+
* This allows offloading Keccak computations to a hardware
442+
* accelerator that holds only a single Keccak state locally,
443+
* rather than requiring support for multiple concurrent
444+
* Keccak states.
445+
*
446+
* NOTE: Depending on the target CPU, this may reduce
447+
* performance when using software FIPS202 implementations.
448+
* Only enable this when you have to.
449+
*
450+
*****************************************************************************/
451+
/* #define MLD_CONFIG_SERIAL_FIPS202_ONLY */
431452

432453
/************************* Config internals ********************************/
433454

integration/liboqs/config_aarch64.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,29 @@ static MLD_INLINE void mld_randombytes(uint8_t *ptr, size_t len)
272272
#define MLD_CONFIG_EXTERNAL_API_QUALIFIER OQS_API
273273
#endif /* !__ASSEMBLER__ */
274274

275+
/******************************************************************************
276+
* Name: MLD_CONFIG_SERIAL_FIPS202_ONLY
277+
*
278+
* Description: Set this to use a FIPS202 implementation with global state
279+
* that supports only one active Keccak computation at a time
280+
* (e.g. some hardware accelerators).
281+
*
282+
* If this option is set, ML-DSA will use FIPS202 operations
283+
* serially, ensuring that only one SHAKE context is active
284+
* at any given time.
285+
*
286+
* This allows offloading Keccak computations to a hardware
287+
* accelerator that holds only a single Keccak state locally,
288+
* rather than requiring support for multiple concurrent
289+
* Keccak states.
290+
*
291+
* NOTE: Depending on the target CPU, this may reduce
292+
* performance when using software FIPS202 implementations.
293+
* Only enable this when you have to.
294+
*
295+
*****************************************************************************/
296+
/* #define MLD_CONFIG_SERIAL_FIPS202_ONLY */
297+
275298
/************************* Config internals ********************************/
276299

277300
/* Default namespace

integration/liboqs/config_c.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,29 @@ static MLD_INLINE void mld_randombytes(uint8_t *ptr, size_t len)
276276
#define MLD_CONFIG_EXTERNAL_API_QUALIFIER OQS_API
277277
#endif /* !__ASSEMBLER__ */
278278

279+
/******************************************************************************
280+
* Name: MLD_CONFIG_SERIAL_FIPS202_ONLY
281+
*
282+
* Description: Set this to use a FIPS202 implementation with global state
283+
* that supports only one active Keccak computation at a time
284+
* (e.g. some hardware accelerators).
285+
*
286+
* If this option is set, ML-DSA will use FIPS202 operations
287+
* serially, ensuring that only one SHAKE context is active
288+
* at any given time.
289+
*
290+
* This allows offloading Keccak computations to a hardware
291+
* accelerator that holds only a single Keccak state locally,
292+
* rather than requiring support for multiple concurrent
293+
* Keccak states.
294+
*
295+
* NOTE: Depending on the target CPU, this may reduce
296+
* performance when using software FIPS202 implementations.
297+
* Only enable this when you have to.
298+
*
299+
*****************************************************************************/
300+
/* #define MLD_CONFIG_SERIAL_FIPS202_ONLY */
301+
279302
/************************* Config internals ********************************/
280303

281304
/* Default namespace

integration/liboqs/config_x86_64.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,29 @@ static MLD_INLINE void mld_randombytes(uint8_t *ptr, size_t len)
274274
*****************************************************************************/
275275
/* #define MLD_CONFIG_NO_ASM_VALUE_BARRIER */
276276

277+
/******************************************************************************
278+
* Name: MLD_CONFIG_SERIAL_FIPS202_ONLY
279+
*
280+
* Description: Set this to use a FIPS202 implementation with global state
281+
* that supports only one active Keccak computation at a time
282+
* (e.g. some hardware accelerators).
283+
*
284+
* If this option is set, ML-DSA will use FIPS202 operations
285+
* serially, ensuring that only one SHAKE context is active
286+
* at any given time.
287+
*
288+
* This allows offloading Keccak computations to a hardware
289+
* accelerator that holds only a single Keccak state locally,
290+
* rather than requiring support for multiple concurrent
291+
* Keccak states.
292+
*
293+
* NOTE: Depending on the target CPU, this may reduce
294+
* performance when using software FIPS202 implementations.
295+
* Only enable this when you have to.
296+
*
297+
*****************************************************************************/
298+
/* #define MLD_CONFIG_SERIAL_FIPS202_ONLY */
299+
277300
/************************* Config internals ********************************/
278301

279302
/* Default namespace

mldsa/src/config.h

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,28 @@
412412
*****************************************************************************/
413413
/* #define MLD_CONFIG_NO_ASM_VALUE_BARRIER */
414414

415-
415+
/******************************************************************************
416+
* Name: MLD_CONFIG_SERIAL_FIPS202_ONLY
417+
*
418+
* Description: Set this to use a FIPS202 implementation with global state
419+
* that supports only one active Keccak computation at a time
420+
* (e.g. some hardware accelerators).
421+
*
422+
* If this option is set, ML-DSA will use FIPS202 operations
423+
* serially, ensuring that only one SHAKE context is active
424+
* at any given time.
425+
*
426+
* This allows offloading Keccak computations to a hardware
427+
* accelerator that holds only a single Keccak state locally,
428+
* rather than requiring support for multiple concurrent
429+
* Keccak states.
430+
*
431+
* NOTE: Depending on the target CPU, this may reduce
432+
* performance when using software FIPS202 implementations.
433+
* Only enable this when you have to.
434+
*
435+
*****************************************************************************/
436+
/* #define MLD_CONFIG_SERIAL_FIPS202_ONLY */
416437

417438
/************************* Config internals ********************************/
418439

test/break_pct_config.h

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,28 @@ static MLD_INLINE int mld_break_pct(void)
432432
*****************************************************************************/
433433
/* #define MLD_CONFIG_NO_ASM_VALUE_BARRIER */
434434

435-
435+
/******************************************************************************
436+
* Name: MLD_CONFIG_SERIAL_FIPS202_ONLY
437+
*
438+
* Description: Set this to use a FIPS202 implementation with global state
439+
* that supports only one active Keccak computation at a time
440+
* (e.g. some hardware accelerators).
441+
*
442+
* If this option is set, ML-DSA will use FIPS202 operations
443+
* serially, ensuring that only one SHAKE context is active
444+
* at any given time.
445+
*
446+
* This allows offloading Keccak computations to a hardware
447+
* accelerator that holds only a single Keccak state locally,
448+
* rather than requiring support for multiple concurrent
449+
* Keccak states.
450+
*
451+
* NOTE: Depending on the target CPU, this may reduce
452+
* performance when using software FIPS202 implementations.
453+
* Only enable this when you have to.
454+
*
455+
*****************************************************************************/
456+
/* #define MLD_CONFIG_SERIAL_FIPS202_ONLY */
436457

437458
/************************* Config internals ********************************/
438459

test/custom_memcpy_config.h

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,28 @@ static MLD_INLINE void *mld_memcpy(void *dest, const void *src, size_t n)
435435
*****************************************************************************/
436436
/* #define MLD_CONFIG_NO_ASM_VALUE_BARRIER */
437437

438-
438+
/******************************************************************************
439+
* Name: MLD_CONFIG_SERIAL_FIPS202_ONLY
440+
*
441+
* Description: Set this to use a FIPS202 implementation with global state
442+
* that supports only one active Keccak computation at a time
443+
* (e.g. some hardware accelerators).
444+
*
445+
* If this option is set, ML-DSA will use FIPS202 operations
446+
* serially, ensuring that only one SHAKE context is active
447+
* at any given time.
448+
*
449+
* This allows offloading Keccak computations to a hardware
450+
* accelerator that holds only a single Keccak state locally,
451+
* rather than requiring support for multiple concurrent
452+
* Keccak states.
453+
*
454+
* NOTE: Depending on the target CPU, this may reduce
455+
* performance when using software FIPS202 implementations.
456+
* Only enable this when you have to.
457+
*
458+
*****************************************************************************/
459+
/* #define MLD_CONFIG_SERIAL_FIPS202_ONLY */
439460

440461
/************************* Config internals ********************************/
441462

0 commit comments

Comments
 (0)