Nat represents an arbitrary natural number
Each Nat has an announced length, which is the number of limbs it has stored.
Operations on this number are allowed to leak this length, but will not leak
any information about the values contained in those limbs. Add computes x = x + y mod m.
The length of both operands must be the same as the modulus. Both operands
must already be reduced modulo m. BitLenVarTime returns the actual size of x in bits.
The actual size of x (but nothing more) leaks through timing side-channels.
Note that this is ordinarily secret, as opposed to the announced size of x. Bytes returns x as a zero-extended big-endian byte slice. The size of the
slice will match the size of m.
x must have the same size as m and it must be less than or equal to m. Equal returns 1 if x == y, and 0 otherwise.
Both operands must have the same announced length. Exp calculates out = x^e mod m.
The exponent e is represented in big-endian order. The output will be resized
to the size of m and overwritten. x must already be reduced modulo m.
m must be odd, or Exp will panic. ExpShortVarTime calculates out = x^e mod m.
The output will be resized to the size of m and overwritten. x must already
be reduced modulo m. This leaks the exponent through timing side-channels.
m must be odd, or ExpShortVarTime will panic. ExpandFor ensures x has the right size to work with operations modulo m.
The announced size of x must be smaller than or equal to that of m. InverseVarTime calculates x = a⁻¹ mod m and returns (x, true) if a is
invertible. Otherwise, InverseVarTime returns (x, false) and x is not
modified.
a must be reduced modulo m, but doesn't need to have the same size. The
output will be resized to the size of m and overwritten. IsMinusOne returns 1 if x == -1 mod m, and 0 otherwise.
The length of x must be the same as the modulus. x must already be reduced
modulo m. IsOdd returns 1 if x is odd, and 0 otherwise. IsOne returns 1 if x == 1, and 0 otherwise. IsZero returns 1 if x == 0, and 0 otherwise. Mod calculates out = x mod m.
This works regardless how large the value of x is.
The output will be resized to the size of m and overwritten. Mul calculates x = x * y mod m.
The length of both operands must be the same as the modulus. Both operands
must already be reduced modulo m. SetBytes assigns x = b, where b is a slice of big-endian bytes.
SetBytes returns an error if b >= m.
The output will be resized to the size of m and overwritten. SetOverflowingBytes assigns x = b, where b is a slice of big-endian bytes.
SetOverflowingBytes returns an error if b has a longer bit length than m, but
reduces overflowing values up to 2^⌈log2(m)⌉ - 1.
The output will be resized to the size of m and overwritten. SetUint assigns x = y.
The output will be resized to a single limb and overwritten. ShiftRightVarTime sets x = x >> n.
The announced length of x is unchanged. Sub computes x = x - y mod m.
The length of both operands must be the same as the modulus. Both operands
must already be reduced modulo m. SubOne computes x = x - 1 mod m.
The length of x must be the same as the modulus. TrailingZeroBitsVarTime returns the number of trailing zero bits in x.
func NewNat() *Nat
func (*Modulus).Nat() *Nat
func (*Nat).Add(y *Nat, m *Modulus) *Nat
func (*Nat).Exp(x *Nat, e []byte, m *Modulus) *Nat
func (*Nat).ExpandFor(m *Modulus) *Nat
func (*Nat).ExpShortVarTime(x *Nat, e uint, m *Modulus) *Nat
func (*Nat).InverseVarTime(a *Nat, m *Modulus) (*Nat, bool)
func (*Nat).Mod(x *Nat, m *Modulus) *Nat
func (*Nat).Mul(y *Nat, m *Modulus) *Nat
func (*Nat).SetBytes(b []byte, m *Modulus) (*Nat, error)
func (*Nat).SetOverflowingBytes(b []byte, m *Modulus) (*Nat, error)
func (*Nat).SetUint(y uint) *Nat
func (*Nat).ShiftRightVarTime(n uint) *Nat
func (*Nat).Sub(y *Nat, m *Modulus) *Nat
func (*Nat).SubOne(m *Modulus) *Nat
func (*Nat).Add(y *Nat, m *Modulus) *Nat
func (*Nat).Equal(y *Nat) choice
func (*Nat).Exp(x *Nat, e []byte, m *Modulus) *Nat
func (*Nat).ExpShortVarTime(x *Nat, e uint, m *Modulus) *Nat
func (*Nat).InverseVarTime(a *Nat, m *Modulus) (*Nat, bool)
func (*Nat).Mod(x *Nat, m *Modulus) *Nat
func (*Nat).Mul(y *Nat, m *Modulus) *Nat
func (*Nat).Sub(y *Nat, m *Modulus) *Nat
Package-Level Functions (total 3)
NewModulus creates a new Modulus from a slice of big-endian bytes. The
modulus must be greater than one.
The number of significant bits and whether the modulus is even is leaked
through timing side-channels.
NewModulusProduct creates a new Modulus from the product of two numbers
represented as big-endian byte slices. The result must be greater than one.
NewNat returns a new nat with a size of zero, just like new(Nat), but with
the preallocated capacity to hold a number of up to preallocTarget bits.
NewNat inlines, so the allocation can live on the stack.
The pages are generated with Goldsv0.7.3-preview. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.