Skip to content

Commit d731285

Browse files
mkannwischerrod-chapman
authored andcommitted
Add MLK_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 MLK_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 0d8fcae commit d731285

File tree

11 files changed

+248
-5
lines changed

11 files changed

+248
-5
lines changed

integration/liboqs/config_aarch64.h

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

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

276299
/* Default namespace

integration/liboqs/config_c.h

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

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

280303
/* Default namespace

integration/liboqs/config_x86_64.h

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

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

278301
/* Default namespace

mldsa/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: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,29 @@ static MLD_INLINE int mld_break_pct(void)
306306
*****************************************************************************/
307307
/* #define MLD_CONFIG_NO_ASM_VALUE_BARRIER */
308308

309+
/******************************************************************************
310+
* Name: MLD_CONFIG_SERIAL_FIPS202_ONLY
311+
*
312+
* Description: Set this to use a FIPS202 implementation with global state
313+
* that supports only one active Keccak computation at a time
314+
* (e.g. some hardware accelerators).
315+
*
316+
* If this option is set, ML-DSA will use FIPS202 operations
317+
* serially, ensuring that only one SHAKE context is active
318+
* at any given time.
319+
*
320+
* This allows offloading Keccak computations to a hardware
321+
* accelerator that holds only a single Keccak state locally,
322+
* rather than requiring support for multiple concurrent
323+
* Keccak states.
324+
*
325+
* NOTE: Depending on the target CPU, this may reduce
326+
* performance when using software FIPS202 implementations.
327+
* Only enable this when you have to.
328+
*
329+
*****************************************************************************/
330+
/* #define MLD_CONFIG_SERIAL_FIPS202_ONLY */
331+
309332
/************************* Config internals ********************************/
310333

311334
/* Default namespace

test/custom_memcpy_config.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,29 @@ static MLD_INLINE void *mld_memcpy(void *dest, const void *src, size_t n)
396396
*****************************************************************************/
397397
/* #define MLD_CONFIG_NO_ASM_VALUE_BARRIER */
398398

399+
/******************************************************************************
400+
* Name: MLD_CONFIG_SERIAL_FIPS202_ONLY
401+
*
402+
* Description: Set this to use a FIPS202 implementation with global state
403+
* that supports only one active Keccak computation at a time
404+
* (e.g. some hardware accelerators).
405+
*
406+
* If this option is set, ML-DSA will use FIPS202 operations
407+
* serially, ensuring that only one SHAKE context is active
408+
* at any given time.
409+
*
410+
* This allows offloading Keccak computations to a hardware
411+
* accelerator that holds only a single Keccak state locally,
412+
* rather than requiring support for multiple concurrent
413+
* Keccak states.
414+
*
415+
* NOTE: Depending on the target CPU, this may reduce
416+
* performance when using software FIPS202 implementations.
417+
* Only enable this when you have to.
418+
*
419+
*****************************************************************************/
420+
/* #define MLD_CONFIG_SERIAL_FIPS202_ONLY */
421+
399422
/************************* Config internals ********************************/
400423

401424
/* Default namespace

test/custom_memset_config.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,29 @@ static MLD_INLINE void *mld_memset(void *s, int c, size_t n)
396396
*****************************************************************************/
397397
/* #define MLD_CONFIG_NO_ASM_VALUE_BARRIER */
398398

399+
/******************************************************************************
400+
* Name: MLD_CONFIG_SERIAL_FIPS202_ONLY
401+
*
402+
* Description: Set this to use a FIPS202 implementation with global state
403+
* that supports only one active Keccak computation at a time
404+
* (e.g. some hardware accelerators).
405+
*
406+
* If this option is set, ML-DSA will use FIPS202 operations
407+
* serially, ensuring that only one SHAKE context is active
408+
* at any given time.
409+
*
410+
* This allows offloading Keccak computations to a hardware
411+
* accelerator that holds only a single Keccak state locally,
412+
* rather than requiring support for multiple concurrent
413+
* Keccak states.
414+
*
415+
* NOTE: Depending on the target CPU, this may reduce
416+
* performance when using software FIPS202 implementations.
417+
* Only enable this when you have to.
418+
*
419+
*****************************************************************************/
420+
/* #define MLD_CONFIG_SERIAL_FIPS202_ONLY */
421+
399422
/************************* Config internals ********************************/
400423

401424
/* Default namespace

test/custom_randombytes_config.h

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,28 @@ static MLD_INLINE void mld_randombytes(uint8_t *ptr, size_t len)
368368
*****************************************************************************/
369369
/* #define MLD_CONFIG_NO_ASM_VALUE_BARRIER */
370370

371-
371+
/******************************************************************************
372+
* Name: MLD_CONFIG_SERIAL_FIPS202_ONLY
373+
*
374+
* Description: Set this to use a FIPS202 implementation with global state
375+
* that supports only one active Keccak computation at a time
376+
* (e.g. some hardware accelerators).
377+
*
378+
* If this option is set, ML-DSA will use FIPS202 operations
379+
* serially, ensuring that only one SHAKE context is active
380+
* at any given time.
381+
*
382+
* This allows offloading Keccak computations to a hardware
383+
* accelerator that holds only a single Keccak state locally,
384+
* rather than requiring support for multiple concurrent
385+
* Keccak states.
386+
*
387+
* NOTE: Depending on the target CPU, this may reduce
388+
* performance when using software FIPS202 implementations.
389+
* Only enable this when you have to.
390+
*
391+
*****************************************************************************/
392+
/* #define MLD_CONFIG_SERIAL_FIPS202_ONLY */
372393

373394
/************************* Config internals ********************************/
374395

test/custom_stdlib_config.h

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,28 @@ static MLD_INLINE void *mld_memset(void *s, int c, size_t n)
402402
*****************************************************************************/
403403
/* #define MLD_CONFIG_NO_ASM_VALUE_BARRIER */
404404

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

407428
/************************* Config internals ********************************/
408429

test/custom_zeroize_config.h

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,28 @@ static MLD_INLINE void mld_zeroize_native(void *ptr, size_t len)
302302
*****************************************************************************/
303303
/* #define MLD_CONFIG_NO_ASM_VALUE_BARRIER */
304304

305-
305+
/******************************************************************************
306+
* Name: MLD_CONFIG_SERIAL_FIPS202_ONLY
307+
*
308+
* Description: Set this to use a FIPS202 implementation with global state
309+
* that supports only one active Keccak computation at a time
310+
* (e.g. some hardware accelerators).
311+
*
312+
* If this option is set, ML-DSA will use FIPS202 operations
313+
* serially, ensuring that only one SHAKE context is active
314+
* at any given time.
315+
*
316+
* This allows offloading Keccak computations to a hardware
317+
* accelerator that holds only a single Keccak state locally,
318+
* rather than requiring support for multiple concurrent
319+
* Keccak states.
320+
*
321+
* NOTE: Depending on the target CPU, this may reduce
322+
* performance when using software FIPS202 implementations.
323+
* Only enable this when you have to.
324+
*
325+
*****************************************************************************/
326+
/* #define MLD_CONFIG_SERIAL_FIPS202_ONLY */
306327

307328
/************************* Config internals ********************************/
308329

0 commit comments

Comments
 (0)