bbs

package
v0.0.0-...-15dc43f Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2024 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Overview

Package bbs implements the Blum-Blum-Shub pseudo-random number generator. The implementation should be considered to be insecure. x(n+1)=x(n)^2 mod (p*q). p,q are large primes, gcd(φ(p − 1), φ(q − 1)) should be small. p and q, should both be congruent to 3 (mod 4) initial seed xn should be neither 1 or 0, and not divisible by p or q. xi = x0^(2^i mod lcm(p-1,q-1)) mod p*q

Index

Constants

This section is empty.

Variables

View Source
var Rand = rand.Reader

Rand is the upstream random source for initialisation

View Source
var Reader io.Reader

Reader is a conveniance reader

Functions

func Params

func Params(bits int, lastStep int64) (p, q, x *big.Int, step int64)

Params generates new BBS params. bits is the number of bits that initial values should have (the more the better), step is the step to which the RNG should jump when using it like this: New(Params(bits,lastStep))

Types

type BBS

type BBS struct {
	X0 *big.Int // x at 0
	M  *big.Int // M = p*q
	L  *big.Int // lcm(p-1,q-1)

	Step    int64
	Maxbits int // log (bits M)
	// contains filtered or unexported fields
}

BBS contains the state of a Blum-Blum-Shub

func New

func New(p, q, x *big.Int, step int64) *BBS

New sets up a new BBS

func (*BBS) Bytes

func (bbs *BBS) Bytes(n int) []byte

Bytes returns n bytes of random data from the generator

func (*BBS) BytesAt

func (bbs *BBS) BytesAt(n int64, m int) []byte

BytesAt returns m bytes from position xn. This moves the whole generator to n.

func (*BBS) Read

func (bbs *BBS) Read(p []byte) (n int, err error)

Read implements BBS as io.Reader as drop-in RNG

Jump to

Keyboard shortcuts

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