5 // Common big integers often used
13 Big32 = big.NewInt(32)
14 Big36 = big.NewInt(36)
15 Big97 = big.NewInt(97)
16 Big98 = big.NewInt(98)
17 Big256 = big.NewInt(0xff)
18 Big257 = big.NewInt(257)
19 MaxBig = String2Big("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")
24 // Returns the power of two big integers
25 func BigPow(a, b int) *big.Int {
27 c.Exp(big.NewInt(int64(a)), big.NewInt(int64(b)), big.NewInt(0))
33 // Shortcut for new(big.Int).SetString(..., 0)
34 func Big(num string) *big.Int {
42 func BytesToBig(data []byte) *big.Int {
48 func Bytes2Big(data []byte) *big.Int { return BytesToBig(data) }
50 func BigD(data []byte) *big.Int { return BytesToBig(data) }
52 func String2Big(num string) *big.Int {
58 func BitTest(num *big.Int, i int) bool {
64 // "cast" the big int to a 256 big int (i.e., limit to)
65 var tt256 = new(big.Int).Lsh(big.NewInt(1), 256)
66 var tt256m1 = new(big.Int).Sub(new(big.Int).Lsh(big.NewInt(1), 256), big.NewInt(1))
67 var tt255 = new(big.Int).Lsh(big.NewInt(1), 255)
69 func U256(x *big.Int) *big.Int {
70 //if x.Cmp(Big0) < 0 {
71 // return new(big.Int).Add(tt256, x)
78 func S256(x *big.Int) *big.Int {
82 // We don't want to modify x, ever
83 return new(big.Int).Sub(x, tt256)
87 func FirstBitSet(v *big.Int) int {
88 for i := 0; i < v.BitLen(); i++ {
98 // Returns the bytes of a big integer with the size specified by **base**
99 // Attempts to pad the byte array with zeros.
100 func BigToBytes(num *big.Int, base int) []byte {
101 ret := make([]byte, base/8)
103 if len(num.Bytes()) > base/8 {
107 return append(ret[:len(ret)-len(num.Bytes())], num.Bytes()...)
112 // Creates a copy of the given big integer
113 func BigCopy(src *big.Int) *big.Int {
114 return new(big.Int).Set(src)
119 // Returns the maximum size big integer
120 func BigMax(x, y *big.Int) *big.Int {
129 // Returns the minimum size big integer
130 func BigMin(x, y *big.Int) *big.Int {