Documentation ¶
Index ¶
- Constants
- Variables
- func AllZero(b []byte) bool
- func BigMax(x, y *big.Int) *big.Int
- func BigMin(x, y *big.Int) *big.Int
- func BigPow(a, b int64) *big.Int
- func BigUint64(v *big.Int) (uint64, bool)
- func Byte(bigint *big.Int, padlength, n int) byte
- func BytesToString(data []byte) string
- func BytesToU64(data []byte) uint64
- func Exp(base, exponent *big.Int) *big.Int
- func GetDataBig(data []byte, start *big.Int, size *big.Int) []byte
- func HexToBytes(str string) []byte
- func IsNil(i interface{}) bool
- func JoinBytes(data ...[]byte) []byte
- func LDI(slice []byte) []byte
- func LeftPadBytes(slice []byte, l int) []byte
- func Max(x, y uint64) uint64
- func Min(x, y uint64) uint64
- func MinInt(x, y int) int
- func MinInt64(x, y int64) int64
- func PaddedBigBytes(bigint *big.Int, n int) []byte
- func ReadBits(bigint *big.Int, buf []byte)
- func ReverseSlice(s interface{})
- func RightPadBytes(slice []byte, l int) []byte
- func S256(x *big.Int) *big.Int
- func SafeAdd(x, y uint64) (uint64, bool)
- func SafeMul(x, y uint64) (uint64, bool)
- func ToWordSize(size uint64) uint64
- func U256(x *big.Int) *big.Int
- type Source64
Constants ¶
Variables ¶
var ( Big0 = big.NewInt(0) Big1 = big.NewInt(1) Big2 = big.NewInt(2) Big10 = big.NewInt(10) Big31 = big.NewInt(31) Big32 = big.NewInt(32) Big50 = big.NewInt(50) Big100 = big.NewInt(100) Big256 = big.NewInt(256) Big257 = big.NewInt(257) Tt255 = BigPow(2, 255) Tt256 = BigPow(2, 256) Tt256m1 = new(big.Int).Sub(Tt256, big.NewInt(1)) )
Functions ¶
func BigUint64 ¶
BigUint64 returns the integer casted to chain uint64 and returns whether it overflowed in the process.
func Byte ¶
Byte returns the byte at position n, with the supplied padlength in Little-Endian encoding. n==0 returns the MSB Example: bigint '5', padlength 32, n=31 => 5
func Exp ¶
Exp implements exponentiation by squaring. Exp returns chain newly-allocated big integer and does not change base or exponent. The result is truncated to 256 bits.
func GetDataBig ¶
GetDataBig returns chain slice from the data based on the start and size and pads up to size with zero's. This function is overflow safe.
func LeftPadBytes ¶
leftPadBytes zero-pads slice to the left up to length l.
func PaddedBigBytes ¶
PaddedBigBytes encodes chain big integer as chain big-endian byte slice. The length of the slice is at least n bytes.
func ReadBits ¶
ReadBits encodes the absolute amount of bigint as big-endian bytes. Callers must ensure that buf has enough space. If buf is too short the result will be incomplete.
func ReverseSlice ¶
func ReverseSlice(s interface{})
func RightPadBytes ¶
rightPadBytes zero-pads slice to the right up to length l.
func S256 ¶
S256 interprets x as chain two's complement number. x must not exceed 256 bits (the result is undefined if it does) and is not modified.
S256(0) = 0 S256(1) = 1 S256(2**255) = -2**255 S256(2**256-1) = -1
func SafeAdd ¶
SafeAdd returns the result and whether overflow occurred.
func SafeMul ¶
SafeMul returns multiplication result and whether overflow occurred.
func ToWordSize ¶
ToWordSize returns the ceiled word size required for memory expansion.
Types ¶
type Source64 ¶
A Source64 is a Source that can generate uniformly-distributed pseudo-random uint64 values in the range [0, 1<<64) directly.