QSC Post Quantum Cryptographic Library 1.0.0.6c (A6)
A post quantum secure library written in Ansi C
 
Loading...
Searching...
No Matches
rcs.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_RCS_H
42#define QSC_RCS_H
43
44#include "common.h"
45#include "sha3.h"
46#if defined(QSC_SYSTEM_AESNI_ENABLED)
47# include "intrinsics.h"
48# include <immintrin.h>
49#endif
50
51QSC_CPLUSPLUS_ENABLED_START
52
104
105/***********************************
106* USER CONFIGURABLE SETTINGS *
107***********************************/
108
113#if !defined(QSC_RCS_AUTHENTICATED)
114# define QSC_RCS_AUTHENTICATED
115#endif
116
117/* Enable one of the authentication options:
118 a 24 round KMAC, a reduced rounds KMAC, or the QMAC post quantum GMAC function */
119#if defined(QSC_RCS_AUTHENTICATED)
121// * \def QSC_RCS_AUTH_KMACR24
122// * \brief Sets the authentication mode to standard KMAC-R24.
123// * Remove this definition to enable the reduced rounds version using KMAC-R12.
124// */
125//# define QSC_RCS_AUTH_KMACR24
126
128// * \def QSC_RCS_AUTH_KMACR12
129// * \brief Enables the reduced rounds KMAC-R12 implementation.
130// */
131//# define QSC_RCS_AUTH_KMACR12
132
137 # define QSC_RCS_AUTH_QMAC
138#endif
139
140/* The default authentication MAC */
141#if defined(QSC_RCS_AUTHENTICATED)
142# if !defined(QSC_RCS_AUTH_KMACR24) && !defined(QSC_RCS_AUTH_KMACR12) && !defined(QSC_RCS_AUTH_QMAC)
143# define QSC_RCS_AUTH_KMACR24
144# endif
145#endif
146
147#if defined(QSC_RCS_AUTH_QMAC)
148# include "qmac.h"
149#endif
150
151/***********************************
152* RCS CONSTANTS AND SIZES *
153***********************************/
154
159#define QSC_RCS_BLOCK_SIZE 32ULL
160
165#define QSC_RCS256_KEY_SIZE 32ULL
166
171#define QSC_RCS256_MAC_SIZE 32ULL
172
177#define QSC_RCS512_KEY_SIZE 64ULL
178
179#if defined(QSC_RCS_AUTH_QMAC)
184#define QSC_RCS512_MAC_SIZE 32ULL
185#else
190#define QSC_RCS512_MAC_SIZE 64ULL
191#endif
192
197#define QSC_RCS_NONCE_SIZE 32ULL
198
202typedef enum
203{
204 RCS256 = 0x01,
205 RCS512 = 0x02,
207
216QSC_EXPORT_API typedef struct
217{
218 const uint8_t* key;
219 size_t keylen;
220 uint8_t* nonce;
221 const uint8_t* info;
222 size_t infolen;
224
228QSC_EXPORT_API typedef struct
229{
231#if defined(QSC_SYSTEM_AESNI_ENABLED)
232 __m128i roundkeys[62];
233# if defined(QSC_SYSTEM_HAS_AVX512)
234 __m512i roundkeysw[31];
235# endif
236#else
237 uint32_t roundkeys[248];
238#endif
239 size_t roundkeylen;
240 size_t rounds;
241#if defined(QSC_RCS_AUTH_QMAC)
243#else
245#endif
247 uint64_t counter;
248 bool encrypt;
250
260
268QSC_EXPORT_API void qsc_rcs_initialize(qsc_rcs_state* ctx, const qsc_rcs_keyparams* keyparams, bool encryption);
269
281QSC_EXPORT_API void qsc_rcs_set_associated(qsc_rcs_state* ctx, const uint8_t* data, size_t length);
282
292
307QSC_EXPORT_API bool qsc_rcs_transform(qsc_rcs_state* ctx, uint8_t* output, const uint8_t* input, size_t length);
308
325QSC_EXPORT_API bool qsc_rcs_extended_transform(qsc_rcs_state* ctx, uint8_t* output, const uint8_t* input, size_t length, bool finalize);
326
327QSC_CPLUSPLUS_ENABLED_END
328
329#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:520
QMAC function definitions.
QSC_EXPORT_API void qsc_rcs_initialize(qsc_rcs_state *ctx, const qsc_rcs_keyparams *keyparams, bool encryption)
Initialize the state with the input cipher-key and optional info tweak.
Definition rcs.c:723
rcs_cipher_type
The pre-defined cipher mode implementations.
Definition rcs.h:203
@ RCS512
Definition rcs.h:205
@ RCS256
Definition rcs.h:204
QSC_EXPORT_API void qsc_rcs_store_nonce(const qsc_rcs_state *ctx, uint8_t nonce[QSC_RCS_NONCE_SIZE])
Retrieves the current nonce from the state.
Definition rcs.c:775
#define QSC_RCS_NONCE_SIZE
The nonce size in bytes.
Definition rcs.h:197
QSC_EXPORT_API bool qsc_rcs_transform(qsc_rcs_state *ctx, uint8_t *output, const uint8_t *input, size_t length)
Transform an array of bytes.
Definition rcs.c:782
QSC_EXPORT_API void qsc_rcs_set_associated(qsc_rcs_state *ctx, const uint8_t *data, size_t length)
Set the associated data string used in authenticating the message.
Definition rcs.c:757
QSC_EXPORT_API bool qsc_rcs_extended_transform(qsc_rcs_state *ctx, uint8_t *output, const uint8_t *input, size_t length, bool finalize)
A multi-call transform for a large array of bytes.
Definition rcs.c:856
QSC_EXPORT_API void qsc_rcs_dispose(qsc_rcs_state *ctx)
Dispose of the RCS cipher state.
Definition rcs.c:693
SHA3 family of hash functions.
The Keccak state array; state array must be initialized by the caller.
Definition sha3.h:240
The QMAC state.
Definition qmac.h:122
The key parameters structure containing key, nonce, and info arrays and lengths.
Definition rcs.h:217
uint8_t * nonce
Definition rcs.h:220
const uint8_t * key
Definition rcs.h:218
size_t infolen
Definition rcs.h:222
size_t keylen
Definition rcs.h:219
const uint8_t * info
Definition rcs.h:221
The internal state structure containing the round-key array.
Definition rcs.h:229
uint64_t counter
Definition rcs.h:247
rcs_cipher_type ctype
Definition rcs.h:230
qsc_qmac_state kstate
Definition rcs.h:242
size_t roundkeylen
Definition rcs.h:239
size_t rounds
Definition rcs.h:240
uint8_t nonce[QSC_RCS_NONCE_SIZE]
Definition rcs.h:246
uint32_t roundkeys[248]
Definition rcs.h:237
bool encrypt
Definition rcs.h:248