utils

package
v0.0.0-...-e525fad Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

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 GCD

func GCD(a, b uint64) uint64

GCD computes the greatest common divisor gcd(a,b) for a,b uint64 variables.

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 RotateUint64SliceAllocFree

func RotateUint64SliceAllocFree(s []uint64, k int, sout []uint64)

RotateUint64SliceAllocFree rotates slice s by k positions to the left and writes the result in sout. without allocating new memory.

func RotateUint64SliceInPlace

func RotateUint64SliceInPlace(s []uint64, k int)

RotateUint64SliceInPlace rotates slice s in place 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) Read

func (prng *KeyedPRNG) Read(sum []byte) (n int, err error)

Read reads bytes from the KeyedPRNG on sum.

func (*KeyedPRNG) Reset

func (prng *KeyedPRNG) Reset()

Reset resets the PRNG to its initial state.

type PRNG

type PRNG interface {
	io.Reader
}

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