Crates.io | glass_pumpkin |
lib.rs | glass_pumpkin |
version | 1.7.0 |
source | src |
created_at | 2019-01-03 19:33:40.485584 |
updated_at | 2024-05-24 18:40:29.796759 |
description | A cryptographically secure prime number generator based on rust's own num-bigint and num-integer |
homepage | https://crates.io/crates/glass_pumpkin |
repository | https://github.com/mikelodder7/glass_pumpkin |
max_upload_size | |
id | 105283 |
size | 63,420 |
A random number generator for generating large prime numbers, suitable for cryptography.
glass_pumpkin
is a cryptographically-secure, random number generator, useful for generating large prime numbers.
This library is 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
. I have found
num-bigint
to be just as fast as ramp
for generating primes. On average, generating primes takes less
than 200ms and safe primes about 10 seconds on modern hardware.
Add the following to your Cargo.toml
file:
glass_pumpkin = "1.0"
use glass_pumpkin::prime;
fn main() {
let p = prime::new(1024).unwrap();
let q = prime::new(1024).unwrap();
let n = p * q;
println!("{}", n);
}
You can also supply OsRng
and generate primes from that.
use glass_pumpkin::prime;
use rand::rngs::OsRng;
fn main() {
let mut rng = OsRng;
let p = prime::from_rng(1024, &mut rng).unwrap();
let q = prime::from_rng(1024, &mut rng).unwrap();
let n = p * q;
println!("{}", n);
}
Primes
are generated similarly to OpenSSL except it applies some recommendations from the Prime and Prejudice paper and uses
the Baillie-PSW method:
2
.Safe primes require (n-1)/2 also be prime.
You can use this crate to check numbers for primality.
use glass_pumpkin::prime;
use glass_pumpkin::safe_prime;
use num_bigint::BigUint;
fn main() {
if prime::check(&BigUint::new([5].to_vec())) {
println!("is prime");
}
if safe_prime::check(&BigUint::new([7].to_vec())) {
println!("is safe prime");
}
}
Stronger prime checking that uses the Baillie-PSW method is an option
by using the strong_check
methods available in the prime
and safe_prime
modules. Primes generated by this crate will pass the Baillie-PSW
test when using cryptographically secure random number generators. For now,
prime::new()
and safe_prime::new()
will continue to use generation
method as describe earlier.
This crate is part of the Hyperledger Labs Agora Project.