utils

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2022 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const FileChunk = 1 * (1 << 20) // 1 MB, change this to your requirement
View Source
const G = M * 1024
View Source
const M = 1024 * 1034

Variables

View Source
var Reader rngReader

Reader is a global, shared instance of a cryptographically strong pseudo- random generator. Reader is safe for concurrent use by multiple goroutines.

Functions

func BigIntn

func BigIntn(n *big.Int) *big.Int

BigIntn returns a uniform random *big.Int in [0,n). It panics if n <= 0.

func ByteArrayToInt

func ByteArrayToInt(arr []byte) int

func ByteArrayToInt16

func ByteArrayToInt16(arr []byte) int16

func ByteArrayToInt32

func ByteArrayToInt32(arr []byte) int32

func ByteArrayToInt64

func ByteArrayToInt64(arr []byte) int64

func Bytes

func Bytes(n int) []byte

Bytes is a helper function that allocates and returns n bytes of random data.

func CreateRamdisk

func CreateRamdisk(diskSize int) (mountVolume string)

func DestroyRamdisk

func DestroyRamdisk(mountPoint string)

func DumpFileToScreen

func DumpFileToScreen(fileName string)

func EightByteArrayToInt

func EightByteArrayToInt(arr []byte) int

func EightByteArrayToInt32

func EightByteArrayToInt32(arr []byte) int32

func Entropy128

func Entropy128() [16]byte

Entropy128 is a helper function that returns 128 bits of random data.

func Entropy192

func Entropy192() [24]byte

Entropy192 is a helper function that returns 192 bits of random data.

func Entropy256

func Entropy256() [32]byte

Entropy256 is a helper function that returns 256 bits of random data.

func FileExists

func FileExists(path string) bool

func Float64

func Float64() float64

Float64 returns a random float64 in [0,1).

func GenerateRandomPin added in v1.1.1

func GenerateRandomPin() string

func GenerateSeed

func GenerateSeed(key string, nonce int32) (seed int32)

func GenerateSeed32Bytes

func GenerateSeed32Bytes(key string, nonce int32) (seed []byte)

func GenerateSeedAndNonce

func GenerateSeedAndNonce(key string) (seed, nonce int32)

func GenerateSeedAndNonce32Bytes

func GenerateSeedAndNonce32Bytes(key string) (seed []byte, nonce int32)

func GetCiphers

func GetCiphers(data ecdata) (ciphers [][]int)

func GetDefaultMountPoint

func GetDefaultMountPoint() string

func GetNonce

func GetNonce(data ecdata) (nonce int32)

func GetRandomName added in v1.1.1

func GetRandomName() string

func GetRandomNameWithPin added in v1.1.1

func GetRandomNameWithPin() string

GetRandomName returns mnemonicoded random name

func GetRandomName_Sized added in v1.1.1

func GetRandomName_Sized(size int) (rname string)

func InitMountPoint

func InitMountPoint()

func Int16ToByteArray

func Int16ToByteArray(num int16) []byte

func Int32ToByteArray

func Int32ToByteArray(num int32) []byte

func Int64ToByteArray

func Int64ToByteArray(num int64) []byte

func IntToByteArray

func IntToByteArray(num int) []byte

func Intn

func Intn(n int) int

Intn returns a uniform random int in [0,n). It panics if n <= 0.

func Join

func Join(chunksdir string, joinedfile string)

func MakeRamdisk added in v1.1.0

func MakeRamdisk(diskSize int64) (mountVolume string)

func Perm

func Perm(n int) []int

Perm returns a random permutation of the integers [0,n). It panics if n < 0.

func Read

func Read(b []byte) (int, error)

Read fills b with random data. It always returns len(b), nil.

func ReadCipherData

func ReadCipherData(filename string) (data ecdata)

func SetDefaultMountPoint

func SetDefaultMountPoint(mountpoint string)

func Shuffle

func Shuffle(n int, swap func(i, j int))

Shuffle randomly permutes n elements by repeatedly calling swap in the range [0,n). It panics if n < 0.

func Split

func Split(fileToBeChunked string) (chunksdir string)

func Uint64n

func Uint64n(n uint64) uint64

Uint64n returns a uniform random uint64 in [0,n). It panics if n == 0.

func WriteByteArray

func WriteByteArray(data []byte, filename string)

func WriteCipherData

func WriteCipherData(nonce int32, ciphers *[][]int, filename string)

func WriteIndexArray

func WriteIndexArray(cipherindicies []int, filename string)

func WriteIndexArrays

func WriteIndexArrays(ciphers [][]int, filename string)

func WriteNonce

func WriteNonce(nonce int32, filename string)

Types

type AdditiveCongruential

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

func CreateAdditiveCongruential

func CreateAdditiveCongruential(seed int32) AdditiveCongruential

func (*AdditiveCongruential) Random

func (rng *AdditiveCongruential) Random(r int32) int32

type Frand

type Frand struct {
	Csprng *mrand.Rand
}

func CreateFrand

func CreateFrand(seed int64) Frand

type RNG

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

An RNG is a cryptographically-strong RNG constructed from the ChaCha stream cipher.

func New

func New() *RNG

New returns a new RNG instance. The instance is seeded with entropy from crypto/rand, albeit indirectly; its seed is generated by a global "master" RNG, which itself is seeded from crypto/rand. This means the frand package only reads system entropy once, at startup.

func NewCustom

func NewCustom(seed []byte, bufsize int, rounds int) *RNG

NewCustom returns a new RNG instance seeded with the provided entropy and using the specified buffer size and number of ChaCha rounds. It panics if len(seed) != 32, bufsize < 32, or rounds != 8, 12 or 20.

func (*RNG) BigIntn

func (r *RNG) BigIntn(n *big.Int) *big.Int

BigIntn returns a uniform random *big.Int in [0,n). It panics if n <= 0.

func (*RNG) Bytes

func (r *RNG) Bytes(n int) []byte

Bytes is a helper function that allocates and returns n bytes of random data.

func (*RNG) Entropy128

func (r *RNG) Entropy128() (entropy [16]byte)

Entropy128 is a helper function that returns 128 bits of random data.

func (*RNG) Entropy192

func (r *RNG) Entropy192() (entropy [24]byte)

Entropy192 is a helper function that returns 192 bits of random data.

func (*RNG) Entropy256

func (r *RNG) Entropy256() (entropy [32]byte)

Entropy256 is a helper function that returns 256 bits of random data.

func (*RNG) Float64

func (r *RNG) Float64() float64

Float64 returns a random float64 in [0,1).

func (*RNG) Intn

func (r *RNG) Intn(n int) int

Intn returns a uniform random int in [0,n). It panics if n <= 0.

func (*RNG) Perm

func (r *RNG) Perm(n int) []int

Perm returns a random permutation of the integers [0,n). It panics if n < 0.

func (*RNG) Read

func (r *RNG) Read(b []byte) (int, error)

Read fills b with random data. It always returns len(b), nil.

For performance reasons, calling Read once on a "large" buffer (larger than the RNG's internal buffer) will produce different output than calling Read multiple times on smaller buffers. If deterministic output is required, clients should call Read in a loop; when copying to an io.Writer, use io.CopyBuffer instead of io.Copy. Callers should also be aware that b is xored with random data, not directly overwritten; this means that the new contents of b depend on its previous contents.

func (*RNG) Shuffle

func (r *RNG) Shuffle(n int, swap func(i, j int))

Shuffle randomly permutes n elements by repeatedly calling swap in the range [0,n). It panics if n < 0.

func (*RNG) Uint64n

func (r *RNG) Uint64n(n uint64) uint64

Uint64n returns a uniform random uint64 in [0,n). It panics if n == 0.

type Source

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

A Source is a math/rand-compatible source of entropy. It is safe for concurrent use by multiple goroutines

func NewSource

func NewSource() *Source

NewSource returns a source for use with the math/rand package.

func (*Source) Int63

func (s *Source) Int63() int64

Int63 returns a non-negative random 63-bit integer as an int64.

func (*Source) Seed

func (s *Source) Seed(i int64)

Seed uses the provided seed value to initialize the Source to a deterministic state.

func (*Source) Uint64

func (s *Source) Uint64() uint64

Uint64 returns a random 64-bit integer.

Jump to

Keyboard shortcuts

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