mirror of
https://github.com/rosenpass/rosenpass.git
synced 2026-02-28 14:33:37 -08:00
chore: Cargo fmt
This commit is contained in:
committed by
Karolin Varner
parent
ca972e8b70
commit
9690085156
@@ -9,9 +9,7 @@ const_assert!(KEY_LEN == hash_domain::KEY_LEN);
|
|||||||
|
|
||||||
/// Authenticated encryption with associated data
|
/// Authenticated encryption with associated data
|
||||||
pub mod aead {
|
pub mod aead {
|
||||||
pub use crate::subtle::chacha20poly1305_ietf::{
|
pub use crate::subtle::chacha20poly1305_ietf::{decrypt, encrypt, KEY_LEN, NONCE_LEN, TAG_LEN};
|
||||||
decrypt, encrypt, KEY_LEN, NONCE_LEN, TAG_LEN,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Authenticated encryption with associated data with a constant nonce
|
/// Authenticated encryption with associated data with a constant nonce
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
use zeroize::Zeroizing;
|
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::generic_array::GenericArray;
|
||||||
use blake2::digest::crypto_common::typenum::U32;
|
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;
|
use rosenpass_util::typenum2const;
|
||||||
|
|
||||||
type Impl = Blake2bMac<U32>;
|
type Impl = Blake2bMac<U32>;
|
||||||
@@ -14,8 +14,8 @@ type Impl = Blake2bMac<U32>;
|
|||||||
type KeyLen = <Impl as KeySizeUser>::KeySize;
|
type KeyLen = <Impl as KeySizeUser>::KeySize;
|
||||||
type OutLen = <Impl as OutputSizeUser>::OutputSize;
|
type OutLen = <Impl as OutputSizeUser>::OutputSize;
|
||||||
|
|
||||||
const KEY_LEN : usize = typenum2const! { KeyLen };
|
const KEY_LEN: usize = typenum2const! { KeyLen };
|
||||||
const OUT_LEN : usize = typenum2const! { OutLen };
|
const OUT_LEN: usize = typenum2const! { OutLen };
|
||||||
|
|
||||||
pub const KEY_MIN: usize = KEY_LEN;
|
pub const KEY_MIN: usize = KEY_LEN;
|
||||||
pub const KEY_MAX: usize = KEY_LEN;
|
pub const KEY_MAX: usize = KEY_LEN;
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
use rosenpass_to::To;
|
|
||||||
use rosenpass_to::ops::copy_slice;
|
use rosenpass_to::ops::copy_slice;
|
||||||
|
use rosenpass_to::To;
|
||||||
use rosenpass_util::typenum2const;
|
use rosenpass_util::typenum2const;
|
||||||
|
|
||||||
use chacha20poly1305::aead::generic_array::GenericArray;
|
use chacha20poly1305::aead::generic_array::GenericArray;
|
||||||
use chacha20poly1305::{ChaCha20Poly1305 as AeadImpl};
|
use chacha20poly1305::ChaCha20Poly1305 as AeadImpl;
|
||||||
use chacha20poly1305::{AeadCore, KeySizeUser, KeyInit, AeadInPlace};
|
use chacha20poly1305::{AeadCore, AeadInPlace, KeyInit, KeySizeUser};
|
||||||
|
|
||||||
pub const KEY_LEN: usize = typenum2const! { <AeadImpl as KeySizeUser>::KeySize };
|
pub const KEY_LEN: usize = typenum2const! { <AeadImpl as KeySizeUser>::KeySize };
|
||||||
pub const TAG_LEN: usize = typenum2const! { <AeadImpl as AeadCore>::TagSize };
|
pub const TAG_LEN: usize = typenum2const! { <AeadImpl as AeadCore>::TagSize };
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
pub mod incorrect_hmac_blake2b;
|
|
||||||
pub mod chacha20poly1305_ietf;
|
|
||||||
pub mod xchacha20poly1305_ietf;
|
|
||||||
pub mod blake2b;
|
pub mod blake2b;
|
||||||
|
pub mod chacha20poly1305_ietf;
|
||||||
|
pub mod incorrect_hmac_blake2b;
|
||||||
|
pub mod xchacha20poly1305_ietf;
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
use rosenpass_to::To;
|
|
||||||
use rosenpass_to::ops::copy_slice;
|
use rosenpass_to::ops::copy_slice;
|
||||||
|
use rosenpass_to::To;
|
||||||
use rosenpass_util::typenum2const;
|
use rosenpass_util::typenum2const;
|
||||||
|
|
||||||
use chacha20poly1305::aead::generic_array::GenericArray;
|
use chacha20poly1305::aead::generic_array::GenericArray;
|
||||||
use chacha20poly1305::{XChaCha20Poly1305 as AeadImpl};
|
use chacha20poly1305::XChaCha20Poly1305 as AeadImpl;
|
||||||
use chacha20poly1305::{AeadCore, KeySizeUser, KeyInit, AeadInPlace};
|
use chacha20poly1305::{AeadCore, AeadInPlace, KeyInit, KeySizeUser};
|
||||||
|
|
||||||
pub const KEY_LEN: usize = typenum2const! { <AeadImpl as KeySizeUser>::KeySize };
|
pub const KEY_LEN: usize = typenum2const! { <AeadImpl as KeySizeUser>::KeySize };
|
||||||
pub const TAG_LEN: usize = typenum2const! { <AeadImpl as AeadCore>::TagSize };
|
pub const TAG_LEN: usize = typenum2const! { <AeadImpl as AeadCore>::TagSize };
|
||||||
|
|||||||
@@ -30,13 +30,7 @@ pub fn xor(src: &[u8]) -> impl To<[u8], ()> + '_ {
|
|||||||
#[inline]
|
#[inline]
|
||||||
pub fn memcmp(a: &[u8], b: &[u8]) -> bool {
|
pub fn memcmp(a: &[u8], b: &[u8]) -> bool {
|
||||||
a.len() == b.len()
|
a.len() == b.len()
|
||||||
&& unsafe {
|
&& unsafe { memsec::memeq(a.as_ptr() as *const u8, b.as_ptr() as *const u8, a.len()) }
|
||||||
memsec::memeq(
|
|
||||||
a.as_ptr() as *const u8,
|
|
||||||
b.as_ptr() as *const u8,
|
|
||||||
a.len(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use log::error;
|
use log::error;
|
||||||
use std::process::exit;
|
|
||||||
use rosenpass::cli::Cli;
|
use rosenpass::cli::Cli;
|
||||||
|
use std::process::exit;
|
||||||
|
|
||||||
/// Catches errors, prints them through the logger, then exits
|
/// Catches errors, prints them through the logger, then exits
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
|
|||||||
@@ -77,10 +77,10 @@ use rosenpass_cipher_traits::Kem;
|
|||||||
use rosenpass_ciphers::hash_domain::{SecretHashDomain, SecretHashDomainNamespace};
|
use rosenpass_ciphers::hash_domain::{SecretHashDomain, SecretHashDomainNamespace};
|
||||||
use rosenpass_ciphers::kem::{EphemeralKem, StaticKem};
|
use rosenpass_ciphers::kem::{EphemeralKem, StaticKem};
|
||||||
use rosenpass_ciphers::{aead, xaead, KEY_LEN};
|
use rosenpass_ciphers::{aead, xaead, KEY_LEN};
|
||||||
|
use rosenpass_constant_time as constant_time;
|
||||||
use rosenpass_lenses::LenseView;
|
use rosenpass_lenses::LenseView;
|
||||||
use rosenpass_secret_memory::{Public, Secret};
|
use rosenpass_secret_memory::{Public, Secret};
|
||||||
use rosenpass_util::{cat, mem::cpy_min, ord::max_usize, time::Timebase};
|
use rosenpass_util::{cat, mem::cpy_min, ord::max_usize, time::Timebase};
|
||||||
use rosenpass_constant_time as constant_time;
|
|
||||||
|
|
||||||
use crate::{hash_domains, msgs::*};
|
use crate::{hash_domains, msgs::*};
|
||||||
|
|
||||||
@@ -1364,8 +1364,7 @@ impl HandshakeState {
|
|||||||
// indicates retransmission
|
// indicates retransmission
|
||||||
// TODO: Handle retransmissions without involving the crypto code
|
// TODO: Handle retransmissions without involving the crypto code
|
||||||
ensure!(
|
ensure!(
|
||||||
constant_time::compare(biscuit.biscuit_no(), &*peer.get(srv).biscuit_used)
|
constant_time::compare(biscuit.biscuit_no(), &*peer.get(srv).biscuit_used) >= 0,
|
||||||
>= 0,
|
|
||||||
"Rejecting biscuit: Outdated biscuit number"
|
"Rejecting biscuit: Outdated biscuit number"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,17 @@
|
|||||||
use typenum::bit::{B1, B0};
|
use typenum::bit::{B0, B1};
|
||||||
use typenum::int::{Z0, NInt, PInt};
|
use typenum::int::{NInt, PInt, Z0};
|
||||||
use typenum::uint::{UInt, UTerm};
|
|
||||||
use typenum::marker_traits as markers;
|
use typenum::marker_traits as markers;
|
||||||
|
use typenum::uint::{UInt, UTerm};
|
||||||
|
|
||||||
/// Convenience macro to convert type numbers to constant integers
|
/// Convenience macro to convert type numbers to constant integers
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! typenum2const {
|
macro_rules! typenum2const {
|
||||||
($val:ty) => { typenum2const!($val as _) };
|
($val:ty) => {
|
||||||
($val:ty as $type:ty) => { < $val as $crate::typenum::IntoConst<$type> >::VALUE };
|
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
|
/// Trait implemented by constant integers to facilitate conversion to constant integers
|
||||||
@@ -15,9 +19,15 @@ pub trait IntoConst<T> {
|
|||||||
const VALUE: T;
|
const VALUE: T;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ConstApplyNegSign<T: AssociatedUnsigned, Param: IntoConst<<T as AssociatedUnsigned>::Type>>(*const T, *const Param);
|
struct ConstApplyNegSign<T: AssociatedUnsigned, Param: IntoConst<<T as AssociatedUnsigned>::Type>>(
|
||||||
struct ConstApplyPosSign<T: AssociatedUnsigned, Param: IntoConst<<T as AssociatedUnsigned>::Type>>(*const T, *const Param);
|
*const T,
|
||||||
struct ConstLshift<T, Param: IntoConst<T>, const SHIFT : i32>(*const T, *const Param); // impl IntoConst<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>
|
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
|
/// Assigns an unsigned type to a signed type
|
||||||
@@ -28,7 +38,7 @@ trait AssociatedUnsigned {
|
|||||||
macro_rules! impl_into_const {
|
macro_rules! impl_into_const {
|
||||||
( $from:ty as $to:ty := $impl:expr) => {
|
( $from:ty as $to:ty := $impl:expr) => {
|
||||||
impl IntoConst<$to> for $from {
|
impl IntoConst<$to> for $from {
|
||||||
const VALUE : $to = $impl;
|
const VALUE: $to = $impl;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -40,14 +50,19 @@ macro_rules! impl_numeric_into_const_common {
|
|||||||
impl_into_const! { B1 as $type := 1 }
|
impl_into_const! { B1 as $type := 1 }
|
||||||
impl_into_const! { UTerm as $type := 0 }
|
impl_into_const! { UTerm as $type := 0 }
|
||||||
|
|
||||||
impl<Param: IntoConst<$type>, const SHIFT : i32> IntoConst<$type> for ConstLshift<$type, Param, SHIFT> {
|
impl<Param: IntoConst<$type>, const SHIFT: i32> IntoConst<$type>
|
||||||
const VALUE : $type = Param::VALUE << SHIFT;
|
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> {
|
impl<Lhs: IntoConst<$type>, Rhs: IntoConst<$type>> IntoConst<$type>
|
||||||
const VALUE: $type = <Lhs as IntoConst<$type>>::VALUE + <Rhs as IntoConst<$type>>::VALUE;
|
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 {
|
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! { B0 as bool := false }
|
||||||
impl_into_const! { B1 as bool := true }
|
impl_into_const! { B1 as bool := true }
|
||||||
impl_numeric_into_const_unsigned!{ usize, u8, u16, u32, u64, 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 }
|
impl_numeric_into_const_signed! { isize : usize, i8 : u8, i16 : u16, i32 : u32, i64 : u64, i128 : u128 }
|
||||||
|
|
||||||
// Unsigned type numbers to const integers
|
// Unsigned type numbers to const integers
|
||||||
impl<Ret, Rest, Bit> IntoConst<Ret> for UInt<Rest, Bit>
|
impl<Ret, Rest, Bit> IntoConst<Ret> for UInt<Rest, Bit>
|
||||||
where
|
where
|
||||||
Rest: IntoConst<Ret>,
|
Rest: IntoConst<Ret>,
|
||||||
Bit: IntoConst<Ret>,
|
Bit: IntoConst<Ret>,
|
||||||
ConstLshift<Ret, Rest, 1>: IntoConst<Ret>,
|
ConstLshift<Ret, Rest, 1>: IntoConst<Ret>,
|
||||||
ConstAdd<Ret, ConstLshift<Ret, Rest, 1>, Bit>: IntoConst<Ret>,
|
ConstAdd<Ret, ConstLshift<Ret, Rest, 1>, Bit>: IntoConst<Ret>,
|
||||||
{
|
{
|
||||||
const VALUE: Ret = <
|
const VALUE: Ret = <ConstAdd<Ret, ConstLshift<Ret, Rest, 1>, Bit> as IntoConst<Ret>>::VALUE;
|
||||||
ConstAdd<Ret, ConstLshift<Ret, Rest, 1>, Bit> as IntoConst<Ret>
|
|
||||||
>::VALUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Signed type numbers with positive sign to const integers
|
// Signed type numbers with positive sign to const integers
|
||||||
impl<Ret, Unsigned> IntoConst<Ret> for PInt<Unsigned>
|
impl<Ret, Unsigned> IntoConst<Ret> for PInt<Unsigned>
|
||||||
where
|
where
|
||||||
Ret: AssociatedUnsigned,
|
Ret: AssociatedUnsigned,
|
||||||
Unsigned: markers::Unsigned + markers::NonZero + IntoConst<<Ret as AssociatedUnsigned>::Type>,
|
Unsigned: markers::Unsigned + markers::NonZero + IntoConst<<Ret as AssociatedUnsigned>::Type>,
|
||||||
ConstApplyPosSign<Ret, Unsigned>: IntoConst<Ret> {
|
ConstApplyPosSign<Ret, Unsigned>: IntoConst<Ret>,
|
||||||
const VALUE: Ret = <ConstApplyPosSign::<Ret, Unsigned> as IntoConst<Ret>>::VALUE;
|
{
|
||||||
|
const VALUE: Ret = <ConstApplyPosSign<Ret, Unsigned> as IntoConst<Ret>>::VALUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Signed type numbers with negative sign to const integers
|
// Signed type numbers with negative sign to const integers
|
||||||
impl<Ret, Unsigned> IntoConst<Ret> for NInt<Unsigned>
|
impl<Ret, Unsigned> IntoConst<Ret> for NInt<Unsigned>
|
||||||
where
|
where
|
||||||
Ret: AssociatedUnsigned,
|
Ret: AssociatedUnsigned,
|
||||||
Unsigned: markers::Unsigned + markers::NonZero + IntoConst<<Ret as AssociatedUnsigned>::Type>,
|
Unsigned: markers::Unsigned + markers::NonZero + IntoConst<<Ret as AssociatedUnsigned>::Type>,
|
||||||
ConstApplyNegSign<Ret, Unsigned>: IntoConst<Ret> {
|
ConstApplyNegSign<Ret, Unsigned>: IntoConst<Ret>,
|
||||||
const VALUE: Ret = <ConstApplyNegSign::<Ret, Unsigned> as IntoConst<Ret>>::VALUE;
|
{
|
||||||
|
const VALUE: Ret = <ConstApplyNegSign<Ret, Unsigned> as IntoConst<Ret>>::VALUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
mod test {
|
mod test {
|
||||||
|
|||||||
Reference in New Issue
Block a user