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
|
package otr3
import "math/big"
func modExp(g, x *big.Int) *big.Int {
return new(big.Int).Exp(g, x, p)
}
func modInverse(g, x *big.Int) *big.Int {
return new(big.Int).ModInverse(g, x)
}
func mul(l, r *big.Int) *big.Int {
return new(big.Int).Mul(l, r)
}
func sub(l, r *big.Int) *big.Int {
return new(big.Int).Sub(l, r)
}
func mulMod(l, r, m *big.Int) *big.Int {
res := mul(l, r)
res.Mod(res, m)
return res
}
// Fast division over a modular field, without using division
func divMod(l, r, m *big.Int) *big.Int {
return mulMod(l, modInverse(r, m), m)
}
func subMod(l, r, m *big.Int) *big.Int {
res := sub(l, r)
res.Mod(res, m)
return res
}
func mod(l, m *big.Int) *big.Int {
return new(big.Int).Mod(l, m)
}
func lt(l, r *big.Int) bool {
return l.Cmp(r) == -1
}
func lte(l, r *big.Int) bool {
return l.Cmp(r) != 1
}
func eq(l, r *big.Int) bool {
return l.Cmp(r) == 0
}
func gt(l, r *big.Int) bool {
return l.Cmp(r) == 1
}
func gte(l, r *big.Int) bool {
return l.Cmp(r) != -1
}
|