QSC Post Quantum Cryptographic Library 1.3.0.0 (C1)
A post quantum secure library written in Ansi C
Loading...
Searching...
No Matches
chacha.h
Go to the documentation of this file.
1/* 2020-2026 Quantum Resistant Cryptographic Solutions Corporation
2 * All Rights Reserved.
3 *
4 * NOTICE:
5 * This software and all accompanying materials are the exclusive property of
6 * Quantum Resistant Cryptographic Solutions Corporation (QRCS). The intellectual
7 * and technical concepts contained herein are proprietary to QRCS and are
8 * protected under applicable Canadian, U.S., and international copyright,
9 * patent, and trade secret laws.
10 *
11 * CRYPTOGRAPHIC ALGORITHMS AND IMPLEMENTATIONS:
12 * - This software includes implementations of cryptographic primitives and
13 * algorithms that are standardized or in the public domain, such as AES
14 * and SHA-3, which are not proprietary to QRCS.
15 * - This software also includes cryptographic primitives, constructions, and
16 * algorithms designed by QRCS, including but not limited to RCS, SCB, CSX, QMAC, and
17 * related components, which are proprietary to QRCS.
18 * - All source code, implementations, protocol compositions, optimizations,
19 * parameter selections, and engineering work contained in this software are
20 * original works of QRCS and are protected under this license.
21 *
22 * LICENSE AND USE RESTRICTIONS:
23 * - This software is licensed under the Quantum Resistant Cryptographic Solutions
24 * Public Research and Evaluation License (QRCS-PREL), 2025-2026.
25 * - Permission is granted solely for non-commercial evaluation, academic research,
26 * cryptographic analysis, interoperability testing, and feasibility assessment.
27 * - Commercial use, production deployment, commercial redistribution, or
28 * integration into products or services is strictly prohibited without a
29 * separate written license agreement executed with QRCS.
30 * - Licensing and authorized distribution are solely at the discretion of QRCS.
31 *
32 * EXPERIMENTAL CRYPTOGRAPHY NOTICE:
33 * Portions of this software may include experimental, novel, or evolving
34 * cryptographic designs. Use of this software is entirely at the user's risk.
35 *
36 * DISCLAIMER:
37 * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
38 * IMPLIED, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS
39 * FOR A PARTICULAR PURPOSE, SECURITY, OR NON-INFRINGEMENT. QRCS DISCLAIMS ALL
40 * LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
41 * ARISING FROM THE USE OR MISUSE OF THIS SOFTWARE.
42 *
43 * FULL LICENSE:
44 * This software is subject to the Quantum Resistant Cryptographic Solutions
45 * Public Research and Evaluation License (QRCS-PREL), 2025-2026. The complete license terms
46 * are provided in the accompanying LICENSE file or at https://www.qrcscorp.ca.
47 *
48 * Written by: John G. Underhill
49 * Contact: contact@qrcscorp.ca
50 */
51
52#ifndef QSC_CHACHA20_H
53#define QSC_CHACHA20_H
54
55#include "qsccommon.h"
56#include "poly1305.h"
57
58QSC_CPLUSPLUS_ENABLED_START
59
91
96#define QSC_CHACHA_BLOCK_SIZE 64U
97
102#define QSC_CHACHA_KEY128_SIZE 16U
103
108#define QSC_CHACHA_KEY256_SIZE 32U
109
114#define QSC_CHACHA_NONCE_SIZE 12U
115
120#define QSC_CHACHA_ROUND_COUNT 20U
121
128QSC_EXPORT_API typedef struct
129{
130 uint32_t state[16U];
132
140QSC_EXPORT_API typedef struct
141{
142 const uint8_t* key;
143 size_t keylen;
144 uint8_t* nonce;
146
155
165
177QSC_EXPORT_API void qsc_chacha_transform(qsc_chacha_state* ctx, uint8_t* output, const uint8_t* input, size_t length);
178
179/* chacha-poly1305*/
180
188
201QSC_EXPORT_API void qsc_chacha_poly1305_set_associated(qsc_chacha_poly1305_state* ctx, const uint8_t* data, size_t datalen);
202
218QSC_EXPORT_API bool qsc_chacha_poly1305_decrypt(qsc_chacha_poly1305_state* ctx, uint8_t* output, const uint8_t* input, size_t length);
219
232
249
263QSC_EXPORT_API void qsc_chacha_poly1305_encrypt(qsc_chacha_poly1305_state* ctx, uint8_t* output, const uint8_t* input, size_t length);
264
265QSC_CPLUSPLUS_ENABLED_END
266
267#endif
QSC_EXPORT_API void qsc_chacha_dispose(qsc_chacha_state *ctx)
Dispose of the ChaCha20 cipher state.
Definition chacha.c:648
QSC_EXPORT_API void qsc_chacha_transform(qsc_chacha_state *ctx, uint8_t *output, const uint8_t *input, size_t length)
Process a block of input data using the ChaCha20 cipher.
Definition chacha.c:709
QSC_EXPORT_API void qsc_chacha_poly1305_encrypt(qsc_chacha_poly1305_state *ctx, uint8_t *output, const uint8_t *input, size_t length)
Encrypt data using the ChaCha-Poly1305 authenticated encryption mode.
Definition chacha.c:990
QSC_EXPORT_API void qsc_chacha_poly1305_set_associated(qsc_chacha_poly1305_state *ctx, const uint8_t *data, size_t datalen)
Set the associated data (AAD) for ChaCha-Poly1305 authenticated encryption.
Definition chacha.c:917
QSC_EXPORT_API void qsc_chacha_poly1305_dispose(qsc_chacha_poly1305_state *ctx)
Dispose of an ChaCha-Poly1305 state.
Definition chacha.c:977
QSC_EXPORT_API void qsc_chacha_initialize(qsc_chacha_state *ctx, const qsc_chacha_keyparams *keyparams)
Initialize the ChaCha20 cipher state with the secret key and nonce.
Definition chacha.c:658
QSC_EXPORT_API bool qsc_chacha_poly1305_decrypt(qsc_chacha_poly1305_state *ctx, uint8_t *output, const uint8_t *input, size_t length)
Decrypt data using the ChaCha-Poly1305 authenticated encryption mode.
Definition chacha.c:938
QSC_EXPORT_API void qsc_chacha_poly1305_initialize(qsc_chacha_poly1305_state *ctx, const qsc_chacha_keyparams *keyparams)
Initialize the ChaCha-Poly1305 state for authenticated encryption or decryption.
Definition chacha.c:1015
Poly1305 function definitions Contains the public api and documentation for the Poly1305 implementat...
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 qsccommon.h:645
Key parameters for the ChaCha20 cipher.
Definition chacha.h:141
uint8_t * nonce
Definition chacha.h:144
const uint8_t * key
Definition chacha.h:142
size_t keylen
Definition chacha.h:143
Definition chacha.h:182
qsc_poly1305_state pstate
Definition chacha.h:184
size_t aadlen
Definition chacha.h:185
qsc_chacha_state cstate
Definition chacha.h:183
size_t msglen
Definition chacha.h:186
Internal state structure for the ChaCha20 cipher.
Definition chacha.h:129
uint32_t state[16U]
Definition chacha.h:130
Contains the Poly1305 internal state.
Definition poly1305.h:116