Leancrypto 1.6.0
Post-Quantum Cryptographic Library
Loading...
Searching...
No Matches
lc_hqc.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2024 - 2025, Stephan Mueller <smueller@chronox.de>
3 *
4 * License: see LICENSE file in root directory
5 *
6 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
7 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
8 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
9 * WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
10 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
11 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
12 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
13 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
14 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
15 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
16 * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH
17 * DAMAGE.
18 */
19
20#ifndef LC_HQC_H
21#define LC_HQC_H
22
23#include "ext_headers.h"
24
25#if defined __has_include
26#if __has_include("lc_hqc_256.h")
27#include "lc_hqc_256.h"
28#define LC_HQC_256_ENABLED
29#endif
30#if __has_include("lc_hqc_192.h")
31#include "lc_hqc_192.h"
32#define LC_HQC_192_ENABLED
33#endif
34#if __has_include("lc_hqc_128.h")
35#include "lc_hqc_128.h"
36#define LC_HQC_128_ENABLED
37#endif
38#else
39#error "Compiler misses __has_include"
40#endif
41
42#ifdef __cplusplus
43extern "C" {
44#endif
45
52
76
77/************************************* KEM ************************************/
81struct lc_hqc_sk {
83 union {
84#ifdef LC_HQC_256_ENABLED
85 struct lc_hqc_256_sk sk_256;
86#endif
87#ifdef LC_HQC_192_ENABLED
88 struct lc_hqc_192_sk sk_192;
89#endif
90#ifdef LC_HQC_128_ENABLED
91 struct lc_hqc_128_sk sk_128;
92#endif
93 } key;
94};
95
99struct lc_hqc_pk {
101 union {
102#ifdef LC_HQC_256_ENABLED
103 struct lc_hqc_256_pk pk_256;
104#endif
105#ifdef LC_HQC_192_ENABLED
106 struct lc_hqc_192_pk pk_192;
107#endif
108#ifdef LC_HQC_128_ENABLED
109 struct lc_hqc_128_pk pk_128;
110#endif
112};
113
117struct lc_hqc_ct {
119 union {
120#ifdef LC_HQC_256_ENABLED
121 struct lc_hqc_256_ct ct_256;
122#endif
123#ifdef LC_HQC_192_ENABLED
124 struct lc_hqc_192_ct ct_192;
125#endif
126#ifdef LC_HQC_128_ENABLED
127 struct lc_hqc_128_ct ct_128;
128#endif
130};
131
135struct lc_hqc_ss {
137 union {
138#ifdef LC_HQC_256_ENABLED
139 struct lc_hqc_256_ss ss_256;
140#endif
141#ifdef LC_HQC_192_ENABLED
142 struct lc_hqc_192_ss ss_192;
143#endif
144#ifdef LC_HQC_128_ENABLED
145 struct lc_hqc_128_ss ss_128;
146#endif
148};
149
158enum lc_hqc_type lc_hqc_sk_type(const struct lc_hqc_sk *sk);
159
168enum lc_hqc_type lc_hqc_pk_type(const struct lc_hqc_pk *pk);
169
178enum lc_hqc_type lc_hqc_ct_type(const struct lc_hqc_ct *ct);
179
188enum lc_hqc_type lc_hqc_ss_type(const struct lc_hqc_ss *ss);
189
198LC_PURE
199unsigned int lc_hqc_sk_size(enum lc_hqc_type hqc_type);
200
209LC_PURE
210unsigned int lc_hqc_pk_size(enum lc_hqc_type hqc_type);
211
220LC_PURE
221unsigned int lc_hqc_ct_size(enum lc_hqc_type hqc_type);
222
231LC_PURE
232unsigned int lc_hqc_ss_size(enum lc_hqc_type hqc_type);
233
245int lc_hqc_sk_load(struct lc_hqc_sk *sk, const uint8_t *src_key,
246 size_t src_key_len);
247
259int lc_hqc_pk_load(struct lc_hqc_pk *pk, const uint8_t *src_key,
260 size_t src_key_len);
261
275int lc_hqc_ct_load(struct lc_hqc_ct *ct, const uint8_t *src_key,
276 size_t src_key_len);
277
291int lc_hqc_ss_load(struct lc_hqc_ss *ss, const uint8_t *src_key,
292 size_t src_key_len);
293
307int lc_hqc_sk_ptr(uint8_t **hqc_key, size_t *hqc_key_len, struct lc_hqc_sk *sk);
308
322int lc_hqc_pk_ptr(uint8_t **hqc_key, size_t *hqc_key_len, struct lc_hqc_pk *pk);
323
338int lc_hqc_ct_ptr(uint8_t **hqc_ct, size_t *hqc_ct_len, struct lc_hqc_ct *ct);
339
354int lc_hqc_ss_ptr(uint8_t **hqc_ss, size_t *hqc_ss_len, struct lc_hqc_ss *ss);
355
368int lc_hqc_keypair(struct lc_hqc_pk *pk, struct lc_hqc_sk *sk,
369 struct lc_rng_ctx *rng_ctx, enum lc_hqc_type hqc_type);
370
393 const uint8_t *seed, size_t seedlen,
394 enum lc_hqc_type hqc_type);
395
409int lc_hqc_enc(struct lc_hqc_ct *ct, struct lc_hqc_ss *ss,
410 const struct lc_hqc_pk *pk);
411
431int lc_hqc_enc_kdf(struct lc_hqc_ct *ct, uint8_t *ss, size_t ss_len,
432 const struct lc_hqc_pk *pk);
433
449int lc_hqc_dec(struct lc_hqc_ss *ss, const struct lc_hqc_ct *ct,
450 const struct lc_hqc_sk *sk);
451
473int lc_hqc_dec_kdf(uint8_t *ss, size_t ss_len, const struct lc_hqc_ct *ct,
474 const struct lc_hqc_sk *sk);
475
476#ifdef __cplusplus
477}
478#endif
479
480#endif /* LC_HQC_H */
int lc_hqc_dec(struct lc_hqc_ss *ss, const struct lc_hqc_ct *ct, const struct lc_hqc_sk *sk)
Key decapsulation.
int lc_hqc_keypair_from_seed(struct lc_hqc_pk *pk, struct lc_hqc_sk *sk, const uint8_t *seed, size_t seedlen, enum lc_hqc_type hqc_type)
Generates HQC public and private key from a given seed.
int lc_hqc_enc(struct lc_hqc_ct *ct, struct lc_hqc_ss *ss, const struct lc_hqc_pk *pk)
Key encapsulation.
enum lc_hqc_type lc_hqc_ss_type(const struct lc_hqc_ss *ss)
Obtain HQC type from shared secret.
LC_PURE unsigned int lc_hqc_pk_size(enum lc_hqc_type hqc_type)
Return the size of the HQC public key.
int lc_hqc_sk_load(struct lc_hqc_sk *sk, const uint8_t *src_key, size_t src_key_len)
Load a HQC secret key provided with a buffer into the leancrypto data structure.
LC_PURE unsigned int lc_hqc_ct_size(enum lc_hqc_type hqc_type)
Return the size of the HQC ciphertext.
int lc_hqc_ct_ptr(uint8_t **hqc_ct, size_t *hqc_ct_len, struct lc_hqc_ct *ct)
Obtain the reference to the HQC ciphertext and its length.
int lc_hqc_pk_ptr(uint8_t **hqc_key, size_t *hqc_key_len, struct lc_hqc_pk *pk)
Obtain the reference to the HQC key and its length.
int lc_hqc_ct_load(struct lc_hqc_ct *ct, const uint8_t *src_key, size_t src_key_len)
Load a HQC ciphertext key provided with a buffer into the leancrypto data structure.
int lc_hqc_pk_load(struct lc_hqc_pk *pk, const uint8_t *src_key, size_t src_key_len)
Load a HQC public key provided with a buffer into the leancrypto data structure.
int lc_hqc_ss_load(struct lc_hqc_ss *ss, const uint8_t *src_key, size_t src_key_len)
Load a HQC shared secret provided with a buffer into the leancrypto data structure.
LC_PURE unsigned int lc_hqc_sk_size(enum lc_hqc_type hqc_type)
Return the size of the HQC secret key.
int lc_hqc_enc_kdf(struct lc_hqc_ct *ct, uint8_t *ss, size_t ss_len, const struct lc_hqc_pk *pk)
Key encapsulation with KDF applied to shared secret.
LC_PURE unsigned int lc_hqc_ss_size(enum lc_hqc_type hqc_type)
Return the size of the HQC shared secret.
int lc_hqc_sk_ptr(uint8_t **hqc_key, size_t *hqc_key_len, struct lc_hqc_sk *sk)
Obtain the reference to the HQC key and its length.
enum lc_hqc_type lc_hqc_ct_type(const struct lc_hqc_ct *ct)
Obtain HQC type from HQC ciphertext.
enum lc_hqc_type lc_hqc_sk_type(const struct lc_hqc_sk *sk)
Obtain HQC type from secret key.
int lc_hqc_dec_kdf(uint8_t *ss, size_t ss_len, const struct lc_hqc_ct *ct, const struct lc_hqc_sk *sk)
Key decapsulation with KDF applied to shared secret.
enum lc_hqc_type lc_hqc_pk_type(const struct lc_hqc_pk *pk)
Obtain HQC type from public key.
int lc_hqc_ss_ptr(uint8_t **hqc_ss, size_t *hqc_ss_len, struct lc_hqc_ss *ss)
Obtain the reference to the HQC shared secret and its length.
int lc_hqc_keypair(struct lc_hqc_pk *pk, struct lc_hqc_sk *sk, struct lc_rng_ctx *rng_ctx, enum lc_hqc_type hqc_type)
Generates public and private key for IND-CCA2-secure HQC key encapsulation mechanism.
enum lc_hqc_type hqc_type
Definition lc_hqc.h:82
union lc_hqc_pk::@035140023341273367341066260121114102352303165040 key
union lc_hqc_sk::@277011270306077302103004123166265263064060374206 key
enum lc_hqc_type hqc_type
Definition lc_hqc.h:100
union lc_hqc_ss::@300214321151341161115047234062220323136301166037 key
enum lc_hqc_type hqc_type
Definition lc_hqc.h:118
enum lc_hqc_type hqc_type
Definition lc_hqc.h:136
union lc_hqc_ct::@131304226346244126225011227345330032163170154262 key
lc_hqc_type
Definition lc_hqc.h:46
@ LC_HQC_128
Definition lc_hqc.h:50
@ LC_HQC_UNKNOWN
Definition lc_hqc.h:47
@ LC_HQC_192
Definition lc_hqc.h:49
@ LC_HQC_256
Definition lc_hqc.h:48
HQC ciphertext.
Definition lc_hqc.h:117
HQC public key.
Definition lc_hqc.h:99
HQC secret key.
Definition lc_hqc.h:81
HQC shared secret.
Definition lc_hqc.h:135