chore: Cargo fmt

This commit is contained in:
Karolin Varner
2024-01-21 20:53:16 +01:00
committed by Karolin Varner
parent ca972e8b70
commit 9690085156
9 changed files with 71 additions and 65 deletions

View File

@@ -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

View File

@@ -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<U32>;
@@ -14,8 +14,8 @@ type Impl = Blake2bMac<U32>;
type KeyLen = <Impl as KeySizeUser>::KeySize;
type OutLen = <Impl as OutputSizeUser>::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;

View File

@@ -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! { <AeadImpl as KeySizeUser>::KeySize };
pub const TAG_LEN: usize = typenum2const! { <AeadImpl as AeadCore>::TagSize };

View File

@@ -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;

View File

@@ -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! { <AeadImpl as KeySizeUser>::KeySize };
pub const TAG_LEN: usize = typenum2const! { <AeadImpl as AeadCore>::TagSize };

View File

@@ -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]

View File

@@ -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() {

View File

@@ -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"
);

View File

@@ -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<T> {
const VALUE: T;
}
struct ConstApplyNegSign<T: AssociatedUnsigned, Param: IntoConst<<T as AssociatedUnsigned>::Type>>(*const T, *const Param);
struct ConstApplyPosSign<T: AssociatedUnsigned, Param: IntoConst<<T as AssociatedUnsigned>::Type>>(*const T, *const Param);
struct ConstLshift<T, Param: IntoConst<T>, const SHIFT : i32>(*const T, *const Param); // impl IntoConst<T>
struct ConstApplyNegSign<T: AssociatedUnsigned, Param: IntoConst<<T as AssociatedUnsigned>::Type>>(
*const T,
*const Param,
);
struct ConstApplyPosSign<T: AssociatedUnsigned, Param: IntoConst<<T as AssociatedUnsigned>::Type>>(
*const T,
*const Param,
);
struct ConstLshift<T, Param: IntoConst<T>, const SHIFT: i32>(*const T, *const Param); // impl IntoConst<T>
struct ConstAdd<T, Lhs: IntoConst<T>, Rhs: IntoConst<T>>(*const T, *const Lhs, *const Rhs); // impl IntoConst<T>
/// 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<Param: IntoConst<$type>, const SHIFT : i32> IntoConst<$type> for ConstLshift<$type, Param, SHIFT> {
const VALUE : $type = Param::VALUE << SHIFT;
impl<Param: IntoConst<$type>, const SHIFT: i32> IntoConst<$type>
for ConstLshift<$type, Param, SHIFT>
{
const VALUE: $type = Param::VALUE << SHIFT;
}
impl<Lhs: IntoConst<$type>, Rhs: IntoConst<$type>> IntoConst<$type> for ConstAdd<$type, Lhs, Rhs> {
const VALUE: $type = <Lhs as IntoConst<$type>>::VALUE + <Rhs as IntoConst<$type>>::VALUE;
impl<Lhs: IntoConst<$type>, Rhs: IntoConst<$type>> IntoConst<$type>
for ConstAdd<$type, Lhs, Rhs>
{
const VALUE: $type =
<Lhs as IntoConst<$type>>::VALUE + <Rhs as IntoConst<$type>>::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<Ret, Rest, Bit> IntoConst<Ret> for UInt<Rest, Bit>
where
Rest: IntoConst<Ret>,
Bit: IntoConst<Ret>,
ConstLshift<Ret, Rest, 1>: IntoConst<Ret>,
ConstAdd<Ret, ConstLshift<Ret, Rest, 1>, Bit>: IntoConst<Ret>,
where
Rest: IntoConst<Ret>,
Bit: IntoConst<Ret>,
ConstLshift<Ret, Rest, 1>: IntoConst<Ret>,
ConstAdd<Ret, ConstLshift<Ret, Rest, 1>, Bit>: IntoConst<Ret>,
{
const VALUE: Ret = <
ConstAdd<Ret, ConstLshift<Ret, Rest, 1>, Bit> as IntoConst<Ret>
>::VALUE;
const VALUE: Ret = <ConstAdd<Ret, ConstLshift<Ret, Rest, 1>, Bit> as IntoConst<Ret>>::VALUE;
}
// Signed type numbers with positive sign to const integers
impl<Ret, Unsigned> IntoConst<Ret> for PInt<Unsigned>
where
Ret: AssociatedUnsigned,
Unsigned: markers::Unsigned + markers::NonZero + IntoConst<<Ret as AssociatedUnsigned>::Type>,
ConstApplyPosSign<Ret, Unsigned>: IntoConst<Ret> {
const VALUE: Ret = <ConstApplyPosSign::<Ret, Unsigned> as IntoConst<Ret>>::VALUE;
where
Ret: AssociatedUnsigned,
Unsigned: markers::Unsigned + markers::NonZero + IntoConst<<Ret as AssociatedUnsigned>::Type>,
ConstApplyPosSign<Ret, Unsigned>: IntoConst<Ret>,
{
const VALUE: Ret = <ConstApplyPosSign<Ret, Unsigned> as IntoConst<Ret>>::VALUE;
}
// Signed type numbers with negative sign to const integers
impl<Ret, Unsigned> IntoConst<Ret> for NInt<Unsigned>
where
Ret: AssociatedUnsigned,
Unsigned: markers::Unsigned + markers::NonZero + IntoConst<<Ret as AssociatedUnsigned>::Type>,
ConstApplyNegSign<Ret, Unsigned>: IntoConst<Ret> {
const VALUE: Ret = <ConstApplyNegSign::<Ret, Unsigned> as IntoConst<Ret>>::VALUE;
where
Ret: AssociatedUnsigned,
Unsigned: markers::Unsigned + markers::NonZero + IntoConst<<Ret as AssociatedUnsigned>::Type>,
ConstApplyNegSign<Ret, Unsigned>: IntoConst<Ret>,
{
const VALUE: Ret = <ConstApplyNegSign<Ret, Unsigned> as IntoConst<Ret>>::VALUE;
}
mod test {