diff --git a/ciphers/src/lib.rs b/ciphers/src/lib.rs index 6ee1934..d57bd00 100644 --- a/ciphers/src/lib.rs +++ b/ciphers/src/lib.rs @@ -9,9 +9,7 @@ const_assert!(KEY_LEN == hash_domain::KEY_LEN); /// Authenticated encryption with associated data pub mod aead { - pub use crate::subtle::chacha20poly1305_ietf::{ - decrypt, encrypt, KEY_LEN, NONCE_LEN, TAG_LEN, - }; + pub use crate::subtle::chacha20poly1305_ietf::{decrypt, encrypt, KEY_LEN, NONCE_LEN, TAG_LEN}; } /// Authenticated encryption with associated data with a constant nonce diff --git a/ciphers/src/subtle/blake2b.rs b/ciphers/src/subtle/blake2b.rs index 38f9497..4f8933d 100644 --- a/ciphers/src/subtle/blake2b.rs +++ b/ciphers/src/subtle/blake2b.rs @@ -1,12 +1,12 @@ use zeroize::Zeroizing; -use blake2::Blake2bMac; -use blake2::digest::{OutputSizeUser, Mac, FixedOutput}; -use blake2::digest::crypto_common::KeySizeUser; use blake2::digest::crypto_common::generic_array::GenericArray; use blake2::digest::crypto_common::typenum::U32; +use blake2::digest::crypto_common::KeySizeUser; +use blake2::digest::{FixedOutput, Mac, OutputSizeUser}; +use blake2::Blake2bMac; -use rosenpass_to::{with_destination, To, ops::copy_slice}; +use rosenpass_to::{ops::copy_slice, with_destination, To}; use rosenpass_util::typenum2const; type Impl = Blake2bMac; @@ -14,8 +14,8 @@ type Impl = Blake2bMac; type KeyLen = ::KeySize; type OutLen = ::OutputSize; -const KEY_LEN : usize = typenum2const! { KeyLen }; -const OUT_LEN : usize = typenum2const! { OutLen }; +const KEY_LEN: usize = typenum2const! { KeyLen }; +const OUT_LEN: usize = typenum2const! { OutLen }; pub const KEY_MIN: usize = KEY_LEN; pub const KEY_MAX: usize = KEY_LEN; diff --git a/ciphers/src/subtle/chacha20poly1305_ietf.rs b/ciphers/src/subtle/chacha20poly1305_ietf.rs index b00b23a..4f2db50 100644 --- a/ciphers/src/subtle/chacha20poly1305_ietf.rs +++ b/ciphers/src/subtle/chacha20poly1305_ietf.rs @@ -1,10 +1,10 @@ -use rosenpass_to::To; use rosenpass_to::ops::copy_slice; +use rosenpass_to::To; use rosenpass_util::typenum2const; use chacha20poly1305::aead::generic_array::GenericArray; -use chacha20poly1305::{ChaCha20Poly1305 as AeadImpl}; -use chacha20poly1305::{AeadCore, KeySizeUser, KeyInit, AeadInPlace}; +use chacha20poly1305::ChaCha20Poly1305 as AeadImpl; +use chacha20poly1305::{AeadCore, AeadInPlace, KeyInit, KeySizeUser}; pub const KEY_LEN: usize = typenum2const! { ::KeySize }; pub const TAG_LEN: usize = typenum2const! { ::TagSize }; diff --git a/ciphers/src/subtle/mod.rs b/ciphers/src/subtle/mod.rs index b6cbe5f..d9c9ecf 100644 --- a/ciphers/src/subtle/mod.rs +++ b/ciphers/src/subtle/mod.rs @@ -1,4 +1,4 @@ -pub mod incorrect_hmac_blake2b; -pub mod chacha20poly1305_ietf; -pub mod xchacha20poly1305_ietf; pub mod blake2b; +pub mod chacha20poly1305_ietf; +pub mod incorrect_hmac_blake2b; +pub mod xchacha20poly1305_ietf; diff --git a/ciphers/src/subtle/xchacha20poly1305_ietf.rs b/ciphers/src/subtle/xchacha20poly1305_ietf.rs index 64c349e..3d172b3 100644 --- a/ciphers/src/subtle/xchacha20poly1305_ietf.rs +++ b/ciphers/src/subtle/xchacha20poly1305_ietf.rs @@ -1,10 +1,10 @@ -use rosenpass_to::To; use rosenpass_to::ops::copy_slice; +use rosenpass_to::To; use rosenpass_util::typenum2const; use chacha20poly1305::aead::generic_array::GenericArray; -use chacha20poly1305::{XChaCha20Poly1305 as AeadImpl}; -use chacha20poly1305::{AeadCore, KeySizeUser, KeyInit, AeadInPlace}; +use chacha20poly1305::XChaCha20Poly1305 as AeadImpl; +use chacha20poly1305::{AeadCore, AeadInPlace, KeyInit, KeySizeUser}; pub const KEY_LEN: usize = typenum2const! { ::KeySize }; pub const TAG_LEN: usize = typenum2const! { ::TagSize }; diff --git a/constant-time/src/lib.rs b/constant-time/src/lib.rs index 319c91b..b5ea516 100644 --- a/constant-time/src/lib.rs +++ b/constant-time/src/lib.rs @@ -30,13 +30,7 @@ pub fn xor(src: &[u8]) -> impl To<[u8], ()> + '_ { #[inline] pub fn memcmp(a: &[u8], b: &[u8]) -> bool { a.len() == b.len() - && unsafe { - memsec::memeq( - a.as_ptr() as *const u8, - b.as_ptr() as *const u8, - a.len(), - ) - } + && unsafe { memsec::memeq(a.as_ptr() as *const u8, b.as_ptr() as *const u8, a.len()) } } #[inline] diff --git a/rosenpass/src/main.rs b/rosenpass/src/main.rs index a077fc1..c5cd7e1 100644 --- a/rosenpass/src/main.rs +++ b/rosenpass/src/main.rs @@ -1,6 +1,6 @@ use log::error; -use std::process::exit; use rosenpass::cli::Cli; +use std::process::exit; /// Catches errors, prints them through the logger, then exits pub fn main() { diff --git a/rosenpass/src/protocol.rs b/rosenpass/src/protocol.rs index 9b381f3..63af5fe 100644 --- a/rosenpass/src/protocol.rs +++ b/rosenpass/src/protocol.rs @@ -77,10 +77,10 @@ use rosenpass_cipher_traits::Kem; use rosenpass_ciphers::hash_domain::{SecretHashDomain, SecretHashDomainNamespace}; use rosenpass_ciphers::kem::{EphemeralKem, StaticKem}; use rosenpass_ciphers::{aead, xaead, KEY_LEN}; +use rosenpass_constant_time as constant_time; use rosenpass_lenses::LenseView; use rosenpass_secret_memory::{Public, Secret}; use rosenpass_util::{cat, mem::cpy_min, ord::max_usize, time::Timebase}; -use rosenpass_constant_time as constant_time; use crate::{hash_domains, msgs::*}; @@ -1364,8 +1364,7 @@ impl HandshakeState { // indicates retransmission // TODO: Handle retransmissions without involving the crypto code ensure!( - constant_time::compare(biscuit.biscuit_no(), &*peer.get(srv).biscuit_used) - >= 0, + constant_time::compare(biscuit.biscuit_no(), &*peer.get(srv).biscuit_used) >= 0, "Rejecting biscuit: Outdated biscuit number" ); diff --git a/util/src/typenum.rs b/util/src/typenum.rs index d2e17a7..d14944a 100644 --- a/util/src/typenum.rs +++ b/util/src/typenum.rs @@ -1,13 +1,17 @@ -use typenum::bit::{B1, B0}; -use typenum::int::{Z0, NInt, PInt}; -use typenum::uint::{UInt, UTerm}; +use typenum::bit::{B0, B1}; +use typenum::int::{NInt, PInt, Z0}; use typenum::marker_traits as markers; +use typenum::uint::{UInt, UTerm}; /// Convenience macro to convert type numbers to constant integers #[macro_export] macro_rules! typenum2const { - ($val:ty) => { typenum2const!($val as _) }; - ($val:ty as $type:ty) => { < $val as $crate::typenum::IntoConst<$type> >::VALUE }; + ($val:ty) => { + typenum2const!($val as _) + }; + ($val:ty as $type:ty) => { + <$val as $crate::typenum::IntoConst<$type>>::VALUE + }; } /// Trait implemented by constant integers to facilitate conversion to constant integers @@ -15,9 +19,15 @@ pub trait IntoConst { const VALUE: T; } -struct ConstApplyNegSign::Type>>(*const T, *const Param); -struct ConstApplyPosSign::Type>>(*const T, *const Param); -struct ConstLshift, const SHIFT : i32>(*const T, *const Param); // impl IntoConst +struct ConstApplyNegSign::Type>>( + *const T, + *const Param, +); +struct ConstApplyPosSign::Type>>( + *const T, + *const Param, +); +struct ConstLshift, const SHIFT: i32>(*const T, *const Param); // impl IntoConst struct ConstAdd, Rhs: IntoConst>(*const T, *const Lhs, *const Rhs); // impl IntoConst /// Assigns an unsigned type to a signed type @@ -26,28 +36,33 @@ trait AssociatedUnsigned { } macro_rules! impl_into_const { - ( $from:ty as $to:ty := $impl:expr) => { + ( $from:ty as $to:ty := $impl:expr) => { impl IntoConst<$to> for $from { - const VALUE : $to = $impl; + const VALUE: $to = $impl; } }; } macro_rules! impl_numeric_into_const_common { - ($type:ty) => { + ($type:ty) => { impl_into_const! { Z0 as $type := 0 } impl_into_const! { B0 as $type := 0 } impl_into_const! { B1 as $type := 1 } impl_into_const! { UTerm as $type := 0 } - impl, const SHIFT : i32> IntoConst<$type> for ConstLshift<$type, Param, SHIFT> { - const VALUE : $type = Param::VALUE << SHIFT; + impl, const SHIFT: i32> IntoConst<$type> + for ConstLshift<$type, Param, SHIFT> + { + const VALUE: $type = Param::VALUE << SHIFT; } - impl, Rhs: IntoConst<$type>> IntoConst<$type> for ConstAdd<$type, Lhs, Rhs> { - const VALUE: $type = >::VALUE + >::VALUE; + impl, Rhs: IntoConst<$type>> IntoConst<$type> + for ConstAdd<$type, Lhs, Rhs> + { + const VALUE: $type = + >::VALUE + >::VALUE; } - } + }; } macro_rules! impl_numeric_into_const_unsigned { @@ -99,38 +114,38 @@ macro_rules! impl_numeric_into_const_signed { impl_into_const! { B0 as bool := false } impl_into_const! { B1 as bool := true } -impl_numeric_into_const_unsigned!{ usize, u8, u16, u32, u64, u128 } -impl_numeric_into_const_signed!{ isize : usize, i8 : u8, i16 : u16, i32 : u32, i64 : u64, i128 : u128 } +impl_numeric_into_const_unsigned! { usize, u8, u16, u32, u64, u128 } +impl_numeric_into_const_signed! { isize : usize, i8 : u8, i16 : u16, i32 : u32, i64 : u64, i128 : u128 } // Unsigned type numbers to const integers impl IntoConst for UInt - where - Rest: IntoConst, - Bit: IntoConst, - ConstLshift: IntoConst, - ConstAdd, Bit>: IntoConst, +where + Rest: IntoConst, + Bit: IntoConst, + ConstLshift: IntoConst, + ConstAdd, Bit>: IntoConst, { - const VALUE: Ret = < - ConstAdd, Bit> as IntoConst - >::VALUE; + const VALUE: Ret = , Bit> as IntoConst>::VALUE; } // Signed type numbers with positive sign to const integers impl IntoConst for PInt - where - Ret: AssociatedUnsigned, - Unsigned: markers::Unsigned + markers::NonZero + IntoConst<::Type>, - ConstApplyPosSign: IntoConst { - const VALUE: Ret = as IntoConst>::VALUE; +where + Ret: AssociatedUnsigned, + Unsigned: markers::Unsigned + markers::NonZero + IntoConst<::Type>, + ConstApplyPosSign: IntoConst, +{ + const VALUE: Ret = as IntoConst>::VALUE; } // Signed type numbers with negative sign to const integers impl IntoConst for NInt - where - Ret: AssociatedUnsigned, - Unsigned: markers::Unsigned + markers::NonZero + IntoConst<::Type>, - ConstApplyNegSign: IntoConst { - const VALUE: Ret = as IntoConst>::VALUE; +where + Ret: AssociatedUnsigned, + Unsigned: markers::Unsigned + markers::NonZero + IntoConst<::Type>, + ConstApplyNegSign: IntoConst, +{ + const VALUE: Ret = as IntoConst>::VALUE; } mod test {