QSC Post Quantum Cryptographic Library 1.0.0.6c (A6)
A post quantum secure library written in Ansi C
 
Loading...
Searching...
No Matches
ec25519.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_EC25519_H
41#define QSC_EC25519_H
42
43#include "common.h"
44
45QSC_CPLUSPLUS_ENABLED_START
46
78
83#define EC25519_SEED_SIZE 32ULL
84
89#define EC25519_SIGNATURE_SIZE 64ULL
90
95#define EC25519_PUBLICKEY_SIZE 32ULL
96
101#define EC25519_PRIVATEKEY_SIZE 64ULL
102
107#define EC25519_CURVE_SIZE 32ULL
108
113typedef QSC_SIMD_ALIGN int32_t fe25519[10];
114
121typedef struct
122{
126} ge25519_p2;
127
142
156
169
183
191void fe25519_0(fe25519 h);
192
200void fe25519_1(fe25519 h);
201
210void fe25519_copy(fe25519 h, const fe25519 f);
211
221void fe25519_add(fe25519 h, const fe25519 f, const fe25519 g);
222
233void fe25519_cswap(fe25519 f, fe25519 g, uint32_t b);
234
248void fe25519_sub(fe25519 h, const fe25519 f, const fe25519 g);
249
258void fe25519_neg(fe25519 h, const fe25519 f);
259
270void fe25519_cmov(fe25519 f, const fe25519 g, uint32_t b);
271
281int32_t fe25519_isnegative(const fe25519 f);
282
292int32_t fe25519_iszero(const fe25519 f);
293
303void fe25519_mul(fe25519 h, const fe25519 f, const fe25519 g);
304
314void fe25519_mul32(fe25519 h, const fe25519 f, uint32_t n);
315
324void fe25519_sq(fe25519 h, const fe25519 f);
325
334void fe25519_sq2(fe25519 h, const fe25519 f);
335
344void fe25519_frombytes(fe25519 h, const uint8_t* s);
345
355void fe25519_reduce(fe25519 h, const fe25519 f);
356
365void fe25519_tobytes(uint8_t* s, const fe25519 h);
366
376void fe25519_invert(fe25519 out, const fe25519 z);
377
387
397
406void ge25519_scalarmult_base(ge25519_p3* h, const uint8_t* a);
407
416void ge25519_p3_tobytes(uint8_t* s, const ge25519_p3* h);
417
426int32_t ge25519_is_canonical(const uint8_t* s);
427
436int32_t ge25519_has_small_order(const uint8_t s[32]);
437
448int32_t ge25519_frombytes_negate_vartime(ge25519_p3* h, const uint8_t* s);
449
459
469void ge25519_add_cached(ge25519_p1p1* r, const ge25519_p3* p, const ge25519_cached* q);
470
482
494void ge25519_double_scalarmult_vartime(ge25519_p2* r, const uint8_t* a, const ge25519_p3* A, const uint8_t* b);
495
506void ge25519_sub_cached(ge25519_p1p1* r, const ge25519_p3* p, const ge25519_cached* q);
507
516void ge25519_tobytes(uint8_t* s, const ge25519_p2* h);
517
525void sc25519_clamp(uint8_t* k);
526
536int32_t ed25519_small_order(const uint8_t s[32]);
537
546int32_t sc25519_is_canonical(const uint8_t s[32]);
547
559void sc25519_muladd(uint8_t s[32], const uint8_t a[32], const uint8_t b[32], const uint8_t c[32]);
560
576void sc25519_reduce(uint8_t s[64]);
577
591int32_t qsc_sc25519_verify(const uint8_t* x, const uint8_t* y, const size_t n);
592
593QSC_CPLUSPLUS_ENABLED_END
594
595#endif
596
Contains common definitions for the Quantum Secure Cryptographic (QSC) library.
#define QSC_SIMD_ALIGN
Fallback macro for SIMD alignment (no specific alignment).
Definition common.h:953
void ge25519_add_cached(ge25519_p1p1 *r, const ge25519_p3 *p, const ge25519_cached *q)
Add a cached point to a point.
Definition ec25519.c:3037
void sc25519_reduce(uint8_t s[64])
Reduce a 64-byte scalar modulo 2^255 - 19.
Definition ec25519.c:3846
void ge25519_sub_precomp(ge25519_p1p1 *r, const ge25519_p3 *p, const ge25519_precomp *q)
Subtract a precomputed point from a point.
void ge25519_p3_tobytes(uint8_t *s, const ge25519_p3 *h)
Compress a point in P3 coordinates to a 32-byte representation.
Definition ec25519.c:2849
void fe25519_0(fe25519 h)
Set a field element to zero.
Definition ec25519.c:151
int32_t ed25519_small_order(const uint8_t s[32])
Check if a compressed point has small order.
Definition ec25519.c:3261
void ge25519_double_scalarmult_vartime(ge25519_p2 *r, const uint8_t *a, const ge25519_p3 *A, const uint8_t *b)
Compute a double scalar multiplication.
Definition ec25519.c:3081
int32_t sc25519_is_canonical(const uint8_t s[32])
Check if a scalar is canonical.
Definition ec25519.c:3341
void ge25519_p1p1_to_p2(ge25519_p2 *r, const ge25519_p1p1 *p)
Convert a point from P1P1 to P2 coordinates.
Definition ec25519.c:2787
void fe25519_sub(fe25519 h, const fe25519 f, const fe25519 g)
Subtract one field element from another.
Definition ec25519.c:282
void fe25519_tobytes(uint8_t *s, const fe25519 h)
Convert a field element to a 32-byte array.
Definition ec25519.c:1124
int32_t fe25519_iszero(const fe25519 f)
Determine if a field element is zero.
Definition ec25519.c:376
void fe25519_cswap(fe25519 f, fe25519 g, uint32_t b)
Conditionally swap two field elements in constant time.
Definition ec25519.c:181
void fe25519_mul(fe25519 h, const fe25519 f, const fe25519 g)
Multiply two field elements.
Definition ec25519.c:385
void fe25519_reduce(fe25519 h, const fe25519 f)
Reduce a field element modulo 2^255 - 19.
Definition ec25519.c:1023
void fe25519_1(fe25519 h)
Set a field element to one.
Definition ec25519.c:156
void fe25519_mul32(fe25519 h, const fe25519 f, uint32_t n)
Multiply a field element by a scalar.
Definition ec25519.c:559
int32_t ge25519_is_canonical(const uint8_t *s)
Check if a compressed point is canonical.
Definition ec25519.c:2862
void fe25519_copy(fe25519 h, const fe25519 f)
Copy a field element.
Definition ec25519.c:162
void fe25519_sq(fe25519 h, const fe25519 f)
Square a field element.
Definition ec25519.c:630
int32_t qsc_sc25519_verify(const uint8_t *x, const uint8_t *y, const size_t n)
Performs a constant-time comparison of two byte arrays.
Definition ec25519.c:115
void fe25519_invert(fe25519 out, const fe25519 z)
Compute the multiplicative inverse of a field element.
Definition ec25519.c:1237
void ge25519_sub_cached(ge25519_p1p1 *r, const ge25519_p3 *p, const ge25519_cached *q)
Subtract a cached point from a point.
Definition ec25519.c:3216
void ge25519_tobytes(uint8_t *s, const ge25519_p2 *h)
Compress a point in P2 coordinates to a 32-byte representation.
Definition ec25519.c:3237
void ge25519_p1p1_to_p3(ge25519_p3 *r, const ge25519_p1p1 *p)
Convert a point from P1P1 to P3 coordinates.
Definition ec25519.c:2779
void fe25519_frombytes(fe25519 h, const uint8_t *s)
Convert a 32-byte array to a field element.
Definition ec25519.c:954
int32_t fe25519_isnegative(const fe25519 f)
Determine if a field element is negative.
Definition ec25519.c:367
void sc25519_muladd(uint8_t s[32], const uint8_t a[32], const uint8_t b[32], const uint8_t c[32])
Compute s = a * b + c for scalars.
Definition ec25519.c:3369
void ge25519_p3_to_cached(ge25519_cached *r, const ge25519_p3 *p)
Convert a point from P3 coordinates to a cached representation.
Definition ec25519.c:3026
void ge25519_scalarmult_base(ge25519_p3 *h, const uint8_t *a)
Multiply the base point by a scalar.
Definition ec25519.c:2794
QSC_SIMD_ALIGN int32_t fe25519[10]
The ecc fe25519 polynomial.
Definition ec25519.h:113
int32_t ge25519_frombytes_negate_vartime(ge25519_p3 *h, const uint8_t *s)
Decode and conditionally negate a compressed point.
Definition ec25519.c:2958
void fe25519_add(fe25519 h, const fe25519 f, const fe25519 g)
Add two field elements.
Definition ec25519.c:167
void fe25519_neg(fe25519 h, const fe25519 f)
Negate a field element.
Definition ec25519.c:305
void fe25519_sq2(fe25519 h, const fe25519 f)
Compute 2 * f^2.
Definition ec25519.c:802
int32_t ge25519_has_small_order(const uint8_t s[32])
Determine if a compressed point has small order.
Definition ec25519.c:2880
void fe25519_cmov(fe25519 f, const fe25519 g, uint32_t b)
Conditionally move a field element in constant time.
Definition ec25519.c:319
void sc25519_clamp(uint8_t *k)
Clamp a secret scalar.
Definition ec25519.c:3252
Cached point representation.
Definition ec25519.h:177
fe25519 t2d
Definition ec25519.h:181
fe25519 yplusx
Definition ec25519.h:178
fe25519 yminusx
Definition ec25519.h:179
fe25519 z
Definition ec25519.h:180
Intermediate coordinate representation.
Definition ec25519.h:150
fe25519 t
Definition ec25519.h:154
fe25519 y
Definition ec25519.h:152
fe25519 x
Definition ec25519.h:151
fe25519 z
Definition ec25519.h:153
Projective coordinate representation.
Definition ec25519.h:122
fe25519 y
Definition ec25519.h:124
fe25519 x
Definition ec25519.h:123
fe25519 z
Definition ec25519.h:125
Extended projective coordinate representation.
Definition ec25519.h:136
fe25519 t
Definition ec25519.h:140
fe25519 y
Definition ec25519.h:138
fe25519 x
Definition ec25519.h:137
fe25519 z
Definition ec25519.h:139
Precomputed point representation.
Definition ec25519.h:164
fe25519 yplusx
Definition ec25519.h:165
fe25519 xy2d
Definition ec25519.h:167
fe25519 yminusx
Definition ec25519.h:166