2018-07-17 21:16:31 +02:00
# RSA
2020-12-02 17:12:48 +01:00
[](https://crates.io/crates/rsa) [](https://docs.rs/rsa) [](https://github.com/RustCrypto/RSA/actions) 
2018-07-17 21:16:31 +02:00
2018-12-03 10:47:09 +00:00
A portable RSA implementation in pure Rust.
2018-07-17 21:16:31 +02:00
2020-11-30 04:07:40 -06:00
:warning: **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 ](https://github.com/RustCrypto/RSA/issues/60 ) for more information.
2018-07-17 21:16:31 +02:00
2019-02-20 20:54:35 +01:00
## Example
```rust
use rsa::{PublicKey, RSAPrivateKey, PaddingScheme};
use rand::rngs::OsRng;
2019-12-11 01:15:49 +01:00
let mut rng = OsRng;
2019-02-20 20:54:35 +01:00
let bits = 2048;
2020-03-06 20:05:24 +01:00
let priv_key = RSAPrivateKey::new(& mut rng, bits).expect("failed to generate a key");
2020-11-24 15:01:04 +01:00
let pub_key = RSAPublicKey::from(&priv_key);
2019-02-20 20:54:35 +01:00
// Encrypt
let data = b"hello world";
2020-03-06 21:11:24 +01:00
let enc_data = pub_key.encrypt(& mut rng, PaddingScheme::new_pkcs1v15(), & data[..]).expect("failed to encrypt");
2019-02-20 20:54:35 +01:00
assert_ne!(& data[..], &enc_data[..]);
// Decrypt
2020-03-06 21:11:24 +01:00
let dec_data = priv_key.decrypt(PaddingScheme::new_pkcs1v15(), & enc_data).expect("failed to decrypt");
2019-02-20 20:54:35 +01:00
assert_eq!(& data[..], &dec_data[..]);
```
2018-07-17 21:16:31 +02:00
## Status
2018-07-24 22:05:29 +02:00
Currently at Phase 1 (v) :construction:.
2018-07-17 21:16:31 +02:00
There will be three phases before `1.0` :ship: can be released.
1. :construction: Make it work
2019-02-20 20:29:49 +01:00
- [x] Prime generation :white_check_mark:
- [x] Key generation :white_check_mark:
- [x] PKCS1v1.5: Encryption & Decryption :white_check_mark:
- [x] PKCS1v1.5: Sign & Verify :white_check_mark:
- [ ] PKCS1v1.5 (session key): Encryption & Decryption
2020-03-06 20:05:24 +01:00
- [x] OAEP: Encryption & Decryption
2020-03-06 21:11:24 +01:00
- [x] PSS: Sign & Verify
2019-02-20 20:29:49 +01:00
- [x] Key import & export
2018-07-17 21:16:31 +02:00
2. :rocket: Make it fast
2019-02-20 20:29:49 +01:00
- [x] Benchmarks :white_check_mark:
- [ ] compare to other implementations :construction:
- [ ] optimize :construction:
2018-07-17 21:16:31 +02:00
3. :lock: Make it secure
2019-02-20 20:29:49 +01:00
- [ ] Fuzz testing
- [ ] Security Audits
2018-07-17 21:16:31 +02:00
## License
2018-12-03 10:47:09 +00:00
Licensed under either of
* [Apache License, Version 2.0 ](http://www.apache.org/licenses/LICENSE-2.0 )
* [MIT license ](http://opensource.org/licenses/MIT )
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
2019-02-20 20:29:49 +01:00
dual licensed as above, without any additional terms or conditions.