safeprime

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2020 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Overview

Package safeprime computes safe primes, i.e. primes of the form 2p+1 where p is also prime.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Generate

func Generate(bitsize int, stop chan struct{}) (*big.Int, error)

Generate a safe prime of the given size, using the fact that:

If q is prime and 2^(2q) = 1 mod (2q+1), then 2q+1 is a safe prime.

We take a random bigint q; if the above formula holds and q is prime, then we return 2q+1. (See https://www.ijipbangalore.org/abstracts_2(1)/p5.pdf and https://groups.google.com/group/sci.crypt/msg/34c4abf63568a8eb)

In order to cancel the generation algorithm, send a struct{} on the stop parameter or close() it. (Passing nil is allowed; then the algorithm cannot be cancelled).

func GenerateConcurrent

func GenerateConcurrent(bitsize int, stop chan struct{}) (<-chan *big.Int, <-chan error)

GenerateConcurrent concurrently and continuously generates safeprimes on all CPU cores, until the stop channel receives a struct or is closed. If an error is encountered, generation is stopped in all goroutines, and the error is sent on the second return parameter.

func ProbablySafePrime

func ProbablySafePrime(x *big.Int, n int) bool

ProbablySafePrime reports whether x is probably safe prime, by calling big.Int.ProbablyPrime(n) on x as well as on (x-1)/2.

If x is safe prime, ProbablySafePrime returns true. If x is chosen randomly and not safe prime, ProbablyPrime probably returns false.

Types

This section is empty.

Jump to

Keyboard shortcuts

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