Skip to content

Commit 74544ff

Browse files
SWilson4baentsch
andcommitted
Pull new HQC implementation from upstream (#1585)
* 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]>
1 parent fce7424 commit 74544ff

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

tests/KATs/kem/kats.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,4 @@
103103
"all": "36e1e53d4e6e295e8fb804449958ad9a3719aa350e91933c65791b9117382d57",
104104
"single": "afc42c3a5b10f4ef69654250097ebda9b9564570f4086744b24a6daf2bd1f89a"
105105
}
106-
}
106+
}

tests/kat_kem.c

+35
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,39 @@ static int is_mceliece(const char *method_name) {
8888
|| !strcmp(method_name, OQS_KEM_alg_classic_mceliece_8192128f) );
8989
}
9090

91+
/* HQC-specific functions */
92+
static inline bool is_hqc(const char *method_name) {
93+
return (0 == strcmp(method_name, OQS_KEM_alg_hqc_128))
94+
|| (0 == strcmp(method_name, OQS_KEM_alg_hqc_192))
95+
|| (0 == strcmp(method_name, OQS_KEM_alg_hqc_256));
96+
}
97+
98+
static void HQC_randombytes_init(const uint8_t *entropy_input, const uint8_t *personalization_string) {
99+
uint8_t domain = HQC_PRNG_DOMAIN;
100+
if (shake_prng_state.ctx != NULL) {
101+
OQS_SHA3_shake256_inc_ctx_reset(&shake_prng_state);
102+
} else {
103+
OQS_SHA3_shake256_inc_init(&shake_prng_state);
104+
}
105+
OQS_SHA3_shake256_inc_absorb(&shake_prng_state, entropy_input, 48);
106+
if (personalization_string != NULL) {
107+
OQS_SHA3_shake256_inc_absorb(&shake_prng_state, personalization_string, 48);
108+
}
109+
OQS_SHA3_shake256_inc_absorb(&shake_prng_state, &domain, 1);
110+
OQS_SHA3_shake256_inc_finalize(&shake_prng_state);
111+
}
112+
113+
static void HQC_randombytes(uint8_t *random_array, size_t bytes_to_read) {
114+
OQS_SHA3_shake256_inc_squeeze(random_array, bytes_to_read, &shake_prng_state);
115+
}
116+
117+
static void HQC_randombytes_free(void) {
118+
if (shake_prng_state.ctx != NULL) {
119+
OQS_SHA3_shake256_inc_ctx_release(&shake_prng_state);
120+
shake_prng_state.ctx = NULL;
121+
}
122+
}
123+
91124
static OQS_STATUS kem_kat(const char *method_name, bool all) {
92125

93126
uint8_t entropy_input[48];
@@ -105,6 +138,8 @@ static OQS_STATUS kem_kat(const char *method_name, bool all) {
105138
void (*randombytes_free)(void) = NULL;
106139
int max_count;
107140
int max_count;
141+
void (*randombytes_init)(const uint8_t *, const uint8_t *) = NULL;
142+
void (*randombytes_free)(void) = NULL;
108143

109144
kem = OQS_KEM_new(method_name);
110145
if (kem == NULL) {

0 commit comments

Comments
 (0)