tor-llcrypto: remove use of arrayref
This commit is contained in:
parent
744d32d554
commit
dfcbd7d4ee
|
@ -4245,7 +4245,6 @@ name = "tor-llcrypto"
|
|||
version = "0.5.0"
|
||||
dependencies = [
|
||||
"aes",
|
||||
"arrayref",
|
||||
"base64ct",
|
||||
"cipher",
|
||||
"ctr",
|
||||
|
|
|
@ -32,7 +32,6 @@ __is_experimental = []
|
|||
|
||||
[dependencies]
|
||||
aes = { version = "0.8", features = ["zeroize"] }
|
||||
arrayref = "0.3"
|
||||
base64ct = "1.5.1"
|
||||
cipher = { version = "0.4.3", optional = true, features = ["zeroize"] }
|
||||
ctr = { version = "0.9", features = ["zeroize"] }
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
//! unvalidated Ed25519 "identity keys" that we use throughout the Tor
|
||||
//! protocol to uniquely identify a relay.
|
||||
|
||||
use arrayref::array_ref;
|
||||
use base64ct::{Base64Unpadded, Encoding as _};
|
||||
use std::fmt::{self, Debug, Display, Formatter};
|
||||
use subtle::{Choice, ConstantTimeEq};
|
||||
|
@ -90,11 +89,7 @@ impl Ed25519Identity {
|
|||
}
|
||||
/// If `id` is of the correct length, wrap it in an Ed25519Identity.
|
||||
pub fn from_bytes(id: &[u8]) -> Option<Self> {
|
||||
if id.len() == 32 {
|
||||
Some(Ed25519Identity::new(*array_ref!(id, 0, 32)))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
Some(Ed25519Identity::new(id.try_into().ok()?))
|
||||
}
|
||||
/// Return a reference to the bytes in this key.
|
||||
pub fn as_bytes(&self) -> &[u8] {
|
||||
|
|
|
@ -217,7 +217,6 @@ pub fn blind_keypair(
|
|||
keypair: &ExpandedKeypair,
|
||||
h: [u8; 32],
|
||||
) -> Result<ExpandedKeypair, BlindingError> {
|
||||
use arrayref::{array_mut_ref, array_ref};
|
||||
use zeroize::Zeroizing;
|
||||
|
||||
/// Fixed string specified in rend-spec-v3.txt, used for blinding the
|
||||
|
@ -230,7 +229,11 @@ pub fn blind_keypair(
|
|||
let mut blinded_key_bytes = Zeroizing::new([0_u8; 64]);
|
||||
|
||||
{
|
||||
let secret_key = Scalar::from_bits(*array_ref!(secret_key_bytes, 0, 32));
|
||||
let secret_key = Scalar::from_bits(
|
||||
secret_key_bytes[0..32]
|
||||
.try_into()
|
||||
.expect("32-byte array not 32 bytes long!?"),
|
||||
);
|
||||
let blinded_key = secret_key * blinding_factor;
|
||||
blinded_key_bytes[0..32].copy_from_slice(blinded_key.as_bytes());
|
||||
}
|
||||
|
@ -240,7 +243,11 @@ pub fn blind_keypair(
|
|||
h.update(RH_BLIND_STRING);
|
||||
h.update(&secret_key_bytes[32..]);
|
||||
let mut d = Zeroizing::new([0_u8; 64]);
|
||||
h.finalize_into(array_mut_ref!(d, 0, 64).into());
|
||||
h.finalize_into(
|
||||
d.as_mut()
|
||||
.try_into()
|
||||
.expect("64-byte array not 64 bytes long!?"),
|
||||
);
|
||||
blinded_key_bytes[32..64].copy_from_slice(&d[0..32]);
|
||||
}
|
||||
|
||||
|
@ -413,7 +420,7 @@ mod tests {
|
|||
} else {
|
||||
let blinded_sk_bytes = blinded_kp.secret.to_bytes();
|
||||
let blinded_sk_scalar =
|
||||
Scalar::from_bits(*arrayref::array_ref!(blinded_sk_bytes, 0, 32));
|
||||
Scalar::from_bits(blinded_sk_bytes[0..32].try_into().unwrap());
|
||||
let pk2 = blinded_sk_scalar * curve25519_dalek::constants::ED25519_BASEPOINT_POINT;
|
||||
let pk2 = pk2.compress();
|
||||
assert_eq!(pk2.as_bytes(), blinded_pk.as_bytes());
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
//!
|
||||
//! This module should expose RustCrypto trait-based wrappers,
|
||||
//! but the [`rsa`] crate didn't support them as of initial writing.
|
||||
use arrayref::array_ref;
|
||||
use rsa::pkcs1::{DecodeRsaPrivateKey, DecodeRsaPublicKey};
|
||||
use std::fmt;
|
||||
use subtle::{Choice, ConstantTimeEq};
|
||||
|
@ -151,13 +150,9 @@ impl RsaIdentity {
|
|||
/// assert_eq!(id, None);
|
||||
/// ```
|
||||
pub fn from_bytes(bytes: &[u8]) -> Option<Self> {
|
||||
if bytes.len() == RSA_ID_LEN {
|
||||
Some(RsaIdentity {
|
||||
id: CtByteArray::from(*array_ref![bytes, 0, RSA_ID_LEN]),
|
||||
})
|
||||
} else {
|
||||
None
|
||||
}
|
||||
Some(RsaIdentity {
|
||||
id: CtByteArray::from(<[u8; RSA_ID_LEN]>::try_from(bytes).ok()?),
|
||||
})
|
||||
}
|
||||
/// Decode an `RsaIdentity` from a hexadecimal string.
|
||||
///
|
||||
|
|
Loading…
Reference in New Issue