Skip to content

Commit 1103423

Browse files
committed
update 'ring' to 0.16.20
My main motivation was to fix the build on darwin-aarch64 (Mac M1, briansmith/ring#1063) Note that I don't really have any particular expertise here, I just made the 'mechanical' change and made the changes needed to make the compiler and the tests happy.
1 parent ad3385c commit 1103423

2 files changed

Lines changed: 9 additions & 17 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ num-derive = "0.3.0"
4242
crc32fast = "1.1.2"
4343
log = "0.4.5"
4444
env_logger = "0.7.0"
45-
ring = "0.14.2"
45+
ring = "0.16.20"
4646
untrusted = "0.6.2"
4747
structopt = "0.2.10"
4848
openssl = "0.10.12"

src/crypto.rs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use openssl::ec::PointConversionForm;
1111
use openssl::symm::{self, Cipher, Crypter};
1212
use ring::rand::{SecureRandom, SystemRandom};
1313
use ring::signature;
14-
use {ring, untrusted};
14+
use ring;
1515

1616
/// Generates a random 12-Byte nonce using the OS random number generator.
1717
///
@@ -127,12 +127,8 @@ pub fn verify_signature(
127127
.to_bytes(group, PointConversionForm::UNCOMPRESSED, &mut bncx)
128128
.unwrap();
129129

130-
signature::verify(
131-
&signature::ECDSA_P256_SHA256_FIXED,
132-
untrusted::Input::from(&uncompressed_bytes),
133-
untrusted::Input::from(&data),
134-
untrusted::Input::from(&signature[..]),
135-
)
130+
let public_key = signature::UnparsedPublicKey::new(&signature::ECDSA_P256_SHA256_FIXED, uncompressed_bytes);
131+
public_key.verify(&data, &signature[..])
136132
.map_err(|_| ErrorKind::InvalidSignature)?;
137133
Ok(())
138134
}
@@ -153,15 +149,15 @@ pub fn create_signature(keypair: &P256KeyPair, data_to_sign: &[u8]) -> Result<[u
153149

154150
let keypair = signature::EcdsaKeyPair::from_private_key_and_public_key(
155151
&signature::ECDSA_P256_SHA256_FIXED_SIGNING,
156-
untrusted::Input::from(&priv_key),
157-
untrusted::Input::from(&pub_key),
152+
&priv_key,
153+
&pub_key,
158154
)
159155
.map_err(|_| ErrorKind::ParseError)?;
160156

161157
let sig = keypair
162158
.sign(
163159
&ring::rand::SystemRandom::new(),
164-
untrusted::Input::from(data_to_sign),
160+
data_to_sign,
165161
)
166162
.map_err(|e| Error::with_details(ErrorKind::Other, e.to_string()))?
167163
.as_ref()
@@ -171,12 +167,8 @@ pub fn create_signature(keypair: &P256KeyPair, data_to_sign: &[u8]) -> Result<[u
171167
if cfg!(debug_assertions) {
172168
// Just to make sure everything worked, verify the created signature right
173169
// afterwards.
174-
signature::verify(
175-
&signature::ECDSA_P256_SHA256_FIXED,
176-
untrusted::Input::from(&pub_key),
177-
untrusted::Input::from(data_to_sign),
178-
untrusted::Input::from(&sig),
179-
)
170+
let public_key = signature::UnparsedPublicKey::new(&signature::ECDSA_P256_SHA256_FIXED, &pub_key);
171+
public_key.verify(data_to_sign, &sig)
180172
.expect("created signature could not be verified");
181173
}
182174

0 commit comments

Comments
 (0)