Skip to content

Commit

Permalink
update crates
Browse files Browse the repository at this point in the history
  • Loading branch information
simonwicky committed May 21, 2024
1 parent ca107d9 commit 8488fe9
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 37 deletions.
33 changes: 17 additions & 16 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sphinx-packet"
version = "0.1.0"
version = "0.1.1"
authors = ["Ania Piotrowska <[email protected]>", "Dave Hrycyszyn <[email protected]>", "Jędrzej Stuczyński <[email protected]>"]
edition = "2018"
license = "Apache-2.0"
Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/crypto/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}

Expand Down
33 changes: 20 additions & 13 deletions src/crypto/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<D> = crypto_mac::Output<Hmac<D>>;
// Type alias for ease of use
pub type HmacOutput<D> = CtOutput<Hmac<D>>;
type Aes128Ctr = ctr::Ctr64BE<Aes128>;

pub fn generate_pseudorandom_bytes(
// TODO: those should use proper generic arrays to begin with!!
Expand All @@ -49,9 +55,10 @@ pub fn generate_pseudorandom_bytes(
/// Compute keyed hmac
pub fn compute_keyed_hmac<D>(key: &[u8], data: &[u8]) -> HmacOutput<D>
where
D: Update + BlockInput + FixedOutput + Reset + Default + Clone,
D::BlockSize: ArrayLength<u8>,
D::OutputSize: ArrayLength<u8>,
D: CoreProxy,
D::Core: HashMarker + FixedOutputCore + BufferKindUser<BufferKind = Eager> + Default + Clone,
<D::Core as BlockSizeUser>::BlockSize: IsLess<U256>,
Le<<D::Core as BlockSizeUser>::BlockSize, U256>: NonZero,
{
let mut hmac =
Hmac::<D>::new_from_slice(key).expect("HMAC should be able to take key of any size!");
Expand Down
4 changes: 2 additions & 2 deletions src/header/delays.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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());
Expand Down
4 changes: 2 additions & 2 deletions src/header/filler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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()),
Expand Down
2 changes: 1 addition & 1 deletion src/header/routing/destination.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion src/header/routing/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion src/header/routing/nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down

0 comments on commit 8488fe9

Please sign in to comment.