package mod
import "go.dedis.ch/kyber/v3/group/mod"
Package mod contains a generic implementation of finite field arithmetic on integer fields with a constant modulus.
Index ¶
- type ByteOrder
- type Int
- func NewInt(v *big.Int, m *big.Int) *Int
- func NewInt64(v int64, M *big.Int) *Int
- func NewIntBytes(a []byte, m *big.Int, byteOrder ByteOrder) *Int
- func NewIntString(n, d string, base int, m *big.Int) *Int
- func (i *Int) Add(a, b kyber.Scalar) kyber.Scalar
- func (i *Int) BigEndian(min, max int) []byte
- func (i *Int) Clone() kyber.Scalar
- func (i *Int) Cmp(s2 kyber.Scalar) int
- func (i *Int) Div(a, b kyber.Scalar) kyber.Scalar
- func (i *Int) Equal(s2 kyber.Scalar) bool
- func (i *Int) Exp(a kyber.Scalar, e *big.Int) kyber.Scalar
- func (i *Int) Init(V *big.Int, m *big.Int) *Int
- func (i *Int) Init64(v int64, m *big.Int) *Int
- func (i *Int) InitBytes(a []byte, m *big.Int, byteOrder ByteOrder) *Int
- func (i *Int) InitString(n, d string, base int, m *big.Int) *Int
- func (i *Int) Int64() int64
- func (i *Int) Inv(a kyber.Scalar) kyber.Scalar
- func (i *Int) Jacobi(as kyber.Scalar) kyber.Scalar
- func (i *Int) LittleEndian(min, max int) []byte
- func (i *Int) MarshalBinary() ([]byte, error)
- func (i *Int) MarshalID() [8]byte
- func (i *Int) MarshalSize() int
- func (i *Int) MarshalTo(w io.Writer) (int, error)
- func (i *Int) Mul(a, b kyber.Scalar) kyber.Scalar
- func (i *Int) Neg(a kyber.Scalar) kyber.Scalar
- func (i *Int) Nonzero() bool
- func (i *Int) One() kyber.Scalar
- func (i *Int) Pick(rand cipher.Stream) kyber.Scalar
- func (i *Int) Set(a kyber.Scalar) kyber.Scalar
- func (i *Int) SetBytes(a []byte) kyber.Scalar
- func (i *Int) SetInt64(v int64) kyber.Scalar
- func (i *Int) SetString(n, d string, base int) (*Int, bool)
- func (i *Int) SetUint64(v uint64) kyber.Scalar
- func (i *Int) Sqrt(as kyber.Scalar) bool
- func (i *Int) String() string
- func (i *Int) Sub(a, b kyber.Scalar) kyber.Scalar
- func (i *Int) Uint64() uint64
- func (i *Int) UnmarshalBinary(buf []byte) error
- func (i *Int) UnmarshalFrom(r io.Reader) (int, error)
- func (i *Int) Zero() kyber.Scalar
Types ¶
type ByteOrder ¶
type ByteOrder bool
ByteOrder denotes the endianness of the operation.
const ( // LittleEndian endianness LittleEndian ByteOrder = true // BigEndian endianness BigEndian ByteOrder = false )
type Int ¶
type Int struct { V big.Int // Integer value from 0 through M-1 M *big.Int // Modulus for finite field arithmetic BO ByteOrder // Endianness which will be used on input and output }
Int is a generic implementation of finite field arithmetic on integer finite fields with a given constant modulus, built using Go's built-in big.Int package. Int satisfies the kyber.Scalar interface, and hence serves as a basic implementation of kyber.Scalar, e.g., representing discrete-log exponents of Schnorr groups or scalar multipliers for elliptic curves.
Int offers an API similar to and compatible with big.Int, but "carries around" a pointer to the relevant modulus and automatically normalizes the value to that modulus after all arithmetic operations, simplifying modular arithmetic. Binary operations assume that the source(s) have the same modulus, but do not check this assumption. Unary and binary arithmetic operations may be performed on uninitialized target objects, and receive the modulus of the first operand. For efficiency the modulus field M is a pointer, whose target is assumed never to change.
func NewInt ¶
NewInt creaters a new Int with a given big.Int and a big.Int modulus.
func NewInt64 ¶
NewInt64 creates a new Int with a given int64 value and big.Int modulus.
func NewIntBytes ¶
NewIntBytes creates a new Int with a given slice of bytes and a big.Int modulus.
func NewIntString ¶
NewIntString creates a new Int with a given string and a big.Int modulus. The value is set to a rational fraction n/d in a given base.
func (*Int) Add ¶
func (i *Int) Add(a, b kyber.Scalar) kyber.Scalar
Add sets the target to a + b mod M, where M is a's modulus..
func (*Int) BigEndian ¶
BigEndian encodes the value of this Int into a big-endian byte-slice at least min bytes but no more than max bytes long. Panics if max != 0 and the Int cannot be represented in max bytes.
func (*Int) Clone ¶
func (i *Int) Clone() kyber.Scalar
Clone returns a separate duplicate of this Int.
func (*Int) Cmp ¶
Cmp compares two Ints for equality or inequality
func (*Int) Div ¶
func (i *Int) Div(a, b kyber.Scalar) kyber.Scalar
Div sets the target to a * b^-1 mod M, where b^-1 is the modular inverse of b.
func (*Int) Equal ¶
Equal returns true if the two Ints are equal
func (*Int) Exp ¶
Exp sets the target to a^e mod M, where e is an arbitrary big.Int exponent (not necessarily 0 <= e < M).
func (*Int) Init ¶
Init a Int with a given big.Int value and modulus pointer. Note that the value is copied; the modulus is not.
func (*Int) Init64 ¶
Init64 creates an Int with an int64 value and big.Int modulus.
func (*Int) InitBytes ¶
InitBytes init the Int to a number represented in a big-endian byte string.
func (*Int) InitString ¶
InitString inits the Int to a rational fraction n/d specified with a pair of strings in a given base.
func (*Int) Int64 ¶
Int64 returns the int64 representation of the value. If the value is not representable in an int64 the result is undefined.
func (*Int) Inv ¶
func (i *Int) Inv(a kyber.Scalar) kyber.Scalar
Inv sets the target to the modular inverse of a with respect to modulus M.
func (*Int) Jacobi ¶
func (i *Int) Jacobi(as kyber.Scalar) kyber.Scalar
Jacobi computes the Jacobi symbol of (a/M), which indicates whether a is zero (0), a positive square in M (1), or a non-square in M (-1).
func (*Int) LittleEndian ¶
LittleEndian encodes the value of this Int into a little-endian byte-slice at least min bytes but no more than max bytes long. Panics if max != 0 and the Int cannot be represented in max bytes.
func (*Int) MarshalBinary ¶
MarshalBinary encodes the value of this Int into a byte-slice exactly Len() bytes long. It uses i's ByteOrder to determine which byte order to output.
func (*Int) MarshalID ¶
MarshalID returns a unique identifier for this type
func (*Int) MarshalSize ¶
MarshalSize returns the length in bytes of encoded integers with modulus M. The length of encoded Ints depends only on the size of the modulus, and not on the the value of the encoded integer, making the encoding is fixed-length for simplicity and security.
func (*Int) MarshalTo ¶
MarshalTo encodes this Int to the given Writer.
func (*Int) Mul ¶
func (i *Int) Mul(a, b kyber.Scalar) kyber.Scalar
Mul sets the target to a * b mod M. Target receives a's modulus.
func (*Int) Neg ¶
func (i *Int) Neg(a kyber.Scalar) kyber.Scalar
Neg sets the target to -a mod M.
func (*Int) Nonzero ¶
Nonzero returns true if the integer value is nonzero.
func (*Int) One ¶
func (i *Int) One() kyber.Scalar
One sets the Int to the value 1. The modulus must already be initialized.
func (*Int) Pick ¶
Pick a [pseudo-]random integer modulo M using bits from the given stream cipher.
func (*Int) Set ¶
func (i *Int) Set(a kyber.Scalar) kyber.Scalar
Set both value and modulus to be equal to another Int. Since this method copies the modulus as well, it may be used as an alternative to Init().
func (*Int) SetBytes ¶
SetBytes set the value value to a number represented by a byte string. Endianness depends on the endianess set in i.
func (*Int) SetInt64 ¶
SetInt64 sets the Int to an arbitrary 64-bit "small integer" value. The modulus must already be initialized.
func (*Int) SetString ¶
SetString sets the Int to a rational fraction n/d represented by a pair of strings. If d == "", then the denominator is taken to be 1. Returns (i,true) on success, or (nil,false) if either string fails to parse.
func (*Int) SetUint64 ¶
SetUint64 sets the Int to an arbitrary uint64 value. The modulus must already be initialized.
func (*Int) Sqrt ¶
Sqrt computes some square root of a mod M of one exists. Assumes the modulus M is an odd prime. Returns true on success, false if input a is not a square.
func (*Int) String ¶
Return the Int's integer value in hexadecimal string representation.
func (*Int) Sub ¶
func (i *Int) Sub(a, b kyber.Scalar) kyber.Scalar
Sub sets the target to a - b mod M. Target receives a's modulus.
func (*Int) Uint64 ¶
Uint64 returns the uint64 representation of the value. If the value is not representable in an uint64 the result is undefined.
func (*Int) UnmarshalBinary ¶
UnmarshalBinary tries to decode a Int from a byte-slice buffer. Returns an error if the buffer is not exactly Len() bytes long or if the contents of the buffer represents an out-of-range integer.
func (*Int) UnmarshalFrom ¶
UnmarshalFrom tries to decode an Int from the given Reader.
func (*Int) Zero ¶
func (i *Int) Zero() kyber.Scalar
Zero set the Int to the value 0. The modulus must already be initialized.
Source Files ¶
int.go
- Version
- v3.1.0 (latest)
- Published
- Nov 30, 2022
- Platform
- linux/amd64
- Imports
- 8 packages
- Last checked
- 1 month ago –
Tools for package owners.