Skip to content

rnza0u/rsa-oaep-pss

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RSA-OAEP-PSS

Build Status docs.rs crates.io

A pure Rust implementation of the RSA public key cryptosystem.

The following features are available:

⚠️ This crate has not been audited by any peer and is not production-ready: We encourage you to review the code carefully before using it.

Useful links

Installation

Add the following line to your Cargo.toml dependencies:

[dependencies]
rsa-oaep-pss = "1"

Check out the crates.io page to see what is the latest version of this crate.

How to use ?

Keys generation

let (public_key, private_key) = rsa_oaep_pss::generate_rsa_keys(&mut rng, 2048)
    .expect("keys generation error");

Encryption using OAEP scheme

let message = b"some secret";

let mut oaep = rsa_oaep_pss::RsaOaep::new(rand::rngs::OsRng, &sha2::Sha256::new());

let ciphertext = oaep
    .encrypt(&public_key, message)
    .expect("encryption error");

let recovered = oaep
    .decrypt(&private_key, &ciphertext)
    .expect("decryption error");

assert_eq!(recovered, message);

Signature using PSS scheme

let message = b"message to sign";

let mut pss = rsa_oaep_pss::RsaPss::new(rand::rngs::OsRng, &sha2::Sha256::new());

let signature = pss.sign(&private_key, message).expect("signature error");

let verification = pss.verify(&public_key, message, &signature);

assert!(verification.is_ok());

Importing and exporting of keys

use rsa_oaep_pss::{FromPem, ToPem};

let pem_public_key = std::fs::read_to_string("public.pem")?;

let public_key = RsaPublicKey::from_pem(&pem_public_key)?;

let re_exported_pem_public_key = public_key.to_pem()?;

assert_eq!(pem_public_key, re_exported_pem_public_key);

You can also use FromDer and ToDer for dealing with raw DER data.

Run the examples

You can run examples contained in the examples folder by using the following command:

cargo run --example <filename> --release 

Todo

  • Zeroize everything (using zeroize crate)
  • Implement miller rabin pour prime checking
  • Implement Signer trait from signature crate

Releases

No releases published

Packages

No packages published

Languages