kem.h
Go to the documentation of this file.
1 /**
2  * @file kem.h
3  * @brief Key encapsulation mechanism (KEM)
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2024 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneCRYPTO Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 2.4.0
29  **/
30 
31 #ifndef _KEM_H
32 #define _KEM_H
33 
34 //Dependencies
35 #include "core/crypto.h"
36 
37 //Streamlined NTRU Prime 761 KEM supported?
38 #if (SNTRUP761_SUPPORT == ENABLED)
39  #include "pqc/sntrup761.h"
40 #endif
41 
42 //Kyber-512 KEM supported?
43 #if (KYBER512_SUPPORT == ENABLED)
44  #include "pqc/kyber512.h"
45 #endif
46 
47 //Kyber-768 KEM supported?
48 #if (KYBER768_SUPPORT == ENABLED)
49  #include "pqc/kyber768.h"
50 #endif
51 
52 //Kyber-1024 KEM supported?
53 #if (KYBER1024_SUPPORT == ENABLED)
54  #include "pqc/kyber1024.h"
55 #endif
56 
57 //C++ guard
58 #ifdef __cplusplus
59 extern "C" {
60 #endif
61 
62 
63 /**
64  * @brief KEM context
65  **/
66 
67 typedef struct
68 {
69  const KemAlgo *kemAlgo; ///<Key encapsulation mechanism
70  uint8_t *sk; ///<Secret key
71  uint8_t *pk; ///<Public key
72 } KemContext;
73 
74 
75 //KEM related functions
76 void kemInit(KemContext *context, const KemAlgo *kemAlgo);
77 void kemFree(KemContext *context);
78 
79 error_t kemGenerateKeyPair(KemContext *context, const PrngAlgo *prngAlgo,
80  void *prngContext);
81 
82 error_t kemLoadPublicKey(KemContext *context, const uint8_t *pk);
83 
84 error_t kemEncapsulate(KemContext *context, const PrngAlgo *prngAlgo,
85  void *prngContext, uint8_t *ct, uint8_t *ss);
86 
87 error_t kemDecapsulate(KemContext *context, const uint8_t *ct, uint8_t *ss);
88 
89 //C++ guard
90 #ifdef __cplusplus
91 }
92 #endif
93 
94 #endif
General definitions for cryptographic algorithms.
#define PrngAlgo
Definition: crypto.h:917
error_t
Error codes.
Definition: error.h:43
void kemFree(KemContext *context)
Release KEM context.
Definition: kem.c:62
error_t kemEncapsulate(KemContext *context, const PrngAlgo *prngAlgo, void *prngContext, uint8_t *ct, uint8_t *ss)
Encapsulation algorithm.
Definition: kem.c:209
error_t kemDecapsulate(KemContext *context, const uint8_t *ct, uint8_t *ss)
Decapsulation algorithm.
Definition: kem.c:240
void kemInit(KemContext *context, const KemAlgo *kemAlgo)
Initialize KEM context.
Definition: kem.c:48
error_t kemGenerateKeyPair(KemContext *context, const PrngAlgo *prngAlgo, void *prngContext)
Key pair generation.
Definition: kem.c:100
error_t kemLoadPublicKey(KemContext *context, const uint8_t *pk)
Load public key.
Definition: kem.c:160
Kyber-1024 KEM.
Kyber-512 KEM.
Kyber-768 KEM.
Streamlined NTRU Prime 761 KEM.
Common interface for key encapsulation mechanisms (KEM)
Definition: crypto.h:1055
KEM context.
Definition: kem.h:68
uint8_t * pk
Public key.
Definition: kem.h:71
uint8_t * sk
Secret key.
Definition: kem.h:70
const KemAlgo * kemAlgo
Key encapsulation mechanism.
Definition: kem.h:69