diff --git a/Cargo.toml b/Cargo.toml index a990396..202f796 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sphinx-packet" -version = "0.1.0" +version = "0.1.1" authors = ["Ania Piotrowska ", "Dave Hrycyszyn ", "Jędrzej Stuczyński "] edition = "2018" license = "Apache-2.0" @@ -11,27 +11,28 @@ readme = "README.md" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -aes = { version = "0.7.4", features = ["ctr"] } -bs58 = "0.4.0" -curve25519-dalek = "3.0.0" -hmac = "0.11.0" -digest = "0.9" -log = "0.4" -rand = {version = "0.7.3", features = ["wasm-bindgen"]} -rand_distr = "0.3" -sha2 = "0.9.1" -hkdf = "0.11.0" +aes = "0.8.4" +ctr = "0.9.2" +bs58 = "0.5.1" +curve25519-dalek = {version = "4.1.2", features = ["legacy_compatibility"] } +hmac = "0.12.1" +digest = "0.10.7" +log = "0.4.21" +rand = "0.8.5" +rand_distr = "0.4.3" +sha2 = "0.10.8" +hkdf = "0.12.4" lioness = "0.1.2" -arrayref = "0.3.5" +arrayref = "0.3.7" chacha = "0.3.0" blake2 = "0.8.0" # cannot be updated due to outdated dependency inside lioness -byteorder = "1.3.2" -subtle = "2.3.0" +byteorder = "1.5.0" +subtle = "2.4.1" [dev-dependencies] -mockall = "0.10.2" -criterion = "0.3" +mockall = "0.12.1" +criterion = "0.5.1" [[bench]] name = "benchmarks" diff --git a/src/crypto/keys.rs b/src/crypto/keys.rs index 77dee4f..b99b51b 100644 --- a/src/crypto/keys.rs +++ b/src/crypto/keys.rs @@ -129,7 +129,7 @@ impl<'a> From<&'a PrivateKey> for PublicKey { fn from(private_key: &'a PrivateKey) -> PublicKey { // multiplication in edwards using the precomputed ed25519 basepoint table is over 3x quicker // than multiplication inside montgomery using the curve generator - PublicKey((&ED25519_BASEPOINT_TABLE * &private_key.0).to_montgomery()) + PublicKey((ED25519_BASEPOINT_TABLE * &private_key.0).to_montgomery()) } } diff --git a/src/crypto/mod.rs b/src/crypto/mod.rs index bca3580..64b5945 100644 --- a/src/crypto/mod.rs +++ b/src/crypto/mod.rs @@ -12,22 +12,28 @@ // See the License for the specific language governing permissions and // limitations under the License. -use aes::cipher::{NewCipher, StreamCipher}; -use aes::Aes128Ctr; -use digest::generic_array::{ArrayLength, GenericArray}; -use digest::{BlockInput, FixedOutput, Reset, Update}; -use hmac::{crypto_mac, Hmac, Mac, NewMac}; - +use aes::{ + cipher::{KeyIvInit, StreamCipher}, + Aes128, +}; +use digest::{ + block_buffer::Eager, + consts::U256, + core_api::{BlockSizeUser, BufferKindUser, CoreProxy, FixedOutputCore}, + generic_array::GenericArray, + typenum::{IsLess, Le, NonZero}, + CtOutput, HashMarker, +}; +use hmac::{Hmac, Mac}; pub mod keys; - -// to not break existing imports pub use keys::*; pub const STREAM_CIPHER_KEY_SIZE: usize = 16; pub const STREAM_CIPHER_INIT_VECTOR: [u8; 16] = [0u8; 16]; -// Type alias for ease of use so that it would not require explicit import of crypto_mac or Hmac -pub type HmacOutput = crypto_mac::Output>; +// Type alias for ease of use +pub type HmacOutput = CtOutput>; +type Aes128Ctr = ctr::Ctr64BE; pub fn generate_pseudorandom_bytes( // TODO: those should use proper generic arrays to begin with!! @@ -49,9 +55,10 @@ pub fn generate_pseudorandom_bytes( /// Compute keyed hmac pub fn compute_keyed_hmac(key: &[u8], data: &[u8]) -> HmacOutput where - D: Update + BlockInput + FixedOutput + Reset + Default + Clone, - D::BlockSize: ArrayLength, - D::OutputSize: ArrayLength, + D: CoreProxy, + D::Core: HashMarker + FixedOutputCore + BufferKindUser + Default + Clone, + ::BlockSize: IsLess, + Le<::BlockSize, U256>: NonZero, { let mut hmac = Hmac::::new_from_slice(key).expect("HMAC should be able to take key of any size!"); diff --git a/src/header/delays.rs b/src/header/delays.rs index 35add6c..e281350 100644 --- a/src/header/delays.rs +++ b/src/header/delays.rs @@ -176,7 +176,7 @@ mod delay_summing { let delay2 = Delay(123); let expected1 = Delay(165); - assert_eq!(expected1, &delay1 + &delay2); + assert_eq!(expected1, delay1 + delay2); let expected2 = Delay(265); let delay3 = Delay(100); @@ -185,7 +185,7 @@ mod delay_summing { #[test] fn works_with_iterator() { - let delays = vec![Delay(42), Delay(123), Delay(100)]; + let delays = [Delay(42), Delay(123), Delay(100)]; let expected = Delay(265); assert_eq!(expected, delays.iter().sum()); diff --git a/src/header/filler.rs b/src/header/filler.rs index 2712f7a..9b209e4 100644 --- a/src/header/filler.rs +++ b/src/header/filler.rs @@ -102,7 +102,7 @@ mod test_creating_pseudorandom_bytes { #[test] fn with_1_key_it_generates_filler_of_length_1_times_3_times_security_parameter() { - let shared_keys = vec![SharedSecret::from(&EphemeralSecret::new())]; + let shared_keys = [SharedSecret::from(&EphemeralSecret::new())]; let routing_keys: Vec<_> = shared_keys .iter() .map(|&key| keys::RoutingKeys::derive(key)) @@ -114,7 +114,7 @@ mod test_creating_pseudorandom_bytes { #[test] fn with_3_key_it_generates_filler_of_length_3_times_3_times_security_parameter() { - let shared_keys = vec![ + let shared_keys = [ SharedSecret::from(&EphemeralSecret::new()), SharedSecret::from(&EphemeralSecret::new()), SharedSecret::from(&EphemeralSecret::new()), diff --git a/src/header/routing/destination.rs b/src/header/routing/destination.rs index 69282df..cdb6985 100644 --- a/src/header/routing/destination.rs +++ b/src/header/routing/destination.rs @@ -76,7 +76,7 @@ impl FinalRoutingInformation { // return D || I || PAD PaddedFinalRoutingInformation { value: std::iter::once(self.flag) - .chain(self.version.to_bytes().into_iter()) + .chain(self.version.to_bytes()) .chain(self.destination.as_bytes().iter().cloned()) .chain(self.identifier.iter().cloned()) .chain(padding.iter().cloned()) diff --git a/src/header/routing/mod.rs b/src/header/routing/mod.rs index f78a069..ee64664 100644 --- a/src/header/routing/mod.rs +++ b/src/header/routing/mod.rs @@ -289,7 +289,7 @@ mod encapsulating_forward_routing_information { let delay0 = Delay::new_from_nanos(10); let delay1 = Delay::new_from_nanos(20); let delay2 = Delay::new_from_nanos(30); - let delays = [delay0.clone(), delay1.clone(), delay2].to_vec(); + let delays = [delay0, delay1, delay2].to_vec(); let routing_keys = [ routing_keys_fixture(), routing_keys_fixture(), diff --git a/src/header/routing/nodes.rs b/src/header/routing/nodes.rs index 31358ff..87d5881 100644 --- a/src/header/routing/nodes.rs +++ b/src/header/routing/nodes.rs @@ -69,7 +69,7 @@ impl RoutingInformation { .chain(self.version.to_bytes().iter().cloned()) .chain(self.node_address.as_bytes_ref().iter().cloned()) .chain(self.delay.to_bytes().iter().cloned()) - .chain(self.header_integrity_mac.into_inner().into_iter()) + .chain(self.header_integrity_mac.into_inner()) .chain(self.next_routing_information.iter().cloned()) .collect() }