mirror of
https://github.com/rosenpass/rosenpass.git
synced 2026-01-06 18:14:51 -08:00
This finishes the last step of removing sodium.rs from the rosenpass crate itself and also removes the NOTHING and NONCE0 constants. Hashing functions now use destination parameters; rosenpass_constant_time::xor now does too.
27 lines
612 B
Rust
27 lines
612 B
Rust
use rosenpass_to::{with_destination, To};
|
|
|
|
/// Xors the source into the destination
|
|
///
|
|
/// # Examples
|
|
///
|
|
/// ```
|
|
/// use rosenpass_constant_time::xor;
|
|
/// use rosenpass_to::To;
|
|
/// assert_eq!(
|
|
/// xor(b"world").to_this(|| b"hello".to_vec()),
|
|
/// b"\x1f\n\x1e\x00\x0b");
|
|
/// ```
|
|
///
|
|
/// # Panics
|
|
///
|
|
/// If source and destination are of different sizes.
|
|
#[inline]
|
|
pub fn xor<'a>(src: &'a [u8]) -> impl To<[u8], ()> + 'a {
|
|
with_destination(|dst: &mut [u8]| {
|
|
assert!(src.len() == dst.len());
|
|
for (dv, sv) in dst.iter_mut().zip(src.iter()) {
|
|
*dv ^= *sv;
|
|
}
|
|
})
|
|
}
|