package bigmod

Import Path
	crypto/internal/bigmod (on go.dev)

Dependency Relation
	imports 5 packages, and imported by 2 packages

Involved Source Files nat.go nat_asm.go nat_amd64.s
Package-Level Type Names (total 3, in which 2 are exported)
/* sort exporteds by: | */
Modulus is used for modular arithmetic, precomputing relevant constants. Moduli are assumed to be odd numbers. Moduli can also leak the exact number of bits needed to store their value, and are stored without padding. Their actual value is still kept secret. BitLen returns the size of m in bits. Nat returns m as a Nat. The return value must not be written to. Size returns the size of m in bytes. func NewModulusFromBig(n *big.Int) (*Modulus, error) func (*Nat).Add(y *Nat, m *Modulus) *Nat func (*Nat).Bytes(m *Modulus) []byte func (*Nat).Exp(x *Nat, e []byte, m *Modulus) *Nat func (*Nat).ExpandFor(m *Modulus) *Nat func (*Nat).ExpShort(x *Nat, e uint, m *Modulus) *Nat 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).Sub(y *Nat, m *Modulus) *Nat
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. 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 reduced modulo 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. ExpShort 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 exact bit size of the exponent. 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. 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. 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. 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).ExpShort(x *Nat, e uint, m *Modulus) *Nat 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).Sub(y *Nat, 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).ExpShort(x *Nat, e uint, m *Modulus) *Nat 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 14, in which 2 are exported)
NewModulusFromBig creates a new Modulus from a [big.Int]. The Int must be odd. The number of significant bits (and nothing else) is leaked through timing side-channels.
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.
Package-Level Variables (only one, which is unexported)
Package-Level Constants (total 6, none are exported)