-
Notifications
You must be signed in to change notification settings - Fork 0
/
gf.h
90 lines (75 loc) · 3.6 KB
/
gf.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#ifndef GF_H
#define GF_H
#include "ec.h"
#ifdef __cplusplus
extern "C" {
#endif
extern const u64 unity[13];
extern const EcPoint uPEd;
extern const EcPoint uPW;
extern const EcPointProj uPPEd;
extern const EcPointProj uPPW;
extern const u64 p192[3];
extern const u64 p224[4];
extern const u64 p256[4];
extern const u64 p384[6];
extern const u64 p521[9];
extern const u64 zero[26];
/* Common Arithmetics */
void shr(u64 n, const u64* a, u64* res, u64 bits);
#define div2(n, a) shr((n), (a), (a), 1)
void shl(u64 n, const u64* a, u64* res, u64 bits);
#define mul2(n, a) shl((n), (a), (a), 1)
u64 get_bit(const u64* a, u64 num);
void copy(u64* a, const u64* b, int len);
u64 add(u64 n, const u64* a, const u64* b, u64* c);
u64 sub(u64 n, const u64* a, const u64* b, u64* c);
void _mul_raw(u64 a, u64 b, u64* low, u64* high);
u64 _add_raw(u64 a, u64 b, u64* c);
void mul_by_word(u64 n, const u64* a, u64 d, u64* c);
void mul(u64 n, const u64* a, const u64* b, u64* c);
void imul(u64 n, const u64* a, const u64* b, u64* c);
void sqr(u64 n, const u64* a, u64* res);
int word_bit_len(u64 w);
int bigint_bit_len(u64 n, const u64* a);
u64 sub_word(u64 n, const u64* a, const u64 b, u64* c);
u64 add_word(u64 n, const u64* a, const u64 b, u64* c);
void divide(u64 n, const u64* a, const u64* b, u64* quotient, u64* reminder);
int cmp(u64 n, const u64* a, const u64* b);
void add_mod(u64 n, const BigInt a, const BigInt b, const BigInt m, BigInt res);
void mul_mod(u64 n, const BigInt a, const BigInt b, const BigInt m, BigInt res);
void exp_mod(u64 n, const BigInt a, const BigInt b, const BigInt m, BigInt res);
void inv_mod(u64 n, const BigInt a, const BigInt m, BigInt res);
/* Galois' Fields Arithmetics */
void GFSqrt(const Ec* ecc, const GFElement a, GFElement r); // via Tonelli-Shanks
void GFInitFromString(GFElement a, const char* str);
void GFDump(const Ec* ecc, const GFElement a);
void GFAdd(const Ec* ecc, const GFElement a, const GFElement b, GFElement c);
void GFSub(const Ec* ecc, const GFElement a, const GFElement b, GFElement c);
void GFNeg(const Ec* ecc, const GFElement a, GFElement c);
void GFPow(const Ec* ecc, const GFElement a, const BigInt n, GFElement b);
void GFInv(const Ec* ecc, const GFElement a, GFElement b);
int GFCmp(const Ec* ecc, const GFElement a, const GFElement b);
void GFMul(const Ec* ecc, const GFElement a, const GFElement b, GFElement c);
void GFSqr(const Ec* ecc, const GFElement a, GFElement c);
void GFMulBy2Power(const Ec* ecc, const GFElement a, int pp, GFElement b);
#define GFMulBy2(e, a, b) GFAdd(e, a, a, b);
void GFMulByD(const EcEd* ecc, GFElement a);
void GFMulByA(const EcEd* ecc, GFElement a, GFElement res);
int GFLegendreSymbol(const Ec* ecc, const GFElement a);
void GFMul_Cmn(const Ec* ecc, const GFElement a, const GFElement b, GFElement c);
void GFMul_FIPS192(const Ec* ecc, const GFElement a, const GFElement b, GFElement c);
void GFMul_FIPS224(const Ec* ecc, const GFElement a, const GFElement b, GFElement c);
void GFMul_FIPS256(const Ec* ecc, const GFElement a, const GFElement b, GFElement c);
void GFMul_FIPS384(const Ec* ecc, const GFElement a, const GFElement b, GFElement c);
void GFMul_FIPS521(const Ec* ecc, const GFElement a, const GFElement b, GFElement c);
void GFSqr_Cmn(const Ec* ecc, const GFElement a, GFElement c);
void GFSqr_FIPS192(const Ec* ecc, const GFElement a, GFElement c);
void GFSqr_FIPS224(const Ec* ecc, const GFElement a, GFElement c);
void GFSqr_FIPS256(const Ec* ecc, const GFElement a, GFElement c);
void GFSqr_FIPS384(const Ec* ecc, const GFElement a, GFElement c);
void GFSqr_FIPS521(const Ec* ecc, const GFElement a, GFElement c);
#ifdef __cplusplus
}
#endif
#endif /* GF_H */