52#ifndef QSC_FALCONBASE_AVX2_H
53#define QSC_FALCONBASE_AVX2_H
59#if defined(QSC_SYSTEM_HAS_AVX2)
61#include "intrinsics.h"
67#if defined(QSC_FALCON_S3SHAKE256F512)
68# define FALCON_CRYPTO_SECRETKEYBYTES 1281
69# define FALCON_CRYPTO_PUBLICKEY_BYTES 897
70# define FALCON_CRYPTO_SIGNATURE_BYTES 658
71# define CRYPTO_ALGNAME "Falcon-512"
72#elif defined(QSC_FALCON_S5SHAKE256F1024)
73# define FALCON_CRYPTO_SECRETKEYBYTES 2305
74# define FALCON_CRYPTO_PUBLICKEY_BYTES 1793
75# define FALCON_CRYPTO_SIGNATURE_BYTES 1276
76# define CRYPTO_ALGNAME "Falcon-1024"
81#define FALCON_FPR_GM_TAB_SIZE 2048
82#define FALCON_FPR_INV_SIGMA_SIZE 11
83#define FALCON_FPR_GM_P2_SIZE 11
85#define FALCON_Q0I 12287
87#define FALCON_R2 10952
88#define FALCON_GMB_SIZE 1024
89#define FALCON_KEYGEN_TEMP_1 136
90#define FALCON_KEYGEN_TEMP_2 272
91#define FALCON_KEYGEN_TEMP_3 224
92#define FALCON_KEYGEN_TEMP_4 448
93#define FALCON_KEYGEN_TEMP_5 896
94#define FALCON_KEYGEN_TEMP_6 1792
95#define FALCON_KEYGEN_TEMP_7 3584
96#define FALCON_KEYGEN_TEMP_8 7168
97#define FALCON_KEYGEN_TEMP_9 14336
98#define FALCON_KEYGEN_TEMP_10 28672
99#define FALCON_SMALL_PRIME_SIZE 522
100#define FALCON_GAUS_1024_12289_SIZE 27
101#define FALCON_MAX_BL_SMALL_SIZE 11
102#define FALCON_MAX_BL_LARGE_SIZE 10
103#define FALCON_DEPTH_INT_FG 4
104#define FALCON_NONCE_SIZE 40
105#define FALCON_L2BOUND_SIZE 11
106#define FALCON_MAXBITS_SIZE 11
107#define FALCON_REV10_SIZE 1024
110# if defined(FALCON_FMA)
111# define FALCON_TARGET_AVX2 __attribute__((target("avx2,fma")))
113# define FALCON_TARGET_AVX2 __attribute__((target("avx2")))
115#elif defined(_MSC_VER)
116# define FALCON_TARGET_AVX2
117# pragma warning( disable : 4752 )
120inline static __m256d falcon_fmadd(__m256d a, __m256d b, __m256d c)
122#if defined(FALCON_FMA)
123 return _mm256_fmadd_pd(a, b, c);
126 tmp = _mm256_mul_pd(a, b);
127 tmp = _mm256_add_pd(tmp, c);
132inline static __m256d falcon_fmsub(__m256d a, __m256d b, __m256d c)
135#if defined(FALCON_FMA)
136 return _mm256_fmsub_pd(a, b, c);
139 tmp = _mm256_mul_pd(a, b);
140 return _mm256_sub_pd(tmp, c);
178# pragma STDC FP_CONTRACT OFF
179#elif defined __GNUC__
180# pragma GCC optimize ("fp-contract=off")
199typedef struct {
double v; } falcon_fpr;
201static const falcon_fpr falcon_fpr_q = { 12289.0 };
202static const falcon_fpr falcon_fpr_inverse_of_q = { 1.0 / 12289.0 };
203static const falcon_fpr falcon_fpr_inv_2sqrsigma0 = { 0.150865048875372721532312163019 };
204static const falcon_fpr falcon_fpr_log2 = { 0.69314718055994530941723212146 };
205static const falcon_fpr falcon_fpr_inv_log2 = { 1.4426950408889634073599246810 };
206static const falcon_fpr falcon_fpr_bnorm_max = { 16822.4121 };
207static const falcon_fpr falcon_fpr_zero = { 0.0 };
208static const falcon_fpr falcon_fpr_one = { 1.0 };
209static const falcon_fpr falcon_fpr_two = { 2.0 };
210static const falcon_fpr falcon_fpr_onehalf = { 0.5 };
211static const falcon_fpr falcon_fpr_invsqrt2 = { 0.707106781186547524400844362105 };
212static const falcon_fpr falcon_fpr_invsqrt8 = { 0.353553390593273762200422181052 };
213static const falcon_fpr falcon_fpr_ptwo31 = { 2147483648.0 };
214static const falcon_fpr falcon_fpr_ptwo31m1 = { 2147483647.0 };
215static const falcon_fpr falcon_fpr_mtwo31m1 = { -2147483647.0 };
216static const falcon_fpr falcon_fpr_ptwo63m1 = { 9223372036854775807.0 };
217static const falcon_fpr falcon_fpr_mtwo63m1 = { -9223372036854775807.0 };
218static const falcon_fpr falcon_fpr_ptwo63 = { 9223372036854775808.0 };
227extern const falcon_fpr falcon_avx2_fpr_inv_sigma[FALCON_FPR_INV_SIGMA_SIZE];
228extern const falcon_fpr falcon_avx2_fpr_sigma_min[FALCON_FPR_INV_SIGMA_SIZE];
229extern const falcon_fpr falcon_avx2_fpr_gm_tab[FALCON_FPR_GM_TAB_SIZE];
230extern const falcon_fpr falcon_avx2_fpr_p2_tab[FALCON_FPR_GM_P2_SIZE];
231extern const uint8_t falcon_avx2_max_fg_bits[FALCON_MAXBITS_SIZE];
232extern const uint8_t falcon_falcon_max_FG_bits[FALCON_MAXBITS_SIZE];
233extern const uint32_t falcon_avx2_l2bound[FALCON_L2BOUND_SIZE];
234extern const uint64_t falcon_avx2_gauss_1024_12289[FALCON_GAUS_1024_12289_SIZE];
235extern const uint16_t falcon_avx2_falcon_rev10[FALCON_REV10_SIZE];
236extern const size_t falcon_avx2_max_bl_small[FALCON_MAX_BL_SMALL_SIZE];
237extern const size_t falcon_avx2_max_bl_large[FALCON_MAX_BL_LARGE_SIZE];
238extern const uint16_t falcon_avx2_GMb[FALCON_GMB_SIZE];
239extern const uint16_t falcon_avx2_iGMb[FALCON_GMB_SIZE];
240extern const falcon_small_prime falcon_avx2_small_primes[FALCON_SMALL_PRIME_SIZE];
250int32_t qsc_falcon_avx2_generate_keypair(uint8_t *pk, uint8_t *sk,
bool (*rng_generate)(uint8_t*,
size_t));
262int32_t qsc_falcon_avx2_sign(uint8_t *sm,
size_t *smlen,
const uint8_t *m,
size_t mlen,
const uint8_t *sk,
bool (*rng_generate)(uint8_t*,
size_t));
274bool qsc_falcon_avx2_open(uint8_t *m,
size_t *mlen,
const uint8_t *sm,
size_t smlen,
const uint8_t *pk);\
Contains common definitions for the Quantum Secure Cryptographic (QSC) library.
#define QSC_ALIGN(x)
Macro for aligning data to 'x' bytes using GCC/Clang.
Definition qsccommon.h:1025
SHA3 family of hash functions.