Skip to content
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

Update the ring dev dependency version. #23

Merged
merged 2 commits into from
Feb 7, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions libraries/crypto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ arrayref = "0.3.6"
subtle = { version = "2.2", default-features = false, features = ["nightly"] }
byteorder = { version = "1", default-features = false }
hex = { version = "0.3.2", default-features = false, optional = true }
ring = { version = "0.14.6", optional = true }
untrusted = { version = "0.6.2", optional = true }
ring = { version = "0.16.11", optional = true }
untrusted = { version = "0.7.0", optional = true }
rand = { version = "0.6.5", optional = true }
serde = { version = "1.0", optional = true, features = ["derive"] }
serde_json = { version = "1.0", optional = true }
Expand Down
43 changes: 21 additions & 22 deletions libraries/crypto/src/ecdsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -495,14 +495,13 @@ mod test {
#[test]
fn test_ring_sign_ring_verify() {
use ring::rand::SecureRandom;
use ring::signature::KeyPair;
use ring::signature::{KeyPair, VerificationAlgorithm};

let ring_rng = ring::rand::SystemRandom::new();

for _ in 0..ITERATIONS {
let mut msg_bytes: [u8; 64] = [Default::default(); 64];
ring_rng.fill(&mut msg_bytes).unwrap();
let msg = untrusted::Input::from(&msg_bytes);

let pkcs8_bytes = ring::signature::EcdsaKeyPair::generate_pkcs8(
&ring::signature::ECDSA_P256_SHA256_FIXED_SIGNING,
Expand All @@ -511,21 +510,21 @@ mod test {
.unwrap();
let key_pair = ring::signature::EcdsaKeyPair::from_pkcs8(
&ring::signature::ECDSA_P256_SHA256_FIXED_SIGNING,
untrusted::Input::from(pkcs8_bytes.as_ref()),
pkcs8_bytes.as_ref(),
)
.unwrap();
let public_key_bytes = key_pair.public_key().as_ref();

let sig = key_pair.sign(&ring_rng, msg).unwrap();
let sig = key_pair.sign(&ring_rng, &msg_bytes).unwrap();
let sig_bytes = sig.as_ref();

assert!(ring::signature::verify(
&ring::signature::ECDSA_P256_SHA256_FIXED,
untrusted::Input::from(public_key_bytes),
msg,
untrusted::Input::from(sig_bytes)
)
.is_ok());
assert!(ring::signature::ECDSA_P256_SHA256_FIXED
.verify(
untrusted::Input::from(public_key_bytes),
untrusted::Input::from(&msg_bytes),
untrusted::Input::from(sig_bytes)
)
.is_ok());
}
}

Expand All @@ -548,14 +547,12 @@ mod test {
.unwrap();
let key_pair = ring::signature::EcdsaKeyPair::from_pkcs8(
&ring::signature::ECDSA_P256_SHA256_FIXED_SIGNING,
untrusted::Input::from(pkcs8_bytes.as_ref()),
pkcs8_bytes.as_ref(),
)
.unwrap();
let public_key_bytes = key_pair.public_key().as_ref();

let sig = key_pair
.sign(&ring_rng, untrusted::Input::from(&msg_bytes))
.unwrap();
let sig = key_pair.sign(&ring_rng, &msg_bytes).unwrap();
let sig_bytes = sig.as_ref();

let pk = PubKey::from_bytes_uncompressed(public_key_bytes).unwrap();
Expand All @@ -567,6 +564,8 @@ mod test {
// Test that messages signed by this code are correctly verified by the ring crate.
#[test]
fn test_self_sign_ring_verify() {
use ring::signature::VerificationAlgorithm;

let mut rng = ThreadRng256 {};

for _ in 0..ITERATIONS {
Expand All @@ -580,13 +579,13 @@ mod test {
let mut sig_bytes: [u8; 64] = [Default::default(); 64];
sign.to_bytes(&mut sig_bytes);

assert!(ring::signature::verify(
&ring::signature::ECDSA_P256_SHA256_FIXED,
untrusted::Input::from(&public_key_bytes),
untrusted::Input::from(&msg_bytes),
untrusted::Input::from(&sig_bytes)
)
.is_ok());
assert!(ring::signature::ECDSA_P256_SHA256_FIXED
.verify(
untrusted::Input::from(&public_key_bytes),
untrusted::Input::from(&msg_bytes),
untrusted::Input::from(&sig_bytes)
)
.is_ok());
}
}

Expand Down