pnc

package module
v0.0.0-...-ebe53a7 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2014 License: MIT Imports: 6 Imported by: 0

README

pnc

A library of pseudorandom number generators (PRNGs), ideal for playing with cryptography. These are not built to be secure and will get you hacked if deployed in a real system.

pnc contains standalone, clean implementations. You should be able to:

  • Generate numbers as part of a larger system.
  • Attack third-party generators to recover their internal state.
  • Understand and modify the code to better understand how the generators work.

Usage

Install Golang on your machine.

Run go get github.com/46bit/pnc to fetch the code.

Try the examples in $GOPATH/github.com/46bit/pnc/examples.

Generators implemented

  • Mersenne Twister [1, 2], an incredibly common, insecure PRNG.
  • Linear Congruential Generator [1], a common but defective PRNG.
  • Tausworthe Generator [1, 2], a weak PRNG once used in slot machines.
  • Blum Blum Shub [1, 2], a CSPRNG secured by integer factorisation.
  • Blum Micali [1], a CSPRNG secured by the discrete-logarithm problem (DLP).
  • Dual EC DRBG [1, 2, 3], a famously backdoored CSPRNG secured by elliptic curve DLP.

About

Built by Michael Mokrysz from December 2013. Licensed under MIT and formerly known as Pinocchio.

Documentation

Index

Constants

View Source
const (
	L = 32
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BlumBlumShub

type BlumBlumShub struct {
	P    *big.Int
	Q    *big.Int
	M    *big.Int
	Term *big.Int
}

func NewBlumBlumShub

func NewBlumBlumShub() BlumBlumShub

func (*BlumBlumShub) Bit

func (b *BlumBlumShub) Bit() uint32

func (*BlumBlumShub) Seed

func (b *BlumBlumShub) Seed(p *big.Int, q *big.Int, s *big.Int)

p: large prime congruent to 3 mod 4, with small gcd(φ(p-1), φ(q-1)) q: large prime congruent to 3 mod 4, with small gcd(φ(p-1), φ(q-1)) s: integer coprime to M=PQ, not 0 or 1

func (*BlumBlumShub) Urand32

func (b *BlumBlumShub) Urand32() uint32

We generate uint32 from the LSB of 32 terms. Therefore the periodicity really needs to be a large multiple of that. @TODO: determine bits we can extract using http://www.win.tue.nl/~berry/papers/ima05bbs.pdf @TODO: refactor PRNGs to output specified n bits as opposed to uint32.

type BlumMicali

type BlumMicali struct {
	P    *big.Int
	G    *big.Int
	Term *big.Int
}

func NewBlumMicali

func NewBlumMicali() BlumMicali

func (*BlumMicali) Bit

func (b *BlumMicali) Bit() uint32

func (*BlumMicali) Seed

func (b *BlumMicali) Seed(p *big.Int, g *big.Int, s *big.Int)

p: large prime g: primitive root modulo p

func (*BlumMicali) Urand32

func (b *BlumMicali) Urand32() uint32

type DualECDRBG

type DualECDRBG struct {
	C *ec.PrimeCurve
	Q *ec.Point

	S  *big.Int
	Sp *ec.Point
	Z  *big.Int
	Zp *ec.Point

	ZBytes     []byte
	StateIndex uint64
	StateBit   uint32
}

func NewDualECDRBG

func NewDualECDRBG(c *ec.PrimeCurve, qx, qy, seed *big.Int) *DualECDRBG

func (*DualECDRBG) Bit

func (g *DualECDRBG) Bit() uint32

func (*DualECDRBG) Byte

func (g *DualECDRBG) Byte() byte

func (*DualECDRBG) Bytes

func (g *DualECDRBG) Bytes(length uint32) []byte

func (*DualECDRBG) Selfcheck

func (g *DualECDRBG) Selfcheck() error

func (*DualECDRBG) Urand32

func (g *DualECDRBG) Urand32() uint32

type LCG

type LCG struct {
	State      uint32
	StateBit   uint32
	StateIndex uint64
}

func NewLCG

func NewLCG() LCG

func (*LCG) Bit

func (l *LCG) Bit() uint32

func (*LCG) Seed

func (l *LCG) Seed(seed uint32)

func (*LCG) Urand32

func (l *LCG) Urand32() uint32

type MersenneTwister

type MersenneTwister struct {
	State [mersenne_twister_n]uint32
	// contains filtered or unexported fields
}

func NewMersenneTwister

func NewMersenneTwister(seed uint32) MersenneTwister

func (*MersenneTwister) SeedFromUrand32s

func (m *MersenneTwister) SeedFromUrand32s(urand32s [mersenne_twister_n]uint32)

func (*MersenneTwister) Urand32

func (m *MersenneTwister) Urand32() uint32

func (*MersenneTwister) Urand32ToState

func (m *MersenneTwister) Urand32ToState(urand32 uint32) uint32

type TauswortheGenerator

type TauswortheGenerator struct {
	Registers  [lfsr_width]uint32
	StateBit   uint32
	StateIndex uint64
}

func NewTauswortheGenerator

func NewTauswortheGenerator() TauswortheGenerator

func NewTauswortheGeneratorFromJSON

func NewTauswortheGeneratorFromJSON(tg_json []byte) (TauswortheGenerator, error)

func NewTauswortheGeneratorFromJSONFile

func NewTauswortheGeneratorFromJSONFile(jpath string) (TauswortheGenerator, error)

func (*TauswortheGenerator) AsJSON

func (t *TauswortheGenerator) AsJSON() ([]byte, error)

func (*TauswortheGenerator) Bit

func (t *TauswortheGenerator) Bit() uint32

func (*TauswortheGenerator) Seed

func (t *TauswortheGenerator) Seed(seed uint32)

func (*TauswortheGenerator) Urand32

func (t *TauswortheGenerator) Urand32() uint32

Directories

Path Synopsis
ec

Jump to

Keyboard shortcuts

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