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.4
29  **/
30 
31 #ifndef _KEM_H
32 #define _KEM_H
33 
34 //Dependencies
35 #include "core/crypto.h"
36 
37 //ML-KEM-512 key encapsulation mechanism supported?
38 #if (MLKEM512_SUPPORT == ENABLED)
39  #include "pqc/mlkem512.h"
40 #endif
41 
42 //ML-KEM-768 key encapsulation mechanism supported?
43 #if (MLKEM768_SUPPORT == ENABLED)
44  #include "pqc/mlkem768.h"
45 #endif
46 
47 //ML-KEM-1024 key encapsulation mechanism supported?
48 #if (MLKEM1024_SUPPORT == ENABLED)
49  #include "pqc/mlkem1024.h"
50 #endif
51 
52 //Streamlined NTRU Prime 761 KEM supported?
53 #if (SNTRUP761_SUPPORT == ENABLED)
54  #include "pqc/sntrup761.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
uint8_t * sk
Secret key.
Definition: kem.h:70
error_t kemEncapsulate(KemContext *context, const PrngAlgo *prngAlgo, void *prngContext, uint8_t *ct, uint8_t *ss)
Encapsulation algorithm.
Definition: kem.c:209
uint8_t * pk
Public key.
Definition: kem.h:71
#define PrngAlgo
Definition: crypto.h:938
void kemFree(KemContext *context)
Release KEM context.
Definition: kem.c:62
ML-KEM-768 key encapsulation mechanism.
error_t
Error codes.
Definition: error.h:43
KEM context.
Definition: kem.h:68
General definitions for cryptographic algorithms.
error_t kemLoadPublicKey(KemContext *context, const uint8_t *pk)
Load public key.
Definition: kem.c:160
error_t kemDecapsulate(KemContext *context, const uint8_t *ct, uint8_t *ss)
Decapsulation algorithm.
Definition: kem.c:240
Common interface for key encapsulation mechanisms (KEM)
Definition: crypto.h:1087
void kemInit(KemContext *context, const KemAlgo *kemAlgo)
Initialize KEM context.
Definition: kem.c:48
const KemAlgo * kemAlgo
Key encapsulation mechanism.
Definition: kem.h:69
Streamlined NTRU Prime 761 KEM.
ML-KEM-512 key encapsulation mechanism.
ML-KEM-1024 key encapsulation mechanism.
error_t kemGenerateKeyPair(KemContext *context, const PrngAlgo *prngAlgo, void *prngContext)
Key pair generation.
Definition: kem.c:100