cyclic

package
v0.0.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 6, 2023 License: BSD-2-Clause Imports: 10 Imported by: 63

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

View Source
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 NewGroup

func NewGroup(p, g *large.Int) *Group

NewGroup returns a group with the given prime and generator

func (*Group) BytesInside

func (g *Group) BytesInside(buffers ...[]byte) bool

bytesInside returns true of the all the Ints represented by the byte slices are within the group, false if it isn't

func (Group) Exp

func (g Group) Exp(x, y, z *Int) *Int

Exp sets z = x**y mod p, and returns z.

func (Group) ExpG

func (g Group) ExpG(y, z *Int) *Int

ExpG sets z = g**y mod p, and returns z.

func (Group) FindSmallCoprimeInverse

func (g Group) FindSmallCoprimeInverse(z *Int, bitLen uint32) *Int

func (*Group) FullBytes

func (g *Group) FullBytes(x *Int) []byte

FullBytes gets cyclicInt left-padded to the size of the prime

func (*Group) GetFingerprint

func (g *Group) GetFingerprint() uint64

GetFingerprint gets the group's fingerprint

func (*Group) GetFingerprintText

func (g *Group) GetFingerprintText() string

func (*Group) GetG

func (g *Group) GetG() *large.Int

GetG returns a copy of the group's generator

func (*Group) GetGCyclic

func (g *Group) GetGCyclic() *Int

GetGCyclic returns a new cyclicInt with the group's generator

func (*Group) GetP

func (g *Group) GetP() *large.Int

GetP returns a copy of the group's prime

func (*Group) GetPBytes

func (g *Group) GetPBytes() []byte

GetPBytes returns a copy of the group's prime bytes

func (*Group) GetPSub1

func (g *Group) GetPSub1() *Int

GetPSub1 returns a copy of the group's p-1

func (*Group) GetPSub1Cyclic

func (g *Group) GetPSub1Cyclic() *Int

GetPSub1Cyclic returns a new cyclicInt with the group's p-1

func (*Group) GetPSub1Factor

func (g *Group) GetPSub1Factor() *large.Int

GetPSub1Factor returns a copy of the group's (p-1)/2

func (*Group) GetPSub1FactorCyclic

func (g *Group) GetPSub1FactorCyclic() *Int

GetPSub1FactorCyclic returns a new cyclicInt with the group's (p-1)/2

func (*Group) GobDecode

func (g *Group) GobDecode(b []byte) error

GobDecode overwrites the receiver, which must be a pointer, with Group represented by the byte slice, which was written by GobEncode().

func (*Group) GobEncode

func (g *Group) GobEncode() ([]byte, error)

GobEncode returns a byte slice representing the encoding of Group for the transmission to a GobDecode().

func (*Group) Inside

func (g *Group) Inside(a *large.Int) bool

Inside returns true of the Int is within the group, false if it isn't

func (*Group) Inverse

func (g *Group) Inverse(a, b *Int) *Int

Inverse sets b equal to the inverse of a within the group and returns b

func (*Group) MarshalJSON

func (g *Group) MarshalJSON() ([]byte, error)

MarshalJSON extracts prime, gen and primeQ to a json object. Returns the json object as a byte slice.

func (Group) ModP

func (g Group) ModP(x *large.Int, z *Int) *Int

ModP sets z ≡ x mod prime within the group and returns z.

func (*Group) Mul

func (g *Group) Mul(a, b, c *Int) *Int

Mul multiplies a and b within the group, putting the result in c and returning c

func (Group) MulMulti

func (g Group) MulMulti(c *Int, ints ...*Int) *Int

GroupMul Multiplies all ints in the passed slice slc together and places the result in c

func (*Group) NewInt

func (g *Group) NewInt(x int64) *Int

NewInt creates a new cyclicInt in the group from an int64 value

func (*Group) NewIntBuffer

func (g *Group) NewIntBuffer(length uint32, defaultValue *Int) *IntBuffer

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

func (g *Group) NewIntFromBits(b large.Bits) *Int

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

func (g *Group) NewIntFromBytes(buf []byte) *Int

NewIntFromBytes creates a new cyclicInt in the group from a byte buffer

func (*Group) NewIntFromLargeInt

func (g *Group) NewIntFromLargeInt(x *large.Int) *Int

NewIntFromLargeInt creates a new cyclicInt in the group from a large.Int value

func (*Group) NewIntFromString

func (g *Group) NewIntFromString(str string, base int) *Int

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

func (g *Group) NewIntFromUInt(i uint64) *Int

NewIntFromUInt creates a new cyclicInt in the group from an uint64 value

func (*Group) NewMaxInt

func (g *Group) NewMaxInt() *Int

