1#ifndef _FP_KARATSUBA_H_
2#define _FP_KARATSUBA_H_
22typedef uint64_t
fp[NUMBER_OF_WORDS];
26#define uintbig_1 COMMON(uintbig_1)
29#define fp_1 COMMON(fp_1)
32#define inv_min_p_mod_r COMMON(inv_min_p_mod_r)
34#define p_minus_2 COMMON(p_minus_2)
38#define r_squared_mod_p COMMON(r_squared_mod_p)
40#define p_minus_2 COMMON(p_minus_2)
42#define inv_min_p_mod_r COMMON(inv_min_p_mod_r)
45#define uintbig_bit COMMON(uintbig_bit)
47#define uintbig_add COMMON(uintbig_add)
49#define uintbig_sub COMMON(uintbig_sub)
57#define fp_1 COMMON(fp_1)
59#define fp_0 COMMON(fp_0)
62#define redc_alpha COMMON(redc_alpha)
65#define fp_enc COMMON(fp_enc)
68#define fp_dec COMMON(fp_dec)
71#define fp_pow COMMON(fp_pow)
74#define fp_add_s COMMON(fp_add_s)
77#define fp_add COMMON(fp_add)
80#define fp_sub_s COMMON(fp_sub_s)
83#define fp_sub COMMON(fp_sub)
86#define fp_mul COMMON(fp_mul)
89#define fp_sqr COMMON(fp_sqr)
92#define fp_squaring COMMON(fp_squaring)
93void fp_squaring(uint64_t *c,
const uint64_t *
a,
const uint64_t *b);
95#define fp_issquare COMMON(fp_issquare)
98#define fp_copy COMMON(fp_copy)
101#define fp_cswap COMMON(fp_cswap)
104#define fp_mont_redc_a COMMON(fp_mont_redc_a)
107#define fp_random COMMON(fp_random)
110#define fp_inv COMMON(fp_inv)
113#define fp_mont_redc COMMON(fp_mont_redc)
204 #define fp_mult_32x32 COMMON(fp_mult_32x32)
205 void fp_mult_32x32(uint64_t *c,
const uint64_t *
a,
const uint64_t *b);
210 #define fp_word_redc COMMON(fp_word_redc)
211 void fp_word_redc(uint64_t *c,
const uint64_t *
a);
218static inline void fp_sq1_rep(
fp x,
long long n)
226static inline void fp_2oct(uint8_t *buf,
const fp *
a)
228 for (
int i = 0;
i < NUMBER_OF_WORDS;
i++)
230 for (
int j = 0;
j < 8;
j++)
232 buf[
i * 8 +
j] =
a[0][
i] >>
j * 8;
237static inline void oct2_fp(
fp *
a,
const uint8_t *buf)
243 for (
int i = 0;
i < NUMBER_OF_WORDS;
i++)
245 for (
int j = 0;
j < 8;
j++)
247 tmp = buf[
i * 8 +
j];
248 a[0][
i] += tmp <<
j * 8;
256static inline void fp_set0(
fp a)
262static inline void uintbig_set1(
fp a)
268static inline void fp_set1(
fp a)
274static inline void fp_set(
fp a, uint64_t value)
281static inline uint64_t fp_issmaller(
fp const a,
fp const b)
284 int64_t r = 0, ab, c;
286 for (
i = 0;
i < NUMBER_OF_WORDS;
i++)
291 c ^= ab & (c ^
a[
i]);
296 return 1 - (uint64_t)(r + 1);
300static inline uint64_t fp_isequal(
fp const a,
fp const b)
305 for (
i = 0;
i < NUMBER_OF_WORDS;
i++)
308 unsigned char *ta = (
unsigned char *)&
a[
i];
309 unsigned char *tb = (
unsigned char *)&b[
i];
310 t = (ta[0] ^ tb[0]) | (ta[1] ^ tb[1]) | (ta[2] ^ tb[2]) | (ta[3] ^ tb[3]) | (ta[4] ^ tb[4]) | (ta[5] ^ tb[5]) | (ta[6] ^ tb[6]) | (ta[7] ^ tb[7]);
317 return (uint64_t)(1 - r);
321static inline int fp_iszero(
fp const a)
325 for (
i=NUMBER_OF_WORDS-1;
i >= 0;
i--)
331static inline uint64_t fp_isone(
fp const a)
333 return fp_isequal(
a,
fp_1);
353 #define UINTBIG_LIMBS ((UBITS+63)/64)
362 #define uintbig_p COMMON(uintbig_p)
368 #define uintbig_four_sqrt_p COMMON(uintbig_four_sqrt_p)
371 #define uintbig_set COMMON(uintbig_set)
375 #define uintbig_mul3_64 COMMON(uintbig_mul3_64)
378 static inline long long uintbig_uint64_iszero(uint64_t t)
388 return 1-(
long long) t;
391 static inline long long uintbig_iszero(
const uintbig *x)
396 return uintbig_uint64_iszero(t);
399 static inline long long uintbig_isequal(
const uintbig *x,
const uintbig *y)
403 t |= (
x->c[
i])^(y->
c[
i]);
404 return uintbig_uint64_iszero(t);
407 #define fp_2 COMMON(fp_2)
410 #define uintbig_1_ctidh COMMON(uintbig_1_ctidh)
413 #define fp_cmov COMMON(fp_cmov)
420 static inline void fp_mul3(
fp *c,
fp const *
a,
fp const *b) {
424 static inline void fp_mul2(
fp *c,
fp const *
a) {
428 static inline void fp_add3(
fp *c,
fp const *
a,
fp const *b) {
432 static inline void fp_add2(
fp *c,
fp const *
a) {
436 static inline void fp_sub2(
fp *c,
fp const *
a) {
444 static inline void fp_cmov_ctidh(
fp *
a,
const fp *b, uint8_t c) {
448 static inline void fp_sub3(
fp *c,
fp const *
a,
fp const *b) {
452 static inline void fp_neg1(
fp *x)
457 static inline void fp_neg2(
fp *x,
fp const *y)
462 static inline void fp_sq1(
fp *x)
467 static inline void fp_sq2(
fp *x,
fp const *y)
472 static inline void fp_double1(
fp *x)
474 fp_add2(x, (
const fp*) x);
477 static inline void fp_double2(
fp *x,
fp const *y)
482 static inline void fp_quadruple1(
fp *x)
488 static inline void fp_quadruple2(
fp *x,
fp const *y)
uint64_t fp[NUMBER_OF_WORDS]
#define uintbig_four_sqrt_p
void fp_mont_redc(fp a, const uint64_t b[2 *NUMBER_OF_WORDS])
void fp_sqrt(fp_t output, const fp_t input)
uint64_t c[UINTBIG_LIMBS]