Skip to content

Add OAEP Encryption & Decryption #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ rand = "0.7.0"
byteorder = "1.3.1"
failure = "0.1.5"
subtle = "2.0.0"
digest = { version = "0.8.0", features = ["std"] }
sha-1 = "0.8.1"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would really like to avoid these dependencies, especially as I want to change signing to be abstract over Digest. See RustCrypto/signatures#7 for some details on the plans there

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I agree that depending on every hashing crates is not a good idea. The digest implementation should be passed. I tried that in the first place but failed, fighting the Rust compiler due to my limited Rust experience, I don't remember the exact reason...
I'll see what I can do (see my other comment on my commitment)

sha2 = "0.8.0"
sha3 = "0.8.1"

[dependencies.zeroize]
version = "1.1.0"
Expand All @@ -34,8 +38,6 @@ features = ["std", "derive"]

[dev-dependencies]
base64 = "0.11.0"
sha-1 = "0.8.1"
sha2 = "0.8.0"
hex = "0.4.0"
serde_test = "1.0.89"
rand_xorshift = "0.2.0"
Expand Down
1 change: 1 addition & 0 deletions src/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub trait Hash {

/// Returns the ASN1 DER prefix for the the hash function.
fn asn1_prefix(&self) -> Vec<u8>;

}

/// A list of provided hashes, implementing `Hash`.
Expand Down
11 changes: 11 additions & 0 deletions src/internals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,14 @@ pub fn left_pad(input: &[u8], size: usize) -> Vec<u8> {
out[size - n..].copy_from_slice(input);
out
}

#[inline]
pub fn copy_with_left_pad(dest: &mut [u8], src: &[u8]) {
// left pad with zeros
let padding_bytes = dest.len() - src.len();
for el in dest.iter_mut().take(padding_bytes) {
*el = 0;
}
dest[padding_bytes..].copy_from_slice(src);
}

1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ pub mod hash;
pub mod padding;

mod key;
pub mod oaep;
mod pkcs1v15;

pub use self::key::{PublicKey, RSAPrivateKey, RSAPublicKey};
Expand Down
Loading