NewMaxInt creates a new cyclicInt in the group at the max group value

func (*Group) OverwriteBits

func (g *Group) OverwriteBits(x *Int, b large.Bits) *Int

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

func (g *Group) Random(r *Int) *Int

Random securely generates a random number in the group: 2 <= rand <= p-1 Sets r to the number and returns it

func (*Group) RandomCoprime

func (g *Group) RandomCoprime(r *Int) *Int

RandomCoprime randomly generates coprimes in the group (coprime against g.prime-1)

func (Group) RootCoprime

func (g Group) RootCoprime(x, y, z *Int) *Int

RootCoprime sets tmp = y√x mod p, and returns tmp. Only works with y's coprime with g.prime-1 (g.psub1)

func (*Group) Set

func (g *Group) Set(x, y *Int) *Int

Set sets x to y in the group and returns x

func (*Group) SetBits

func (g *Group) SetBits(x *Int, b large.Bits) *Int

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) SetBytes

func (g *Group) SetBytes(x *Int, buf []byte) *Int

SetBytes sets x in the group to bytes and returns x

func (*Group) SetLargeInt

func (g *Group) SetLargeInt(x *Int, y *large.Int) *Int

SetLargeInt sets x's value to y s.t. y is inside the group

func (*Group) SetMaxInt

func (g *Group) SetMaxInt(x *Int) *Int

SetMaxInt sets x in the group to Max4KInt value and returns x

func (*Group) SetString

func (g *Group) SetString(x *Int, s string, base int) *Int

SetString sets x in the group to string and returns x or nil if error parsing the string

func (*Group) SetUint64

func (g *Group) SetUint64(x *Int, u uint64) *Int

SetUint64 sets x in the group to uint64 value and returns x

func (*Group) UnmarshalJSON

func (g *Group) UnmarshalJSON(b []byte) error

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

func (z *Int) BinaryDecode(b []byte) error

BinaryDecode decompresses the encoded byte slice to an Int.

func (*Int) BinaryEncode

func (z *Int) BinaryEncode() []byte

BinaryEncode encodes the Int into a compressed byte format.

func (*Int) BitLen

func (z *Int) BitLen() int

BitLen gets the length of the cyclic int

func (*Int) Bits

func (z *Int) Bits() large.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) ByteLen

func (z *Int) ByteLen() int

ByteLen gets the byte length of cyclic int

func (*Int) Bytes

func (z *Int) Bytes() []byte

Bytes gets the bytes of cyclicInt value

func (*Int) Cmp

func (z *Int) Cmp(x *Int) int

Compare two cyclicInts returns -2 if fingerprint differs returns value.Cmp otherwise

func (*Int) DeepCopy

func (z *Int) DeepCopy() *Int

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

func (z *Int) GetGroupFingerprint() uint64

GetGroupFingerprint gets the group fingerprint from cyclicInt

func (*Int) GetLargeInt

func (z *Int) GetLargeInt() *large.Int

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) GobDecode

func (z *Int) GobDecode(in []byte) error

GOB decode bytes to cyclicInt

func (*Int) GobEncode

func (z *Int) GobEncode() ([]byte, error)

GOB encode cyclicInt to bytes

func (*Int) LeftpadBytes

func (z *Int) LeftpadBytes(length uint64) []byte

LeftpadBytes gets left padded bytes of cyclicInt value

func (*Int) MarshalJSON

func (z *Int) MarshalJSON() ([]byte, error)

MarshalJSON is a custom marshaling function for cyclic int. It is used when json.Marshal is called on a large int.

func (*Int) Reset

func (z *Int) Reset()

Reset cyclicInt to 1

func (*Int) Text

func (z *Int) Text(base int) string

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

func (z *Int) TextVerbose(base int, length int) string

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

func (z *Int) UnmarshalJSON(b []byte) error

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

func (ib *IntBuffer) Contains(index uint32) bool

Contains checks that the index is within the amount of the values slice

func (*IntBuffer) DeepCopy

func (ib *IntBuffer) DeepCopy() *IntBuffer

DeepCopy gets a deep copy of an intBuffer

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) Get

func (ib *IntBuffer) Get(index uint32) *Int

Get gets the cyclic int at a specific index in the int buffer

func (*IntBuffer) GetFingerprint

func (ib *IntBuffer) GetFingerprint() uint64

GetFingerprint gets the int buffer's group fingerprint

func (*IntBuffer) GetSubBuffer

func (ib *IntBuffer) GetSubBuffer(begin, end uint32) *IntBuffer

GetSubBuffer get an intBuffer representing a specific region in the int buffer

func (*IntBuffer) Len

func (ib *IntBuffer) Len() int

Len gets the length of the int buffer

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL