slowrand

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2023 License: MIT Imports: 6 Imported by: 0

README

slowrand

build-img pkg-img reportcard-img coverage-img version-img

Slow deterministic random generator.

Rationale

Some problems might require random deterministic generator, but this might be problematic due to brute-force attacks. This (deterministic) random generator addresses this problem by increasing it's work time.

Note

Inspired by cornfeedhobo/ssh-keydgen

Features

  • Slow
  • Deterministic
  • Random
  • Dependency-free

Install

Go version 1.15+

go get github.com/cristalhq/slowrand

Example

seed := []byte("some-secure-seed")
rounds := 3
time := uint32(5)
memory := uint32(7)
threads := uint8(11)

r, err := slowrand.New(seed, rounds, time, memory, threads)
if err != nil {
    t.Fatal(err)
}

var buf [42]byte
n, err := r.Read(buf[:])
if n != 42 {
    panic("not 42")
}
_ = err // is always nil

Documentation

See these docs.

License

MIT License.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Reader

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

Reader represents a deterministic rand source from seed. Slowness is a feature to prevent brute-force attack.

func New

func New(seed []byte, rounds int, time, memory uint32, threads uint8) (*Reader, error)

New instance of slow reader. Seed as a start of the pseudorandom sequence. Rounds, time, memory and threads are params to the underlying PBKDF2 & Argon2 algorithms.

func (*Reader) Len

func (r *Reader) Len() int

Len returns number of read bytes.

func (*Reader) Read

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

Jump to

Keyboard shortcuts

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