Skip to content

Commit

Permalink
Pull new HQC implementation from upstream (#1585)
Browse files Browse the repository at this point in the history
* Update Sphincs+ PQClean patch

* Don't apply PQClean Dilithium and Kyber patches

* Run copy_from_upstream; don't apply Dilithium and Kyber changes

* Run HQC KATs with custom PRNG

* Satisfy astyle

* Add licence for common code

* Fix CI build errors

* Update HQC version, OQS version, and SOVERSION

* Move HQC PRNG into test file

* Satisfy astyle

* Fix SHA3 link error

* Reset HQC issues/passes

* fixup! Fix SHA3 link error

* fix kat_kem linkage to make HQC PR pass CI (#1601)

* fix kat_kem linkage

* remove armhf CI support

* Revert "remove armhf CI support"

This reverts commit af759bb.

---------

Co-authored-by: Michael Baentsch <[email protected]>
  • Loading branch information
SWilson4 and baentsch committed Jan 19, 2024
1 parent 80a9872 commit 2728759
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tests/KATs/kem/kats.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,4 @@
"all": "36e1e53d4e6e295e8fb804449958ad9a3719aa350e91933c65791b9117382d57",
"single": "afc42c3a5b10f4ef69654250097ebda9b9564570f4086744b24a6daf2bd1f89a"
}
}
}
35 changes: 35 additions & 0 deletions tests/kat_kem.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,39 @@ static int is_mceliece(const char *method_name) {
|| !strcmp(method_name, OQS_KEM_alg_classic_mceliece_8192128f) );
}

/* HQC-specific functions */
static inline bool is_hqc(const char *method_name) {
return (0 == strcmp(method_name, OQS_KEM_alg_hqc_128))
|| (0 == strcmp(method_name, OQS_KEM_alg_hqc_192))
|| (0 == strcmp(method_name, OQS_KEM_alg_hqc_256));
}

static void HQC_randombytes_init(const uint8_t *entropy_input, const uint8_t *personalization_string) {
uint8_t domain = HQC_PRNG_DOMAIN;
if (shake_prng_state.ctx != NULL) {
OQS_SHA3_shake256_inc_ctx_reset(&shake_prng_state);
} else {
OQS_SHA3_shake256_inc_init(&shake_prng_state);
}
OQS_SHA3_shake256_inc_absorb(&shake_prng_state, entropy_input, 48);
if (personalization_string != NULL) {
OQS_SHA3_shake256_inc_absorb(&shake_prng_state, personalization_string, 48);
}
OQS_SHA3_shake256_inc_absorb(&shake_prng_state, &domain, 1);
OQS_SHA3_shake256_inc_finalize(&shake_prng_state);
}

static void HQC_randombytes(uint8_t *random_array, size_t bytes_to_read) {
OQS_SHA3_shake256_inc_squeeze(random_array, bytes_to_read, &shake_prng_state);
}

static void HQC_randombytes_free(void) {
if (shake_prng_state.ctx != NULL) {
OQS_SHA3_shake256_inc_ctx_release(&shake_prng_state);
shake_prng_state.ctx = NULL;
}
}

static OQS_STATUS kem_kat(const char *method_name, bool all) {

uint8_t entropy_input[48];
Expand All @@ -106,6 +139,8 @@ static OQS_STATUS kem_kat(const char *method_name, bool all) {
void (*randombytes_free)(void) = NULL;
int max_count;
int max_count;
void (*randombytes_init)(const uint8_t *, const uint8_t *) = NULL;
void (*randombytes_free)(void) = NULL;

kem = OQS_KEM_new(method_name);
if (kem == NULL) {
Expand Down

0 comments on commit 2728759

Please sign in to comment.