Skip to content

Commit 59f621a

Browse files
committed
FIPS: add lc_fips_integrity_checker API
Signed-off-by: Stephan Mueller <smueller@chronox.de>
1 parent c3fde18 commit 59f621a

File tree

9 files changed

+41
-10
lines changed

9 files changed

+41
-10
lines changed

README.fips.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,13 @@ NOTE2: The referenced ACVP proxy definitions explicitly exclude SHA LDT tests. T
4242

4343
The `leancrypto-fips` FIPS module implements a global service indicator. This implies that all algorithms are FIPS-approved and the fact that the FIPS module is active is the indicator that FIPS-approved services are available.
4444

45+
The API of `lc_status` provides the version information along with the status whether the FIPS mode is active.
46+
4547
## Cryptographic Algorithm Self Test
4648

4749
Each cryptographic algorithm has its own power-up self test which is executed before this algorithm is used for the first time.
4850

49-
The caller may trigger a complete new round of self tests, i.e. all algorithms will perform a new self test before the next use, when using the API of `lc_rerun_selftests`.
51+
The caller may trigger a complete new round of self tests, i.e. all algorithms will perform a new self test before the next use, when using the API of `lc_rerun_selftests`. To reperform the integrity test, the API `lc_fips_integrity_checker` is provided.
5052

5153
When a self-test fails, `leancrypto-fips` aborts and terminates itself as well as the calling application.
5254

internal/api/lc_status.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ extern "C" {
3232
*/
3333
void lc_rerun_selftests(void);
3434

35+
/**
36+
* @brief Re-run the FIPS 140 integrity test
37+
*
38+
* \note This API is only present in the FIPS module instance of leancrypto.
39+
*/
40+
void lc_fips_integrity_checker(void);
41+
3542
/**
3643
* @brief Status information about leancrypto
3744
*

internal/src/fips_integrity_checker_elf.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#include "build_bug_on.h"
2121
#include "fips_integrity_check.h"
2222
#include "helper.h"
23+
#include "lc_status.h"
24+
#include "visibility.h"
2325

2426
/*
2527
* The GNU linker creates these variables as start and endpoint of ELF sections
@@ -179,17 +181,22 @@ fips_integrity_checker_build(struct lc_fips_integrity_section_actual *act)
179181
fprintf(stderr, "} };\n");
180182
}
181183

182-
/*
183-
* This constructor is part of the regular "text" section and thus subject to
184-
* the integrity test.
185-
*/
186-
__attribute__((constructor)) static void fips_integrity_checker(void)
184+
LC_INTERFACE_FUNCTION(void, lc_fips_integrity_checker, void)
187185
{
188186
struct lc_fips_integrity_section_actual act[ARRAY_SIZE(secs)];
189187

190-
fips140_mode_enable();
191188
if (fips_integrity_check(secs, act, ARRAY_SIZE(secs))) {
192189
fips_integrity_checker_build(act);
193190
exit(1);
194191
}
195192
}
193+
194+
/*
195+
* This constructor is part of the regular "text" section and thus subject to
196+
* the integrity test.
197+
*/
198+
__attribute__((constructor)) static void fips_integrity_checker_dep(void)
199+
{
200+
fips140_mode_enable();
201+
lc_fips_integrity_checker();
202+
}

internal/src/meson.build

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ if (host_machine.system() == 'linux' and get_option('efi').disabled())
4141
src_fips_wrapper_generator += files([
4242
'fips_integrity_checker_elf_generator.c'
4343
])
44+
else
45+
# Catchall for all other environments
46+
src_fips_wrapper += files([
47+
'fips_integrity_checker_none.c'
48+
])
4449
endif
4550

4651
if (dilithium_enabled or

linux_kernel/Kbuild.basics

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ leancrypto-y += ../internal/src/left_encode.o \
8181
../internal/src/compare.o \
8282
../internal/src/fips_integrity_check.o \
8383
../internal/src/null_buffer.o \
84+
../internal/src/fips_integrity_checker_none.o\
8485
../internal/src/status.o
8586

8687
leancrypto-$(CONFIG_LEANCRYPTO_SIG_SUPPORT) \

meson.build

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,6 @@ meson.add_dist_script(dist_script, meson.project_version())
249249
# Find Doxygen program
250250
doxygen = find_program('doxygen', required : false)
251251

252-
# Find objcopy
253-
objcopy = find_program('objcopy', required : false)
254-
255252
################################################################################
256253
# EFI-specific defines
257254
################################################################################

ml-dsa/tests/dilithium_keygen_fips_tester.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "ext_headers.h"
2121
#include "lc_dilithium.h"
2222
#include "lc_sha3.h"
23+
#include "lc_status.h"
2324
#include "ret_checkers.h"
2425
#include "small_stack_support.h"
2526
#include "visibility.h"
@@ -41,6 +42,9 @@ static int dilithium_keygen_fips_tester(void)
4142
LC_DECLARE_MEM(ws, struct workspace, sizeof(uint64_t));
4243
int ret = 0;
4344

45+
/* Rerun power up integrity test */
46+
lc_fips_integrity_checker();
47+
4448
CKINT(lc_dilithium_keypair(&ws->pk, &ws->sk, lc_seeded_rng,
4549
DILITHIUM_TYPE));
4650

ml-kem/tests/kyber_keygen_fips_tester.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
*/
1919

2020
#include "lc_kyber.h"
21+
#include "lc_status.h"
2122
#include "ret_checkers.h"
2223
#include "small_stack_support.h"
2324
#include "visibility.h"
@@ -42,6 +43,9 @@ static int kyber_keygen(void)
4243
#error
4344
#endif
4445

46+
/* Rerun power up integrity test */
47+
lc_fips_integrity_checker();
48+
4549
CKINT(lc_kyber_keypair(&ws->pk, &ws->sk, lc_seeded_rng, kyber_type));
4650

4751
out:

slh-dsa/tests/sphincs_keygen_fips_tester.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "compare.h"
2121
#include "cpufeatures.h"
2222
#include "lc_sphincs.h"
23+
#include "lc_status.h"
2324
#include "small_stack_support.h"
2425
#include "ret_checkers.h"
2526
#include "visibility.h"
@@ -47,6 +48,9 @@ static int lc_sphincs_fips_keygen_test(void)
4748
int ret;
4849
LC_DECLARE_MEM(ws, struct workspace, sizeof(uint64_t));
4950

51+
/* Rerun power up integrity test */
52+
lc_fips_integrity_checker();
53+
5054
CKINT(lc_sphincs_keypair(&ws->pk, &ws->sk, lc_seeded_rng,
5155
lc_sphincs_type));
5256

0 commit comments

Comments
 (0)