diff --git a/src/common/rand/rand_nist.c b/src/common/rand/rand_nist.c index e316c1e34c..2fd9a24825 100644 --- a/src/common/rand/rand_nist.c +++ b/src/common/rand/rand_nist.c @@ -32,13 +32,7 @@ You are solely responsible for determining the appropriateness of using and dist void OQS_randombytes_nist_kat(unsigned char *x, size_t xlen); -typedef struct { - unsigned char Key[32]; - unsigned char V[16]; - int reseed_counter; -} AES256_CTR_DRBG_struct; - -static AES256_CTR_DRBG_struct DRBG_ctx; +static OQS_NIST_DRBG_struct DRBG_ctx; static void AES256_CTR_DRBG_Update(unsigned char *provided_data, unsigned char *Key, unsigned char *V); #ifdef OQS_USE_OPENSSL @@ -129,7 +123,7 @@ void OQS_randombytes_nist_kat(unsigned char *x, size_t xlen) { } void OQS_randombytes_nist_kat_get_state(void *out) { - AES256_CTR_DRBG_struct *out_state = (AES256_CTR_DRBG_struct *)out; + OQS_NIST_DRBG_struct *out_state = (OQS_NIST_DRBG_struct *)out; if (out_state != NULL) { memcpy(out_state->Key, DRBG_ctx.Key, sizeof(DRBG_ctx.Key)); memcpy(out_state->V, DRBG_ctx.V, sizeof(DRBG_ctx.V)); @@ -138,7 +132,7 @@ void OQS_randombytes_nist_kat_get_state(void *out) { } void OQS_randombytes_nist_kat_set_state(const void *in) { - AES256_CTR_DRBG_struct *in_state = (AES256_CTR_DRBG_struct *)in; + OQS_NIST_DRBG_struct *in_state = (OQS_NIST_DRBG_struct *)in; if (in_state != NULL) { memcpy(DRBG_ctx.Key, in_state->Key, sizeof(DRBG_ctx.Key)); memcpy(DRBG_ctx.V, in_state->V, sizeof(DRBG_ctx.V)); diff --git a/src/common/rand/rand_nist.h b/src/common/rand/rand_nist.h index aeb32327b5..d124773fed 100644 --- a/src/common/rand/rand_nist.h +++ b/src/common/rand/rand_nist.h @@ -11,6 +11,12 @@ #include #include +typedef struct { + unsigned char Key[32]; + unsigned char V[16]; + int reseed_counter; +} OQS_NIST_DRBG_struct; + /** * Initializes the NIST DRBG with a given seed and with 256-bit security. * diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index e0ff5c25d8..e564c8d2b9 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -81,7 +81,7 @@ add_executable(example_sig example_sig.c) target_link_libraries(example_sig PRIVATE ${TEST_DEPS}) add_executable(kat_sig kat_sig.c test_helpers.c) -target_link_libraries(kat_sig PRIVATE ${API_TEST_DEPS}) +target_link_libraries(kat_sig PRIVATE ${TEST_DEPS}) add_executable(test_sig test_sig.c) target_link_libraries(test_sig PRIVATE ${TEST_DEPS}) diff --git a/tests/test_helpers.c b/tests/test_helpers.c index 03bf9e172b..20baaebb1c 100644 --- a/tests/test_helpers.c +++ b/tests/test_helpers.c @@ -4,8 +4,8 @@ #include #include -#include // Internal NIST DRBG API -#include // Internal SHA3 API +#include // Internal NIST DRBG API +#include // Internal SHA3 API #include "test_helpers.h" @@ -92,24 +92,18 @@ OQS_KAT_PRNG *OQS_KAT_PRNG_new(const char *method_name) { hqc_prng_new(); // initialize saved state OQS_SHA3_shake256_inc_init(&prng->saved_state.hqc_state); - // TODO set callbacks prng->seed = &hqc_prng_seed; prng->get_state = &hqc_prng_get_state; prng->set_state = &hqc_prng_set_state; prng->free = &hqc_prng_free; - } else { - // set randombytes function - if (OQS_randombytes_switch_algorithm(OQS_RAND_alg_nist_kat) == OQS_SUCCESS) { - // TODO set callbacks - prng->seed = &OQS_randombytes_nist_kat_init_256bit; - prng->get_state = &OQS_randombytes_nist_kat_get_state; - prng->set_state = &OQS_randombytes_nist_kat_set_state; - prng->free = &nist_drbg_free; - } else { - OQS_MEM_insecure_free(prng); - prng = NULL; - } - } + } else { + // set randombytes function + OQS_randombytes_custom_algorithm(&OQS_randombytes_nist_kat); + prng->seed = &OQS_randombytes_nist_kat_init_256bit; + prng->get_state = &OQS_randombytes_nist_kat_get_state; + prng->set_state = &OQS_randombytes_nist_kat_set_state; + prng->free = &nist_drbg_free; + } } return prng; } diff --git a/tests/test_helpers.h b/tests/test_helpers.h index 244e9d4b48..4dfffb61db 100644 --- a/tests/test_helpers.h +++ b/tests/test_helpers.h @@ -10,12 +10,7 @@ typedef union { OQS_SHA3_shake256_inc_ctx hqc_state; - // struct definition copied from rand_nist.c - struct { - unsigned char Key[32]; - unsigned char V[16]; - int reseed_counter; - } nist_state; + OQS_NIST_DRBG_struct nist_state; } OQS_KAT_PRNG_state; typedef struct {