gobbs

package module
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2019 License: MIT Imports: 3 Imported by: 0

README

gobbs

Build Status Go Report Card Godoc

A Blum-Blum-Shub-Generator in Go.

Status

Testing

Usage

Create a new generator with default config:

import "github.com/tsdtsdtsd/gobbs"

g, err := gobbs.New()

New() will generate two random blum primes, a blum integer and a random seed. If you want to use your own numbers from an other source, you can use NewWithConfig():

g, err := gobbs.NewWithConfig(&gobbs.Config{
    PrimeP: myPrimeOne,
    PrimeQ: myPrimeTwo,
    Seed: mySeed,
    Bits: 1024,
})

The generator implements io.Reader:

buf := make([]byte, 1)

for {
    g.Read(buf)
    fmt.Printf("%02x.", buf)
}

Benchmarks

bits = 1024
readLength = 512

> go test -bench=. -benchmem -count 3
goos: windows
goarch: amd64
pkg: github.com/tsdtsdtsd/gobbs
BenchmarkInit-8               10         298040350 ns/op         2540071 B/op       8105 allocs/op
BenchmarkInit-8                3         399833433 ns/op         3571288 B/op      11109 allocs/op
BenchmarkInit-8                5         297086520 ns/op         2594611 B/op       8185 allocs/op
BenchmarkRead-8               50          37528676 ns/op         9440499 B/op      16393 allocs/op
BenchmarkRead-8               50          37291990 ns/op         9440641 B/op      16394 allocs/op
BenchmarkRead-8               50          38036620 ns/op         9440500 B/op      16393 allocs/op
PASS
ok      github.com/tsdtsdtsd/gobbs      13.857s

Credits

Heavily inspired by (basically a port of) https://github.com/foolean/blum-blum-shub

Documentation

Overview

Package gobbs provides a Blum-Blum-Shub generator. See: https://en.wikipedia.org/wiki/Blum_Blum_Shub

Index

Constants

This section is empty.

Variables

View Source
var DefaultConfig = &Config{
	Bits: 1024,
}

DefaultConfig contains some good starter settings

Functions

This section is empty.

Types

type Config

type Config struct {
	PrimeP *big.Int
	PrimeQ *big.Int
	Seed   *big.Int

	Bits int
}

Config contains configuration settings for a generator

type Generator

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

Generator defines a Blum-Blum-Shub generator

func New

func New() (*Generator, error)

New returns a Generator with default config

func NewWithConfig

func NewWithConfig(config *Config) (*Generator, error)

NewWithConfig returns a Generator with given config

func (*Generator) CalcBlumUnits

func (g *Generator) CalcBlumUnits() (*big.Int, *big.Int, *big.Int, error)

CalcBlumUnits calculates, sets to *g and returns two Blum primes (p) and (q), as well as their product, the Blum integer (n).

func (*Generator) CalcRandomSeed

func (g *Generator) CalcRandomSeed() (*big.Int, error)

CalcRandomSeed finds, sets to *g and returns a random large integer (x), that is relatively prime to (n).

func (*Generator) Read

func (g *Generator) Read(p []byte) (n int, err error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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