Skip to content

Commit 97043b8

Browse files
committed
FIPS: PCT enter error state upon 5 failures
Signed-off-by: Stephan Mueller <smueller@chronox.de>
1 parent ae0a59d commit 97043b8

File tree

5 files changed

+20
-8
lines changed

5 files changed

+20
-8
lines changed

curve25519/src/ed25519_pct.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ static inline int _lc_ed25519_pct_fips(const struct lc_ed25519_pk *pk,
5151
static inline int lc_ed25519_pct_fips(const struct lc_ed25519_pk *pk,
5252
const struct lc_ed25519_sk *sk)
5353
{
54-
if (fips140_mode_enabled())
55-
return _lc_ed25519_pct_fips(pk, sk);
54+
FIPS140_PCT_LOOP(_lc_ed25519_pct_fips(pk, sk))
55+
5656
return 0;
5757
}
5858

internal/api/fips_mode.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,19 @@ extern "C" {
3131
*/
3232
int fips140_mode_enabled(void);
3333

34+
#define FIPS140_PCT_LOOP(func) \
35+
if (fips140_mode_enabled()) { \
36+
unsigned int __i; \
37+
int __ret; \
38+
\
39+
for (__i = 0; __i < 5; __i++) { \
40+
__ret = func; \
41+
if (!__ret) \
42+
return __ret; \
43+
} \
44+
assert(0); \
45+
}
46+
3447
#ifdef __cplusplus
3548
}
3649
#endif

ml-dsa/src/dilithium_pct.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ static inline int _lc_dilithium_pct_fips(const struct lc_dilithium_pk *pk,
5151
static inline int lc_dilithium_pct_fips(const struct lc_dilithium_pk *pk,
5252
const struct lc_dilithium_sk *sk)
5353
{
54-
if (fips140_mode_enabled())
55-
return _lc_dilithium_pct_fips(pk, sk);
54+
FIPS140_PCT_LOOP(_lc_dilithium_pct_fips(pk, sk))
55+
5656
return 0;
5757
}
5858

ml-kem/src/kyber_pct.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ static inline int _lc_kyber_pct_fips(const struct lc_kyber_pk *pk,
7272
static inline int lc_kyber_pct_fips(const struct lc_kyber_pk *pk,
7373
const struct lc_kyber_sk *sk)
7474
{
75-
if (fips140_mode_enabled())
76-
return _lc_kyber_pct_fips(pk, sk);
75+
FIPS140_PCT_LOOP(_lc_kyber_pct_fips(pk, sk))
7776
return 0;
7877
}
7978

slh-dsa/src/sphincs_pct.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ static inline int _lc_sphincs_pct_fips(const struct lc_sphincs_pk *pk,
5151
static inline int lc_sphincs_pct_fips(const struct lc_sphincs_pk *pk,
5252
const struct lc_sphincs_sk *sk)
5353
{
54-
if (fips140_mode_enabled())
55-
return _lc_sphincs_pct_fips(pk, sk);
54+
FIPS140_PCT_LOOP(_lc_sphincs_pct_fips(pk, sk))
55+
5656
return 0;
5757
}
5858

0 commit comments

Comments
 (0)