Skip to content

Commit

Permalink
Clean up after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
SWilson4 committed Jan 22, 2024
1 parent 6d56d90 commit f90bfb6
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 32 deletions.
12 changes: 3 additions & 9 deletions src/common/rand/rand_nist.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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));
Expand All @@ -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));
Expand Down
6 changes: 6 additions & 0 deletions src/common/rand/rand_nist.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
#include <stddef.h>
#include <stdint.h>

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.
*
Expand Down
2 changes: 1 addition & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
26 changes: 10 additions & 16 deletions tests/test_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#include <string.h>

#include <oqs/oqs.h>
#include <oqs/rand_nist_internal.h> // Internal NIST DRBG API
#include <oqs/sha3.h> // Internal SHA3 API
#include <oqs/rand_nist.h> // Internal NIST DRBG API
#include <oqs/sha3.h> // Internal SHA3 API

#include "test_helpers.h"

Expand Down Expand Up @@ -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;
}
Expand Down
7 changes: 1 addition & 6 deletions tests/test_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit f90bfb6

Please sign in to comment.