     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77

    #![feature(test)]
    //#![deny(missing_docs)]

    //! A crate for generating large, cryptographically secure prime numbers.
    //! `Primes` are seeded from the operating system's main source of entropy,
    //! ensuring proper randomness.
    //!
    //! `Primes` must be AT LEAST 512-bits long. Attempting to generate a `Prime`
    //! less than 512-bits long will cause a panic.
    //!
    //! ## Example
    //!
    //! ```
    //! extern crate pumpkin;
    //!
    //! use pumpkin::Prime;
    //!
    //! fn main() {
    //!     // Generate 2048-bit primes
    //!     let p = Prime::new(2048);
    //!     let q = Prime::new(2048);
    //!
    //!     let n = p * q;
    //!     println!("{}", n); // Some 4096-bit composite number
    //! }
    //! ```

    #[macro_use] extern crate custom_derive;
    #[macro_use] extern crate newtype_derive;
    extern crate ramp;
    extern crate rand;
    extern crate test;

    mod prime;
    pub use prime::Prime;

    #[cfg(test)]
    mod tests {
        use rand::OsRng;
        use super::*;
        use test::Bencher;

        #[test]
        #[should_panic]
        fn test_new_small_prime() {
            Prime::new(511);
        }

        #[test]
        #[should_panic]
        fn test_new_small_prime_from_rng() {
            let mut rngesus = match OsRng::new() {
                Ok(rng) => rng,
                Err(reason) => panic!("An error occurred when initializing the RNG: {}", reason)
            };

            Prime::from_rng(511, &mut rngesus);
        }

        #[bench]
        #[ignore]
        fn bench_generate_512_bit_prime(b: &mut Bencher) {
            b.iter(|| Prime::new(512));
        }

        #[bench]
        #[ignore]
        fn bench_generate_1024_bit_prime(b: &mut Bencher) {
            b.iter(|| Prime::new(1024));
        }

        #[bench]
        #[ignore]
        fn bench_generate_2048_bit_prime(b: &mut Bencher) {
            b.iter(|| Prime::new(2048));
        }
    }

# Help

## Keyboard Shortcuts

?
  Show this help dialog
S
  Focus the search field
⇤
  Move up in search results
⇥
  Move down in search results
⏎
  Go to active search result

## Search Tricks

Prefix searches with a type followed by a colon (e.g. `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g. `vec -> usize` or `* -> vec`)