Skip to content

Commit

Permalink
More cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
justsmth committed Jun 18, 2024
1 parent b2a37c3 commit 1ba44cc
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
1 change: 0 additions & 1 deletion crypto/fipsmodule/rand/rand.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
#include "internal.h"
#include "fork_detect.h"
#include "../../internal.h"
#include "../delocate.h"


// It's assumed that the operating system always has an unfailing source of
Expand Down
4 changes: 0 additions & 4 deletions crypto/fipsmodule/rand/snapsafe_detect.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,7 @@ static int aws_snapsafe_check_kernel_support(void) {
}

static void do_aws_snapsafe_init(void) {
#if defined(AWSLC_SYSGENID_PATH)
*sgc_file_path_bss_get() = AWSLC_SYSGENID_PATH;
#else
*sgc_file_path_bss_get() = "/dev/sysgenid";
#endif
*sgc_addr_bss_get() = NULL;

if (aws_snapsafe_check_kernel_support() != 1) {
Expand Down
4 changes: 4 additions & 0 deletions crypto/fipsmodule/rand/snapsafe_detect.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
extern "C" {
#endif

#if !defined(AWSLC_SYSGENID_PATH)
#define AWSLC_SYSGENID_PATH "/dev/sysgenid"
#endif

// Snapsafe-type uniqueness breaking event (ube detection).
//
// CRYPTO_get_snapsafe_generation provides the snapsafe generation number for the
Expand Down
14 changes: 7 additions & 7 deletions crypto/fipsmodule/rand/snapsafe_detect_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ int init_sgn_file(sgn_test_s* sgn_test) {
return 0;
}

unsigned int set_sgn = 0;
uint32_t set_sgn = 0;
if(0 >= write(fd_sgn, &set_sgn, sizeof(unsigned int))) {
return 0;
}
Expand All @@ -53,8 +53,8 @@ int init_sgn_file(sgn_test_s* sgn_test) {
return 1;
}

int set_sgn(const sgn_test_s* sgn_test, unsigned int val);
int set_sgn(const sgn_test_s* sgn_test, unsigned int val) {
int set_sgn(const sgn_test_s* sgn_test, uint32_t val);
int set_sgn(const sgn_test_s* sgn_test, uint32_t val) {
memcpy(sgn_test->addr, &val, sizeof(unsigned int));
if(0 != msync(sgn_test->addr, sgn_test->pgsize, MS_SYNC)) {
return 0;
Expand All @@ -73,7 +73,7 @@ TEST(SnapsafeGenerationTest, SysGenIDretrievalTesting) {
ASSERT_TRUE(CRYPTO_get_snapsafe_supported());
ASSERT_TRUE(CRYPTO_get_snapsafe_active());

unsigned int current_snapsafe_gen_num = 0;
uint32_t current_snapsafe_gen_num = 0;
ASSERT_TRUE(set_sgn(&sgn_test, 7));
ASSERT_TRUE(CRYPTO_get_snapsafe_generation(&current_snapsafe_gen_num));
ASSERT_EQ((unsigned int)7, current_snapsafe_gen_num);
Expand All @@ -88,15 +88,15 @@ TEST(SnapsafeGenerationTest, SysGenIDretrievalTesting) {

for (size_t i = 0; i < NUMBER_OF_TEST_VALUES; i++) {
// Exercise all bytes of the 32-bit generation number.
unsigned int new_sysgenid_value_hint = test_sysgenid_values[i];
uint32_t new_sysgenid_value_hint = test_sysgenid_values[i];
ASSERT_TRUE(set_sgn(&sgn_test, new_sysgenid_value_hint));
ASSERT_TRUE(CRYPTO_get_snapsafe_generation(&current_snapsafe_gen_num));
EXPECT_EQ(new_sysgenid_value_hint, current_snapsafe_gen_num);
}
}
#elif defined(OPENSSL_LINUX)
TEST(SnapsafeGenerationTest, SysGenIDretrievalLinux) {
unsigned int current_snapsafe_gen_num = 0xffffffff;
uint32_t current_snapsafe_gen_num = 0xffffffff;
ASSERT_TRUE(CRYPTO_get_snapsafe_generation(&current_snapsafe_gen_num));
if(CRYPTO_get_snapsafe_supported()) {
ASSERT_TRUE(CRYPTO_get_snapsafe_active());
Expand All @@ -112,7 +112,7 @@ TEST(SnapsafeGenerationTest, SysGenIDretrievalLinux) {
TEST(SnapsafeGenerationTest, SysGenIDretrievalNonLinux) {
ASSERT_FALSE(CRYPTO_get_snapsafe_supported());
ASSERT_FALSE(CRYPTO_get_snapsafe_active());
unsigned int current_snapsafe_gen_num = 0xffffffff;
uint32_t current_snapsafe_gen_num = 0xffffffff;
ASSERT_TRUE(CRYPTO_get_snapsafe_generation(&current_snapsafe_gen_num));
ASSERT_EQ((unsigned int)0, current_snapsafe_gen_num);
}
Expand Down

0 comments on commit 1ba44cc

Please sign in to comment.