QSC Post Quantum Cryptographic Library 1.0.0.6c (A6)
A post quantum secure library written in Ansi C
 
Loading...
Searching...
No Matches
kyberbase_avx2.h
1/* 2025 Quantum Resistant Cryptographic Solutions Corporation
2 * All Rights Reserved.
3 *
4 * NOTICE: This software and all accompanying materials are the exclusive
5 * property of Quantum Resistant Cryptographic Solutions Corporation (QRCS).
6 * The intellectual and technical concepts contained within this implementation
7 * are proprietary to QRCS and its authorized licensors and are protected under
8 * applicable U.S. and international copyright, patent, and trade secret laws.
9 *
10 * CRYPTOGRAPHIC STANDARDS:
11 * - This software includes implementations of cryptographic algorithms such as
12 * SHA3, AES, and others. These algorithms are public domain or standardized
13 * by organizations such as NIST and are NOT the property of QRCS.
14 * - However, all source code, optimizations, and implementations in this library
15 * are original works of QRCS and are protected under this license.
16 *
17 * RESTRICTIONS:
18 * - Redistribution, modification, or unauthorized distribution of this software,
19 * in whole or in part, is strictly prohibited.
20 * - This software is provided for non-commercial, educational, and research
21 * purposes only. Commercial use in any form is expressly forbidden.
22 * - Licensing and authorized distribution are solely at the discretion of QRCS.
23 * - Any use of this software implies acceptance of these restrictions.
24 *
25 * DISCLAIMER:
26 * This software is provided "as is," without warranty of any kind, express or
27 * implied, including but not limited to warranties of merchantability or fitness
28 * for a particular purpose. QRCS disclaims all liability for any direct, indirect,
29 * incidental, or consequential damages resulting from the use or misuse of this software.
30 *
31 * FULL LICENSE:
32 * This software is subject to the **Quantum Resistant Cryptographic Solutions
33 * Proprietary License (QRCS-PL)**. The complete license terms are included
34 * in the LICENSE.txt file distributed with this software.
35 *
36 * Written by: John G. Underhill
37 * Contact: john.underhill@protonmail.com
38 */
39
40#ifndef QSC_KYBERBASE_AVX2_H
41#define QSC_KYBERBASE_AVX2_H
42
43#include "common.h"
44
45/* \cond */
46
47QSC_CPLUSPLUS_ENABLED_START
48
53
54#if defined(QSC_SYSTEM_HAS_AVX2)
55
60#if defined(QSC_KYBER_S1P1632)
61# define QSC_KYBER_K 2
62#elif defined(QSC_KYBER_S3P2400)
63# define QSC_KYBER_K 3
64#elif defined(QSC_KYBER_S5P3168)
65# define QSC_KYBER_K 4
66#elif defined(QSC_KYBER_S6P3936)
67# define QSC_KYBER_K 5
68#else
69# error "The Kyber parameter set is invalid!"
70#endif
71
76#define QSC_KYBER_N 256
77
82#define QSC_KYBER_Q 3329
83
88#define QSC_KYBER_ETA2 2
89
94#define QSC_KYBER_MSGBYTES 32
95
100#define QSC_KYBER_SYMBYTES 32
101
106#define QSC_KYBER_POLYBYTES 384
107
108#if (QSC_KYBER_K == 2)
109# define QSC_KYBER_POLYVECBASE_BYTES 320
110# define QSC_KYBER_POLYCOMPRESSED_BYTES 128
111# define QSC_KYBER_ETA1 3
112#elif (QSC_KYBER_K == 3)
113# define QSC_KYBER_POLYVECBASE_BYTES 320
114# define QSC_KYBER_POLYCOMPRESSED_BYTES 128
115# define QSC_KYBER_ETA1 2
116#elif (QSC_KYBER_K == 4)
117# define QSC_KYBER_POLYVECBASE_BYTES 352
118# define QSC_KYBER_POLYCOMPRESSED_BYTES 160
119# define QSC_KYBER_ETA1 2
120#elif (QSC_KYBER_K == 5)
121# define QSC_KYBER_POLYVECBASE_BYTES 352
122# define QSC_KYBER_POLYCOMPRESSED_BYTES 160
123# define QSC_KYBER_ETA1 2
124#endif
125
130#define QSC_KYBER_POLYVEC_COMPRESSED_BYTES (QSC_KYBER_K * QSC_KYBER_POLYVECBASE_BYTES)
131
136#define QSC_KYBER_POLYVEC_BYTES (QSC_KYBER_K * QSC_KYBER_POLYBYTES)
137
142#define QSC_KYBER_INDCPA_PUBLICKEY_BYTES (QSC_KYBER_POLYVEC_BYTES + QSC_KYBER_SYMBYTES)
143
148#define QSC_KYBER_INDCPA_SECRETKEY_BYTES (QSC_KYBER_POLYVEC_BYTES)
149
154#define QSC_KYBER_INDCPA_BYTES (QSC_KYBER_POLYVEC_COMPRESSED_BYTES + QSC_KYBER_POLYCOMPRESSED_BYTES)
155
160#define QSC_KYBER_PUBLICKEY_BYTES (QSC_KYBER_INDCPA_PUBLICKEY_BYTES)
161
166#define QSC_KYBER_SECRETKEY_BYTES (QSC_KYBER_INDCPA_SECRETKEY_BYTES + QSC_KYBER_INDCPA_PUBLICKEY_BYTES + 2 * QSC_KYBER_SYMBYTES)
167
172#define QSC_KYBER_CIPHERTEXT_BYTES (QSC_KYBER_INDCPA_BYTES)
173
174/* kem.h */
175
184bool qsc_kyber_avx2_decapsulate(uint8_t ss[QSC_KYBER_MSGBYTES], const uint8_t ct[QSC_KYBER_CIPHERTEXT_BYTES],
185 const uint8_t sk[QSC_KYBER_SECRETKEY_BYTES]);
186
195void qsc_kyber_avx2_encapsulate(uint8_t ct[QSC_KYBER_CIPHERTEXT_BYTES], uint8_t ss[QSC_KYBER_MSGBYTES],
196 const uint8_t pk[QSC_KYBER_PUBLICKEY_BYTES], bool (*rng_generate)(uint8_t*, size_t));
197
205void qsc_kyber_avx2_generate_keypair(uint8_t pk[QSC_KYBER_PUBLICKEY_BYTES], uint8_t sk[QSC_KYBER_SECRETKEY_BYTES],
206 bool (*rng_generate)(uint8_t*, size_t));
207
208#endif
209
210QSC_CPLUSPLUS_ENABLED_END
211
212/* \endcond */
213
214#endif
Contains common definitions for the Quantum Secure Cryptographic (QSC) library.