ssh_cipher/
block_cipher.rs1#[cfg(feature = "aes")]
7mod aes;
8mod decryptor;
9mod encryptor;
10mod state;
11
12pub use self::{decryptor::Decryptor, encryptor::Encryptor};
13pub use ::cipher::{
14 Block, BlockModeDecrypt, BlockModeEncrypt, common::BlockSizeUser, common::InvalidLength,
15};
16
17#[cfg(feature = "aes")]
18pub use self::aes::Aes;
19#[cfg(feature = "tdes")]
20pub use ::des::TdesEde3 as Tdes;
21
22use self::state::State;
23
24#[cfg(feature = "tdes")]
25use {crate::Cipher, ::cipher::common::KeyInit};
26
27pub(crate) mod sealed {
29 use crate::Cipher;
30 use ::cipher::{BlockCipherDecrypt, BlockCipherEncrypt, common::InvalidLength};
31
32 pub trait BlockCipher: BlockCipherDecrypt + BlockCipherEncrypt {
38 fn new_from_slice(slice: &[u8]) -> Result<Self, InvalidLength>;
45
46 fn is_supported(cipher: Cipher) -> bool;
48 }
49}
50
51#[derive(Copy, Clone, Debug, Eq, PartialEq)]
53pub(crate) enum BlockMode {
54 Cbc,
56
57 Ctr,
59}
60
61#[cfg(feature = "aes")]
63pub type AesEncryptor = Encryptor<Aes>;
64#[cfg(feature = "aes")]
66pub type AesDecryptor = Decryptor<Aes>;
67
68#[cfg(feature = "tdes")]
70pub type TdesEncryptor = Encryptor<Tdes>;
71#[cfg(feature = "tdes")]
73pub type TdesDecryptor = Decryptor<Tdes>;
74
75#[cfg(feature = "tdes")]
76impl sealed::BlockCipher for Tdes {
77 fn new_from_slice(slice: &[u8]) -> Result<Self, InvalidLength> {
78 KeyInit::new_from_slice(slice)
79 }
80
81 fn is_supported(cipher: Cipher) -> bool {
82 cipher == Cipher::TdesCbc
83 }
84}