Documentation
¶
Overview ¶
Package num provides arbitrary-precision arithmetic for cryptographic applications. It is built over the constant-time numct package and is suitable for high-level applications.
See README.md for details.
Index ¶
- Variables
- type Int
- func (i *Int) Abs() *Nat
- func (i *Int) Add(other *Int) *Int
- func (i *Int) AnnouncedLen() int
- func (i *Int) Big() *big.Int
- func (i *Int) Bytes() []byte
- func (i *Int) Cardinal() cardinal.Cardinal
- func (i *Int) Clone() *Int
- func (i *Int) Compare(other *Int) base.Ordering
- func (i *Int) Coprime(other *Int) bool
- func (i *Int) Decrement() *Int
- func (i *Int) DivRound(other *Int) (*Int, error)
- func (i *Int) DivRoundVarTime(other *Int) (*Int, error)
- func (i *Int) Double() *Int
- func (i *Int) Equal(other *Int) bool
- func (i *Int) EuclideanDiv(other *Int) (quot, rem *Int, err error)
- func (i *Int) EuclideanDivVarTime(other *Int) (quot, rem *Int, err error)
- func (i *Int) EuclideanValuation() algebra.Cardinal
- func (i *Int) HashCode() base.HashCode
- func (i *Int) Increment() *Int
- func (i *Int) IsEven() bool
- func (i *Int) IsInRange(modulus *NatPlus) bool
- func (i *Int) IsInRangeSymmetric(modulus *NatPlus) bool
- func (i *Int) IsLessThanOrEqual(other *Int) bool
- func (i *Int) IsNegative() bool
- func (i *Int) IsOdd() bool
- func (i *Int) IsOne() bool
- func (i *Int) IsOpIdentity() bool
- func (i *Int) IsPositive() bool
- func (i *Int) IsProbablyPrime() bool
- func (*Int) IsTorsionFree() bool
- func (i *Int) IsUnit(modulus *NatPlus) bool
- func (i *Int) IsZero() bool
- func (i *Int) Lift() *Int
- func (i *Int) Lsh(shift uint) *Int
- func (i *Int) MarshalCBOR() ([]byte, error)
- func (i *Int) Mod(modulus *NatPlus) *Uint
- func (i *Int) Mul(other *Int) *Int
- func (i *Int) Neg() *Int
- func (i *Int) Op(other *Int) *Int
- func (i *Int) OpInv() *Int
- func (i *Int) OtherOp(other *Int) *Int
- func (i *Int) Rat() *Rat
- func (i *Int) Rsh(shift uint) *Int
- func (i *Int) ScalarMul(other *Int) *Int
- func (i *Int) ScalarOp(other *Int) *Int
- func (i *Int) Square() *Int
- func (i *Int) String() string
- func (*Int) Structure() algebra.Structure[*Int]
- func (i *Int) Sub(other *Int) *Int
- func (i *Int) TrueLen() int
- func (i *Int) TryDiv(other *Int) (*Int, error)
- func (i *Int) TryDivVarTime(other *Int) (*Int, error)
- func (i *Int) TryInv() (*Int, error)
- func (i *Int) TryNeg() (*Int, error)
- func (i *Int) TryOpInv() (*Int, error)
- func (i *Int) TrySub(other *Int) (*Int, error)
- func (i *Int) UnmarshalCBOR(data []byte) error
- func (i *Int) Value() *numct.Int
- type Integers
- func (*Integers) Characteristic() cardinal.Cardinal
- func (*Integers) ElementSize() int
- func (zs *Integers) FromBig(value *big.Int) (*Int, error)
- func (*Integers) FromBytes(input []byte) (*Int, error)
- func (zs *Integers) FromCardinal(value cardinal.Cardinal) (*Int, error)
- func (*Integers) FromInt64(value int64) *Int
- func (*Integers) FromIntCT(value *numct.Int) (*Int, error)
- func (zs *Integers) FromNat(value *Nat) (*Int, error)
- func (*Integers) FromNatCT(value *numct.Nat) (*Int, error)
- func (zs *Integers) FromNatPlus(value *NatPlus) (*Int, error)
- func (*Integers) FromRat(input *Rat) (*Int, error)
- func (zs *Integers) FromUint(input *Uint) (*Int, error)
- func (*Integers) FromUint64(value uint64) *Int
- func (*Integers) FromUintSymmetric(input *Uint) (*Int, error)
- func (*Integers) IsDomain() bool
- func (*Integers) Name() string
- func (*Integers) One() *Int
- func (zs *Integers) OpIdentity() *Int
- func (*Integers) Order() cardinal.Cardinal
- func (*Integers) Random(lowInclusive, highExclusive *Int, prng io.Reader) (*Int, error)
- func (*Integers) ScalarStructure() algebra.Structure[*Int]
- func (*Integers) Zero() *Int
- type Nat
- func (n *Nat) Add(other *Nat) *Nat
- func (n *Nat) AnnouncedLen() int
- func (n *Nat) Big() *big.Int
- func (n *Nat) Bit(i uint) byte
- func (n *Nat) Byte(i uint) byte
- func (n *Nat) Bytes() []byte
- func (n *Nat) BytesBE() []byte
- func (n *Nat) Cardinal() cardinal.Cardinal
- func (n *Nat) Clone() *Nat
- func (n *Nat) Compare(other *Nat) base.Ordering
- func (n *Nat) Coprime(other *Nat) bool
- func (n *Nat) Decrement() (*Nat, error)
- func (n *Nat) DivRound(other *Nat) (*Nat, error)
- func (n *Nat) DivRoundVarTime(other *Nat) (*Nat, error)
- func (n *Nat) Double() *Nat
- func (n *Nat) Equal(other *Nat) bool
- func (n *Nat) EuclideanDiv(other *Nat) (quot, rem *Nat, err error)
- func (n *Nat) EuclideanDivVarTime(other *Nat) (quot, rem *Nat, err error)
- func (n *Nat) EuclideanValuation() cardinal.Cardinal
- func (n *Nat) GCD(other *Nat) *Nat
- func (n *Nat) HashCode() base.HashCode
- func (n *Nat) Increment() *Nat
- func (n *Nat) IsBottom() bool
- func (n *Nat) IsEven() bool
- func (n *Nat) IsLessThanOrEqual(other *Nat) bool
- func (n *Nat) IsOdd() bool
- func (n *Nat) IsOne() bool
- func (n *Nat) IsOpIdentity() bool
- func (n *Nat) IsPositive() bool
- func (n *Nat) IsProbablyPrime() bool
- func (*Nat) IsTorsionFree() bool
- func (n *Nat) IsUnit(modulus *NatPlus) bool
- func (n *Nat) IsZero() bool
- func (n *Nat) Lift() *Int
- func (n *Nat) Lsh(shift uint) *Nat
- func (n *Nat) MarshalCBOR() ([]byte, error)
- func (n *Nat) Mod(modulus *NatPlus) *Uint
- func (n *Nat) Mul(other *Nat) *Nat
- func (n *Nat) Op(other *Nat) *Nat
- func (n *Nat) OtherOp(other *Nat) *Nat
- func (n *Nat) Rsh(shift uint) *Nat
- func (n *Nat) ScalarMul(sc *Nat) *Nat
- func (n *Nat) ScalarOp(sc *Nat) *Nat
- func (n *Nat) Sqrt() (*Nat, error)
- func (n *Nat) Square() *Nat
- func (n *Nat) String() string
- func (*Nat) Structure() algebra.Structure[*Nat]
- func (n *Nat) TrueLen() int
- func (n *Nat) TryDiv(other *Nat) (*Nat, error)
- func (n *Nat) TryDivVarTime(other *Nat) (*Nat, error)
- func (n *Nat) TryInv() (*Nat, error)
- func (*Nat) TryNeg() (*Nat, error)
- func (n *Nat) TryOpInv() (*Nat, error)
- func (n *Nat) TrySub(other *Nat) (*Nat, error)
- func (n *Nat) Uint64() uint64
- func (n *Nat) UnmarshalCBOR(data []byte) error
- func (n *Nat) Value() *numct.Nat
- type NatPlus
- func (np *NatPlus) Abs() *NatPlus
- func (np *NatPlus) Add(other *NatPlus) *NatPlus
- func (np *NatPlus) AnnouncedLen() int
- func (np *NatPlus) Big() *big.Int
- func (np *NatPlus) Bit(i uint) byte
- func (np *NatPlus) Byte(i uint) byte
- func (np *NatPlus) Bytes() []byte
- func (np *NatPlus) BytesBE() []byte
- func (np *NatPlus) Cardinal() cardinal.Cardinal
- func (np *NatPlus) Clone() *NatPlus
- func (np *NatPlus) Compare(other *NatPlus) base.Ordering
- func (np *NatPlus) Decrement() (*NatPlus, error)
- func (np *NatPlus) Double() *NatPlus
- func (np *NatPlus) Equal(other *NatPlus) bool
- func (np *NatPlus) HashCode() base.HashCode
- func (np *NatPlus) Increment() *NatPlus
- func (np *NatPlus) IsBottom() bool
- func (np *NatPlus) IsEven() bool
- func (np *NatPlus) IsLessThanOrEqual(other *NatPlus) bool
- func (np *NatPlus) IsOdd() bool
- func (np *NatPlus) IsOne() bool
- func (np *NatPlus) IsOpIdentity() bool
- func (np *NatPlus) IsProbablyPrime() bool
- func (np *NatPlus) IsUnit(modulus *NatPlus) bool
- func (np *NatPlus) Lift() *Int
- func (np *NatPlus) Lsh(shift uint) *NatPlus
- func (np *NatPlus) MarshalCBOR() ([]byte, error)
- func (np *NatPlus) Mod(modulus *NatPlus) *Uint
- func (np *NatPlus) ModulusCT() *numct.Modulus
- func (np *NatPlus) Mul(other *NatPlus) *NatPlus
- func (np *NatPlus) Nat() *Nat
- func (np *NatPlus) Op(other *NatPlus) *NatPlus
- func (np *NatPlus) OtherOp(other *NatPlus) *NatPlus
- func (np *NatPlus) Rsh(shift uint) *NatPlus
- func (np *NatPlus) Square() *NatPlus
- func (np *NatPlus) String() string
- func (*NatPlus) Structure() algebra.Structure[*NatPlus]
- func (np *NatPlus) TrueLen() int
- func (np *NatPlus) TryDiv(other *NatPlus) (*NatPlus, error)
- func (np *NatPlus) TryInv() (*NatPlus, error)
- func (np *NatPlus) TryOpInv() (*NatPlus, error)
- func (np *NatPlus) TryRsh(shift uint) (*NatPlus, error)
- func (np *NatPlus) TrySub(other *NatPlus) (*NatPlus, error)
- func (np *NatPlus) Uint64() uint64
- func (np *NatPlus) UnmarshalCBOR(data []byte) error
- func (np *NatPlus) Value() *numct.Nat
- type NaturalNumbers
- func (ns *NaturalNumbers) Bottom() *Nat
- func (*NaturalNumbers) Characteristic() cardinal.Cardinal
- func (*NaturalNumbers) ElementSize() int
- func (ns *NaturalNumbers) FromBig(value *big.Int) (*Nat, error)
- func (*NaturalNumbers) FromBytes(input []byte) (*Nat, error)
- func (ns *NaturalNumbers) FromBytesBE(input []byte) (*Nat, error)
- func (ns *NaturalNumbers) FromCardinal(value cardinal.Cardinal) (*Nat, error)
- func (ns *NaturalNumbers) FromInt(value *Int) (*Nat, error)
- func (*NaturalNumbers) FromNatCT(value *numct.Nat) (*Nat, error)
- func (*NaturalNumbers) FromNatPlus(value *NatPlus) (*Nat, error)
- func (ns *NaturalNumbers) FromRat(value *Rat) (*Nat, error)
- func (*NaturalNumbers) FromUint64(value uint64) *Nat
- func (*NaturalNumbers) Name() string
- func (*NaturalNumbers) One() *Nat
- func (ns *NaturalNumbers) OpIdentity() *Nat
- func (*NaturalNumbers) Order() cardinal.Cardinal
- func (ns *NaturalNumbers) Random(lowInclusive, highExclusive *Nat, prng io.Reader) (*Nat, error)
- func (*NaturalNumbers) ScalarStructure() algebra.Structure[*Nat]
- func (*NaturalNumbers) Zero() *Nat
- type PositiveNaturalNumbers
- func (nps *PositiveNaturalNumbers) Bottom() *NatPlus
- func (*PositiveNaturalNumbers) Characteristic() cardinal.Cardinal
- func (*PositiveNaturalNumbers) ElementSize() int
- func (nps *PositiveNaturalNumbers) FromBig(b *big.Int) (*NatPlus, error)
- func (*PositiveNaturalNumbers) FromBytes(input []byte) (*NatPlus, error)
- func (nps *PositiveNaturalNumbers) FromBytesBE(input []byte) (*NatPlus, error)
- func (*PositiveNaturalNumbers) FromCardinal(c algebra.Cardinal) (*NatPlus, error)
- func (*PositiveNaturalNumbers) FromInt(value *Int) (*NatPlus, error)
- func (*PositiveNaturalNumbers) FromModulusCT(m *numct.Modulus) *NatPlus
- func (*PositiveNaturalNumbers) FromNat(value *Nat) (*NatPlus, error)
- func (*PositiveNaturalNumbers) FromNatCT(value *numct.Nat) (*NatPlus, error)
- func (nps *PositiveNaturalNumbers) FromRat(v *Rat) (*NatPlus, error)
- func (*PositiveNaturalNumbers) FromUint64(value uint64) (*NatPlus, error)
- func (*PositiveNaturalNumbers) Name() string
- func (*PositiveNaturalNumbers) One() *NatPlus
- func (nps *PositiveNaturalNumbers) OpIdentity() *NatPlus
- func (*PositiveNaturalNumbers) Order() cardinal.Cardinal
- func (nps *PositiveNaturalNumbers) Random(lowInclusive, highExclusive *NatPlus, prng io.Reader) (*NatPlus, error)
- type Rat
- func (r *Rat) Add(rhs *Rat) *Rat
- func (r *Rat) Big() *big.Rat
- func (r *Rat) Bytes() []byte
- func (r *Rat) Canonical() *Rat
- func (r *Rat) Ceil() (*Int, error)
- func (r *Rat) Clone() *Rat
- func (r *Rat) Denominator() *NatPlus
- func (r *Rat) Double() *Rat
- func (r *Rat) Equal(rhs *Rat) bool
- func (r *Rat) EuclideanDiv(rhs *Rat) (quo, rem *Rat, err error)
- func (r *Rat) EuclideanValuation() cardinal.Cardinal
- func (r *Rat) Floor() (*Int, error)
- func (r *Rat) HashCode() base.HashCode
- func (r *Rat) IsInt() bool
- func (r *Rat) IsLessThanOrEqual(rhs *Rat) bool
- func (r *Rat) IsNegative() bool
- func (r *Rat) IsOne() bool
- func (r *Rat) IsOpIdentity() bool
- func (r *Rat) IsPositive() bool
- func (r *Rat) IsProbablyPrime() bool
- func (r *Rat) IsZero() bool
- func (r *Rat) MarshalCBOR() ([]byte, error)
- func (r *Rat) Mul(rhs *Rat) *Rat
- func (r *Rat) Neg() *Rat
- func (r *Rat) Numerator() *Int
- func (r *Rat) Op(rhs *Rat) *Rat
- func (r *Rat) OpInv() *Rat
- func (r *Rat) OtherOp(rhs *Rat) *Rat
- func (r *Rat) Square() *Rat
- func (r *Rat) String() string
- func (*Rat) Structure() algebra.Structure[*Rat]
- func (r *Rat) Sub(rhs *Rat) *Rat
- func (r *Rat) TryDiv(rhs *Rat) (*Rat, error)
- func (r *Rat) TryInv() (*Rat, error)
- func (r *Rat) TryNeg() (*Rat, error)
- func (r *Rat) TryOpInv() (*Rat, error)
- func (r *Rat) TrySub(rhs *Rat) (*Rat, error)
- func (r *Rat) UnmarshalCBOR(data []byte) error
- type Rationals
- func (*Rationals) Characteristic() algebra.Cardinal
- func (*Rationals) ElementSize() int
- func (*Rationals) ExtensionDegree() uint
- func (*Rationals) FromBig(n *big.Int) (*Rat, error)
- func (*Rationals) FromBigRat(n *big.Rat) (*Rat, error)
- func (*Rationals) FromBytes(data []byte) (*Rat, error)
- func (*Rationals) FromInt(n *Int) (*Rat, error)
- func (*Rationals) FromInt64(n int64) *Rat
- func (*Rationals) FromNat(n *Nat) (*Rat, error)
- func (*Rationals) FromNatPlus(n *NatPlus) (*Rat, error)
- func (*Rationals) FromUint(n *Uint) (*Rat, error)
- func (*Rationals) FromUint64(n uint64) *Rat
- func (*Rationals) IsDomain() bool
- func (*Rationals) Name() string
- func (*Rationals) New(a *Int, b *NatPlus) (*Rat, error)
- func (*Rationals) One() *Rat
- func (q *Rationals) OpIdentity() *Rat
- func (*Rationals) Order() algebra.Cardinal
- func (*Rationals) Random(lowInclusive, highExclusive *Rat, prng io.Reader) (*Rat, error)
- func (*Rationals) RandomInt(lowInclusive, highExclusive *Rat, prng io.Reader) (*Int, error)
- func (*Rationals) Zero() *Rat
- type Uint
- func (u *Uint) Abs() *Nat
- func (u *Uint) Add(other *Uint) *Uint
- func (u *Uint) AnnouncedLen() int
- func (u *Uint) Big() *big.Int
- func (u *Uint) Bit(i uint) byte
- func (u *Uint) Bytes() []byte
- func (u *Uint) BytesBE() []byte
- func (u *Uint) Cardinal() cardinal.Cardinal
- func (u *Uint) Clone() *Uint
- func (u *Uint) Compare(other *Uint) base.Ordering
- func (u *Uint) CondAssign(choice ct.Choice, x *Uint)
- func (u *Uint) Coprime(other *Uint) bool
- func (u *Uint) Decrement() *Uint
- func (u *Uint) Double() *Uint
- func (u *Uint) Equal(other *Uint) bool
- func (u *Uint) EqualModulus(other *Uint) bool
- func (u *Uint) EuclideanDiv(other *Uint) (quot, rem *Uint, err error)
- func (u *Uint) EuclideanValuation() algebra.Cardinal
- func (u *Uint) Exp(exponent *Nat) *Uint
- func (u *Uint) ExpBounded(exponent *Nat, bits uint) *Uint
- func (u *Uint) ExpI(exponent *Int) *Uint
- func (u *Uint) ExpIBounded(exponent *Int, bits uint) *Uint
- func (u *Uint) Group() *ZMod
- func (u *Uint) HashCode() base.HashCode
- func (u *Uint) Increment() *Uint
- func (u *Uint) IsBottom() bool
- func (u *Uint) IsEven() bool
- func (u *Uint) IsLessThanOrEqual(other *Uint) bool
- func (u *Uint) IsNegative() bool
- func (u *Uint) IsOdd() bool
- func (u *Uint) IsOne() bool
- func (u *Uint) IsOpIdentity() bool
- func (u *Uint) IsPositive() bool
- func (u *Uint) IsProbablyPrime() bool
- func (u *Uint) IsQuadraticResidue() bool
- func (u *Uint) IsTop() bool
- func (*Uint) IsTorsionFree() bool
- func (u *Uint) IsUnit() bool
- func (u *Uint) IsZero() bool
- func (u *Uint) Lift() *Int
- func (u *Uint) Lsh(shift uint) *Uint
- func (u *Uint) MarshalCBOR() ([]byte, error)
- func (u *Uint) Modulus() *NatPlus
- func (u *Uint) ModulusCT() *numct.Modulus
- func (u *Uint) Mul(other *Uint) *Uint
- func (u *Uint) Nat() *Nat
- func (u *Uint) Neg() *Uint
- func (u *Uint) Op(other *Uint) *Uint
- func (u *Uint) OpInv() *Uint
- func (u *Uint) OtherOp(other *Uint) *Uint
- func (u *Uint) PartialCompare(other *Uint) base.PartialOrdering
- func (u *Uint) Rsh(shift uint) *Uint
- func (u *Uint) ScalarExp(other *Nat) *Uint
- func (u *Uint) ScalarMul(other *Nat) *Uint
- func (u *Uint) ScalarOp(other *Nat) *Uint
- func (u *Uint) Select(choice ct.Choice, x0, x1 *Uint)
- func (u *Uint) Sqrt() (*Uint, error)
- func (u *Uint) Square() *Uint
- func (u *Uint) String() string
- func (u *Uint) Structure() algebra.Structure[*Uint]
- func (u *Uint) Sub(other *Uint) *Uint
- func (u *Uint) TrueLen() int
- func (u *Uint) TryDiv(other *Uint) (*Uint, error)
- func (u *Uint) TryInv() (*Uint, error)
- func (u *Uint) TryNeg() (*Uint, error)
- func (u *Uint) TryOpInv() (*Uint, error)
- func (u *Uint) TrySub(other *Uint) (*Uint, error)
- func (u *Uint) UnmarshalCBOR(data []byte) error
- func (u *Uint) Value() *numct.Nat
- type ZMod
- func (*ZMod) AmbientStructure() algebra.Structure[*Int]
- func (zn *ZMod) Bottom() *Uint
- func (zn *ZMod) Characteristic() cardinal.Cardinal
- func (zn *ZMod) ElementSize() int
- func (zn *ZMod) FromBig(v *big.Int) (*Uint, error)
- func (zn *ZMod) FromBytes(input []byte) (*Uint, error)
- func (zn *ZMod) FromBytesBE(input []byte) (*Uint, error)
- func (zn *ZMod) FromBytesBEReduce(input []byte) (*Uint, error)
- func (zn *ZMod) FromCardinal(v cardinal.Cardinal) (*Uint, error)
- func (zn *ZMod) FromInt(v *Int) (*Uint, error)
- func (zn *ZMod) FromInt64(value int64) (*Uint, error)
- func (zn *ZMod) FromNat(v *Nat) (*Uint, error)
- func (zn *ZMod) FromNatCT(v *numct.Nat) (*Uint, error)
- func (zn *ZMod) FromNatCTReduced(reducedV *numct.Nat) (*Uint, error)
- func (zn *ZMod) FromNatPlus(v *NatPlus) (*Uint, error)
- func (zn *ZMod) FromRat(v *Rat) (*Uint, error)
- func (zn *ZMod) FromUint64(value uint64) *Uint
- func (zn *ZMod) Hash(input []byte) (*Uint, error)
- func (zn *ZMod) IsDomain() bool
- func (zn *ZMod) IsInRange(v *Nat) bool
- func (z *ZMod) MarshalCBOR() ([]byte, error)
- func (zn *ZMod) Modulus() *NatPlus
- func (zn *ZMod) ModulusCT() *numct.Modulus
- func (zn *ZMod) Name() string
- func (zn *ZMod) One() *Uint
- func (zn *ZMod) OpIdentity() *Uint
- func (zn *ZMod) Order() cardinal.Cardinal
- func (zn *ZMod) Random(prng io.Reader) (*Uint, error)
- func (*ZMod) ScalarStructure() algebra.Structure[*Nat]
- func (zn *ZMod) Top() *Uint
- func (z *ZMod) UnmarshalCBOR(data []byte) error
- func (zn *ZMod) WideElementSize() int
- func (zn *ZMod) Zero() *Uint
Constants ¶
This section is empty.
Variables ¶
var ( ErrInexactDivision = errs.New("inexact division") ErrUndefined = errs.New("operation is undefined") ErrOutOfRange = errs.New("value is out of range") ErrUnequalModuli = errs.New("moduli are unequal") ErrIsNil = errs.New("value must not be nil") ErrDivisionByZero = errs.New("division by zero") )
Functions ¶
This section is empty.
Types ¶
type Int ¶
type Int struct {
// contains filtered or unexported fields
}
Int represents an integer in the ring of integers Z.
func (*Int) AnnouncedLen ¶
AnnouncedLen returns the announced length of the integer in bytes.
func (*Int) DivRound ¶
DivRound performs the division of the integer by another integer returning the quotient rounded towards zero.
func (*Int) DivRoundVarTime ¶
DivRoundVarTime performs the division of the integer by another integer returning the quotient rounded towards zero. It is not constant-time due to having to generate montgomery parameters for the divisor (i.e., leaks divisor).
func (*Int) EuclideanDiv ¶
EuclideanDiv performs Euclidean division of the integer by another integer.
func (*Int) EuclideanDivVarTime ¶
EuclideanDivVarTime performs Euclidean division of the integer by another integer. It is not constant-time due to having to generate montgomery parameters for the divisor (i.e., leaks divisor).
func (*Int) EuclideanValuation ¶
EuclideanValuation returns the Euclidean valuation of the integer.
func (*Int) IsInRange ¶
IsInRange checks if the integer is within the range defined by the modulus i.e., 0 <= x < m.
func (*Int) IsInRangeSymmetric ¶
IsInRangeSymmetric checks if the integer is within the symmetric range defined by the modulus i.e., -m/2 <= x < m/2.
func (*Int) IsLessThanOrEqual ¶
IsLessThanOrEqual checks if the integer is less than or equal to another integer.
func (*Int) IsNegative ¶
IsNegative checks if the integer is negative.
func (*Int) IsOpIdentity ¶
IsOpIdentity checks if the integer is the additive identity (zero).
func (*Int) IsPositive ¶
IsPositive checks if the integer is positive.
func (*Int) IsProbablyPrime ¶
IsProbablyPrime checks if the integer is probably prime.
func (*Int) IsTorsionFree ¶
IsTorsionFree returns true, indicating that the integers are torsion-free.
func (*Int) MarshalCBOR ¶
func (*Int) TryDivVarTime ¶
TryDivVarTime performs the exact division of the integer by another integer. It is not constant-time due to having to generate montgomery parameters for the divisor (i.e., leaks divisor).
func (*Int) UnmarshalCBOR ¶
type Integers ¶
type Integers struct{}
Integers implements the algebra.Structure interface for the ring of integers Z.
func (*Integers) Characteristic ¶
Characteristic returns the characteristic of the integers, which is 0.
func (*Integers) ElementSize ¶
ElementSize returns -1 indicating that the size of integer elements is unbounded.
func (*Integers) FromCardinal ¶
FromCardinal creates an integer from a cardinal.Cardinal value.
func (*Integers) FromNatPlus ¶
FromNatPlus creates an integer from a NatPlus value.
func (*Integers) FromUint64 ¶
FromUint64 creates an integer from a uint64 value.
func (*Integers) FromUintSymmetric ¶
FromUintSymmetric creates an integer from a Uint value using symmetric representation.
func (*Integers) IsDomain ¶
IsDomain returns true, indicating that the integers form a domain (no zero divisors).
func (*Integers) OpIdentity ¶
OpIdentity returns the additive identity element (zero) of the integers.
func (*Integers) Random ¶
Random generates a random integer in the range [lowInclusive, highExclusive).
func (*Integers) ScalarStructure ¶
ScalarStructure returns the structure of the scalars, which is also the integers.
type Nat ¶
type Nat struct {
// contains filtered or unexported fields
}
Nat represents a natural number (non-negative integer).
func (*Nat) AnnouncedLen ¶
AnnouncedLen returns the announced length of the Nat in bytes.
func (*Nat) Decrement ¶
Decrement returns the Nat decremented by 1, returning an error if the result would be negative.
func (*Nat) DivRound ¶
DivRound divides the Nat by another Nat returning quotient rounded towards zero. It returns an error if the division is not exact.
func (*Nat) DivRoundVarTime ¶
DivRoundVarTime divides the Nat by another Nat returning quotient rounded towards zero. It returns an error if the division is not exact. It is not constant-time due to having to generate montgomery parameters for the divisor (i.e., leaks divisor).
func (*Nat) EuclideanDiv ¶
EuclideanDiv performs Euclidean division of the Nat by another Nat, returning the quotient and remainder.
func (*Nat) EuclideanDivVarTime ¶
EuclideanDivVarTime performs Euclidean division of the Nat by another Nat, returning the quotient and remainder. It is not constant-time due to having to generate montgomery parameters for the divisor (i.e., leaks divisor).
func (*Nat) EuclideanValuation ¶
EuclideanValuation computes the Euclidean valuation of the Nat.
func (*Nat) IsLessThanOrEqual ¶
IsLessThanOrEqual checks if the Nat is less than or equal to another Nat.
func (*Nat) IsOpIdentity ¶
IsOpIdentity checks if the Nat is the additive identity (0).
func (*Nat) IsPositive ¶
IsPositive checks if the Nat is positive (greater than 0).
func (*Nat) IsProbablyPrime ¶
IsProbablyPrime checks if the Nat is probably prime.
func (*Nat) IsTorsionFree ¶
IsTorsionFree checks if the Nat is torsion-free under addition, which is always true for natural numbers.
func (*Nat) MarshalCBOR ¶
func (*Nat) Sqrt ¶
Sqrt computes the square root of the Nat, returning an error if the square root is not defined.
func (*Nat) TryDiv ¶
TryDiv attempts to divide the Nat by another Nat. It returns an error if the division is not exact.
func (*Nat) TryDivVarTime ¶
TryDivVarTime attempts to divide the Nat by another Nat. It returns an error if the division is not exact. It is not constant-time due to having to generate montgomery parameters for the divisor (i.e., leaks divisor).
func (*Nat) TryInv ¶
TryInv attempts to compute the multiplicative inverse of the Nat. It returns an error unless the Nat is 1.
func (*Nat) TryNeg ¶
TryNeg attempts to compute the negation of the Nat. It will always return an error since natural numbers do not have negation.
func (*Nat) TryOpInv ¶
TryOpInv attempts to compute the additive inverse of the Nat. It will always return an error since natural numbers do not have additive inverses.
func (*Nat) TrySub ¶
TrySub attempts to subtract another Nat from the current Nat. It returns an error if the result would not be a natural number.
func (*Nat) Uint64 ¶
Uint64 returns the uint64 representation of the Nat. It wraps around if the Nat is too large.
func (*Nat) UnmarshalCBOR ¶
type NatPlus ¶
type NatPlus struct {
// contains filtered or unexported fields
}
NatPlus represents a positive natural number (N\{0}).
func (*NatPlus) AnnouncedLen ¶
AnnouncedLen returns the announced length of the NatPlus in bytes.
func (*NatPlus) Compare ¶
Compare compares the NatPlus with another NatPlus, returning the ordering result.
func (*NatPlus) Decrement ¶
Decrement returns the NatPlus decremented by 1, returning an error if the result would be less than 1.
func (*NatPlus) IsLessThanOrEqual ¶
IsLessThanOrEqual checks if the NatPlus is less than or equal to another NatPlus.
func (*NatPlus) IsOpIdentity ¶
IsOpIdentity checks if the NatPlus is the multiplicative identity (1).
func (*NatPlus) IsProbablyPrime ¶
IsProbablyPrime checks if the NatPlus is probably prime.
func (*NatPlus) MarshalCBOR ¶
func (*NatPlus) Rsh ¶
Rsh performs a right shift operation on the NatPlus. Panics if the result would be zero.
func (*NatPlus) Structure ¶
Structure returns the algebraic structure of NatPlus, which is PositiveNaturalNumbers.
func (*NatPlus) TryDiv ¶
TryDiv attempts to divide the NatPlus by another NatPlus, returning an error if the division is not exact.
func (*NatPlus) TryInv ¶
TryInv attempts to compute the multiplicative inverse of the NatPlus, returning an error since it does not exist.
func (*NatPlus) TryOpInv ¶
TryOpInv attempts to compute the multiplicative inverse of the NatPlus, returning an error since it does not exist.
func (*NatPlus) TryRsh ¶
TryRsh attempts to right shift the NatPlus, returning an error if the result would be zero.
func (*NatPlus) TrySub ¶
TrySub attempts to subtract another NatPlus from the NatPlus, returning an error if the result is not a positive natural number.
func (*NatPlus) UnmarshalCBOR ¶
type NaturalNumbers ¶
type NaturalNumbers struct{}
NaturalNumbers represents the set of natural numbers (non-negative integers).
func (*NaturalNumbers) Bottom ¶
func (ns *NaturalNumbers) Bottom() *Nat
Bottom returns the smallest element in the NaturalNumbers structure, which is 0.
func (*NaturalNumbers) Characteristic ¶
func (*NaturalNumbers) Characteristic() cardinal.Cardinal
Characteristic returns the characteristic of the NaturalNumbers structure, which is 0.
func (*NaturalNumbers) ElementSize ¶
func (*NaturalNumbers) ElementSize() int
ElementSize returns -1 indicating that elements of NaturalNumbers do not have a fixed size.
func (*NaturalNumbers) FromBig ¶
func (ns *NaturalNumbers) FromBig(value *big.Int) (*Nat, error)
FromBig creates a Nat from a big.Int value, returning an error if the input is nil or negative.
func (*NaturalNumbers) FromBytes ¶
func (*NaturalNumbers) FromBytes(input []byte) (*Nat, error)
FromBytes creates a Nat from a byte slice, returning an error if the input is nil.
func (*NaturalNumbers) FromBytesBE ¶
func (ns *NaturalNumbers) FromBytesBE(input []byte) (*Nat, error)
FromBytesBE creates a Nat from a big-endian byte slice, returning an error if the input is nil.
func (*NaturalNumbers) FromCardinal ¶
func (ns *NaturalNumbers) FromCardinal(value cardinal.Cardinal) (*Nat, error)
FromCardinal creates a Nat from a cardinal.Cardinal value, returning an error if the input is nil or infinite.
func (*NaturalNumbers) FromInt ¶
func (ns *NaturalNumbers) FromInt(value *Int) (*Nat, error)
FromInt creates a Nat from an Int value, returning an error if the input is nil or negative.
func (*NaturalNumbers) FromNatCT ¶
func (*NaturalNumbers) FromNatCT(value *numct.Nat) (*Nat, error)
FromNatCT creates a Nat from a numct.Nat value, returning an error if the input is nil.
func (*NaturalNumbers) FromNatPlus ¶
func (*NaturalNumbers) FromNatPlus(value *NatPlus) (*Nat, error)
FromNatPlus creates a Nat from a NatPlus value, returning an error if the input is nil.
func (*NaturalNumbers) FromRat ¶
func (ns *NaturalNumbers) FromRat(value *Rat) (*Nat, error)
FromRat creates a Nat from a Rat value, returning an error if Rat is not a non-negative integer.
func (*NaturalNumbers) FromUint64 ¶
func (*NaturalNumbers) FromUint64(value uint64) *Nat
FromUint64 creates a Nat from a uint64 value.
func (*NaturalNumbers) Name ¶
func (*NaturalNumbers) Name() string
Name returns the name of the structure: "N".
func (*NaturalNumbers) One ¶
func (*NaturalNumbers) One() *Nat
One returns the multiplicative identity element of the NaturalNumbers structure.
func (*NaturalNumbers) OpIdentity ¶
func (ns *NaturalNumbers) OpIdentity() *Nat
OpIdentity returns the identity element for the addition operation in the NaturalNumbers structure.
func (*NaturalNumbers) Order ¶
func (*NaturalNumbers) Order() cardinal.Cardinal
Order returns the order of the NaturalNumbers structure, which is infinite.
func (*NaturalNumbers) Random ¶
Random generates a random Nat in the range [lowInclusive, highExclusive), returning an error if highExclusive is nil.
func (*NaturalNumbers) ScalarStructure ¶
func (*NaturalNumbers) ScalarStructure() algebra.Structure[*Nat]
ScalarStructure returns the regular semi-module structure of NaturalNumbers.
func (*NaturalNumbers) Zero ¶
func (*NaturalNumbers) Zero() *Nat
Zero returns the additive identity element of the NaturalNumbers structure.
type PositiveNaturalNumbers ¶
type PositiveNaturalNumbers struct{}
PositiveNaturalNumbers represents the set of positive natural numbers (N\{0}).
func NPlus ¶
func NPlus() *PositiveNaturalNumbers
NPlus returns the singleton instance of PositiveNaturalNumbers.
func (*PositiveNaturalNumbers) Bottom ¶
func (nps *PositiveNaturalNumbers) Bottom() *NatPlus
Bottom returns the smallest element of PositiveNaturalNumbers, which is 1.
func (*PositiveNaturalNumbers) Characteristic ¶
func (*PositiveNaturalNumbers) Characteristic() cardinal.Cardinal
Characteristic returns the characteristic of PositiveNaturalNumbers, which is 0.
func (*PositiveNaturalNumbers) ElementSize ¶
func (*PositiveNaturalNumbers) ElementSize() int
ElementSize returns -1 indicating that NatPlus does not have a fixed element size.
func (*PositiveNaturalNumbers) FromBig ¶
func (nps *PositiveNaturalNumbers) FromBig(b *big.Int) (*NatPlus, error)
FromBig creates a NatPlus from the given big.Int, returning an error if the integer is nil or not positive.
func (*PositiveNaturalNumbers) FromBytes ¶
func (*PositiveNaturalNumbers) FromBytes(input []byte) (*NatPlus, error)
FromBytes creates a NatPlus from the given big-endian byte slice, returning an error if the input is empty or represents zero.
func (*PositiveNaturalNumbers) FromBytesBE ¶
func (nps *PositiveNaturalNumbers) FromBytesBE(input []byte) (*NatPlus, error)
FromBytesBE creates a NatPlus from the given big-endian byte slice, returning an error if the input is empty or represents zero.
func (*PositiveNaturalNumbers) FromCardinal ¶
func (*PositiveNaturalNumbers) FromCardinal(c algebra.Cardinal) (*NatPlus, error)
FromCardinal creates a NatPlus from the given cardinal, returning an error if the cardinal is zero.
func (*PositiveNaturalNumbers) FromInt ¶
func (*PositiveNaturalNumbers) FromInt(value *Int) (*NatPlus, error)
FromInt creates a NatPlus from the given Int, returning an error if the Int is nil, zero, or negative.
func (*PositiveNaturalNumbers) FromModulusCT ¶
func (*PositiveNaturalNumbers) FromModulusCT(m *numct.Modulus) *NatPlus
FromModulusCT creates a NatPlus from the given numct.Modulus.
func (*PositiveNaturalNumbers) FromNat ¶
func (*PositiveNaturalNumbers) FromNat(value *Nat) (*NatPlus, error)
FromNat creates a NatPlus from the given Nat, returning an error if the Nat is nil or zero.
func (*PositiveNaturalNumbers) FromNatCT ¶
func (*PositiveNaturalNumbers) FromNatCT(value *numct.Nat) (*NatPlus, error)
FromNatCT creates a NatPlus from the given numct.Nat, returning an error if the value is nil or zero.
func (*PositiveNaturalNumbers) FromRat ¶
func (nps *PositiveNaturalNumbers) FromRat(v *Rat) (*NatPlus, error)
FromRat creates a NatPlus from the given Rat, returning an error if the Rat is not a positive integer.
func (*PositiveNaturalNumbers) FromUint64 ¶
func (*PositiveNaturalNumbers) FromUint64(value uint64) (*NatPlus, error)
FromUint64 creates a NatPlus from the given uint64, returning an error if the value is zero.
func (*PositiveNaturalNumbers) Name ¶
func (*PositiveNaturalNumbers) Name() string
Name returns the name of the structure: "N\{0}".
func (*PositiveNaturalNumbers) One ¶
func (*PositiveNaturalNumbers) One() *NatPlus
One returns the multiplicative identity element of PositiveNaturalNumbers, which is 1.
func (*PositiveNaturalNumbers) OpIdentity ¶
func (nps *PositiveNaturalNumbers) OpIdentity() *NatPlus
OpIdentity returns the multiplicative identity element of PositiveNaturalNumbers, which is 1. Note that this OpIdentity isn't standard, as it considers (N\{0}, *, +) to be a hemi ring, NOT the usual (N\{0}, +, *).
func (*PositiveNaturalNumbers) Order ¶
func (*PositiveNaturalNumbers) Order() cardinal.Cardinal
Order returns the order of PositiveNaturalNumbers, which is infinite.
type Rat ¶
type Rat struct {
// contains filtered or unexported fields
}
Rat represents an element of the field of rational numbers Q.
func (*Rat) Denominator ¶
Denominator returns the denominator of the Rat element.
func (*Rat) EuclideanDiv ¶
EuclideanDiv performs Euclidean division of two Rat elements.
func (*Rat) EuclideanValuation ¶
EuclideanValuation returns the Euclidean valuation of the Rat element.
func (*Rat) IsLessThanOrEqual ¶
IsLessThanOrEqual checks if the Rat element is less than another Rat element.
func (*Rat) IsNegative ¶
IsNegative checks if the Rat element is negative.
func (*Rat) IsOpIdentity ¶
IsOpIdentity checks if the Rat element is the additive identity (zero).
func (*Rat) IsPositive ¶
IsPositive checks if the Rat element is positive.
func (*Rat) IsProbablyPrime ¶
IsProbablyPrime checks if the Rat element is probably prime.
func (*Rat) MarshalCBOR ¶
func (*Rat) UnmarshalCBOR ¶
type Rationals ¶
type Rationals struct{}
Rationals represents the field of rational numbers Q.
func (*Rationals) Characteristic ¶
Characteristic returns the characteristic of the field Q, which is 0.
func (*Rationals) ElementSize ¶
ElementSize returns -1 to indicate that elements of Q do not have a fixed size.
func (*Rationals) ExtensionDegree ¶
ExtensionDegree returns the extension degree of Q over itself, which is 1.
func (*Rationals) FromBigRat ¶
FromBigRat creates a *Rat element from a *big.Rat value.
func (*Rationals) FromNatPlus ¶
FromNatPlus creates a Rat element from a NatPlus value.
func (*Rationals) FromUint64 ¶
FromUint64 creates a Rat element from a uint64 value.
func (*Rationals) OpIdentity ¶
OpIdentity returns the additive identity element of Q.
func (*Rationals) Random ¶
Random samples a random *Rat element in the interval [lowInclusive, highExclusive).
func (*Rationals) RandomInt ¶
RandomInt samples a random integer *Int element in the interval [lowInclusive, highExclusive).
The valid integers are those n satisfying lowInclusive <= n < highExclusive, which is equivalent to the half-open integer interval [ceil(lowInclusive), ceil(highExclusive)).
Returns ErrOutOfRange if the interval contains no integers.
type Uint ¶
type Uint struct {
// contains filtered or unexported fields
}
Uint represents an integer modulo n.
func NewUintGivenModulus ¶
NewUintGivenModulus creates a new Uint element given a value Nat and a modulus Modulus.
func (*Uint) AnnouncedLen ¶
AnnouncedLen returns the announced length in bytes of the Uint element.
func (*Uint) BytesBE ¶
BytesBE returns the big-endian byte slice representation of the Uint element.
func (*Uint) CondAssign ¶
CondAssign conditionally assigns the value of x to the Uint element if choice is true.
func (*Uint) EqualModulus ¶
EqualModulus checks if two Uint elements have the same modulus.
func (*Uint) EuclideanDiv ¶
EuclideanDiv performs Euclidean division of the Uint element by another Uint element.
func (*Uint) EuclideanValuation ¶
EuclideanValuation returns the Euclidean valuation of the Uint element.
func (*Uint) ExpBounded ¶
ExpBounded performs exponentiation of the Uint element by a Nat exponent, using only the lower 'bits' bits of the exponent.
func (*Uint) ExpIBounded ¶
ExpIBounded performs exponentiation of the Uint element by an Int exponent, using only the lower 'bits' bits of the exponent.
func (*Uint) IsLessThanOrEqual ¶
IsLessThanOrEqual checks if the Uint element is less than or equal to another Uint element.
func (*Uint) IsNegative ¶
IsNegative checks the Uint would have been wrapped around if interpreted as an element of in [-n/2, n/2).
func (*Uint) IsOpIdentity ¶
IsOpIdentity checks if the Uint element is the additive identity.
func (*Uint) IsPositive ¶
IsPositive checks if the Uint is non-zero.
func (*Uint) IsProbablyPrime ¶
IsProbablyPrime checks if the Uint element is probably prime.
func (*Uint) IsQuadraticResidue ¶
IsQuadraticResidue checks if the Uint element is a quadratic residue modulo the modulus.
func (*Uint) IsTorsionFree ¶
IsTorsionFree checks if the Uint element is torsion-free.
func (*Uint) IsUnit ¶
IsUnit checks if the Uint element is a unit (i.e., has a multiplicative inverse).
func (*Uint) Lsh ¶
Lsh performs left shift on the Uint element. Lsh is equivalent to multiplying by 2^shift mod modulus.
func (*Uint) MarshalCBOR ¶
func (*Uint) OtherOp ¶
OtherOp performs the other group operation (multiplication) on two Uint elements.
func (*Uint) PartialCompare ¶
func (u *Uint) PartialCompare(other *Uint) base.PartialOrdering
PartialCompare performs a partial comparison between two Uint elements.
func (*Uint) Rsh ¶
Rsh performs right shift on the Uint element. Rsh is equivalent to floor division by 2^shift, then mod modulus.
func (*Uint) ScalarMul ¶
ScalarMul performs scalar multiplication of the Uint element by a Nat scalar.
func (*Uint) ScalarOp ¶
ScalarOp performs scalar multiplication of the Uint element by a Nat scalar.
func (*Uint) Select ¶
Select sets the Uint element to x0 if choice is true, and to x1 if choice is false.
func (*Uint) UnmarshalCBOR ¶
type ZMod ¶
type ZMod struct {
// contains filtered or unexported fields
}
ZMod represents the integers modulo n.
func NewZModFromCardinal ¶
NewZModFromCardinal creates a new ZMod structure given a cardinal.
func NewZModFromModulus ¶
NewZModFromModulus creates a new ZMod structure given a modulus Modulus.
func (*ZMod) AmbientStructure ¶
AmbientStructure returns the ambient structure of quotient group ie. Z.
func (*ZMod) Characteristic ¶
Characteristic returns the characteristic of the group.
func (*ZMod) ElementSize ¶
ElementSize returns the size in bytes of an element.
func (*ZMod) FromBig ¶
FromBig creates a Uint element from a big.Int value. It will reduce the value modulo the modulus of the ZMod.
func (*ZMod) FromBytes ¶
FromBytes creates a Uint element from a byte slice. It will NOT reduce the value modulo the modulus, and will return an error if the value is out of range.
func (*ZMod) FromBytesBE ¶
FromBytesBE creates a Uint element from a big-endian byte slice. It will NOT reduce the value modulo the modulus, and will return an error if the value is out of range.
func (*ZMod) FromBytesBEReduce ¶
FromBytesBEReduce creates a Uint element from a big-endian byte slice, reducing it modulo the modulus. It will reduce the value modulo the modulus of the ZMod.
func (*ZMod) FromCardinal ¶
FromCardinal creates a Uint element from a cardinal. It will NOT reduce the value modulo the modulus, and will return an error if the value is out of range.
func (*ZMod) FromInt ¶
FromInt creates a Uint element from an Int value. It will reduce the Int modulo the modulus of the ZMod.
func (*ZMod) FromNat ¶
FromNat creates a Uint element from a Nat value. It will reduce the value modulo the modulus of the ZMod.
func (*ZMod) FromNatCT ¶
FromNatCT creates a Uint element from a numct.Nat value. It will reduce the value modulo the modulus.
func (*ZMod) FromNatCTReduced ¶
FromNatCTReduced creates a Uint element from a reduced numct.Nat value. It will NOT reduce the value modulo the modulus, and will return an error if the value is out of range.
func (*ZMod) FromNatPlus ¶
FromNatPlus creates a Uint element from a NatPlus value. It will reduce the value modulo the modulus of the ZMod.
func (*ZMod) FromRat ¶
FromRat creates a Uint element from a Rat value. It will reduce the Rat modulo the modulus of the ZMod.
func (*ZMod) FromUint64 ¶
FromUint64 creates a Uint element from a uint64 value.
func (*ZMod) IsDomain ¶
IsDomain checks if the group is a domain (i.e., if the modulus is probably prime).
func (*ZMod) MarshalCBOR ¶
func (*ZMod) OpIdentity ¶
OpIdentity returns the additive identity element of the group.
func (*ZMod) ScalarStructure ¶
ScalarStructure returns the scalar structure of the group.
func (*ZMod) UnmarshalCBOR ¶
func (*ZMod) WideElementSize ¶
WideElementSize returns the size in bytes of a wide element.