QSC Post Quantum Cryptographic Library 1.1.0.2 (B2)
A post quantum secure library written in Ansi C
Loading...
Searching...
No Matches
ed25519.h
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_ED25519_H
53#define QSC_ED25519_H
54
55#include "qsccommon.h"
56
57 /* \cond NO_DOCUMENT */
58
59QSC_CPLUSPLUS_ENABLED_START
60
92
97#define ED25519_SEED_SIZE 32U
98
103#define ED25519_SIGNATURE_SIZE 64U
104
109#define ED25519_PUBLICKEY_SIZE 32U
110
115#define ED25519_PRIVATEKEY_SIZE 64U
116
121#define ED25519_CURVE_SIZE 32U
122
127typedef int32_t qsc_fe25519[10U];
128
135typedef struct
136{
137 qsc_fe25519 x;
138 qsc_fe25519 y;
139 qsc_fe25519 z;
140} qsc_ge25519_p2;
141
149typedef struct
150{
151 qsc_fe25519 x;
152 qsc_fe25519 y;
153 qsc_fe25519 z;
154 qsc_fe25519 t;
155} qsc_ge25519_p3;
156
163typedef struct
164{
165 qsc_fe25519 x;
166 qsc_fe25519 y;
167 qsc_fe25519 z;
168 qsc_fe25519 t;
169} qsc_ge25519_p1p1;
170
177typedef struct
178{
179 qsc_fe25519 yplusx;
180 qsc_fe25519 yminusx;
181 qsc_fe25519 xy2d;
182} qsc_ge25519_precomp;
183
190typedef struct
191{
192 qsc_fe25519 yplusx;
193 qsc_fe25519 yminusx;
194 qsc_fe25519 z;
195 qsc_fe25519 t2d;
196} qsc_ge25519_cached;
197
205void qsc_fe25519_0(qsc_fe25519 h);
206
214void qsc_fe25519_1(qsc_fe25519 h);
215
224void qsc_fe25519_copy(qsc_fe25519 h, const qsc_fe25519 f);
225
235void qsc_fe25519_add(qsc_fe25519 h, const qsc_fe25519 f, const qsc_fe25519 g);
236
247void qsc_fe25519_cswap(qsc_fe25519 f, qsc_fe25519 g, uint32_t b);
248
262void qsc_fe25519_sub(qsc_fe25519 h, const qsc_fe25519 f, const qsc_fe25519 g);
263
272void qsc_fe25519_neg(qsc_fe25519 h, const qsc_fe25519 f);
273
284void qsc_fe25519_cmov(qsc_fe25519 f, const qsc_fe25519 g, uint32_t b);
285
295int32_t qsc_fe25519_is_negative(const qsc_fe25519 f);
296
306int32_t qsc_fe25519_is_zero(const qsc_fe25519 f);
307
317void qsc_fe25519_mul(qsc_fe25519 h, const qsc_fe25519 f, const qsc_fe25519 g);
318
328void qsc_fe25519_mul32(qsc_fe25519 h, const qsc_fe25519 f, uint32_t n);
329
338void qsc_fe25519_sq(qsc_fe25519 h, const qsc_fe25519 f);
339
348void qsc_fe25519_sq2(qsc_fe25519 h, const qsc_fe25519 f);
349
358void qsc_fe25519_from_bytes(qsc_fe25519 h, const uint8_t* s);
359
369void qsc_fe25519_reduce(qsc_fe25519 h, const qsc_fe25519 f);
370
379void qsc_fe25519_to_bytes(uint8_t* s, const qsc_fe25519 h);
380
390void qsc_fe25519_invert(qsc_fe25519 out, const qsc_fe25519 z);
391
400void qsc_ge25519_p1p1_to_p3(qsc_ge25519_p3* r, const qsc_ge25519_p1p1* p);
401
410void qsc_ge25519_p1p1_to_p2(qsc_ge25519_p2* r, const qsc_ge25519_p1p1* p);
411
420void qsc_ge25519_scalarmult_base(qsc_ge25519_p3* h, const uint8_t* a);
421
430void qsc_ge25519_p3_to_bytes(uint8_t* s, const qsc_ge25519_p3* h);
431
440int32_t qsc_ge25519_is_canonical(const uint8_t* s);
441
450int32_t qsc_ge25519_has_small_order(const uint8_t s[32U]);
451
462int32_t qsc_ge25519_from_bytes_negate_vartime(qsc_ge25519_p3* h, const uint8_t* s);
463
472void qsc_ge25519_p3_to_cached(qsc_ge25519_cached* r, const qsc_ge25519_p3* p);
473
483void qsc_ge25519_add_cached(qsc_ge25519_p1p1* r, const qsc_ge25519_p3* p, const qsc_ge25519_cached* q);
484
495void qsc_ge25519_sub_precomp(qsc_ge25519_p1p1* r, const qsc_ge25519_p3* p, const qsc_ge25519_precomp* q);
496
508void qsc_ge25519_double_scalarmult_vartime(qsc_ge25519_p2* r, const uint8_t* a, const qsc_ge25519_p3* A, const uint8_t* b);
509
520void qsc_ge25519_sub_cached(qsc_ge25519_p1p1* r, const qsc_ge25519_p3* p, const qsc_ge25519_cached* q);
521
530void qsc_ge25519_to_bytes(uint8_t* s, const qsc_ge25519_p2* h);
531
539void qsc_sc25519_clamp(uint8_t* k);
540
550int32_t qsc_ed25519_small_order(const uint8_t s[32U]);
551
560int32_t qsc_sc25519_is_canonical(const uint8_t s[32U]);
561
573void qsc_sc25519_muladd(uint8_t s[32U], const uint8_t a[32U], const uint8_t b[32U], const uint8_t c[32U]);
574
590void qsc_sc25519_reduce(uint8_t s[64U]);
591
605int32_t qsc_sc25519_verify(const uint8_t* x, const uint8_t* y, const size_t n);
606
607QSC_CPLUSPLUS_ENABLED_END
608
609/* \endcond NO_DOCUMENT */
610
611#endif
612
Contains common definitions for the Quantum Secure Cryptographic (QSC) library.