Documentation ¶
Index ¶
- Variables
- type Bits
- type Int
- func (z *Int) Add(x, y *Int) *Int
- func (z *Int) And(x, y *Int) *Int
- func (z *Int) BigInt() *big.Int
- func (z *Int) BitLen() int
- func (z *Int) Bits() Bits
- func (z *Int) ByteLen() int
- func (z *Int) Bytes() []byte
- func (z *Int) Cmp(y *Int) int
- func (z *Int) DeepCopy() *Int
- func (z *Int) Div(x, y *Int) *Int
- func (z *Int) Exp(x, y, m *Int) *Int
- func (z *Int) FillBytes(buf []byte) []byte
- func (z *Int) Format(s fmt.State, ch rune)
- func (z *Int) GCD(x, y, a, b *Int) *Int
- func (z *Int) GobDecode(in []byte) error
- func (z *Int) GobEncode() ([]byte, error)
- func (z *Int) Int64() int64
- func (z *Int) IsCoprime(x *Int) bool
- func (z *Int) IsInt64() bool
- func (z *Int) IsPrime() bool
- func (z *Int) LeftShift(x *Int, n uint) *Int
- func (z *Int) LeftpadBytes(length uint64) []byte
- func (z *Int) MarshalJSON() ([]byte, error)
- func (z *Int) Mod(x, y *Int) *Int
- func (z *Int) ModInverse(x, n *Int) *Int
- func (z *Int) Mul(x, y *Int) *Int
- func (z *Int) Or(x, y *Int) *Int
- func (z *Int) RightShift(x *Int, n uint) *Int
- func (z *Int) Set(x *Int) *Int
- func (z *Int) SetBigInt(x *big.Int) *Int
- func (z *Int) SetBits(x Bits) *Int
- func (z *Int) SetBytes(buf []byte) *Int
- func (z *Int) SetInt64(x int64) *Int
- func (z *Int) SetString(s string, base int) (*Int, bool)
- func (z *Int) SetUint64(x uint64) *Int
- func (z *Int) Sub(x, y *Int) *Int
- func (z *Int) Text(base int) string
- func (z *Int) TextVerbose(base int, length int) string
- func (z *Int) Uint64() uint64
- func (z *Int) UnmarshalJSON(b []byte) error
- func (z *Int) Xor(x, y *Int) *Int
Constants ¶
This section is empty.
Variables ¶
var Max4kBitInt = []byte{}/* 524 elements not displayed */
Max4kBitInt is a 4128-bit int that is meant to be the size of post mod-ed large ints.
It will probably be made to hold this 4096 bit prime: https://tools.ietf.org/html/rfc3526#page-5
Functions ¶
This section is empty.
Types ¶
type Bits ¶
Bits is a slice of words. It can be used to access underlying word array for faster CUDA staging.
type Int ¶
Int extends Go's big.Int structure
func NewIntFromBigInt ¶
NewIntFromBigInt allocates and returns a new Int from a big.Int.
func NewIntFromBits ¶
NewIntFromBits creates a new Int from a Bits.
func NewIntFromBytes ¶
NewIntFromBytes creates a new Int initialized from a byte buffer.
func NewIntFromString ¶
NewIntFromString creates a new Int from a string using the passed in base. Returns nil if str cannot be parsed.
func NewIntFromUInt ¶
NewIntFromUInt creates a new Int from a uint64.
func (*Int) BitLen ¶
BitLen returns the length of the absolute value of z, in bits. The bit length of 0 is 0.
func (*Int) Bits ¶
Bits returns the underlying big.Int word slice. This is used for copying to gpumaths input.
func (*Int) Exp ¶
Exp sets z = x**y mod |m| (i.e. the sign of m is ignored), and returns z. If y <= 0, then the result is 1 mod |m|; if m == nil or m == 0, then z = x**y.
Modular exponentiation of inputs of a particular size is not a cryptographically constant-time operation.
func (*Int) FillBytes ¶
FillBytes sets buf to the absolute value of x, storing it as a zero-extended big-endian byte slice, and returns buf.
If the absolute value of x does not fit in buf, then FillBytes will panic.
func (*Int) Format ¶
Format implements fmt.Formatter. It accepts the formats 'b' (binary), 'o' (octal with 0 prefix), 'O' (octal with 0o prefix), 'd' (decimal), 'x' (lowercase hexadecimal), and 'X' (uppercase hexadecimal).
Also supported are the full suite of package fmt's format flags for integral types, including '+' and ' ' for sign control, '#' for leading zero in octal and for hexadecimal, a leading "0x" or "0X" for "%#x" and "%#X" respectively, specification of minimum digit precision, output field width, space or zero padding, and '-' for left or right justification.
func (*Int) GCD ¶
GCD sets z to the greatest common divisor of a and b and returns z. If x or y are not nil, GCD sets their value such that z = a*x + b*y.
func (*Int) GobDecode ¶
GobDecode decodes the byte slice into an Int. Error is always nil. This function implements the gob.GobDecoder interface.
func (*Int) GobEncode ¶
GobEncode encodes the Int into a byte slice. Error is always nil. This function implements the gob.GobEncoder interface.
func (*Int) Int64 ¶
Int64 converts the Int to an int64, if possible, or undefined result if not possible.
func (*Int) IsPrime ¶
IsPrime calculates (with high probability) if a number is prime or not. This function uses 40 (can be changed) iterations of the Miller-Rabin prime test. Returns true if number is prime and false if it is not.
func (*Int) LeftpadBytes ¶
LeftpadBytes returns the absolute value of x left-padded with zeroes up to the passed number of bytes. Panics if the byte slice from the Int is longer than the passed length.
func (*Int) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface.
func (*Int) Mod ¶
Mod sets z to the modulus x%y for y != 0 and returns z. If y == 0, a division-by-zero run-time panic occurs. Mod implements Euclidean modulus (unlike Go); see DivMod for more details.
func (*Int) ModInverse ¶
ModInverse sets z to the multiplicative inverse of x in the ring ℤ/nℤ and returns z. If x and n are not relatively prime, g has no multiplicative inverse in the ring ℤ/nℤ. In this case, z is unchanged and the return value is nil. If n == 0, then a division-by-zero run-time panic occurs.
func (*Int) RightShift ¶
RightShift shifts the value right by n bits.
func (*Int) SetBytes ¶
SetBytes interprets buf as the bytes of a big-endian unsigned integer, sets z to that value, and returns z.
func (*Int) SetString ¶
SetString makes the Int equal to the number held in the string s, interpreted to have a base of b. Returns the set Int and a boolean describing if the operation was successful.
func (*Int) Text ¶
Text returns the string representation of z in the given base. Base must be between 2 and 36, inclusive. The result uses the lower-case letters 'a' to 'z' for digit values >= 10. No base prefix (such as "0x") is added to the string.
Text truncates the Int to a length of 10, appending an ellipsis if the Int is too long.
func (*Int) TextVerbose ¶
TextVerbose returns the string representation of z in the given base. Base must be between 2 and 36, inclusive. The result uses the lower-case letters 'a' to 'z' for digit values >= 10. No base prefix (such as "0x") is added to the string.
TextVerbose truncates the Int to a length of length in characters (not runes) and appends an ellipsis to indicate that the whole int wasn't returned, unless len is 0, in which case it will return the whole int as a string.
func (*Int) Uint64 ¶
Uint64 converts the Int to a uint64, if possible, or undefined result if not possible.
func (*Int) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface.