QSC Post Quantum Cryptographic Library 1.0.0.6c (A6)
A post quantum secure library written in Ansi C
 
Loading...
Searching...
No Matches
csx.h
Go to the documentation of this file.
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_CSX_H
41#define QSC_CSX_H
42
43#include "common.h"
44#include "sha3.h"
45
46QSC_CPLUSPLUS_ENABLED_START
47
85
90#if !defined(QSC_CSX_AUTHENTICATED)
91# define QSC_CSX_AUTHENTICATED
92#endif
93
94/* Enable one of the authentication options:
95 a 24 round KMAC, a reduced rounds KMAC, or the QMAC post quantum GMAC function */
96#if defined(QSC_CSX_AUTHENTICATED)
98//* \def QSC_CSX_AUTH_KMAC24
99//* \brief Sets the authentication mode to standard KMAC-R24.
100//*/
101//# define QSC_CSX_AUTH_KMAC24
102
104//\def QSC_CSX_AUTH_KMACR12
105//* \brief Enables the reduced rounds KMAC-R12 implementation.
106//*/
107//# define QSC_CSX_AUTH_KMACR12
108
113# define QSC_CSX_AUTH_QMAC
114#endif
115
121#if defined(QSC_CSX_AUTHENTICATED)
122# if !defined(QSC_CSX_AUTH_KMAC24) && !defined(QSC_CSX_AUTH_KMACR12) && !defined(QSC_CSX_AUTH_QMAC)
123# define QSC_CSX_AUTH_KMAC24
124# endif
125#endif
126
127#if defined(QSC_CSX_AUTH_QMAC)
128# include "qmac.h"
129#endif
130
135#define QSC_CSX_BLOCK_SIZE 128ULL
136
141#define QSC_CSX_INFO_SIZE 48ULL
142
147#define QSC_CSX_KEY_SIZE 64ULL
148
149#if defined(QSC_CSX_AUTH_QMAC)
154#define QSC_CSX_MAC_SIZE 32ULL
155#else
160#define QSC_CSX_MAC_SIZE 64ULL
161#endif
162
167#define QSC_CSX_NONCE_SIZE 16ULL
168
173#define QSC_CSX_STATE_SIZE 16ULL
174
183QSC_EXPORT_API typedef struct
184{
185 const uint8_t* key;
186 size_t keylen;
187 uint8_t* nonce;
188 const uint8_t* info;
189 size_t infolen;
191
196QSC_EXPORT_API typedef struct
197{
199#if defined(QSC_CSX_AUTH_QMAC)
201#else
203#endif
204 uint64_t counter;
205 bool encrypt;
207
208/* public functions */
209
219
227QSC_EXPORT_API void qsc_csx_initialize(qsc_csx_state* ctx, const qsc_csx_keyparams* keyparams, bool encryption);
228
241QSC_EXPORT_API void qsc_csx_set_associated(qsc_csx_state* ctx, const uint8_t* data, size_t length);
242
252
268QSC_EXPORT_API bool qsc_csx_transform(qsc_csx_state* ctx, uint8_t* output, const uint8_t* input, size_t length);
269
290QSC_EXPORT_API bool qsc_csx_extended_transform(qsc_csx_state* ctx, uint8_t* output, const uint8_t* input, size_t length, bool finalize);
291
292QSC_CPLUSPLUS_ENABLED_END
293
294#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
QSC_EXPORT_API bool qsc_csx_transform(qsc_csx_state *ctx, uint8_t *output, const uint8_t *input, size_t length)
Transform an array of bytes. In encryption mode, the input plain-text is encrypted and then an authen...
Definition csx.c:834
QSC_EXPORT_API void qsc_csx_store_nonce(const qsc_csx_state *ctx, uint8_t nonce[QSC_CSX_NONCE_SIZE])
Retrieves the current nonce from the state.
Definition csx.c:826
QSC_EXPORT_API void qsc_csx_set_associated(qsc_csx_state *ctx, const uint8_t *data, size_t length)
Set the associated data string used in authenticating the message. The associated data may be packet ...
Definition csx.c:806
#define QSC_CSX_STATE_SIZE
The uint64 size of the internal state array.
Definition csx.h:173
QSC_EXPORT_API void qsc_csx_dispose(qsc_csx_state *ctx)
Dispose of the CSX cipher state.
Definition csx.c:711
QSC_EXPORT_API void qsc_csx_initialize(qsc_csx_state *ctx, const qsc_csx_keyparams *keyparams, bool encryption)
Initialize the state with the input cipher-key and optional info tweak.
Definition csx.c:732
#define QSC_CSX_NONCE_SIZE
The byte size of the nonce array.
Definition csx.h:167
QSC_EXPORT_API bool qsc_csx_extended_transform(qsc_csx_state *ctx, uint8_t *output, const uint8_t *input, size_t length, bool finalize)
A multi-call transform for a large array of bytes, such as required by file encryption....
Definition csx.c:898
QMAC function definitions.
SHA3 family of hash functions.
The key parameters structure containing key, nonce, and info arrays and lengths. Use this structure t...
Definition csx.h:184
uint8_t * nonce
Definition csx.h:187
const uint8_t * key
Definition csx.h:185
size_t infolen
Definition csx.h:189
size_t keylen
Definition csx.h:186
const uint8_t * info
Definition csx.h:188
The internal state structure containing the round-key array.
Definition csx.h:197
uint64_t counter
Definition csx.h:204
qsc_qmac_state kstate
Definition csx.h:200
uint64_t state[QSC_CSX_STATE_SIZE]
Definition csx.h:198
bool encrypt
Definition csx.h:205
The Keccak state array; state array must be initialized by the caller.
Definition sha3.h:240
The QMAC state.
Definition qmac.h:122