pqg

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

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

Go to latest
Published: Nov 1, 2016 License: MIT Imports: 3 Imported by: 0

README

pqg

Golang simple cyclic group generator Zp with p = 2q + 1, p,q - safe primes.

n - bit width for big.Int.

Based on Miller-Rabin primality test.

Example:

package main

import (
	"flag"
	"fmt"
	"github.com/ldinc/pqg"
	"log"
	"math/big"
	"sync"
	"time"
)

func timeTrack(start time.Time, msg string) {
	elapsed := time.Since(start)
	log.Printf("> %s: %s\n", msg, elapsed)
}

func main() {
	prop := flag.Int("p", 64, "Miller-Rabin test with 1 - 1/(4^p)")
	n := flag.Int("n", 4, "number of generated <p,q,g>")
	bits := flag.Int("bits", 1024, "number of generated <p,q,g>")
	flag.Parse()
	mutex := &sync.Mutex{}
	result := make(chan *big.Int)
	for i := 0; i < *n; i++ {
		go func(id int) {
			defer timeTrack(time.Now(), fmt.Sprintf("gen %d", id))
			p, q, g, err := pqg.Gen(*bits, *prop)
			if err != nil {
				panic(err)
			}
			mutex.Lock()
			result <- p
			result <- q
			result <- g
			mutex.Unlock()
		}(i)
	}
	for i := 0; i < *n; i++ {
		log.Println("p = ", <-result)
		log.Println("q = ", <-result)
		log.Println("g = ", <-result)
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Gen

func Gen(n, probability int) (*big.Int, *big.Int, *big.Int, error)

Gen emit <p,q,g>. p = 2q + 1, p,q - safe primes g - cyclic group generator Zp performs n Miller-Rabin tests with 1 - 1/(4^n) probability false rate. Gain n - bit width for integer & probability rang for MR. It returns p, q, g and write error message.

Types

This section is empty.

Jump to

Keyboard shortcuts

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