Coder Social home page Coder Social logo

ejhfast / pumpkin Goto Github PK

View Code? Open in Web Editor NEW

This project forked from zcdziura/pumpkin

0.0 2.0 0.0 1.22 MB

A random number generator for generating large prime numbers, suitable for cryptography.

Home Page: https://zcdziura.github.io/pumpkin/pumpkin

License: MIT License

Rust 100.00%

pumpkin's Introduction

Pumpkin

A random number generator for generating large prime numbers, suitable for cryptography.

What's up with the name?

Since I began writing this library around Halloween of 2015, I wanted to choose a name that was vaguely related to the holiday. Because "pumpkin" and "prime" both begin with the letter 'p', I decided to use that.

Purpose

pumpkin is a cryptographically-secure, random number generator, useful for generating large prime numbers (at least 512-bits long). On the back-end, pumpkin uses the wonderful ramp library for storing the large numbers. pumpkin generates primes very quickly. In our testing, primes were generated anywhere between 1s and 5s on average, though of course your mileage may vary.

Installation

Add the following to your Cargo.toml file:

pumpkin = "2.0.*"

Note that pumpkin requires the nightly Rust compiler.

Example

extern crate pumpkin;

use pumpkin::Prime;

fn main() {
    let p = Prime::new(2048); // Generate a new 2048-bit prime number
    let q = Prime::new(2048);
    let e = p * q;

    println!("{}", e);

    /*
     * 75222035638256552797269351238215022250546763213674706... Some massive
     * 4096-bit number.
     */
}

You can also initialize your own OsRng and generate Primes from that.

extern crate pumpkin;
extern crate rand;

use pumpkin::Prime;

use rand::OsRng;

fn main() {
    let mut rngesus = match OsRng::new() {
        Ok(rng) => rng,
        Err(e) => panic!("Error trying to initializing RNG: {}", e)
    };

    let p = Prime::from_rng(2048, &mut rngesus);
    let q = Prime::from_rng(2048, &mut rngesus);

    let e = p * q;

    println!("{}", e);

    /*
     * 75222035638256552797269351238215022250546763213674706... Some massive
     * 4096-bit number.
     */
}

Explanation

Primes are generated in much the same way as primes generated by GnuPG:

  1. Create a large candidate number of a given bit-length. All Primes must be at least 512-bits long.

  2. Divide the candidate number by the first 1,000 prime numbers.

  3. Test the candidate number with Fermat's Little Theorem.

  4. Finally, run five iterations of the Miller-Rabin Primality Test.

Primes are seeded by rand::OsRng, which receives its entropy via the operating system's entropy source (such as /dev/urandom). Thus, because we can be confident that the generated candidate number is truly random (or as close to truly random as the user can hope), we don't need to do more than five iterations of the Miller-Rabin test to ensure primality.

Primes are simple "newtype" structs; that is, it is a tuple-like struct surrounding ramp's Int type. Primes have all of the basic algebraic and logical operators implemented, thus allowing you to do any operation that you would require.

Contributing

pumpkin is dual-licenced under the MIT and Unlicense. Should you wish to contribute updates to the project, please consider signing the included WAVER file with your cryptographic digital signature (as allowed by your country's laws). Doing so will release your changes back into the public domain to be used freely by all. I did so with this project, and it would mean a lot if you did too!

To sign the WAIVER, execute the following commands:

$ gpg -sba -u $YOUR_SIGNING_KEY WAIVER
$ cat WAIVER.asc >> WAIVER.sigs && rm WAIVER.asc

pumpkin's People

Contributors

mikelodder7 avatar ddworken avatar tiehuis avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.