utils

package
v3.0.5 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2022 License: Apache-2.0 Imports: 5 Imported by: 20

Documentation

Overview

Package utils contains helper structures and function

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllDistinct

func AllDistinct(s []uint64) bool

AllDistinct returns true if all elements in s are distinct, and false otherwise.

func BitReverse64

func BitReverse64(index, bitLen uint64) uint64

BitReverse64 returns the bit-reverse value of the input value, within a context of 2^bitLen.

func EqualSliceInt64

func EqualSliceInt64(a, b []int64) (v bool)

EqualSliceInt64 checks the equality between two int64 slices.

func EqualSliceUint64

func EqualSliceUint64(a, b []uint64) (v bool)

EqualSliceUint64 checks the equality between two uint64 slices.

func EqualSliceUint8

func EqualSliceUint8(a, b []uint8) (v bool)

EqualSliceUint8 checks the equality between two uint8 slices.

func HammingWeight64

func HammingWeight64(x uint64) uint64

HammingWeight64 returns the hammingweight if the input value.

func IsInSliceInt

func IsInSliceInt(x int, slice []int) (v bool)

IsInSliceInt checks if x is in slice.

func IsInSliceUint64

func IsInSliceUint64(x uint64, slice []uint64) (v bool)

IsInSliceUint64 checks if x is in slice.

func MaxFloat64

func MaxFloat64(a, b float64) (r float64)

MaxFloat64 returns the maximum value of the input slice of float64 values.

func MaxInt

func MaxInt(a, b int) (r int)

MaxInt returns the maximum value of the input of int values.

func MaxSliceUint64

func MaxSliceUint64(slice []uint64) (max uint64)

MaxSliceUint64 returns the maximum value of the input slice of uint64 values.

func MaxUint64

func MaxUint64(a, b uint64) (r uint64)

MaxUint64 returns the maximum value of the input slice of uint64 values.

func MinInt

func MinInt(a, b int) (r int)

MinInt returns the minimum value of the input of int values.

func MinUint64

func MinUint64(a, b uint64) (r uint64)

MinUint64 returns the minimum value of the input of uint64 values.

func RandComplex128

func RandComplex128(min, max float64) complex128

RandComplex128 returns a random complex with the real and imaginary part between min and max

func RandFloat64

func RandFloat64(min, max float64) float64

RandFloat64 returns a random float between min and max

func RandUint64

func RandUint64() uint64

RandUint64 return a random value between 0 and 0xFFFFFFFFFFFFFFFF

func RotateComplex128Slice

func RotateComplex128Slice(s []complex128, k int) []complex128

RotateComplex128Slice returns a new slice corresponding to s rotated by k positions to the left.

func RotateFloat64Slice

func RotateFloat64Slice(s []float64, k int) []float64

RotateFloat64Slice returns a new slice corresponding to s rotated by k positions to the left.

func RotateInt64Slice

func RotateInt64Slice(s []int64, k int) []int64

RotateInt64Slice returns a new slice corresponding to s rotated by k positions to the left.

func RotateSlice

func RotateSlice(s interface{}, k int) interface{}

RotateSlice takes as input an interface slice and returns a new interface slice corresponding to s rotated by k positions to the left. s.(type) can be either []complex128, []float64, []uint64 or []int64.

func RotateUint64Slice

func RotateUint64Slice(s []uint64, k int) []uint64

RotateUint64Slice returns a new slice corresponding to s rotated by k positions to the left.

func RotateUint64Slots

func RotateUint64Slots(s []uint64, k int) []uint64

RotateUint64Slots returns a new slice corresponding to s where each half of the slice have been rotated by k positions to the left.

Types

type Buffer

type Buffer struct {
	// contains filtered or unexported fields
}

Buffer is a simple wrapper around a []byte to facilitate efficient marshaling of lattigo's objects

func NewBuffer

func NewBuffer(s []byte) *Buffer

NewBuffer creates a new buffer from the provided backing slice

func (*Buffer) Bytes

func (b *Buffer) Bytes() []byte

Bytes creates a new byte buffer

func (*Buffer) ReadUint64

func (b *Buffer) ReadUint64() uint64

ReadUint64 reads an uint64 from the target byte buffer.

func (*Buffer) ReadUint64Slice

func (b *Buffer) ReadUint64Slice(rec []uint64)

ReadUint64Slice reads an uint64 slice from the target byte buffer.

func (*Buffer) ReadUint8

func (b *Buffer) ReadUint8() byte

ReadUint8 reads an uint8 from the target byte buffer.

func (*Buffer) ReadUint8Slice

func (b *Buffer) ReadUint8Slice(rec []uint8)

ReadUint8Slice reads an uint8 slice from the target byte buffer.

func (*Buffer) WriteUint64

func (b *Buffer) WriteUint64(v uint64)

WriteUint64 writes an uint64 on the target byte buffer.

func (*Buffer) WriteUint64Slice

func (b *Buffer) WriteUint64Slice(s []uint64)

WriteUint64Slice writes an uint64 slice on the target byte buffer.

func (*Buffer) WriteUint8

func (b *Buffer) WriteUint8(c byte)

WriteUint8 writes an uint8 on the target byte buffer.

func (*Buffer) WriteUint8Slice

func (b *Buffer) WriteUint8Slice(s []uint8)

WriteUint8Slice writes an uint8 slice on the target byte buffer.

type KeyedPRNG

type KeyedPRNG struct {
	// contains filtered or unexported fields
}

KeyedPRNG is a structure storing the parameters used to securely and deterministically generate shared sequences of random bytes among different parties using the hash function blake2b. Backward sequence security (given the digest i, compute the digest i-1) is ensured by default, however forward sequence security (given the digest i, compute the digest i+1) is only ensured if the KeyedPRNG is keyed.

func NewKeyedPRNG

func NewKeyedPRNG(key []byte) (*KeyedPRNG, error)

NewKeyedPRNG creates a new instance of KeyedPRNG. Accepts an optional key, else set key=nil which is treated as key=[]byte{} WARNING: A PRNG INITIALISED WITH key=nil IS INSECURE!

func NewPRNG

func NewPRNG() (*KeyedPRNG, error)

NewPRNG creates KeyedPRNG keyed from rand.Read for instances were no key should be provided by the user

func (*KeyedPRNG) Clock

func (prng *KeyedPRNG) Clock(sum []byte)

Clock reads bytes from the KeyedPRNG on sum.

func (*KeyedPRNG) GetClock

func (prng *KeyedPRNG) GetClock() uint64

GetClock returns the value of the clock cycle of the KeyedPRNG.

func (*KeyedPRNG) SetClock

func (prng *KeyedPRNG) SetClock(sum []byte, n uint64) error

SetClock sets the clock cycle of the KeyedPRNG to a given number by calling Clock until the clock cycle reaches the desired number. Returns an error if the target clock cycle is smaller than the current clock cycle.

type PRNG

type PRNG interface {
	Clock(sum []byte)
	GetClock() uint64
	SetClock(sum []byte, n uint64) error
}

PRNG is an interface for secure (keyed) deterministic generation of random bytes

Jump to

Keyboard shortcuts

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