MCPcopy Index your code
hub / github.com/RustCrypto/RSA

github.com/RustCrypto/RSA @v0.9.10

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.9.10 ↗ · + Follow
317 symbols 764 edges 37 files 78 documented · 25% 77 cross-repo links
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

RustCrypto: RSA

crates.io Documentation Build Status dependency status MSRV [Project Chat]chat-link

A portable RSA implementation in pure Rust.

Example

use rsa::{Pkcs1v15Encrypt, RsaPrivateKey, RsaPublicKey};

let mut rng = rand::thread_rng(); // rand@0.8
let bits = 2048;
let priv_key = RsaPrivateKey::new(&mut rng, bits).expect("failed to generate a key");
let pub_key = RsaPublicKey::from(&priv_key);

// Encrypt
let data = b"hello world";
let enc_data = pub_key.encrypt(&mut rng, Pkcs1v15Encrypt, &data[..]).expect("failed to encrypt");
assert_ne!(&data[..], &enc_data[..]);

// Decrypt
let dec_data = priv_key.decrypt(Pkcs1v15Encrypt, &enc_data).expect("failed to decrypt");
assert_eq!(&data[..], &dec_data[..]);

Note: If you encounter unusually slow key generation time while using RsaPrivateKey::new you can try to compile in release mode or add the following to your Cargo.toml. Key generation is much faster when building with higher optimization levels, but this will increase the compile time a bit. toml [profile.debug] opt-level = 3 If you don't want to turn on optimizations for all dependencies, you can only optimize the num-bigint-dig dependency. This should give most of the speedups. toml [profile.dev.package.num-bigint-dig] opt-level = 3

Status

Currently at Phase 1 (v) 🚧

There will be three phases before 1.0 🚢 can be released.

  1. 🚧 Make it work
    • [x] Prime generation ✅
    • [x] Key generation ✅
    • [x] PKCS1v1.5: Encryption & Decryption ✅
    • [x] PKCS1v1.5: Sign & Verify ✅
    • [ ] PKCS1v1.5 (session key): Encryption & Decryption
    • [x] OAEP: Encryption & Decryption
    • [x] PSS: Sign & Verify
    • [x] Key import & export
  2. 🚀 Make it fast
    • [x] Benchmarks ✅
    • [ ] compare to other implementations 🚧
    • [ ] optimize 🚧
  3. 🔐 Make it secure
    • [ ] Fuzz testing
    • [ ] Security Audits

⚠️Security Warning

This crate has received one security audit by Include Security, with only one minor finding which has since been addressed.

See the open security issues on our issue tracker for other known problems.

~~Notably the implementation of modular exponentiation is not constant time, but timing variability is masked using random blinding, a commonly used technique.~~ This crate is vulnerable to the Marvin Attack which could enable private key recovery by a network attacker (see RUSTSEC-2023-0071).

You can follow our work on mitigating this issue in #390.

Minimum Supported Rust Version (MSRV)

All crates in this repository support Rust 1.65 or higher.

In the future MSRV can be changed, but it will be done with a minor version bump.

License

Licensed under either of

at your option.

Contribution

Unless 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.

Extension points exported contracts — how you extend this code

RsaSignatureAssociatedOid (Interface)
A trait which associates an RSA-specific OID with a type. [5 implementers]
src/pkcs1v15.rs
RandomizedEncryptor (Interface)
Encrypt the message using provided random source [2 implementers]
src/traits/encryption.rs
Decryptor (Interface)
Decrypt the given message [2 implementers]
src/traits/encryption.rs
RandomizedDecryptor (Interface)
Decrypt the given message using provided random source [2 implementers]
src/traits/encryption.rs
PaddingScheme (Interface)
Padding scheme used for encryption. [2 implementers]
src/traits/padding.rs
SignatureScheme (Interface)
Digital signature scheme. [2 implementers]
src/traits/padding.rs

Core symbols most depended-on inside this repo

size
called by 30
src/traits/keys.rs
clone
called by 27
src/pss/verifying_key.rs
n
called by 22
src/key.rs
get_private_key
called by 14
src/pkcs1v15.rs
get_private_key
called by 12
src/pss.rs
e
called by 11
src/key.rs
fill_bytes
called by 11
src/dummy_rng.rs
sign_with_rng
called by 10
src/key.rs

Shape

Method 150
Function 135
Class 22
Interface 9
Enum 1

Languages

Rust100%

Modules by API surface

src/key.rs46 symbols
src/pss.rs30 symbols
src/pkcs1v15.rs29 symbols
src/oaep.rs22 symbols
src/pkcs1v15/signing_key.rs17 symbols
tests/pkcs1.rs16 symbols
src/pss/signing_key.rs16 symbols
src/pss/blinded_signing_key.rs14 symbols
src/pkcs1v15/verifying_key.rs12 symbols
src/pss/verifying_key.rs10 symbols
src/algorithms/rsa.rs10 symbols
src/algorithms/pkcs1v15.rs9 symbols

For agents

$ claude mcp add RSA \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact