Glass Pumpkin
A random number generator for generating large prime numbers, suitable for cryptography.
Purpose
glass_pumpkin
is a cryptographically-secure, random number generator, useful for generating large prime numbers.
This library was inspired by pumpkin except its meant to be used with rust stable.
It also lowers the 512-bit restriction to 128 bits so these can be generated and used for elliptic curve prime fields.
It exposes the prime testing functions as well.
This crate uses num-bigint instead of ramp
. The downside is performance.
When ramp
no longer requires rust nightly, then this crate can possibly be replace with pumpkin.
Installation
Add the following to your Cargo.toml
file:
= "0.1"
Example
extern crate glass_pumpkin;
use prime;
You can also supply OsRng
and generate primes from that.
extern crate glass_pumpkin;
extern crate rand;
use glass_pumpkin::prime;
use rand::rngs::OsRng;
use rand::thread_rng;
fn main() {
let mut rng = OsRng::new().unwrap();
let p = prime::from_rng(1024, &mut rng);
let q = prime::from_rng(1024, &mut rng);
let n = p * q;
println!("{}", n);
}
Prime Generation
Primes
are generated similarly to OpenSSL except it applies some recommendations from the Prime and Prejudice paper:
- Generate a random odd number of a given bit-length.
- Divide the candidate by the first 2048 prime numbers
- Test the candidate with Fermat's Theorem.
- Runs log2(bitlength) + 5 Miller-Rabin tests.