11 unstable releases (5 breaking)

0.5.0 Jul 27, 2021
0.4.0 Mar 28, 2021
0.3.0 Jun 11, 2020
0.2.0 Dec 11, 2019
0.0.0 Jul 24, 2018

#20 in Cryptography

Download history 19427/week @ 2021-08-10 23512/week @ 2021-08-17 23572/week @ 2021-08-24 23712/week @ 2021-08-31 25760/week @ 2021-09-07 28528/week @ 2021-09-14 26710/week @ 2021-09-21 28644/week @ 2021-09-28 29404/week @ 2021-10-05 28346/week @ 2021-10-12 31675/week @ 2021-10-19 30268/week @ 2021-10-26 32117/week @ 2021-11-02 33284/week @ 2021-11-09 38543/week @ 2021-11-16 30417/week @ 2021-11-23

139,308 downloads per month
Used in 152 crates (63 directly)

MIT/Apache

110KB
2K SLoC

RSA

crates.io Documentation Build Status minimum rustc 1.51 Project Chat dependency status

A portable RSA implementation in pure Rust.

⚠️ WARNING: This crate has been audited by a 3rd party, but a full blog post with the results and the updates made since the audit has not been officially released yet. See #60 for more information.

Example

use rsa::{PublicKey, RsaPrivateKey, PaddingScheme};
use rand::rngs::OsRng;

let mut rng = OsRng;
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, PaddingScheme::new_pkcs1v15(), &data[..]).expect("failed to encrypt");
assert_ne!(&data[..], &enc_data[..]);

// Decrypt
let dec_data = priv_key.decrypt(PaddingScheme::new_pkcs1v15(), &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.

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

[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
    • Prime generation ✅
    • Key generation ✅
    • PKCS1v1.5: Encryption & Decryption ✅
    • PKCS1v1.5: Sign & Verify ✅
    • PKCS1v1.5 (session key): Encryption & Decryption
    • OAEP: Encryption & Decryption
    • PSS: Sign & Verify
    • Key import & export
  2. 🚀 Make it fast
    • Benchmarks ✅
    • compare to other implementations 🚧
    • optimize 🚧
  3. 🔒 Make it secure
    • Fuzz testing
    • Security Audits

Minimum Supported Rust Version (MSRV)

All crates in this repository support Rust 1.51 or higher. In future minimally supported version of Rust 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.

Dependencies

~3.5MB
~73K SLoC