Leancrypto 1.6.0
Post-Quantum Cryptographic Library
Loading...
Searching...
No Matches
lc_bike.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_BIKE_H
21#define LC_BIKE_H
22
23#include "ext_headers.h"
24
25#if defined __has_include
26#if __has_include("lc_bike_5.h")
27#include "lc_bike_5.h"
28#define LC_BIKE_5_ENABLED
29#endif
30#if __has_include("lc_bike_3.h")
31#include "lc_bike_3.h"
32#define LC_BIKE_3_ENABLED
33#endif
34#if __has_include("lc_bike_1.h")
35#include "lc_bike_1.h"
36#define LC_BIKE_1_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_bike_sk {
83 union {
84#ifdef LC_BIKE_5_ENABLED
85 struct lc_bike_5_sk sk_5;
86#endif
87#ifdef LC_BIKE_3_ENABLED
88 struct lc_bike_3_sk sk_3;
89#endif
90#ifdef LC_BIKE_1_ENABLED
91 struct lc_bike_1_sk sk_1;
92#endif
93 } key;
94};
95
99struct lc_bike_pk {
101 union {
102#ifdef LC_BIKE_5_ENABLED
103 struct lc_bike_5_pk pk_5;
104#endif
105#ifdef LC_BIKE_3_ENABLED
106 struct lc_bike_3_pk pk_3;
107#endif
108#ifdef LC_BIKE_1_ENABLED
109 struct lc_bike_1_pk pk_1;
110#endif
112};
113
119 union {
120#ifdef LC_BIKE_5_ENABLED
121 struct lc_bike_5_ct ct_5;
122#endif
123#ifdef LC_BIKE_3_ENABLED
124 struct lc_bike_3_ct ct_3;
125#endif
126#ifdef LC_BIKE_1_ENABLED
127 struct lc_bike_1_ct ct_1;
128#endif
130};
131
137 union {
138#ifdef LC_BIKE_5_ENABLED
139 struct lc_bike_5_ss ss_5;
140#endif
141#ifdef LC_BIKE_3_ENABLED
142 struct lc_bike_3_ss ss_3;
143#endif
144#ifdef LC_BIKE_1_ENABLED
145 struct lc_bike_1_ss ss_1;
146#endif
148};
149
159
169
179
189
198LC_PURE
199unsigned int lc_bike_sk_size(enum lc_bike_type bike_type);
200
209LC_PURE
210unsigned int lc_bike_pk_size(enum lc_bike_type bike_type);
211
220LC_PURE
221unsigned int lc_bike_ct_size(enum lc_bike_type bike_type);
222
231LC_PURE
232unsigned int lc_bike_ss_size(enum lc_bike_type bike_type);
233
245int lc_bike_sk_load(struct lc_bike_sk *sk, const uint8_t *src_key,
246 size_t src_key_len);
247
259int lc_bike_pk_load(struct lc_bike_pk *pk, const uint8_t *src_key,
260 size_t src_key_len);
261
275int lc_bike_ct_load(struct lc_bike_ct *ct, const uint8_t *src_key,
276 size_t src_key_len);
277
291int lc_bike_ss_load(struct lc_bike_ss *ss, const uint8_t *src_key,
292 size_t src_key_len);
293
307int lc_bike_sk_ptr(uint8_t **bike_key, size_t *bike_key_len,
308 struct lc_bike_sk *sk);
309
323int lc_bike_pk_ptr(uint8_t **bike_key, size_t *bike_key_len,
324 struct lc_bike_pk *pk);
325
340int lc_bike_ct_ptr(uint8_t **bike_ct, size_t *bike_ct_len,
341 struct lc_bike_ct *ct);
342
357int lc_bike_ss_ptr(uint8_t **bike_ss, size_t *bike_ss_len,
358 struct lc_bike_ss *ss);
359
372int lc_bike_keypair(struct lc_bike_pk *pk, struct lc_bike_sk *sk,
373 struct lc_rng_ctx *rng_ctx, enum lc_bike_type bike_type);
374
397 const uint8_t *seed, size_t seedlen,
398 enum lc_bike_type bike_type);
399
413int lc_bike_enc(struct lc_bike_ct *ct, struct lc_bike_ss *ss,
414 const struct lc_bike_pk *pk);
415
435int lc_bike_enc_kdf(struct lc_bike_ct *ct, uint8_t *ss, size_t ss_len,
436 const struct lc_bike_pk *pk);
437
453int lc_bike_dec(struct lc_bike_ss *ss, const struct lc_bike_ct *ct,
454 const struct lc_bike_sk *sk);
455
477int lc_bike_dec_kdf(uint8_t *ss, size_t ss_len, const struct lc_bike_ct *ct,
478 const struct lc_bike_sk *sk);
479
480#ifdef __cplusplus
481}
482#endif
483
484#endif /* LC_BIKE_H */
LC_PURE unsigned int lc_bike_pk_size(enum lc_bike_type bike_type)
Return the size of the BIKE public key.
LC_PURE unsigned int lc_bike_ss_size(enum lc_bike_type bike_type)
Return the size of the BIKE shared secret.
int lc_bike_ct_ptr(uint8_t **bike_ct, size_t *bike_ct_len, struct lc_bike_ct *ct)
Obtain the reference to the BIKE ciphertext and its length.
int lc_bike_dec(struct lc_bike_ss *ss, const struct lc_bike_ct *ct, const struct lc_bike_sk *sk)
Key decapsulation.
int lc_bike_ss_load(struct lc_bike_ss *ss, const uint8_t *src_key, size_t src_key_len)
Load a BIKE shared secret provided with a buffer into the leancrypto data structure.
int lc_bike_enc_kdf(struct lc_bike_ct *ct, uint8_t *ss, size_t ss_len, const struct lc_bike_pk *pk)
Key encapsulation with KDF applied to shared secret.
int lc_bike_ct_load(struct lc_bike_ct *ct, const uint8_t *src_key, size_t src_key_len)
Load a BIKE ciphertext key provided with a buffer into the leancrypto data structure.
enum lc_bike_type lc_bike_sk_type(const struct lc_bike_sk *sk)
Obtain BIKE type from secret key.
int lc_bike_pk_ptr(uint8_t **bike_key, size_t *bike_key_len, struct lc_bike_pk *pk)
Obtain the reference to the BIKE key and its length.
int lc_bike_keypair(struct lc_bike_pk *pk, struct lc_bike_sk *sk, struct lc_rng_ctx *rng_ctx, enum lc_bike_type bike_type)
Generates public and private key for IND-CCA2-secure BIKE key encapsulation mechanism.
int lc_bike_sk_load(struct lc_bike_sk *sk, const uint8_t *src_key, size_t src_key_len)
Load a BIKE secret key provided with a buffer into the leancrypto data structure.
LC_PURE unsigned int lc_bike_ct_size(enum lc_bike_type bike_type)
Return the size of the BIKE ciphertext.
int lc_bike_ss_ptr(uint8_t **bike_ss, size_t *bike_ss_len, struct lc_bike_ss *ss)
Obtain the reference to the BIKE shared secret and its length.
int lc_bike_enc(struct lc_bike_ct *ct, struct lc_bike_ss *ss, const struct lc_bike_pk *pk)
Key encapsulation.
enum lc_bike_type lc_bike_ct_type(const struct lc_bike_ct *ct)
Obtain BIKE type from BIKE ciphertext.
enum lc_bike_type lc_bike_pk_type(const struct lc_bike_pk *pk)
Obtain BIKE type from public key.
int lc_bike_keypair_from_seed(struct lc_bike_pk *pk, struct lc_bike_sk *sk, const uint8_t *seed, size_t seedlen, enum lc_bike_type bike_type)
Generates BIKE public and private key from a given seed.
int lc_bike_sk_ptr(uint8_t **bike_key, size_t *bike_key_len, struct lc_bike_sk *sk)
Obtain the reference to the BIKE key and its length.
int lc_bike_pk_load(struct lc_bike_pk *pk, const uint8_t *src_key, size_t src_key_len)
Load a BIKE public key provided with a buffer into the leancrypto data structure.
int lc_bike_dec_kdf(uint8_t *ss, size_t ss_len, const struct lc_bike_ct *ct, const struct lc_bike_sk *sk)
Key decapsulation with KDF applied to shared secret.
enum lc_bike_type lc_bike_ss_type(const struct lc_bike_ss *ss)
Obtain BIKE type from shared secret.
LC_PURE unsigned int lc_bike_sk_size(enum lc_bike_type bike_type)
Return the size of the BIKE secret key.
enum lc_bike_type bike_type
Definition lc_bike.h:136
lc_bike_type
Definition lc_bike.h:46
@ LC_BIKE_1
Definition lc_bike.h:50
@ LC_BIKE_3
Definition lc_bike.h:49
@ LC_BIKE_5
Definition lc_bike.h:48
@ LC_BIKE_UNKNOWN
Definition lc_bike.h:47
enum lc_bike_type bike_type
Definition lc_bike.h:118
union lc_bike_ct::@075141013122357067044040073060341316355050221242 key
union lc_bike_pk::@116271161166350021202026271122376246036364015044 key
union lc_bike_ss::@106016031101347344115032136211234116230343337236 key
enum lc_bike_type bike_type
Definition lc_bike.h:82
union lc_bike_sk::@040120127340073073102072071314100373252250331052 key
enum lc_bike_type bike_type
Definition lc_bike.h:100
BIKE ciphertext.
Definition lc_bike.h:117
BIKE public key.
Definition lc_bike.h:99
BIKE secret key.
Definition lc_bike.h:81
BIKE shared secret.
Definition lc_bike.h:135