{"id":20453481,"url":"https://github.com/sheroz/rsa","last_synced_at":"2026-01-04T05:46:17.664Z","repository":{"id":193148378,"uuid":"662758293","full_name":"sheroz/rsa","owner":"sheroz","description":"Samples of RSA (Rivest–Shamir–Adleman) asymmetric cipher implementations in Rust","archived":false,"fork":false,"pushed_at":"2024-05-27T22:05:04.000Z","size":14,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-25T21:26:44.730Z","etag":null,"topics":["crypto","cryptography","public-key-cryptography","rsa","rsa-cipher","rsa-cryptography","rsa-cryptosystem"],"latest_commit_sha":null,"homepage":"https://github.com/sheroz/rsa","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sheroz.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-07-05T20:32:28.000Z","updated_at":"2024-05-27T22:05:07.000Z","dependencies_parsed_at":null,"dependency_job_id":"a2c5d33b-bb73-49e0-8bd2-418903681ee1","html_url":"https://github.com/sheroz/rsa","commit_stats":null,"previous_names":["sheroz/rsa"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sheroz%2Frsa","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sheroz%2Frsa/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sheroz%2Frsa/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sheroz%2Frsa/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sheroz","download_url":"https://codeload.github.com/sheroz/rsa/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244717336,"owners_count":20498283,"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":["crypto","cryptography","public-key-cryptography","rsa","rsa-cipher","rsa-cryptography","rsa-cryptosystem"],"created_at":"2024-11-15T11:12:56.133Z","updated_at":"2026-01-04T05:46:17.639Z","avatar_url":"https://github.com/sheroz.png","language":"Rust","readme":"# RSA (Rivest–Shamir–Adleman) Asymmetric Cipher in Rust\n\nSamples of RSA (Rivest–Shamir–Adleman) public-key cryptosystem implementations for learning purposes\n\n- [src/rsa_gmp.rs](src/rsa_gmp.rs) - uses a [rug](https://crates.io/crates/rug), a high-level interface to the wrapper over [GNU MP / GMP](https://gmplib.org/), a well known arbitrary precision arithmetic library\n- [src/rsa_openssl_bn.rs](src/rsa_openssl_bn.rs) - uses an [openssl](https://crates.io/crates/openssl), a safe interface to the popular [OpenSSL library](https://www.openssl.org/)\n- [src/rsa_num.rs](src/rsa_num.rs) - uses a [num](https://crates.io/crates/num), a collection of numeric types and traits in pure Rust\n\n## Key generation\n\n1. Choose two distinct primes `p` and `q`\n\n   FIPS.186-4, Section: B.3.1 Criteria for IFC Key Pairs\n\n   ```text\n   sqrt(2)*2^((nlen/2)-1) \u003c= p \u003c= 2^(nlen/2)-1\n\n   sqrt(2)*2^((nlen/2)-1) \u003c= q \u003c= 2^(nlen/2)-1\n\n   |p - q| \u003e 2^((nlen/2)-100)  \n   ```\n\n   where:\n\n   `^` is an exponentiation (power) arithmetic operation\n\n   `nlen` is the appropriate length for the desired security strength\n\n2. Compute the modulus, `n`\n\n   ```text\n   n = p * q\n   ```\n\n3. Compute the totient, `t`\n\n- `Euler's totient function` is used in the original RSA\n\n   ```text\n   φ(n) = (p − 1) * (q − 1)\n   ```\n\n   which outputs the amount of numbers that are coprime to `n`\n\n- [Carmichael function](https://en.wikipedia.org/wiki/Carmichael_function) is recommended for modern RSA-based cryptosystems, also known as `reduced totient function` or `least universal exponent function`\n\n   ```text\n   λ(n) = lcm(p − 1, q − 1)\n   ```\n\n   where `lcm()` is the [least common multiple](https://en.wikipedia.org/wiki/Least_common_multiple)\n\n4. Choose a public key exponent, integer `e` (usually `65537` in decimal, or `0x010001` in hex)\n\n   ```text\n   1 \u003c e \u003c t\n   gcd(t, e) = 1\n   ```\n\n5. Compute the [modular multiplicative inverse](https://en.wikipedia.org/wiki/Modular_multiplicative_inverse), `d`\n\n   ```text\n   d = (e ^ (−1)) mod t\n   1 = (d * e) mod t\n   ```\n\n6. Public key\n\n   ```text\n   (e, n)\n   ```\n\n7. Private key\n\n   ```text\n   (d, n)\n   ```\n\nThe numbers `p`, `q`, and `d` must be kept secret\n\n## Encryption\n\nThe encryption of the plaintext message, `m`\n\n```text\nc = (m ^ e) mod n\n```\n\n## Decryption\n\nThe decryption of the ciphertext, `c`\n\n```text\nD = (c ^ d) mod n\n```\n\n## References\n\n- [RSA in Wikipedia](https://en.wikipedia.org/wiki/RSA_(cryptosystem))\n- [FIPS 186-4, Key Pair Generation](https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.186-4.pdf#page=62)\n\n## Disclaimer\n\nThis project was created for research purposes and is not intended for use in production systems.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsheroz%2Frsa","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsheroz%2Frsa","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsheroz%2Frsa/lists"}