large

package
v0.0.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 6, 2023 License: BSD-2-Clause Imports: 3 Imported by: 17

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

type Bits []big.Word

Bits is a slice of words. It can be used to access underlying word array for faster CUDA staging.

type Int

type Int big.Int

Int extends Go's big.Int structure

func NewInt

func NewInt(x int64) *Int

NewInt allocates and returns a new Int set to x.

func NewIntFromBigInt

func NewIntFromBigInt(x *big.Int) *Int

NewIntFromBigInt allocates and returns a new Int from a big.Int.

func NewIntFromBits

func NewIntFromBits(b Bits) *Int

NewIntFromBits creates a new Int from a Bits.

func NewIntFromBytes

func NewIntFromBytes(buf []byte) *Int

NewIntFromBytes creates a new Int initialized from a byte buffer.

func NewIntFromString

func NewIntFromString(str string, base int) *Int

NewIntFromString creates a new Int from a string using the passed in base. Returns nil if str cannot be parsed.

func NewIntFromUInt

func NewIntFromUInt(i uint64) *Int

NewIntFromUInt creates a new Int from a uint64.

func NewMaxInt

func NewMaxInt() *Int

NewMaxInt creates a new Int with the value Max4kBitInt.

func (*Int) Add

func (z *Int) Add(x, y *Int) *Int

Add sets z to the sum x+y and returns z.

func (*Int) And

func (z *Int) And(x, y *Int) *Int

And computes the bitwise and operation between x and y.

func (*Int) BigInt

func (z *Int) BigInt() *big.Int

BigInt converts the Int to a *big.Int representation.

func (*Int) BitLen

func (z *Int) BitLen() int

BitLen returns the length of the absolute value of z, in bits. The bit length of 0 is 0.

func (*Int) Bits

func (z *Int) Bits() Bits

Bits returns the underlying big.Int word slice. This is used for copying to gpumaths input.

func (*Int) ByteLen

func (z *Int) ByteLen() int

ByteLen returns the length of the absolute value of z, in bytes.

func (*Int) Bytes

func (z *Int) Bytes() []byte

Bytes returns the absolute value of x as a big-endian byte slice.

func (*Int) Cmp

func (z *Int) Cmp(y *Int) int

Cmp compares x and y and returns:

-1 if x < y
 0 if x == y
+1 if x > y

func (*Int) DeepCopy

func (z *Int) DeepCopy() *Int

DeepCopy creates a deep copy of the Int.

func (*Int) Div

func (z *Int) Div(x, y *Int) *Int

Div sets z to the quotient x/y and returns z.

func (*Int) Exp

func (z *Int) Exp(x, y, m *Int) *Int

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

func (z *Int) FillBytes(buf []byte) []byte

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

func (z *Int) Format(s fmt.State, ch rune)

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

func (z *Int) GCD(x, y, a, b *Int) *Int

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

func (z *Int) GobDecode(in []byte) error

GobDecode decodes the byte slice into an Int. Error is always nil. This function implements the gob.GobDecoder interface.

func (*Int) GobEncode

func (z *Int) GobEncode() ([]byte, error)

GobEncode encodes the Int into a byte slice. Error is always nil. This function implements the gob.GobEncoder interface.

func (*Int) Int64

func (z *Int) Int64() int64

Int64 converts the Int to an int64, if possible, or undefined result if not possible.

func (*Int) IsCoprime

func (z *Int) IsCoprime(x *Int) bool

IsCoprime returns true if the two numbers are coprime (relatively prime).

func (*Int) IsInt64

func (z *Int) IsInt64() bool

IsInt64 checks if an Int can be converted to an int64.

func (*Int) IsPrime

func (z *Int) IsPrime() bool

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) LeftShift

func (z *Int) LeftShift(x *Int, n uint) *Int

LeftShift shifts the value left by n bits.

func (*Int) LeftpadBytes

func (z *Int) LeftpadBytes(length uint64) []byte

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

func (z *Int) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (*Int) Mod

func (z *Int) Mod(x, y *Int) *Int

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

func (z *Int) ModInverse(x, n *Int) *Int

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) Mul

func (z *Int) Mul(x, y *Int) *Int

Mul sets z to the product x*y and returns z.

func (*Int) Or

func (z *Int) Or(x, y *Int) *Int

Or computes the bitwise or operation between x and y.

func (*Int) RightShift

func (z *Int) RightShift(x *Int, n uint) *Int

RightShift shifts the value right by n bits.

func (*Int) Set

func (z *Int) Set(x *Int) *Int

Set sets z to x and returns z.

func (*Int) SetBigInt

func (z *Int) SetBigInt(x *big.Int) *Int

SetBigInt sets z to big.Int x and returns z.

func (*Int) SetBits

func (z *Int) SetBits(x Bits) *Int

SetBits sets z to the passed Bits.

func (*Int) SetBytes

func (z *Int) SetBytes(buf []byte) *Int

SetBytes interprets buf as the bytes of a big-endian unsigned integer, sets z to that value, and returns z.

func (*Int) SetInt64

func (z *Int) SetInt64(x int64) *Int

SetInt64 sets z to the value of the passed int64.

func (*Int) SetString

func (z *Int) SetString(s string, base int) (*Int, bool)

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) SetUint64

func (z *Int) SetUint64(x uint64) *Int

SetUint64 sets z to the value of the passed uint64.

func (*Int) Sub

func (z *Int) Sub(x, y *Int) *Int

Sub sets z to the difference x-y and returns z.

func (*Int) Text

func (z *Int) Text(base int) string

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

func (z *Int) TextVerbose(base int, length int) string

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

func (z *Int) Uint64() uint64

Uint64 converts the Int to a uint64, if possible, or undefined result if not possible.

func (*Int) UnmarshalJSON

func (z *Int) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

func (*Int) Xor

func (z *Int) Xor(x, y *Int) *Int

Xor computes the bitwise xor operation between the x and y.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL