{"id":15973389,"url":"https://github.com/AtropineTears/ramp-primes","last_synced_at":"2025-10-20T14:31:43.111Z","repository":{"id":62443570,"uuid":"222566768","full_name":"AtropineTears/ramp-primes","owner":"AtropineTears","description":"A Rust Crate For Generating Large Prime and Composite Integers From A CSPRNG","archived":false,"fork":false,"pushed_at":"2021-01-11T04:16:35.000Z","size":56,"stargazers_count":8,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-02T13:33:42.355Z","etag":null,"topics":["crates","crypto","cryptography","csprng","prime-number","prime-numbers","primeng","primes","random","random-generation","random-number-generators","rng","rust","rust-crate","rust-lang","rust-library","rustlang","security"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AtropineTears.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-11-18T23:44:03.000Z","updated_at":"2024-10-10T03:48:00.000Z","dependencies_parsed_at":"2022-11-01T22:31:18.947Z","dependency_job_id":null,"html_url":"https://github.com/AtropineTears/ramp-primes","commit_stats":null,"previous_names":["0xsilene/ramp-primes"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AtropineTears%2Framp-primes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AtropineTears%2Framp-primes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AtropineTears%2Framp-primes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AtropineTears%2Framp-primes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AtropineTears","download_url":"https://codeload.github.com/AtropineTears/ramp-primes/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":237348760,"owners_count":19295414,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["crates","crypto","cryptography","csprng","prime-number","prime-numbers","primeng","primes","random","random-generation","random-number-generators","rng","rust","rust-crate","rust-lang","rust-library","rustlang","security"],"created_at":"2024-10-07T21:04:45.045Z","updated_at":"2025-10-20T14:31:37.817Z","avatar_url":"https://github.com/AtropineTears.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ramp-primes: A Large, Random Composite and Prime Number Generator\n\n[![Crates.io](https://img.shields.io/crates/v/ramp-primes)](https://crates.io/crates/ramp-primes)\n![Crates.io](https://img.shields.io/crates/l/ramp-primes?style=flat-square)\n[![Build Status](https://travis-ci.org/0xAtropine/ramp-primes.svg?branch=master)](https://travis-ci.org/0xAtropine/ramp-primes)\n\n\nThis crate provides a **beautifully simplistic API** for generating large, cryptographically-random, integers in rust, including but not limited to **prime numbers**.\n\nIt takes full advantage of the [RAMP](https://crates.io/crates/ramp) crate, which provides high-performance large integers through in-line assembly and a high level, simplistic interface for users to use, as well as lower-level components allowing complete control over large integers.\n\nThis crate **requires the use of the nightly toolchain** due to the use of ramp with inline-assembly.\n\n## Usage\n\nAdd the following to your `cargo.toml`:\n\n`ramp-primes = \"0.4.0\"`\n\n`ramp = \"0.5\"`\n\nIf you have not already, install the nightly toolchain as this will only work on the nightly branch and then set as default toolchain.\n\n`rustup toolchain install nightly`\n\n`rustup default nightly`\n\n### Example of Prime Number Generation\n\n```rust\nuse ramp_primes::Generator;\n\nfn main(){\n  // Generates two primes (p,q) both of 512 bits\n  let p = Generator::new_prime(512);\n  let q = Generator::new_prime(512);\n  \n  // Generates the modulus n from p and q\n  let n = p * q;\n}\n```\n\n### Example of Safe Prime Number Generation\n\n```rust\nuse ramp_primes::Generator;\n\nfn main(){\n    // Outputs a Large Prime with 64 bits using [(n-1)/2]\n    let p = Generator::safe_prime(64);\n}\n```\n\n### Example of Random Number Generation\n\n```rust\nuse ramp_primes::Generator;\n\nfn main(){\n  // Creates a Large Integer of 1024 bits\n  let x = Generator::new_uint(1024);\n  \n  // Prints out the randomly generated number\n  println!(\"x: {}\",x);\n}\n```\n\n## Prime Number Generation Design\n\nThe Prime Number Generation and parts of its code is based on [Snips-AI's Medium Blog on Generating Prime Numbers](https://medium.com/snips-ai/prime-number-generation-2a02f28508ff).\n\nA **conservative attempt** is made at deciding whether a number is prime or not. The number goes through the generation phase and 3 tests to determine if its prime:\n\n### Generation Phase\n\n1. A single parameter is passed to the generator function that indicates the number of bits the prime should be.\n\n2. The userspace CSPRNG is seeded by the operating system to generate the random numbers using the rand crate.\n\n3. An unsigned integer is generated until it passes the prime test, and before being sent to the test, the LSB is changed to 0 to indicate its odd and its MSB is changed to 1 to make sure its the specified bit length.\n\n4. The number is sent to be processed by **three tests**\n\n### Primality Tests\n\nThe numbers go through multiple tests to determine whether they are composite or prime.\n\n1. An array of the first 2048 primes is used to check whether the number is divisble by any of the primes in the array.\n\n2. **Fermat's Little Theorem** is performed\n\n3. **Miller-Rabin Primality Test**, the gold standard recommended by the official RSA documentation and by [NIST](https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.186-4.pdf) on generating primes, is performed with 16 iterations, the same used by Apple's cryptosystem.\n\nIf the number passes these tests, it is considered with high probability to be prime. Feel free to verify them yourselves on [Wolfram Alpha](https://www.wolframalpha.com/) by simply typing in the prime number.\n\n### Safe Primes\n\nSafe Primes are generated simply by checking if (p-1)/2 is a prime with the tests listed above.\n\n## License\n\nLicensed under either of\n\n* Apache License, Version 2.0\n\n* MIT license\n\nat your option.\n\n## Contribution\n\nUnless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FAtropineTears%2Framp-primes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FAtropineTears%2Framp-primes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FAtropineTears%2Framp-primes/lists"}