Skip to content

Commit 9fc0a48

Browse files
committed
Switch HQC PRNG backend to OQS_randombytes with macro [full tests] [extended tests]
Signed-off-by: Ganyu (Bruce) Xu <g66xu@uwaterloo.ca>
1 parent 84ff774 commit 9fc0a48

11 files changed

Lines changed: 64 additions & 46 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ All names other than `ML-KEM` and `ML-DSA` are subject to change. `liboqs` makes
6161
| BIKE | Not selected by [NIST](https://bikesuite.org/files/v5.1/BIKE_Spec.2022.10.10.1.pdf) | [`awslabs/bike-kem`](https://github.com/awslabs/bike-kem) |
6262
| Classic McEliece | Under [ISO](https://classic.mceliece.org/iso.html) consideration | [`PQClean/PQClean@1eacfda`](https://github.com/PQClean/PQClean/commit/1eacfdafc15ddc5d5759d0b85b4cef26627df181) |
6363
| FrodoKEM | Under [ISO](https://frodokem.org/) consideration | [`microsoft/PQCrypto-LWEKE@a2f9dec`](https://github.com/microsoft/PQCrypto-LWEKE/commit/a2f9dec8917ccc3464b3378d46b140fa7353320d) |
64-
| HQC | Selected by [NIST](https://pqc-hqc.org/doc/hqc_specifications_2025_08_22.pdf) for upcoming standardization | [`xuganyu96/pqc-hqc@1b45cfa`](https://github.com/xuganyu96/pqc-hqc/commit/1b45cfa0b85f0fcf363b5f2d75dcf3286a551b52) |
64+
| HQC | Selected by [NIST](https://pqc-hqc.org/doc/hqc_specifications_2025_08_22.pdf) for upcoming standardization | [`xuganyu96/pqc-hqc@73a974d`](https://github.com/xuganyu96/pqc-hqc/commit/73a974d43e896a9c7d0c601748a5e1c70a195093) |
6565
| Kyber | Selected by [NIST](https://csrc.nist.gov/CSRC/media/Projects/post-quantum-cryptography/documents/round-3/submissions/Kyber-Round3.zip) as basis for ML-KEM (FIPS 203) | [`pq-crystals/kyber@441c051`](https://github.com/pq-crystals/kyber/commit/441c0519a07e8b86c8d079954a6b10bd31d29efc) |
6666
| ML-KEM | Standardized by [NIST](https://csrc.nist.gov/pubs/fips/203/final) | [`pq-code-package/mlkem-native@d2cae2b`](https://github.com/pq-code-package/mlkem-native/commit/d2cae2be522a67bfae26100fdb520576f1b2ef90) |
6767
| NTRU | Not selected by [NIST](https://csrc.nist.gov/CSRC/media/Projects/post-quantum-cryptography/documents/round-3/submissions/NTRU-Round3.zip), under standardization consideration by [NTT](https://info.isl.ntt.co.jp/crypt/ntru/index.html) | [`PQClean/PQClean@4c9e5a3`](https://github.com/PQClean/PQClean/commit/4c9e5a3aa715cc8d1d0e377e4e6e682ebd7602d6) |

docs/algorithms/kem/hqc.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
- **Authors' website**: https://pqc-hqc.org/
88
- **Specification version**: 2025-08-22.
99
- **Primary Source**<a name="primary-source"></a>:
10-
- **Source**: https://github.com/xuganyu96/pqc-hqc/commit/1b45cfa0b85f0fcf363b5f2d75dcf3286a551b52
10+
- **Source**: https://github.com/xuganyu96/pqc-hqc/commit/73a974d43e896a9c7d0c601748a5e1c70a195093
1111
- **Implementation license (SPDX-Identifier)**: Public domain
1212
- **Ancestors of primary source**:
1313
- https://gitlab.com/pqc-hqc, which takes it from:

docs/algorithms/kem/hqc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ parameter-sets:
6868
default: true
6969
primary-upstream:
7070
spdx-license-identifier: Public domain
71-
source: https://github.com/xuganyu96/pqc-hqc/commit/1b45cfa0b85f0fcf363b5f2d75dcf3286a551b52
71+
source: https://github.com/xuganyu96/pqc-hqc/commit/73a974d43e896a9c7d0c601748a5e1c70a195093
7272
default-upstream-id: ref
7373
auxiliary-submitters:
7474
- Carlos Aguilar-Melchor

scripts/copy_from_upstream/copy_from_upstream.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ upstreams:
33
name: xuganyu96-hqc
44
git_url: https://github.com/xuganyu96/pqc-hqc.git
55
git_branch: liboqs-integration
6-
git_commit: 1b45cfa0b85f0fcf363b5f2d75dcf3286a551b52
6+
git_commit: 73a974d43e896a9c7d0c601748a5e1c70a195093
77
kem_meta_path: "integrations/{pretty_name_full}_META.yml"
88
kem_scheme_path: .
99
patches: []

src/kem/hqc/CMakeLists.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,28 @@ set(_HQC_OBJS "")
77

88
if(OQS_ENABLE_KEM_hqc_1)
99
add_library(hqc_1_ref OBJECT kem_hqc_1.c xuganyu96-hqc_hqc-1_ref/code.c xuganyu96-hqc_hqc-1_ref/crypto_memset.c xuganyu96-hqc_hqc-1_ref/fft.c xuganyu96-hqc_hqc-1_ref/gf.c xuganyu96-hqc_hqc-1_ref/gf2x.c xuganyu96-hqc_hqc-1_ref/hqc.c xuganyu96-hqc_hqc-1_ref/kem.c xuganyu96-hqc_hqc-1_ref/parsing.c xuganyu96-hqc_hqc-1_ref/reed_muller.c xuganyu96-hqc_hqc-1_ref/reed_solomon.c xuganyu96-hqc_hqc-1_ref/symmetric.c xuganyu96-hqc_hqc-1_ref/vector.c)
10-
target_compile_options(hqc_1_ref PUBLIC -DHQC_ARCH_REF=1 -DPQCHQC_NAMESPACE_PREFIX=PQCHQC_HQC1_C_)
10+
target_compile_options(hqc_1_ref PUBLIC -DHQC_ARCH_REF=1 -DPQCHQC_NAMESPACE_PREFIX=PQCHQC_HQC1_C_ -DUSE_OQS_RANDOMBYTES)
1111
target_include_directories(hqc_1_ref PRIVATE ${CMAKE_CURRENT_LIST_DIR}/xuganyu96-hqc_hqc-1_ref)
1212
target_include_directories(hqc_1_ref PRIVATE ${PROJECT_SOURCE_DIR}/src/common/pqclean_shims)
13-
target_compile_options(hqc_1_ref PUBLIC -DHQC_ARCH_REF=1 -DPQCHQC_NAMESPACE_PREFIX=PQCHQC_HQC1_C_)
13+
target_compile_options(hqc_1_ref PUBLIC -DHQC_ARCH_REF=1 -DPQCHQC_NAMESPACE_PREFIX=PQCHQC_HQC1_C_ -DUSE_OQS_RANDOMBYTES)
1414
set(_HQC_OBJS ${_HQC_OBJS} $<TARGET_OBJECTS:hqc_1_ref>)
1515
endif()
1616

1717
if(OQS_ENABLE_KEM_hqc_3)
1818
add_library(hqc_3_ref OBJECT kem_hqc_3.c xuganyu96-hqc_hqc-3_ref/code.c xuganyu96-hqc_hqc-3_ref/crypto_memset.c xuganyu96-hqc_hqc-3_ref/fft.c xuganyu96-hqc_hqc-3_ref/gf.c xuganyu96-hqc_hqc-3_ref/gf2x.c xuganyu96-hqc_hqc-3_ref/hqc.c xuganyu96-hqc_hqc-3_ref/kem.c xuganyu96-hqc_hqc-3_ref/parsing.c xuganyu96-hqc_hqc-3_ref/reed_muller.c xuganyu96-hqc_hqc-3_ref/reed_solomon.c xuganyu96-hqc_hqc-3_ref/symmetric.c xuganyu96-hqc_hqc-3_ref/vector.c)
19-
target_compile_options(hqc_3_ref PUBLIC -DHQC_ARCH_REF=1 -DPQCHQC_NAMESPACE_PREFIX=PQCHQC_HQC3_C_)
19+
target_compile_options(hqc_3_ref PUBLIC -DHQC_ARCH_REF=1 -DPQCHQC_NAMESPACE_PREFIX=PQCHQC_HQC3_C_ -DUSE_OQS_RANDOMBYTES)
2020
target_include_directories(hqc_3_ref PRIVATE ${CMAKE_CURRENT_LIST_DIR}/xuganyu96-hqc_hqc-3_ref)
2121
target_include_directories(hqc_3_ref PRIVATE ${PROJECT_SOURCE_DIR}/src/common/pqclean_shims)
22-
target_compile_options(hqc_3_ref PUBLIC -DHQC_ARCH_REF=1 -DPQCHQC_NAMESPACE_PREFIX=PQCHQC_HQC3_C_)
22+
target_compile_options(hqc_3_ref PUBLIC -DHQC_ARCH_REF=1 -DPQCHQC_NAMESPACE_PREFIX=PQCHQC_HQC3_C_ -DUSE_OQS_RANDOMBYTES)
2323
set(_HQC_OBJS ${_HQC_OBJS} $<TARGET_OBJECTS:hqc_3_ref>)
2424
endif()
2525

2626
if(OQS_ENABLE_KEM_hqc_5)
2727
add_library(hqc_5_ref OBJECT kem_hqc_5.c xuganyu96-hqc_hqc-5_ref/code.c xuganyu96-hqc_hqc-5_ref/crypto_memset.c xuganyu96-hqc_hqc-5_ref/fft.c xuganyu96-hqc_hqc-5_ref/gf.c xuganyu96-hqc_hqc-5_ref/gf2x.c xuganyu96-hqc_hqc-5_ref/hqc.c xuganyu96-hqc_hqc-5_ref/kem.c xuganyu96-hqc_hqc-5_ref/parsing.c xuganyu96-hqc_hqc-5_ref/reed_muller.c xuganyu96-hqc_hqc-5_ref/reed_solomon.c xuganyu96-hqc_hqc-5_ref/symmetric.c xuganyu96-hqc_hqc-5_ref/vector.c)
28-
target_compile_options(hqc_5_ref PUBLIC -DHQC_ARCH_REF=1 -DPQCHQC_NAMESPACE_PREFIX=PQCHQC_HQC5_C_)
28+
target_compile_options(hqc_5_ref PUBLIC -DHQC_ARCH_REF=1 -DPQCHQC_NAMESPACE_PREFIX=PQCHQC_HQC5_C_ -DUSE_OQS_RANDOMBYTES)
2929
target_include_directories(hqc_5_ref PRIVATE ${CMAKE_CURRENT_LIST_DIR}/xuganyu96-hqc_hqc-5_ref)
3030
target_include_directories(hqc_5_ref PRIVATE ${PROJECT_SOURCE_DIR}/src/common/pqclean_shims)
31-
target_compile_options(hqc_5_ref PUBLIC -DHQC_ARCH_REF=1 -DPQCHQC_NAMESPACE_PREFIX=PQCHQC_HQC5_C_)
31+
target_compile_options(hqc_5_ref PUBLIC -DHQC_ARCH_REF=1 -DPQCHQC_NAMESPACE_PREFIX=PQCHQC_HQC5_C_ -DUSE_OQS_RANDOMBYTES)
3232
set(_HQC_OBJS ${_HQC_OBJS} $<TARGET_OBJECTS:hqc_5_ref>)
3333
endif()
3434

src/kem/hqc/xuganyu96-hqc_hqc-1_ref/kem.c

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
#include <stdint.h>
77
#include <string.h>
8-
#include <oqs/rand.h>
98
#include "api.h"
109
#include "crypto_memset.h"
1110
#include "hqc.h"
@@ -49,13 +48,7 @@ int crypto_kem_keypair(uint8_t *ek_kem, uint8_t *dk_kem) {
4948
uint8_t ek_pke[PUBLIC_KEY_BYTES] = {0};
5049
uint8_t dk_pke[SEED_BYTES] = {0};
5150

52-
/* FIX: modification for liboqs:
53-
* the PRNG was replaced with OQS_randombytes, need to determined if this
54-
* is ok
55-
*/
56-
// // Sample seed_kem
57-
// prng_get_bytes(seed_kem, SEED_BYTES);
58-
OQS_randombytes(seed_kem, SEED_BYTES);
51+
prng_get_bytes(seed_kem, SEED_BYTES);
5952

6053
// Compute seed_pke and randomness sigma
6154
xof_init(&ctx_kem, seed_kem, SEED_BYTES);
@@ -121,10 +114,8 @@ int crypto_kem_enc(uint8_t *c_kem, uint8_t *K, const uint8_t *ek_kem) {
121114
ciphertext_kem_t c_kem_t = {0};
122115

123116
// Sample message m and salt
124-
// prng_get_bytes(m, PARAM_SECURITY_BYTES);
125-
// prng_get_bytes(c_kem_t.salt, SALT_BYTES);
126-
OQS_randombytes(m, PARAM_SECURITY_BYTES);
127-
OQS_randombytes(c_kem_t.salt, SALT_BYTES);
117+
prng_get_bytes(m, PARAM_SECURITY_BYTES);
118+
prng_get_bytes(c_kem_t.salt, SALT_BYTES);
128119

129120
// Compute shared key K and ciphertext c_kem
130121
hash_h(hash_ek_kem, ek_kem);

src/kem/hqc/xuganyu96-hqc_hqc-1_ref/symmetric.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,20 @@
77
#include "symmetric.h"
88
#include <stdint.h>
99

10+
#ifdef USE_OQS_RANDOMBYTES
11+
#include <oqs/rand.h>
12+
13+
void prng_init(uint8_t *entropy_input, uint8_t *personalization_string, uint32_t enlen, uint32_t perlen) {
14+
(void)entropy_input;
15+
(void)personalization_string;
16+
(void)enlen;
17+
(void)perlen;
18+
}
19+
20+
void prng_get_bytes(uint8_t *output, uint32_t outlen) {
21+
OQS_randombytes(output, outlen);
22+
}
23+
#else
1024
/**
1125
* @typedef shake256_prng_ctx
1226
* @brief Incremental SHAKE-256 prng context.
@@ -44,6 +58,7 @@ void prng_init(uint8_t *entropy_input, uint8_t *personalization_string, uint32_t
4458
void prng_get_bytes(uint8_t *output, uint32_t outlen) {
4559
OQS_SHA3_shake256_inc_squeeze(output, outlen, &shake256_prng_ctx);
4660
}
61+
#endif /* USE_OQS_RANDOMBYTES */
4762

4863
/**
4964
* @brief Initializes a SHAKE256 XOF context with a given seed.

src/kem/hqc/xuganyu96-hqc_hqc-3_ref/kem.c

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
#include <stdint.h>
77
#include <string.h>
8-
#include <oqs/rand.h>
98
#include "api.h"
109
#include "crypto_memset.h"
1110
#include "hqc.h"
@@ -49,13 +48,7 @@ int crypto_kem_keypair(uint8_t *ek_kem, uint8_t *dk_kem) {
4948
uint8_t ek_pke[PUBLIC_KEY_BYTES] = {0};
5049
uint8_t dk_pke[SEED_BYTES] = {0};
5150

52-
/* FIX: modification for liboqs:
53-
* the PRNG was replaced with OQS_randombytes, need to determined if this
54-
* is ok
55-
*/
56-
// // Sample seed_kem
57-
// prng_get_bytes(seed_kem, SEED_BYTES);
58-
OQS_randombytes(seed_kem, SEED_BYTES);
51+
prng_get_bytes(seed_kem, SEED_BYTES);
5952

6053
// Compute seed_pke and randomness sigma
6154
xof_init(&ctx_kem, seed_kem, SEED_BYTES);
@@ -121,10 +114,8 @@ int crypto_kem_enc(uint8_t *c_kem, uint8_t *K, const uint8_t *ek_kem) {
121114
ciphertext_kem_t c_kem_t = {0};
122115

123116
// Sample message m and salt
124-
// prng_get_bytes(m, PARAM_SECURITY_BYTES);
125-
// prng_get_bytes(c_kem_t.salt, SALT_BYTES);
126-
OQS_randombytes(m, PARAM_SECURITY_BYTES);
127-
OQS_randombytes(c_kem_t.salt, SALT_BYTES);
117+
prng_get_bytes(m, PARAM_SECURITY_BYTES);
118+
prng_get_bytes(c_kem_t.salt, SALT_BYTES);
128119

129120
// Compute shared key K and ciphertext c_kem
130121
hash_h(hash_ek_kem, ek_kem);

src/kem/hqc/xuganyu96-hqc_hqc-3_ref/symmetric.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,20 @@
77
#include "symmetric.h"
88
#include <stdint.h>
99

10+
#ifdef USE_OQS_RANDOMBYTES
11+
#include <oqs/rand.h>
12+
13+
void prng_init(uint8_t *entropy_input, uint8_t *personalization_string, uint32_t enlen, uint32_t perlen) {
14+
(void)entropy_input;
15+
(void)personalization_string;
16+
(void)enlen;
17+
(void)perlen;
18+
}
19+
20+
void prng_get_bytes(uint8_t *output, uint32_t outlen) {
21+
OQS_randombytes(output, outlen);
22+
}
23+
#else
1024
/**
1125
* @typedef shake256_prng_ctx
1226
* @brief Incremental SHAKE-256 prng context.
@@ -44,6 +58,7 @@ void prng_init(uint8_t *entropy_input, uint8_t *personalization_string, uint32_t
4458
void prng_get_bytes(uint8_t *output, uint32_t outlen) {
4559
OQS_SHA3_shake256_inc_squeeze(output, outlen, &shake256_prng_ctx);
4660
}
61+
#endif /* USE_OQS_RANDOMBYTES */
4762

4863
/**
4964
* @brief Initializes a SHAKE256 XOF context with a given seed.

src/kem/hqc/xuganyu96-hqc_hqc-5_ref/kem.c

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
#include <stdint.h>
77
#include <string.h>
8-
#include <oqs/rand.h>
98
#include "api.h"
109
#include "crypto_memset.h"
1110
#include "hqc.h"
@@ -49,13 +48,7 @@ int crypto_kem_keypair(uint8_t *ek_kem, uint8_t *dk_kem) {
4948
uint8_t ek_pke[PUBLIC_KEY_BYTES] = {0};
5049
uint8_t dk_pke[SEED_BYTES] = {0};
5150

52-
/* FIX: modification for liboqs:
53-
* the PRNG was replaced with OQS_randombytes, need to determined if this
54-
* is ok
55-
*/
56-
// // Sample seed_kem
57-
// prng_get_bytes(seed_kem, SEED_BYTES);
58-
OQS_randombytes(seed_kem, SEED_BYTES);
51+
prng_get_bytes(seed_kem, SEED_BYTES);
5952

6053
// Compute seed_pke and randomness sigma
6154
xof_init(&ctx_kem, seed_kem, SEED_BYTES);
@@ -121,10 +114,8 @@ int crypto_kem_enc(uint8_t *c_kem, uint8_t *K, const uint8_t *ek_kem) {
121114
ciphertext_kem_t c_kem_t = {0};
122115

123116
// Sample message m and salt
124-
// prng_get_bytes(m, PARAM_SECURITY_BYTES);
125-
// prng_get_bytes(c_kem_t.salt, SALT_BYTES);
126-
OQS_randombytes(m, PARAM_SECURITY_BYTES);
127-
OQS_randombytes(c_kem_t.salt, SALT_BYTES);
117+
prng_get_bytes(m, PARAM_SECURITY_BYTES);
118+
prng_get_bytes(c_kem_t.salt, SALT_BYTES);
128119

129120
// Compute shared key K and ciphertext c_kem
130121
hash_h(hash_ek_kem, ek_kem);

0 commit comments

Comments
 (0)