Skip to content

Commit

Permalink
s2n_is_fips
Browse files Browse the repository at this point in the history
  • Loading branch information
goatgoose committed Mar 11, 2024
1 parent 33b38be commit d3c88a7
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
4 changes: 2 additions & 2 deletions api/s2n.h
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,10 @@ S2N_API extern int s2n_cleanup(void);
* requirements. Applications desiring FIPS compliance should use this API to ensure that s2n-tls
* has been properly linked with a FIPS libcrypto and has successfully entered FIPS mode.
*
* @param fips_mode Set to true if s2n-tls is in FIPS mode, set to false otherwise.
* @param fips Set to true if s2n-tls is in FIPS mode, set to false otherwise.
* @returns S2N_SUCCESS on success. S2N_FAILURE on failure.
*/
S2N_API extern int s2n_get_fips_mode(bool *fips_mode);
S2N_API extern int s2n_is_fips(bool *fips);

/**
* Creates a new s2n_config object. This object can (and should) be associated with many connection
Expand Down
8 changes: 4 additions & 4 deletions crypto/s2n_fips.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ int s2n_is_in_fips_mode(void)
return s2n_fips_mode;
}

int s2n_get_fips_mode(bool *fips_mode)
int s2n_is_fips(bool *fips)
{
POSIX_ENSURE_REF(fips_mode);
*fips_mode = false;
POSIX_ENSURE_REF(fips);
*fips = false;
POSIX_ENSURE(s2n_is_initialized(), S2N_ERR_NOT_INITIALIZED);

if (s2n_is_in_fips_mode()) {
*fips_mode = true;
*fips = true;
}

return S2N_SUCCESS;
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/s2n_build_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,13 @@ int main()

/* Ensure that FIPS mode is enabled when linked to AWS-LC-FIPS, and disabled when linked to AWS-LC */
if (strstr(s2n_libcrypto, "awslc") != NULL) {
bool fips_mode = false;
EXPECT_SUCCESS(s2n_get_fips_mode(&fips_mode));
bool fips = false;
EXPECT_SUCCESS(s2n_is_fips(&fips));

if (strstr(s2n_libcrypto, "fips") != NULL) {
EXPECT_TRUE(fips_mode);
EXPECT_TRUE(fips);
} else {
EXPECT_FALSE(fips_mode);
EXPECT_FALSE(fips);
}
}

Expand Down
20 changes: 10 additions & 10 deletions tests/unit/s2n_fips_mode_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,25 @@ int main()
{
BEGIN_TEST_NO_INIT();

/* s2n_get_fips_mode() fails before init */
/* s2n_is_fips() fails before init */
{
bool fips_mode = true;
EXPECT_FAILURE_WITH_ERRNO(s2n_get_fips_mode(&fips_mode), S2N_ERR_NOT_INITIALIZED);
EXPECT_FALSE(fips_mode);
bool fips = true;
EXPECT_FAILURE_WITH_ERRNO(s2n_is_fips(&fips), S2N_ERR_NOT_INITIALIZED);
EXPECT_FALSE(fips);
}

EXPECT_SUCCESS(s2n_init());

/* Test s2n_get_fips_mode() after init */
/* Test s2n_is_fips() after init */
{
/* Safety */
EXPECT_FAILURE_WITH_ERRNO(s2n_get_fips_mode(NULL), S2N_ERR_NULL);
EXPECT_FAILURE_WITH_ERRNO(s2n_is_fips(NULL), S2N_ERR_NULL);

/* FIPS mode matches s2n_is_in_fips_mode() */
/* FIPS value matches s2n_is_in_fips_mode() */
{
bool fips_mode = false;
EXPECT_SUCCESS(s2n_get_fips_mode(&fips_mode));
EXPECT_EQUAL(fips_mode, s2n_is_in_fips_mode());
bool fips = false;
EXPECT_SUCCESS(s2n_is_fips(&fips));
EXPECT_EQUAL(fips, s2n_is_in_fips_mode());
}
}

Expand Down

0 comments on commit d3c88a7

Please sign in to comment.