• Stars
    star
    528
  • Rank 83,941 (Top 2 %)
  • Language
    Rust
  • License
    Apache License 2.0
  • Created over 6 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

RSA implementation in pure Rust

RustCrypto: RSA

crates.io Documentation Build Status dependency status MSRV Project Chat

A portable RSA implementation in pure Rust.

Example

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

let mut rng = rand::thread_rng();
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.

[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

Security Notes

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.

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.

More Repositories

1

hashes

Collection of cryptographic hash functions written in pure Rust
Rust
1,780
star
2

AEADs

Authenticated Encryption with Associated Data Algorithms: high-level encryption ciphers
Rust
686
star
3

block-ciphers

Collection of block cipher algorithms written in pure Rust
Rust
654
star
4

elliptic-curves

Collection of pure Rust elliptic curve implementations: NIST P-224, P-256, P-384, P-521, secp256k1, SM2
Rust
635
star
5

password-hashes

Password hashing functions / KDFs
Rust
623
star
6

traits

Collection of cryptography-related traits
Rust
552
star
7

signatures

Cryptographic signature algorithms: DSA, ECDSA, Ed25519
Rust
451
star
8

utils

Utility crates used in RustCrypto
Rust
427
star
9

stream-ciphers

Collection of stream cipher algorithms
Rust
252
star
10

MACs

Message authentication code algorithms written in pure Rust
Rust
250
star
11

formats

Cryptography-related format encoders/decoders: DER, PEM, PKCS, PKIX
Rust
231
star
12

crypto-bigint

Cryptography-oriented big integer library with constant-time, stack-allocated (no_std-friendly) implementations of modern formulas
Rust
172
star
13

SSH

Pure Rust implementation of components of the Secure Shell (SSH) protocol
Rust
113
star
14

PAKEs

Password-Authenticated Key Agreement protocols
Rust
102
star
15

KDFs

Collection of Key Derivation Functions written in pure Rust
Rust
64
star
16

nacl-compat

Pure Rust compatibility layer for NaCl-family libraries
Rust
56
star
17

block-modes

Collection of generic block mode algorithms written in pure Rust
Rust
53
star
18

JOSE

Pure Rust implementation of Javascript Object Signing and Encryption (JOSE)
Rust
48
star
19

asm-hashes

Assembly implementations of cryptographic hash functions
Assembly
43
star
20

sponges

Collection of sponge functions written in pure Rust
Rust
40
star
21

rustls-rustcrypto

Rustls cryptography provider built on the pure Rust crates from the RustCrypto organization
Rust
38
star
22

ring-compat

Compatibility library for using *ring* as a backend for RustCrypto's traits
Rust
29
star
23

universal-hashes

Collection of universal hashing functions
Rust
26
star
24

book

Reference manual for the RustCrypto project, implemented as an MDBook [WIP]
Rust
18
star
25

meta

Meta-crates of the RustCrypto project
Rust
11
star
26

KEMs

Collection of Key Encapsulation Mechanisms written in pure Rust
Rust
11
star
27

CSRNGs

Collection of Cryptographically Secure PseudoRandom Number Generators written in pure Rust
11
star
28

key-wraps

Symmetric key-wrapping algorithms
Rust
9
star
29

hybrid-array

Hybrid typenum/const generic arrays
Rust
6
star
30

actions

GitHub Actions configs: composite actions and shared workflow configuration
5
star
31

rust-crypto-decoupled

Experiment on dividing rust-crypto into several small crates
Rust
3
star
32

.github

RustCrypto's profile README.md
3
star
33

media

Media files of the RustCrypto project
2
star