feat: fix tests
This commit is contained in:
@@ -22,7 +22,7 @@ const CHACHA20_COUNTER_OVERFLOW: u64 = ((1 << 32) - 1) * 64;
|
|||||||
/// # Example
|
/// # Example
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// use chacha20_poly1305_aead::encrypt;
|
/// use chacha20_poly1305_stream::encrypt;
|
||||||
///
|
///
|
||||||
/// let key = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
|
/// let key = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
|
||||||
/// 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31];
|
/// 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31];
|
||||||
@@ -99,9 +99,9 @@ pub fn encrypt_read<R: Read, W: Write>(key: &[u8], nonce: &[u8],
|
|||||||
/// # Example
|
/// # Example
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// # use chacha20_poly1305_aead::DecryptError;
|
/// # use chacha20_poly1305_stream::DecryptError;
|
||||||
/// # fn example() -> Result<(), DecryptError> {
|
/// # fn example() -> Result<(), DecryptError> {
|
||||||
/// use chacha20_poly1305_aead::decrypt;
|
/// use chacha20_poly1305_stream::decrypt;
|
||||||
///
|
///
|
||||||
/// let key = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
|
/// let key = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
|
||||||
/// 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31];
|
/// 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31];
|
||||||
@@ -116,7 +116,7 @@ pub fn encrypt_read<R: Read, W: Write>(key: &[u8], nonce: &[u8],
|
|||||||
/// // Vec implements the Write trait
|
/// // Vec implements the Write trait
|
||||||
/// let mut plaintext = Vec::with_capacity(ciphertext.len());
|
/// let mut plaintext = Vec::with_capacity(ciphertext.len());
|
||||||
///
|
///
|
||||||
/// try!(decrypt(&key, &nonce, &aad, &ciphertext, &tag, &mut plaintext));
|
/// decrypt(&key, &nonce, &aad, &ciphertext, &tag, &mut plaintext)?;
|
||||||
///
|
///
|
||||||
/// assert_eq!(plaintext, b"hello, world");
|
/// assert_eq!(plaintext, b"hello, world");
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
|
|||||||
@@ -34,10 +34,17 @@ impl<T: Safe> AsBytes for [T] {
|
|||||||
}
|
}
|
||||||
|
|
||||||
unsafe impl Safe for u8 {}
|
unsafe impl Safe for u8 {}
|
||||||
|
|
||||||
unsafe impl Safe for u16 {}
|
unsafe impl Safe for u16 {}
|
||||||
|
|
||||||
unsafe impl Safe for u32 {}
|
unsafe impl Safe for u32 {}
|
||||||
|
|
||||||
unsafe impl Safe for u64 {}
|
unsafe impl Safe for u64 {}
|
||||||
|
|
||||||
unsafe impl Safe for i8 {}
|
unsafe impl Safe for i8 {}
|
||||||
|
|
||||||
unsafe impl Safe for i16 {}
|
unsafe impl Safe for i16 {}
|
||||||
|
|
||||||
unsafe impl Safe for i32 {}
|
unsafe impl Safe for i32 {}
|
||||||
|
|
||||||
unsafe impl Safe for i64 {}
|
unsafe impl Safe for i64 {}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ use crate::simd::{Vector4, u32x4};
|
|||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct ChaCha20 {
|
pub struct ChaCha20 {
|
||||||
state: [u32x4; 3]
|
state: [u32x4; 3],
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(feature = "clippy", allow(should_implement_trait))]
|
#[cfg_attr(feature = "clippy", allow(should_implement_trait))]
|
||||||
@@ -127,7 +127,7 @@ pub fn selftest() {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use as_bytes::AsBytes;
|
use crate::as_bytes::AsBytes;
|
||||||
use super::ChaCha20;
|
use super::ChaCha20;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
@@ -276,7 +276,7 @@ pub fn selftest() {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use as_bytes::AsBytes;
|
use crate::as_bytes::AsBytes;
|
||||||
use super::Poly1305;
|
use super::Poly1305;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
@@ -23,9 +23,12 @@ pub trait Vector4<T>: Copy {
|
|||||||
fn shuffle_left_2(self) -> Self;
|
fn shuffle_left_2(self) -> Self;
|
||||||
fn shuffle_left_3(self) -> Self;
|
fn shuffle_left_3(self) -> Self;
|
||||||
|
|
||||||
#[inline(always)] fn shuffle_right_1(self) -> Self { self.shuffle_left_3() }
|
#[inline(always)]
|
||||||
#[inline(always)] fn shuffle_right_2(self) -> Self { self.shuffle_left_2() }
|
fn shuffle_right_1(self) -> Self { self.shuffle_left_3() }
|
||||||
#[inline(always)] fn shuffle_right_3(self) -> Self { self.shuffle_left_1() }
|
#[inline(always)]
|
||||||
|
fn shuffle_right_2(self) -> Self { self.shuffle_left_2() }
|
||||||
|
#[inline(always)]
|
||||||
|
fn shuffle_right_3(self) -> Self { self.shuffle_left_1() }
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! impl_vector4 {
|
macro_rules! impl_vector4 {
|
||||||
|
|||||||
@@ -6,7 +6,8 @@
|
|||||||
// copied, modified, or distributed except according to those terms.
|
// copied, modified, or distributed except according to those terms.
|
||||||
|
|
||||||
use crate::simdty::u32x4;
|
use crate::simdty::u32x4;
|
||||||
#[cfg(feature = "simd")] use crate::simdint;
|
#[cfg(feature = "simd")]
|
||||||
|
use crate::simdint;
|
||||||
|
|
||||||
use std::ops::{Add, BitXor, Shl, Shr};
|
use std::ops::{Add, BitXor, Shl, Shr};
|
||||||
|
|
||||||
|
|||||||
@@ -55,5 +55,7 @@ impl<T> Simd4<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
unsafe impl<T: Safe> Safe for Simd4<T> {}
|
unsafe impl<T: Safe> Safe for Simd4<T> {}
|
||||||
|
|
||||||
unsafe impl<T: Safe> Safe for Simd8<T> {}
|
unsafe impl<T: Safe> Safe for Simd8<T> {}
|
||||||
|
|
||||||
unsafe impl<T: Safe> Safe for Simd16<T> {}
|
unsafe impl<T: Safe> Safe for Simd16<T> {}
|
||||||
|
|||||||
Reference in New Issue
Block a user