sntrup761.c
Go to the documentation of this file.
1 /**
2  * @file sntrup761.c
3  * @brief Streamlined NTRU Prime 761 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 //Switch to the appropriate trace level
32 #define TRACE_LEVEL CRYPTO_TRACE_LEVEL
33 
34 //Dependencies
35 #include "core/crypto.h"
36 #include "pqc/sntrup761.h"
37 
38 //Check crypto library configuration
39 #if (SNTRUP761_SUPPORT == ENABLED)
40 
41 //Dependencies (liboqs)
42 #include <oqs/oqs.h>
43 
44 //Common interface for key encapsulation mechanisms (KEM)
46 {
47  "sntrup761",
55 };
56 
57 
58 /**
59  * @brief Key pair generation
60  * @param[in] prngAlgo PRNG algorithm
61  * @param[in] prngContext Pointer to the PRNG context
62  * @param[out] pk Public key
63  * @param[out] sk Secret key
64  * @return Error code
65  **/
66 
67 error_t sntrup761GenerateKeyPair(const PrngAlgo *prngAlgo, void *prngContext,
68  uint8_t *pk, uint8_t *sk)
69 {
70  OQS_STATUS status;
71 
72  //Key pair generation
73  status = OQS_KEM_ntruprime_sntrup761_keypair(pk, sk);
74 
75  //Return status code
76  return (status == OQS_SUCCESS) ? NO_ERROR : ERROR_FAILURE;
77 }
78 
79 
80 /**
81  * @brief Encapsulation algorithm
82  * @param[in] prngAlgo PRNG algorithm
83  * @param[in] prngContext Pointer to the PRNG context
84  * @param[out] ct Ciphertext
85  * @param[out] ss Shared secret
86  * @param[in] pk Public key
87  * @return Error code
88  **/
89 
90 error_t sntrup761Encapsulate(const PrngAlgo *prngAlgo, void *prngContext,
91  uint8_t *ct, uint8_t *ss, const uint8_t *pk)
92 {
93  OQS_STATUS status;
94 
95  //Encapsulation algorithm
96  status = OQS_KEM_ntruprime_sntrup761_encaps(ct, ss, pk);
97 
98  //Return status code
99  return (status == OQS_SUCCESS) ? NO_ERROR : ERROR_FAILURE;
100 }
101 
102 
103 /**
104  * @brief Decapsulation algorithm
105  * @param[out] ss Shared secret
106  * @param[in] ct Ciphertext
107  * @param[in] sk Secret key
108  * @return Error code
109  **/
110 
111 error_t sntrup761Decapsulate(uint8_t *ss, const uint8_t *ct, const uint8_t *sk)
112 {
113  OQS_STATUS status;
114 
115  //Decapsulation algorithm
116  status = OQS_KEM_ntruprime_sntrup761_decaps(ss, ct, sk);
117 
118  //Return status code
119  return (status == OQS_SUCCESS) ? NO_ERROR : ERROR_FAILURE;
120 }
121 
122 #endif
error_t sntrup761Encapsulate(const PrngAlgo *prngAlgo, void *prngContext, uint8_t *ct, uint8_t *ss, const uint8_t *pk)
Encapsulation algorithm.
Definition: sntrup761.c:90
#define SNTRUP761_SECRET_KEY_LEN
Definition: sntrup761.h:40
#define PrngAlgo
Definition: crypto.h:938
const KemAlgo sntrup761KemAlgo
Definition: sntrup761.c:45
#define SNTRUP761_CIPHERTEXT_LEN
Definition: sntrup761.h:42
error_t
Error codes.
Definition: error.h:43
@ ERROR_FAILURE
Generic error code.
Definition: error.h:45
General definitions for cryptographic algorithms.
#define SNTRUP761_PUBLIC_KEY_LEN
Definition: sntrup761.h:38
error_t sntrup761Decapsulate(uint8_t *ss, const uint8_t *ct, const uint8_t *sk)
Decapsulation algorithm.
Definition: sntrup761.c:111
error_t(* KemAlgoGenerateKeyPair)(const PrngAlgo *prngAlgo, void *prngContext, uint8_t *pk, uint8_t *sk)
Definition: crypto.h:1018
#define SNTRUP761_SHARED_SECRET_LEN
Definition: sntrup761.h:44
Common interface for key encapsulation mechanisms (KEM)
Definition: crypto.h:1087
Streamlined NTRU Prime 761 KEM.
error_t(* KemAlgoDecapsulate)(uint8_t *ss, const uint8_t *ct, const uint8_t *sk)
Definition: crypto.h:1024
error_t(* KemAlgoEncapsulate)(const PrngAlgo *prngAlgo, void *prngContext, uint8_t *ct, uint8_t *ss, const uint8_t *pk)
Definition: crypto.h:1021
error_t sntrup761GenerateKeyPair(const PrngAlgo *prngAlgo, void *prngContext, uint8_t *pk, uint8_t *sk)
Key pair generation.
Definition: sntrup761.c:67
@ NO_ERROR
Success.
Definition: error.h:44