Documentation ¶
Overview ¶
Package cyclic wraps our large.Int structure. It is designed to be used in conjunction with the cyclic.Group object. The cyclic.Group object will provide implementations of various modular operations within the group. A cyclic.IntBuffer type will be created to store large batches of groups.
Package cyclic wraps our large.Int structure. It is designed to be used in conjunction with the cyclic.Group object. The cyclic.Group object will provide implementations of various modular operations within the group. A cyclic.IntBuffer type will be created to store large batches of groups.
Package cyclic wraps our large.Int structure. It is designed to be used in conjunction with the cyclic.Group object. The cyclic.Group object will provide implementations of various modular operations within the group. A cyclic.IntBuffer type will be created to store large batches of groups.
Index ¶
- Constants
- type Group
- func (g *Group) BytesInside(buffers ...[]byte) bool
- func (g Group) Exp(x, y, z *Int) *Int
- func (g Group) ExpG(y, z *Int) *Int
- func (g Group) FindSmallCoprimeInverse(z *Int, bitLen uint32) *Int
- func (g *Group) FullBytes(x *Int) []byte
- func (g *Group) GetFingerprint() uint64
- func (g *Group) GetFingerprintText() string
- func (g *Group) GetG() *large.Int
- func (g *Group) GetGCyclic() *Int
- func (g *Group) GetP() *large.Int
- func (g *Group) GetPBytes() []byte
- func (g *Group) GetPSub1() *Int
- func (g *Group) GetPSub1Cyclic() *Int
- func (g *Group) GetPSub1Factor() *large.Int
- func (g *Group) GetPSub1FactorCyclic() *Int
- func (g *Group) GobDecode(b []byte) error
- func (g *Group) GobEncode() ([]byte, error)
- func (g *Group) Inside(a *large.Int) bool
- func (g *Group) Inverse(a, b *Int) *Int
- func (g *Group) MarshalJSON() ([]byte, error)
- func (g Group) ModP(x *large.Int, z *Int) *Int
- func (g *Group) Mul(a, b, c *Int) *Int
- func (g Group) MulMulti(c *Int, ints ...*Int) *Int
- func (g *Group) NewInt(x int64) *Int
- func (g *Group) NewIntBuffer(length uint32, defaultValue *Int) *IntBuffer
- func (g *Group) NewIntFromBits(b large.Bits) *Int
- func (g *Group) NewIntFromBytes(buf []byte) *Int
- func (g *Group) NewIntFromLargeInt(x *large.Int) *Int
- func (g *Group) NewIntFromString(str string, base int) *Int
- func (g *Group) NewIntFromUInt(i uint64) *Int
- func (g *Group) NewMaxInt() *Int
- func (g *Group) OverwriteBits(x *Int, b large.Bits) *Int
- func (g *Group) Random(r *Int) *Int
- func (g *Group) RandomCoprime(r *Int) *Int
- func (g Group) RootCoprime(x, y, z *Int) *Int
- func (g *Group) Set(x, y *Int) *Int
- func (g *Group) SetBits(x *Int, b large.Bits) *Int
- func (g *Group) SetBytes(x *Int, buf []byte) *Int
- func (g *Group) SetLargeInt(x *Int, y *large.Int) *Int
- func (g *Group) SetMaxInt(x *Int) *Int
- func (g *Group) SetString(x *Int, s string, base int) *Int
- func (g *Group) SetUint64(x *Int, u uint64) *Int
- func (g *Group) UnmarshalJSON(b []byte) error
- type Int
- func (z *Int) BinaryDecode(b []byte) error
- func (z *Int) BinaryEncode() []byte
- func (z *Int) BitLen() int
- func (z *Int) Bits() large.Bits
- func (z *Int) ByteLen() int
- func (z *Int) Bytes() []byte
- func (z *Int) Cmp(x *Int) int
- func (z *Int) DeepCopy() *Int
- func (z *Int) Erase()
- func (z *Int) GetGroupFingerprint() uint64
- func (z *Int) GetLargeInt() *large.Int
- func (z *Int) GobDecode(in []byte) error
- func (z *Int) GobEncode() ([]byte, error)
- func (z *Int) LeftpadBytes(length uint64) []byte
- func (z *Int) MarshalJSON() ([]byte, error)
- func (z *Int) Reset()
- func (z *Int) Text(base int) string
- func (z *Int) TextVerbose(base int, length int) string
- func (z *Int) UnmarshalJSON(b []byte) error
- type IntBuffer
- func (ib *IntBuffer) Contains(index uint32) bool
- func (ib *IntBuffer) DeepCopy() *IntBuffer
- func (ib *IntBuffer) Erase()
- func (ib *IntBuffer) Get(index uint32) *Int
- func (ib *IntBuffer) GetFingerprint() uint64
- func (ib *IntBuffer) GetSubBuffer(begin, end uint32) *IntBuffer
- func (ib *IntBuffer) Len() int
Constants ¶
const GroupFingerprintSize = 8
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Group ¶
type Group struct {
// contains filtered or unexported fields
}
Groups provide cyclic int operations that keep the return values confined to a finite field under modulo p
func (*Group) BytesInside ¶
bytesInside returns true of the all the Ints represented by the byte slices are within the group, false if it isn't
func (Group) FindSmallCoprimeInverse ¶
func (*Group) GetFingerprint ¶
GetFingerprint gets the group's fingerprint
func (*Group) GetFingerprintText ¶
func (*Group) GetGCyclic ¶
GetGCyclic returns a new cyclicInt with the group's generator
func (*Group) GetPSub1Cyclic ¶
GetPSub1Cyclic returns a new cyclicInt with the group's p-1
func (*Group) GetPSub1Factor ¶
GetPSub1Factor returns a copy of the group's (p-1)/2
func (*Group) GetPSub1FactorCyclic ¶
GetPSub1FactorCyclic returns a new cyclicInt with the group's (p-1)/2
func (*Group) GobDecode ¶
GobDecode overwrites the receiver, which must be a pointer, with Group represented by the byte slice, which was written by GobEncode().
func (*Group) GobEncode ¶
GobEncode returns a byte slice representing the encoding of Group for the transmission to a GobDecode().
func (*Group) MarshalJSON ¶
MarshalJSON extracts prime, gen and primeQ to a json object. Returns the json object as a byte slice.
func (*Group) Mul ¶
Mul multiplies a and b within the group, putting the result in c and returning c
func (Group) MulMulti ¶
GroupMul Multiplies all ints in the passed slice slc together and places the result in c
func (*Group) NewIntBuffer ¶
NewIntBuffer is a constructor for IntBuffer if defaultValue is nil, it is set to the max value possible in the group, p-1
func (*Group) NewIntFromBits ¶
NewIntFromBits creates a new cyclic int from a words array This method doesn't copy the bits array, so if you need a copy, copy the array before passing it in
func (*Group) NewIntFromBytes ¶
NewIntFromBytes creates a new cyclicInt in the group from a byte buffer
func (*Group) NewIntFromLargeInt ¶
NewIntFromLargeInt creates a new cyclicInt in the group from a large.Int value
func (*Group) NewIntFromString ¶
NewIntFromString creates a new cyclicInt in the group from a string using the passed base returns nil if string cannot be parsed
func (*Group) NewIntFromUInt ¶
NewIntFromUInt creates a new cyclicInt in the group from an uint64 value
func (*Group) OverwriteBits ¶
OverwriteBits copies b over x. If there isn't enough memory available in x already, it allocates a new slice with enough memory Under no circumstance will b be the backing memory of the returned Int This is important for our usage of CGBN, which constantly overwrites the output memory
func (*Group) Random ¶
Random securely generates a random number in the group: 2 <= rand <= p-1 Sets r to the number and returns it
func (*Group) RandomCoprime ¶
RandomCoprime randomly generates coprimes in the group (coprime against g.prime-1)
func (Group) RootCoprime ¶
RootCoprime sets tmp = y√x mod p, and returns tmp. Only works with y's coprime with g.prime-1 (g.psub1)
func (*Group) SetBits ¶
SetBits sets x in the group to bits and returns x This method does not copy. If you need to set the number to a copy, please copy the bits outside of this.
func (*Group) SetLargeInt ¶
SetLargeInt sets x's value to y s.t. y is inside the group
func (*Group) SetString ¶
SetString sets x in the group to string and returns x or nil if error parsing the string
func (*Group) UnmarshalJSON ¶
Overwrites the receiver, which must be a pointer, with Group represented by the byte slice which contains encoded JSON data
type Int ¶
type Int struct {
// contains filtered or unexported fields
}
Create the cyclic.Int type as a wrapper of a large.Int and group fingerprint
func (*Int) BinaryDecode ¶
BinaryDecode decompresses the encoded byte slice to an Int.
func (*Int) BinaryEncode ¶
BinaryEncode encodes the Int into a compressed byte format.
func (*Int) Bits ¶
Bits gets the underlying word slice of cyclic int Use this for low-level functions where speed is critical For speed reasons, I don't copy here. This could allow the int to be set outside of the group
func (*Int) Cmp ¶
Compare two cyclicInts returns -2 if fingerprint differs returns value.Cmp otherwise
func (*Int) DeepCopy ¶
DeepCopy returns a complete copy of the cyclic int such that no underlying data is linked
func (*Int) Erase ¶
func (z *Int) Erase()
Erase overwrite all underlying data from a cyclic Int by setting its value and fingerprint to zero. All underlying released data will be removed by the garbage collector.
func (*Int) GetGroupFingerprint ¶
GetGroupFingerprint gets the group fingerprint from cyclicInt
func (*Int) GetLargeInt ¶
GetLargeInt gets a deepcopy of the largeInt from cyclicInt This is necessary because otherwise the internal value of the into could be edited and made to be outside the group.
func (*Int) LeftpadBytes ¶
LeftpadBytes gets left padded bytes of cyclicInt value
func (*Int) MarshalJSON ¶
MarshalJSON is a custom marshaling function for cyclic int. It is used when json.Marshal is called on a large int.
func (*Int) Text ¶
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 ints to a length of 10, appending an ellipsis if the int is too long. The group fingerprint is base64 encoded and also truncated z is then represented as: value... in GRP: fingerprint...
func (*Int) TextVerbose ¶
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 ints to a length of length in characters (not runes) and append 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. The group fingerprint is base64 encoded and also truncated z is then represented as: value... in GRP: fingerprint...
func (*Int) UnmarshalJSON ¶
UnmarshalJSON is a custom unmarshalling function for cyclic int. It is used when json.Unmarshal is called on a large int.
type IntBuffer ¶
type IntBuffer struct {
// contains filtered or unexported fields
}
Store the same group fingerprint for multiple values
func (*IntBuffer) Contains ¶
Contains checks that the index is within the amount of the values slice
func (*IntBuffer) Erase ¶
func (ib *IntBuffer) Erase()
Erase overwrites all underlying data from an IntBuffer by setting its values slice to nil and its fingerprint to zero. All underlying released data will be removed by the garbage collector.
func (*IntBuffer) GetFingerprint ¶
GetFingerprint gets the int buffer's group fingerprint
func (*IntBuffer) GetSubBuffer ¶
GetSubBuffer get an intBuffer representing a specific region in the int buffer