22typedef uint64_t
fp[NUMBER_OF_WORDS];
26#define uintbig_1 COMMON(uintbig_1)
29#define r_squared_mod_p COMMON(r_squared_mod_p)
31#define p_minus_2 COMMON(p_minus_2)
33#define inv_min_p_mod_r COMMON(inv_min_p_mod_r)
36#define uintbig_bit COMMON(uintbig_bit)
38#define uintbig_add COMMON(uintbig_add)
40#define uintbig_sub COMMON(uintbig_sub)
48#define fp_1 COMMON(fp_1)
50#define fp_0 COMMON(fp_0)
55#define fp_enc COMMON(fp_enc)
58#define fp_dec COMMON(fp_dec)
61#define fp_pow COMMON(fp_pow)
64#define fp_add COMMON(fp_add)
67#define fp_sub COMMON(fp_sub)
70#define fp_mul COMMON(fp_mul)
73#define fp_sqr COMMON(fp_sqr)
76#define fp_issquare COMMON(fp_issquare)
79#define fp_copy COMMON(fp_copy)
82#define fp_cswap COMMON(fp_cswap)
85#define fp_random COMMON(fp_random)
88#define fp_inv COMMON(fp_inv)
91#define fp_mont_redc COMMON(fp_mont_redc)
122 #define fp_mult_32x32 COMMON(fp_mult_32x32)
123 void fp_mult_32x32(uint64_t *c,
const uint64_t *
a,
const uint64_t *b);
129static inline void fp_sq1_rep(
fp x,
long long n)
137static inline void fp_2oct(uint8_t *buf,
const fp *
a)
139 for (
int i = 0;
i < NUMBER_OF_WORDS;
i++)
141 for (
int j = 0;
j < 8;
j++)
143 buf[
i * 8 +
j] =
a[0][
i] >>
j * 8;
148static inline void oct2_fp(
fp *
a,
const uint8_t *buf)
154 for (
int i = 0;
i < NUMBER_OF_WORDS;
i++)
156 for (
int j = 0;
j < 8;
j++)
158 tmp = buf[
i * 8 +
j];
159 a[0][
i] += tmp <<
j * 8;
167static inline void fp_set0(
fp a)
173static inline void uintbig_set1(
fp a)
179static inline void fp_set1(
fp a)
185static inline void fp_set(
fp a, uint64_t value)
192static inline uint64_t fp_issmaller(
fp const a,
fp const b)
195 int64_t r = 0, ab, c;
197 for (
i = 0;
i < NUMBER_OF_WORDS;
i++)
202 c ^= ab & (c ^
a[
i]);
207 return 1 - (uint64_t)(r + 1);
211static inline uint64_t fp_isequal(
fp const a,
fp const b)
216 for (
i = 0;
i < NUMBER_OF_WORDS;
i++)
219 unsigned char *ta = (
unsigned char *)&
a[
i];
220 unsigned char *tb = (
unsigned char *)&b[
i];
221 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]);
228 return (uint64_t)(1 - r);
232static inline int fp_iszero(
fp const a)
236 for (
i=NUMBER_OF_WORDS-1;
i >= 0;
i--)
242static inline uint64_t fp_isone(
fp const a)
244 return fp_isequal(
a,
fp_1);
263#define UINTBIG_LIMBS ((UBITS+63)/64)
272 #define uintbig_p COMMON(uintbig_p)
278 #define uintbig_four_sqrt_p COMMON(uintbig_four_sqrt_p)
281 #define uintbig_set COMMON(uintbig_set)
285 #define uintbig_mul3_64 COMMON(uintbig_mul3_64)
288 static inline long long uintbig_uint64_iszero(uint64_t t)
298 return 1-(
long long) t;
301 static inline long long uintbig_iszero(
const uintbig *x)
306 return uintbig_uint64_iszero(t);
309 static inline long long uintbig_isequal(
const uintbig *x,
const uintbig *y)
313 t |= (
x->c[
i])^(y->
c[
i]);
314 return uintbig_uint64_iszero(t);
317 #define fp_2 COMMON(fp_2)
320 #define uintbig_1_ctidh COMMON(uintbig_1_ctidh)
323 #define fp_cmov COMMON(fp_cmov)
330 static inline void fp_mul3(
fp *c,
fp const *
a,
fp const *b) {
334 static inline void fp_mul2(
fp *c,
fp const *
a) {
338 static inline void fp_add3(
fp *c,
fp const *
a,
fp const *b) {
342 static inline void fp_add2(
fp *c,
fp const *
a) {
346 static inline void fp_sub2(
fp *c,
fp const *
a) {
354 static inline void fp_cmov_ctidh(
fp *
a,
const fp *b, uint8_t c) {
358 static inline void fp_sub3(
fp *c,
fp const *
a,
fp const *b) {
362 static inline void fp_neg1(
fp *x)
367 static inline void fp_neg2(
fp *x,
fp const *y)
372 static inline void fp_sq1(
fp *x)
377 static inline void fp_sq2(
fp *x,
fp const *y)
382 static inline void fp_double1(
fp *x)
384 fp_add2(x, (
const fp*) x);
387 static inline void fp_double2(
fp *x,
fp const *y)
392 static inline void fp_quadruple1(
fp *x)
398 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]