cryprot_core/
lib.rs

1#![cfg_attr(feature = "nightly", feature(test))]
2
3pub mod aes_hash;
4pub mod aes_rng;
5pub mod alloc;
6pub mod block;
7pub mod buf;
8pub mod random_oracle;
9#[cfg(feature = "tokio-rayon")]
10pub mod tokio_rayon;
11pub mod transpose;
12pub mod utils;
13
14pub use block::Block;
15
16#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
17// https://github.com/RustCrypto/block-ciphers/blob/4da9b802de52a3326fdc74d559caddd57042fed2/aes/src/ni.rs#L43
18pub const AES_PAR_BLOCKS: usize = 9;
19#[cfg(target_arch = "aarch64")]
20// https://github.com/RustCrypto/block-ciphers/blob/4da9b802de52a3326fdc74d559caddd57042fed2/aes/src/armv8.rs#L32
21pub const AES_PAR_BLOCKS: usize = 21;
22#[cfg(not(any(target_arch = "x86", target_arch = "x86_64", target_arch = "aarch64")))]
23// TODO what should the fallback be?
24pub const AES_PAR_BLOCKS: usize = 4;
25
26#[cfg(all(test, not(miri), target_feature = "aes"))]
27mod tests {
28    use aes::{
29        cipher::{
30            BlockCipherEncClosure, BlockCipherEncrypt, BlockSizeUser, KeyInit, ParBlocksSizeUser,
31        },
32        Aes128,
33    };
34
35    use crate::AES_PAR_BLOCKS;
36
37    #[test]
38    fn aes_par_block_size() {
39        use hybrid_array::typenum::Unsigned;
40
41        struct GetParBlockSize;
42        impl BlockSizeUser for GetParBlockSize {
43            type BlockSize = aes::cipher::array::sizes::U16;
44        }
45        impl BlockCipherEncClosure for GetParBlockSize {
46            fn call<B: aes::cipher::BlockCipherEncBackend<BlockSize = Self::BlockSize>>(
47                self,
48                _backend: &B,
49            ) {
50                assert_eq!(
51                    AES_PAR_BLOCKS,
52                    // size_of ArrayType<u8> is equal to its length
53                    <<B as ParBlocksSizeUser>::ParBlocksSize as Unsigned>::USIZE,
54                );
55            }
56        }
57        let aes = Aes128::new(&Default::default());
58        aes.encrypt_with_backend(GetParBlockSize);
59    }
60}