utils

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2020 License: Apache-2.0 Imports: 9 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrLessOrEqualBig2 is returned if the field order is less than or equal to 2
	ErrLessOrEqualBig2 = errors.New("less 2")
	//ErrExceedMaxRetry is returned if we retried over times
	ErrExceedMaxRetry = errors.New("exceed max retries")
	//ErrInvalidInput is returned if the input is invalid
	ErrInvalidInput = errors.New("invalid input")
	//ErrLargeRank is returned if the rank is too large
	ErrLargeRank = errors.New("large rank")
	//ErrLargeThreshold is returned if the threshold is too large
	ErrLargeThreshold = errors.New("large threshold")
	// ErrNotInRange is returned if the value is not in the given range.
	ErrNotInRange = errors.New("not in range")
	// ErrLargerFloor is returned if the floor is larger than ceil.
	ErrLargerFloor = errors.New("larger floor")
	// ErrEmptySlice is returned if the length of slice is zero.
	ErrEmptySlice = errors.New("empty slice")
)

Functions

func EnsureFieldOrder

func EnsureFieldOrder(fieldOrder *big.Int) error

EnsureFieldOrder ensures the field order should be more than 2.

func EnsureRank

func EnsureRank(rank uint32, threshold uint32) error

EnsureRank ensures the rank should be smaller than threshold.

func EnsureThreshold

func EnsureThreshold(threshold uint32, n uint32) error

EnsureThreshold ensures the threshold should be smaller than or equal to n.

func EulerFunction

func EulerFunction(primeFactor []*big.Int) (*big.Int, error)

EulerFunction :(Special case) Assume that N is square-free and primeFactor consists of prime integers. Formula: N = prod_i P_i, the output is prod_i (P_i -1). TODO: general case.

func Gcd

func Gcd(a *big.Int, b *big.Int) *big.Int

Gcd calculates greatest common divisor (GCD) via Euclidean algorithm

func GenRandomBytes

func GenRandomBytes(size int) ([]byte, error)

GenRandomBytes generates a random byte array with indicating the legnth.

func HashProtos

func HashProtos(blake2bKey []byte, fieldOrder *big.Int, msgs ...proto.Message) (*big.Int, error)

HashProtos hashes a slice of message to a field.

func InRange

func InRange(checkValue *big.Int, floor *big.Int, ceil *big.Int) error

InRange checks if the checkValue is in [floor, ceil).

func IsRelativePrime

func IsRelativePrime(a *big.Int, b *big.Int) bool

IsRelativePrime returns if a and b are relative primes

func Lcm

func Lcm(a, b *big.Int) (*big.Int, error)

Lcm calculates find Least Common Multiple https://rosettacode.org/wiki/Least_common_multiple#Go

func RandomCoprimeInt

func RandomCoprimeInt(n *big.Int) (*big.Int, error)

RandomCoprimeInt generates a random relative prime number in [2, n)

func RandomInt

func RandomInt(n *big.Int) (*big.Int, error)

RandomInt generates a random number in [0, n).

func RandomPositiveInt

func RandomPositiveInt(n *big.Int) (*big.Int, error)

RandomPositiveInt generates a random number in [1, n).

func RandomPrime

func RandomPrime(bits int) (*big.Int, error)

RandomPrime generates a random prime number with bits size

Types

type Hash

type Hash struct {
	Msgs                 []*any.Any `protobuf:"bytes,1,rep,name=msgs,proto3" json:"msgs,omitempty"`
	XXX_NoUnkeyedLiteral struct{}   `json:"-"`
	XXX_unrecognized     []byte     `json:"-"`
	XXX_sizecache        int32      `json:"-"`
}

func (*Hash) Descriptor

func (*Hash) Descriptor() ([]byte, []int)

func (*Hash) GetMsgs

func (m *Hash) GetMsgs() []*any.Any

func (*Hash) ProtoMessage

func (*Hash) ProtoMessage()

func (*Hash) Reset

func (m *Hash) Reset()

func (*Hash) String

func (m *Hash) String() string

func (*Hash) XXX_DiscardUnknown

func (m *Hash) XXX_DiscardUnknown()

func (*Hash) XXX_Marshal

func (m *Hash) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Hash) XXX_Merge

func (m *Hash) XXX_Merge(src proto.Message)

func (*Hash) XXX_Size

func (m *Hash) XXX_Size() int

func (*Hash) XXX_Unmarshal

func (m *Hash) XXX_Unmarshal(b []byte) error

Jump to

Keyboard shortcuts

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