QSC Post Quantum Cryptographic Library 1.0.0.6b (A6)
A post quantum secure library written in Ansi C
ntru.h
Go to the documentation of this file.
1/*
2 * 2025 Quantum Resistant Cryptographic Solutions Corporation
3 * All Rights Reserved.
4 *
5 * NOTICE: This software and all accompanying materials are the exclusive
6 * property of Quantum Resistant Cryptographic Solutions Corporation (QRCS).
7 * The intellectual and technical concepts contained within this implementation
8 * are proprietary to QRCS and its authorized licensors and are protected under
9 * applicable U.S. and international copyright, patent, and trade secret laws.
10 *
11 * CRYPTOGRAPHIC STANDARDS:
12 * - This software includes implementations of cryptographic algorithms such as
13 * SHA3, AES, and others. These algorithms are public domain or standardized
14 * by organizations such as NIST and are NOT the property of QRCS.
15 * - However, all source code, optimizations, and implementations in this library
16 * are original works of QRCS and are protected under this license.
17 *
18 * RESTRICTIONS:
19 * - Redistribution, modification, or unauthorized distribution of this software,
20 * in whole or in part, is strictly prohibited.
21 * - This software is provided for non-commercial, educational, and research
22 * purposes only. Commercial use in any form is expressly forbidden.
23 * - Licensing and authorized distribution are solely at the discretion of QRCS.
24 * - Any use of this software implies acceptance of these restrictions.
25 *
26 * DISCLAIMER:
27 * This software is provided "as is," without warranty of any kind, express or
28 * implied, including but not limited to warranties of merchantability or fitness
29 * for a particular purpose. QRCS disclaims all liability for any direct, indirect,
30 * incidental, or consequential damages resulting from the use or misuse of this software.
31 *
32 * FULL LICENSE:
33 * This software is subject to the **Quantum Resistant Cryptographic Solutions
34 * Proprietary License (QRCS-PL)**. The complete license terms are included
35 * in the LICENSE.txt file distributed with this software.
36 *
37 * Written by: John G. Underhill
38 * Contact: john.underhill@protonmail.com
39 */
40
41#ifndef QSC_NTRU_H
42#define QSC_NTRU_H
43
57
58
59#include "common.h"
60#include "ntrubase.h"
61
62#if defined(QSC_NTRU_S1HPS2048509)
63
68# define QSC_NTRU_CIPHERTEXT_SIZE 699ULL
69
74# define QSC_NTRU_PRIVATEKEY_SIZE 6492ULL
75
80# define QSC_NTRU_PUBLICKEY_SIZE 699ULL
81
82#elif defined(QSC_NTRU_S3HPS2048677)
83
88# define QSC_NTRU_CIPHERTEXT_SIZE 930ULL
89
94# define QSC_NTRU_PRIVATEKEY_SIZE 1234ULL
95
100# define QSC_NTRU_PUBLICKEY_SIZE 930ULL
101
102#elif defined(QSC_NTRU_S5HPS4096821)
103
108# define QSC_NTRU_CIPHERTEXT_SIZE 1230ULL
109
114# define QSC_NTRU_PRIVATEKEY_SIZE 1590ULL
115
120# define QSC_NTRU_PUBLICKEY_SIZE 1230ULL
121
122#elif defined(QSC_NTRU_S5HRSS701)
123
128# define QSC_NTRU_CIPHERTEXT_SIZE 1138ULL
129
134# define QSC_NTRU_PRIVATEKEY_SIZE 1450ULL
135
140# define QSC_NTRU_PUBLICKEY_SIZE 1138ULL
141
142#else
143# error "The NTRU parameter set is invalid!"
144#endif
145
150#define QSC_NTRU_SEED_SIZE 32ULL
151
156#define QSC_NTRU_SHAREDSECRET_SIZE 32ULL
157
162#define QSC_NTRU_ALGNAME "NTRU"
163
173QSC_EXPORT_API bool qsc_ntru_decapsulate(uint8_t* secret, const uint8_t* ciphertext, const uint8_t* privatekey);
174
184QSC_EXPORT_API bool qsc_ntru_decrypt(uint8_t* secret, const uint8_t* ciphertext, const uint8_t* privatekey);
185
196QSC_EXPORT_API void qsc_ntru_encapsulate(uint8_t* secret, uint8_t* ciphertext, const uint8_t* publickey, bool (*rng_generate)(uint8_t*, size_t));
197
208QSC_EXPORT_API void qsc_ntru_encrypt(uint8_t* secret, uint8_t* ciphertext, const uint8_t* publickey, const uint8_t seed[QSC_NTRU_SEED_SIZE]);
209
219QSC_EXPORT_API void qsc_ntru_generate_keypair(uint8_t* publickey, uint8_t* privatekey, bool (*rng_generate)(uint8_t*, size_t));
220
221#endif
Contains common definitions for the Quantum Secure Cryptographic (QSC) library.
#define QSC_EXPORT_API
API export macro for Microsoft compilers when importing from a DLL.
Definition common.h:511
QSC_EXPORT_API void qsc_ntru_encapsulate(uint8_t *secret, uint8_t *ciphertext, const uint8_t *publickey, bool(*rng_generate)(uint8_t *, size_t))
Encapsulates a shared secret using a public-key.
Definition ntru.c:40
QSC_EXPORT_API bool qsc_ntru_decrypt(uint8_t *secret, const uint8_t *ciphertext, const uint8_t *privatekey)
Decrypts the shared secret using a private-key.
Definition ntru.c:22
QSC_EXPORT_API void qsc_ntru_encrypt(uint8_t *secret, uint8_t *ciphertext, const uint8_t *publickey, const uint8_t seed[QSC_NTRU_SEED_SIZE])
Encrypts and encapsulates a shared secret using a public-key.
Definition ntru.c:53
#define QSC_NTRU_SEED_SIZE
The size of the seed array.
Definition ntru.h:150
QSC_EXPORT_API void qsc_ntru_generate_keypair(uint8_t *publickey, uint8_t *privatekey, bool(*rng_generate)(uint8_t *, size_t))
Generates a public/private key pair for NTRU.
Definition ntru.c:68
QSC_EXPORT_API bool qsc_ntru_decapsulate(uint8_t *secret, const uint8_t *ciphertext, const uint8_t *privatekey)
Decapsulates the shared secret using a private-key.
Definition ntru.c:4