Skip to content

Commit 9ae7d1f

Browse files
committed
PCT: simplify code
Signed-off-by: Stephan Mueller <smueller@chronox.de>
1 parent a0e77e6 commit 9ae7d1f

File tree

5 files changed

+17
-35
lines changed

5 files changed

+17
-35
lines changed

ml-dsa/src/dilithium_api.c

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@
2828
#include "ext_headers.h"
2929
#include "dilithium_helper.h"
3030
#include "lc_dilithium.h"
31-
#include "small_stack_support.h"
32-
#include "ret_checkers.h"
31+
#include "dilithium_pct.h"
3332
#include "visibility.h"
3433

3534
LC_INTERFACE_FUNCTION(int, lc_dilithium_ctx_alloc,
@@ -524,20 +523,7 @@ LC_INTERFACE_FUNCTION(int, lc_dilithium_keypair_from_seed,
524523
LC_INTERFACE_FUNCTION(int, lc_dilithium_pct, const struct lc_dilithium_pk *pk,
525524
const struct lc_dilithium_sk *sk)
526525
{
527-
struct workspace {
528-
uint8_t m[32];
529-
struct lc_dilithium_sig sig;
530-
};
531-
int ret;
532-
LC_DECLARE_MEM(ws, struct workspace, sizeof(uint64_t));
533-
534-
CKINT(lc_dilithium_sign(&ws->sig, ws->m, sizeof(ws->m), sk,
535-
lc_seeded_rng));
536-
CKINT(lc_dilithium_verify(&ws->sig, ws->m, sizeof(ws->m), pk));
537-
538-
out:
539-
LC_RELEASE_MEM(ws);
540-
return ret;
526+
return _lc_dilithium_pct_fips(pk, sk);
541527
}
542528

543529
LC_INTERFACE_FUNCTION(int, lc_dilithium_sign, struct lc_dilithium_sig *sig,

ml-dsa/src/dilithium_pct.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#ifndef DILITHIUM_PCT_H
2121
#define DILITHIUM_PCT_H
2222

23-
#include "dilithium_type.h"
2423
#include "ret_checkers.h"
2524
#include "small_stack_support.h"
2625
#include "visibility.h"

ml-kem/src/kyber_pct.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,19 @@
1717
* DAMAGE.
1818
*/
1919

20-
#include "kyber_type.h"
20+
#ifndef KYBER_PCT_H
21+
#define KYBER_PCT_H
22+
2123
#include "lc_memcmp_secure.h"
2224
#include "small_stack_support.h"
2325
#include "ret_checkers.h"
2426
#include "timecop.h"
2527
#include "visibility.h"
2628

29+
#ifdef __cplusplus
30+
extern "C" {
31+
#endif
32+
2733
static inline int _lc_kyber_pct_fips(const struct lc_kyber_pk *pk,
2834
const struct lc_kyber_sk *sk)
2935
{
@@ -73,3 +79,9 @@ static inline int lc_kyber_pct_fips(const struct lc_kyber_pk *pk,
7379
return 0;
7480
#endif
7581
}
82+
83+
#ifdef __cplusplus
84+
}
85+
#endif
86+
87+
#endif /* KYBER_PCT_H */

slh-dsa/src/sphincs_api.c

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
*/
1919

2020
#include "lc_sphincs.h"
21-
#include "small_stack_support.h"
22-
#include "ret_checkers.h"
21+
#include "sphincs_pct.h"
2322
#include "visibility.h"
2423

2524
LC_INTERFACE_FUNCTION(int, lc_sphincs_ctx_alloc, struct lc_sphincs_ctx **ctx)
@@ -911,20 +910,7 @@ LC_INTERFACE_FUNCTION(int, lc_sphincs_keypair_from_seed,
911910
LC_INTERFACE_FUNCTION(int, lc_sphincs_pct, const struct lc_sphincs_pk *pk,
912911
const struct lc_sphincs_sk *sk)
913912
{
914-
struct workspace {
915-
uint8_t m[32];
916-
struct lc_sphincs_sig sig;
917-
};
918-
int ret;
919-
LC_DECLARE_MEM(ws, struct workspace, sizeof(uint64_t));
920-
921-
CKINT(lc_sphincs_sign(&ws->sig, ws->m, sizeof(ws->m), sk,
922-
lc_seeded_rng));
923-
CKINT(lc_sphincs_verify(&ws->sig, ws->m, sizeof(ws->m), pk));
924-
925-
out:
926-
LC_RELEASE_MEM(ws);
927-
return ret;
913+
return _lc_sphincs_pct_fips(pk, sk);
928914
}
929915

930916
LC_INTERFACE_FUNCTION(int, lc_sphincs_sign, struct lc_sphincs_sig *sig,

slh-dsa/src/sphincs_pct.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#ifndef SPHINCS_PCT_H
2121
#define SPHINCS_PCT_H
2222

23-
#include "sphincs_type.h"
2423
#include "ret_checkers.h"
2524
#include "small_stack_support.h"
2625
#include "visibility.h"

0 commit comments

Comments
 (0)