forked from bnb-chain/tss-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathint.go
60 lines (48 loc) · 1.19 KB
/
int.go
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
// Copyright © 2019 Binance
//
// This file is part of Binance. The full Binance copyright notice, including
// terms governing use, modification, and redistribution, is contained in the
// file LICENSE at the root of the source code distribution tree.
package common
import (
"math/big"
)
// modInt is a *big.Int that performs all of its arithmetic with modular reduction.
type modInt big.Int
var (
zero = big.NewInt(0)
one = big.NewInt(1)
two = big.NewInt(2)
)
func ModInt(mod *big.Int) *modInt {
return (*modInt)(mod)
}
func (mi *modInt) Add(x, y *big.Int) *big.Int {
i := new(big.Int)
i.Add(x, y)
return i.Mod(i, mi.i())
}
func (mi *modInt) Sub(x, y *big.Int) *big.Int {
i := new(big.Int)
i.Sub(x, y)
return i.Mod(i, mi.i())
}
func (mi *modInt) Div(x, y *big.Int) *big.Int {
i := new(big.Int)
i.Div(x, y)
return i.Mod(i, mi.i())
}
func (mi *modInt) Mul(x, y *big.Int) *big.Int {
i := new(big.Int)
i.Mul(x, y)
return i.Mod(i, mi.i())
}
func (mi *modInt) Exp(x, y *big.Int) *big.Int {
return new(big.Int).Exp(x, y, mi.i())
}
func (mi *modInt) ModInverse(g *big.Int) *big.Int {
return new(big.Int).ModInverse(g, mi.i())
}
func (mi *modInt) i() *big.Int {
return (*big.Int)(mi)
}