QSC Post Quantum Cryptographic Library 1.1.0.2 (B2)
A post quantum secure library written in Ansi C
Loading...
Searching...
No Matches
hqcbase.h
Go to the documentation of this file.
1/* 2020-2026 Quantum Resistant Cryptographic Solutions Corporation
2 * All Rights Reserved.
3 *
4 * NOTICE:
5 * This software and all accompanying materials are the exclusive property of
6 * Quantum Resistant Cryptographic Solutions Corporation (QRCS). The intellectual
7 * and technical concepts contained herein are proprietary to QRCS and are
8 * protected under applicable Canadian, U.S., and international copyright,
9 * patent, and trade secret laws.
10 *
11 * CRYPTOGRAPHIC ALGORITHMS AND IMPLEMENTATIONS:
12 * - This software includes implementations of cryptographic primitives and
13 * algorithms that are standardized or in the public domain, such as AES
14 * and SHA-3, which are not proprietary to QRCS.
15 * - This software also includes cryptographic primitives, constructions, and
16 * algorithms designed by QRCS, including but not limited to RCS, SCB, CSX, QMAC, and
17 * related components, which are proprietary to QRCS.
18 * - All source code, implementations, protocol compositions, optimizations,
19 * parameter selections, and engineering work contained in this software are
20 * original works of QRCS and are protected under this license.
21 *
22 * LICENSE AND USE RESTRICTIONS:
23 * - This software is licensed under the Quantum Resistant Cryptographic Solutions
24 * Public Research and Evaluation License (QRCS-PREL), 2025-2026.
25 * - Permission is granted solely for non-commercial evaluation, academic research,
26 * cryptographic analysis, interoperability testing, and feasibility assessment.
27 * - Commercial use, production deployment, commercial redistribution, or
28 * integration into products or services is strictly prohibited without a
29 * separate written license agreement executed with QRCS.
30 * - Licensing and authorized distribution are solely at the discretion of QRCS.
31 *
32 * EXPERIMENTAL CRYPTOGRAPHY NOTICE:
33 * Portions of this software may include experimental, novel, or evolving
34 * cryptographic designs. Use of this software is entirely at the user's risk.
35 *
36 * DISCLAIMER:
37 * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
38 * IMPLIED, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS
39 * FOR A PARTICULAR PURPOSE, SECURITY, OR NON-INFRINGEMENT. QRCS DISCLAIMS ALL
40 * LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
41 * ARISING FROM THE USE OR MISUSE OF THIS SOFTWARE.
42 *
43 * FULL LICENSE:
44 * This software is subject to the Quantum Resistant Cryptographic Solutions
45 * Public Research and Evaluation License (QRCS-PREL), 2025-2026. The complete license terms
46 * are provided in the accompanying LICENSE file or at https://www.qrcscorp.ca.
47 *
48 * Written by: John G. Underhill
49 * Contact: contact@qrcscorp.ca
50 */
51
72
73#ifndef QSC_HQCBASE_H
74#define QSC_HQCBASE_H
75
76/* \cond NO_DOCUMENT */
77
78#include "qsccommon.h"
79
88#if !defined(QSC_HQC_S1N2321) && !defined(QSC_HQC_S3N4602) && !defined(QSC_HQC_S5N7333)
89# define QSC_HQC_S3N4602
90#endif
91
100#if (defined(QSC_HQC_S1N2321) + defined(QSC_HQC_S3N4602) + defined(QSC_HQC_S5N7333)) != 1
101# error "Define exactly one HQC parameter guard: QSC_HQC_S1N2321, QSC_HQC_S3N4602, or QSC_HQC_S5N7333."
102#endif
103
104#if defined(QSC_HQC_S1N2321)
109# define CEIL_DIVIDE(a, b) (((a) / (b)) + (((a) % (b)) == 0 ? 0 : 1))
114# define BITMASK(a, size) ((1UL << ((a) % (size))) - 1UL)
119# define CRYPTO_ALGNAME "HQC-1"
124# define CRYPTO_SECRETKEYBYTES 2321U
129# define CRYPTO_PUBLICKEYBYTES 2241U
134# define CRYPTO_BYTES 32U
139# define CRYPTO_CIPHERTEXTBYTES 4433U
144# define PARAM_N 17669U
149# define PARAM_N1 46U
154# define PARAM_N2 384U
159# define PARAM_N1N2 17664U
164# define PARAM_OMEGA 66U
169# define PARAM_OMEGA_E 75U
174# define PARAM_OMEGA_R 75U
179# define PARAM_SECURITY 128U
184# define PARAM_SECURITY_BYTES 16U
189# define PARAM_DFR_EXP 128U
190# define SECRET_KEY_BYTES CRYPTO_SECRETKEYBYTES
191# define PUBLIC_KEY_BYTES CRYPTO_PUBLICKEYBYTES
192# define SHARED_SECRET_BYTES CRYPTO_BYTES
193# define CIPHERTEXT_BYTES CRYPTO_CIPHERTEXTBYTES
198# define PARAM_DELTA 15U
203# define PARAM_M 8U
208# define PARAM_GF_POLY 0x11DU
213# define PARAM_GF_MUL_ORDER 255U
218# define PARAM_K 16U
223# define PARAM_G 31U
228# define PARAM_FFT 4U
233# define SEED_BYTES 32U
238# define SALT_BYTES 16U
243# define PARAM_N_MU 243079ULL
248# define UTILS_REJECTION_THRESHOLD 16767881U
249#elif defined(QSC_HQC_S3N4602)
250# define CEIL_DIVIDE(a, b) (((a) / (b)) + (((a) % (b)) == 0 ? 0 : 1))
251# define BITMASK(a, size) ((1UL << ((a) % (size))) - 1UL)
252# define CRYPTO_ALGNAME "HQC-3"
253# define CRYPTO_SECRETKEYBYTES 4602U
254# define CRYPTO_PUBLICKEYBYTES 4514U
255# define CRYPTO_BYTES 32U
256# define CRYPTO_CIPHERTEXTBYTES 8978U
257# define PARAM_N 35851U
258# define PARAM_N1 56U
259# define PARAM_N2 640U
260# define PARAM_N1N2 35840U
261# define PARAM_OMEGA 100U
262# define PARAM_OMEGA_E 114U
263# define PARAM_OMEGA_R 114U
264# define PARAM_SECURITY 192U
265# define PARAM_SECURITY_BYTES 24U
266# define PARAM_DFR_EXP 192U
267# define SECRET_KEY_BYTES CRYPTO_SECRETKEYBYTES
268# define PUBLIC_KEY_BYTES CRYPTO_PUBLICKEYBYTES
269# define SHARED_SECRET_BYTES CRYPTO_BYTES
270# define CIPHERTEXT_BYTES CRYPTO_CIPHERTEXTBYTES
271# define PARAM_DELTA 16U
272# define PARAM_M 8U
273# define PARAM_GF_POLY 0x11DU
274# define PARAM_GF_MUL_ORDER 255U
275# define PARAM_K 24U
276# define PARAM_G 33U
277# define PARAM_FFT 5U
278# define SEED_BYTES 32U
279# define SALT_BYTES 16U
280# define PARAM_N_MU 119800ULL
281# define UTILS_REJECTION_THRESHOLD 16742417U
282#elif defined(QSC_HQC_S5N7333)
283# define CEIL_DIVIDE(a, b) (((a) / (b)) + (((a) % (b)) == 0 ? 0 : 1))
284# define BITMASK(a, size) ((1ULL << ((a) % (size))) - 1ULL)
285# define CRYPTO_ALGNAME "HQC-5"
286# define CRYPTO_SECRETKEYBYTES 7333U
287# define CRYPTO_PUBLICKEYBYTES 7237U
288# define CRYPTO_BYTES 32U
289# define CRYPTO_CIPHERTEXTBYTES 14421U
290# define PARAM_N 57637U
291# define PARAM_N1 90U
292# define PARAM_N2 640U
293# define PARAM_N1N2 57600U
294# define PARAM_OMEGA 131U
295# define PARAM_OMEGA_E 149U
296# define PARAM_OMEGA_R 149U
297# define PARAM_SECURITY 256U
298# define PARAM_SECURITY_BYTES 32U
299# define PARAM_DFR_EXP 256U
300# define SECRET_KEY_BYTES CRYPTO_SECRETKEYBYTES
301# define PUBLIC_KEY_BYTES CRYPTO_PUBLICKEYBYTES
302# define SHARED_SECRET_BYTES CRYPTO_BYTES
303# define CIPHERTEXT_BYTES CRYPTO_CIPHERTEXTBYTES
304# define PARAM_DELTA 29U
305# define PARAM_M 8U
306# define PARAM_GF_POLY 0x11DU
307# define PARAM_GF_MUL_ORDER 255U
308# define PARAM_K 32U
309# define PARAM_G 59U
310# define PARAM_FFT 5U
311# define SEED_BYTES 32U
312# define SALT_BYTES 16U
313# define PARAM_N_MU 74517ULL
314# define UTILS_REJECTION_THRESHOLD 16772367U
315#endif
316
317#if defined(QSC_HQC_S1N2321)
322#define RS_POLY_COEFS 89, 69, 153, 116, 176, 117, 111, 75, 73, 233, 242, 233, 65, 210, 21, 139, 103, 173, 67, 118, 105, 210, 174, 110, 74, 69, 228, 82, 255, 181, 1
323#elif defined(QSC_HQC_S3N4602)
328#define RS_POLY_COEFS 45, 216, 239, 24, 253, 104, 27, 40, 107, 50, 163, 210, 227, 134, 224, 158, 119, 13, 158, 1, 238, 164, 82, 43, 15, 232, 246, 142, 50, 189, 29, 232, 1
329#elif defined(QSC_HQC_S5N7333)
334#define RS_POLY_COEFS 49, 167, 49, 39, 200, 121, 124, 91, 240, 63, 148, 71, 150, 123, 87, 101, 32, 215, 159, 71, 201, 115, 97, 210, 186, 183, 141, 217, 123, 12, 31, 243, 180, 219, 152, 239, 99, 141, 4, 246, 191, 144, 8, 232, 47, 27, 141, 178, 130, 64, 124, 47, 39, 188, 216, 48, 199, 187, 1
335#endif
336
341#define VEC_N_SIZE_BYTES CEIL_DIVIDE(PARAM_N, 8U)
346#define VEC_K_SIZE_BYTES PARAM_K
351#define VEC_N1_SIZE_BYTES PARAM_N1
356#define VEC_N1N2_SIZE_BYTES CEIL_DIVIDE(PARAM_N1N2, 8U)
361#define VEC_N_SIZE_64 CEIL_DIVIDE(PARAM_N, 64U)
366#define VEC_N1_SIZE_64 CEIL_DIVIDE(PARAM_N1, 8U)
371#define VEC_N1N2_SIZE_64 CEIL_DIVIDE(PARAM_N1N2, 64U)
376#define QSC_HQC_SEED_SIZE 32U
381#define QSC_HQC_SHAREDSECRET_SIZE 32U
382
393typedef struct
394{
395 uint64_t u[VEC_N_SIZE_64];
396 uint64_t v[VEC_N1N2_SIZE_64];
397} qsc_hqc_ciphertext_pke;
398
407typedef struct
408{
409 qsc_hqc_ciphertext_pke c_pke;
410 uint8_t salt[SALT_BYTES];
411} qsc_hqc_ciphertext_kem;
412
422typedef union
423{
424 uint8_t u8[16];
425 uint16_t u16[8];
426 uint32_t u32[4];
427} rm_codeword_t;
428
442bool qsc_hqc_ref_decapsulate(uint8_t* secret, const uint8_t* ciphertext, const uint8_t* privatekey);
443
458bool qsc_hqc_ref_encapsulate(uint8_t* secret, uint8_t* ciphertext, const uint8_t* publickey, bool (*rng_generate)(uint8_t*, size_t));
459
475void qsc_hqc_ref_seeded_encapsulate(uint8_t* secret, uint8_t* ciphertext, const uint8_t* publickey, const uint8_t seed[QSC_HQC_SEED_SIZE]);
476
489bool qsc_hqc_ref_generate_keypair(uint8_t* publickey, uint8_t* privatekey, bool (*rng_generate)(uint8_t*, size_t));
490
505void qsc_hqc_ref_generate_seeded_keypair(uint8_t* publickey, uint8_t* privatekey, uint8_t* seed);
506
507/* \cond NO_DOCUMENT */
508
509#endif
#define QSC_HQC_SEED_SIZE
The byte size of the seed array.
Definition hqc.h:162
Contains common definitions for the Quantum Secure Cryptographic (QSC) library.