QSC Post Quantum Cryptographic Library 1.0.0.6c (A6)
A post quantum secure library written in Ansi C
 
Loading...
Searching...
No Matches
chacha.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_CHACHA20_H
42#define QSC_CHACHA20_H
43
44#include "common.h"
45#include "poly1305.h"
46
47QSC_CPLUSPLUS_ENABLED_START
48
80
85#define QSC_CHACHA_BLOCK_SIZE 64ULL
86
91#define QSC_CHACHA_KEY128_SIZE 16ULL
92
97#define QSC_CHACHA_KEY256_SIZE 32ULL
98
103#define QSC_CHACHA_NONCE_SIZE 12ULL
104
109#define QSC_CHACHA_ROUND_COUNT 20ULL
110
117QSC_EXPORT_API typedef struct
118{
119 uint32_t state[16];
121
129QSC_EXPORT_API typedef struct
130{
131 const uint8_t* key;
132 size_t keylen;
133 uint8_t* nonce;
135
144
154
166QSC_EXPORT_API void qsc_chacha_transform(qsc_chacha_state* ctx, uint8_t* output, const uint8_t* input, size_t length);
167
168/* chacha-poly1305*/
169
177
190QSC_EXPORT_API void qsc_chacha_poly1305_set_associated(qsc_chacha_poly1305_state* ctx, const uint8_t* data, size_t datalen);
191
207QSC_EXPORT_API bool qsc_chacha_poly1305_decrypt(qsc_chacha_poly1305_state* ctx, uint8_t* output, const uint8_t* input, size_t length);
208
221
235
249QSC_EXPORT_API void qsc_chacha_poly1305_encrypt(qsc_chacha_poly1305_state* ctx, uint8_t* output, const uint8_t* input, size_t length);
250
251QSC_CPLUSPLUS_ENABLED_END
252
253#endif
QSC_EXPORT_API void qsc_chacha_dispose(qsc_chacha_state *ctx)
Dispose of the ChaCha20 cipher state.
Definition chacha.c:643
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:697
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:988
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:927
QSC_EXPORT_API void qsc_chacha_poly1305_dispose(qsc_chacha_poly1305_state *ctx)
Dispose of an ChaCha-Poly1305 state.
Definition chacha.c:961
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:650
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:936
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:974
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
Poly1305 function definitions Contains the public api and documentation for the Poly1305 implementat...
Key parameters for the ChaCha20 cipher.
Definition chacha.h:130
uint8_t * nonce
Definition chacha.h:133
const uint8_t * key
Definition chacha.h:131
size_t keylen
Definition chacha.h:132
Definition chacha.h:171
qsc_poly1305_state pstate
Definition chacha.h:173
size_t aadlen
Definition chacha.h:174
qsc_chacha_state cstate
Definition chacha.h:172
size_t msglen
Definition chacha.h:175
Internal state structure for the ChaCha20 cipher.
Definition chacha.h:118
uint32_t state[16]
Definition chacha.h:119
Contains the Poly1305 internal state.
Definition poly1305.h:82