-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscalar.h
71 lines (51 loc) · 2.02 KB
/
scalar.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
/*
* scalar.h
*
* Copyright 2006 Johan de Jong
*
* This file is part of Frobenius
*
* Frobenius is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Frobenius is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Frobenius; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* */
extern mpz_t modulus;
extern mpz_t prime;
extern mpz_t temp;
void setup_scalars(void);
void close_scalars(void);
void printmscalar(mscalar a);
#ifndef PROFILER
#define make_scalar(a) mpz_init(a)
#define free_scalar(a) mpz_clear(a)
#else
void make_scalar(mscalar a);
void free_scalar(mscalar a);
#endif
#define valuation(x) mpz_remove(temp,x,prime)
#define sc_add(a,b,c) {mpz_add(temp,a,b);mpz_mod(c,temp,modulus);}
#define sc_mult(a,b,c) {mpz_mul(temp,a,b);mpz_mod(c,temp,modulus);}
#define sc_imult(a,b,c) {mpz_mul_si(temp,b,(long)a);mpz_mod(c,temp,modulus);}
#define sc_inv(a,b) mpz_invert(b,a,modulus)
void sc_div(mscalar a, mscalar b, mscalar c);
#define div_p(a) mpz_divexact_ui(a,a,(unsigned long)p)
#define sc_add_replace(a,b) {mpz_add(temp,a,b);mpz_mod(b,temp,modulus);}
#define sc_mult_replace(a,b) {mpz_mul(temp,a,b);mpz_mod(b,temp,modulus);}
#define sc_imult_replace(a,b) {mpz_mul_si(temp,b,(long)a);mpz_mod(b,temp,modulus);}
#define sc_zero(a) mpz_set_ui(a,0)
#define sc_one(a) mpz_set_ui(a,1)
#define sc_copy(a,b) mpz_set(b,a)
#define sc_negate(a) {mpz_neg(temp,a);mpz_mod(a,temp,modulus);}
#define ito_sc(a,b) {mpz_set_si(temp,(long)a);mpz_mod(b,temp,modulus);}
#define sc_is_zero(a) (!mpz_cmp_ui(a, 0))