Skip to content

Commit fc7b1e9

Browse files
committed
ssh-cipher: move Decryptor/Encryptor under block_cipher
1 parent 7b98c13 commit fc7b1e9

5 files changed

Lines changed: 27 additions & 29 deletions

File tree

ssh-cipher/src/block_cipher.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//! Low-level block cipher interface.
2+
//!
3+
//! This module provides APIs which enable streaming and "peeking" when using unauthenticated block
4+
//! cipher modes such as CBC and CTR.
5+
6+
mod aes;
7+
mod decryptor;
8+
mod encryptor;
9+
10+
pub(crate) use self::aes::Aes;
11+
pub use self::{decryptor::Decryptor, encryptor::Encryptor};
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use cipher::{
88
use core::fmt::{self, Debug};
99
#[cfg(feature = "aes")]
1010
use {
11-
crate::aes::Aes,
11+
super::Aes,
1212
cipher::{InnerIvInit, StreamCipher, StreamCipherSeek},
1313
ctr::{Ctr128BE, CtrCore},
1414
};
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use core::fmt::{self, Debug};
66

77
#[cfg(feature = "aes")]
88
use {
9-
crate::aes::Aes,
9+
super::Aes,
1010
cipher::{InnerIvInit, StreamCipher},
1111
ctr::{Ctr128BE, CtrCore},
1212
};

ssh-cipher/src/lib.rs

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,60 +6,47 @@
66
html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/media/6ee8e381/logo.svg"
77
)]
88

9-
mod error;
9+
#[cfg(any(feature = "aes", feature = "tdes"))]
10+
pub mod block_cipher;
1011

11-
#[cfg(feature = "aes")]
12-
mod aes;
1312
#[cfg(feature = "chacha20poly1305")]
1413
mod chacha20poly1305;
15-
#[cfg(any(feature = "aes", feature = "tdes"))]
16-
mod decryptor;
17-
#[cfg(any(feature = "aes", feature = "tdes"))]
18-
mod encryptor;
14+
mod error;
1915

2016
pub use crate::error::{Error, Result};
2117
pub use cipher;
2218

23-
#[cfg(any(feature = "aes", feature = "tdes"))]
24-
pub use crate::{decryptor::Decryptor, encryptor::Encryptor};
25-
2619
#[cfg(feature = "chacha20poly1305")]
2720
pub use crate::chacha20poly1305::{ChaCha20, ChaCha20Poly1305, ChaChaKey, ChaChaNonce};
2821

2922
use cipher::array::{Array, typenum::U16};
3023
use core::{fmt, str};
3124
use encoding::{Label, LabelError};
3225

26+
#[cfg(any(feature = "aes", feature = "chacha20poly1305"))]
27+
use aead::{AeadInOut, KeyInit};
3328
#[cfg(feature = "aes")]
3429
use {
3530
aead::array::typenum::U12,
3631
aes_gcm::{Aes128Gcm, Aes256Gcm},
3732
};
3833

39-
#[cfg(any(feature = "aes", feature = "chacha20poly1305"))]
40-
use aead::{AeadInOut, KeyInit};
41-
4234
/// AES-128 in block chaining (CBC) mode
4335
const AES128_CBC: &str = "aes128-cbc";
44-
4536
/// AES-192 in block chaining (CBC) mode
4637
const AES192_CBC: &str = "aes192-cbc";
47-
4838
/// AES-256 in block chaining (CBC) mode
4939
const AES256_CBC: &str = "aes256-cbc";
5040

5141
/// AES-128 in counter (CTR) mode
5242
const AES128_CTR: &str = "aes128-ctr";
53-
5443
/// AES-192 in counter (CTR) mode
5544
const AES192_CTR: &str = "aes192-ctr";
56-
5745
/// AES-256 in counter (CTR) mode
5846
const AES256_CTR: &str = "aes256-ctr";
5947

6048
/// AES-128 in Galois/Counter Mode (GCM).
6149
const AES128_GCM: &str = "aes128-gcm@openssh.com";
62-
6350
/// AES-256 in Galois/Counter Mode (GCM).
6451
const AES256_GCM: &str = "aes256-gcm@openssh.com";
6552

@@ -81,7 +68,7 @@ pub type Tag = Array<u8, U16>;
8168

8269
/// Cipher algorithms.
8370
///
84-
/// A "cipher" within the context of SSH was originally described in [RFC4253 § 6.3] in the context
71+
/// A "cipher" within the scope of SSH was originally described in [RFC4253 § 6.3] as a part of
8572
/// of the packet encryption protocol, where it refers to the combination of a symmetric block
8673
/// cipher, such as AES or 3DES, with a particular mode of operation, such as CBC or CTR.
8774
///
@@ -313,16 +300,16 @@ impl Cipher {
313300
}
314301
}
315302

316-
/// Get a stateful [`Decryptor`] for the given key and IV.
303+
/// Get a stateful [`block_cipher::Decryptor`] for the given key and IV.
317304
///
318305
/// Only applicable to unauthenticated modes (e.g. AES-CBC, AES-CTR). Not usable with
319306
/// authenticated modes which are inherently one-shot (AES-GCM, ChaCha20Poly1305).
320307
///
321308
/// # Errors
322-
/// Propagates errors from [`Decryptor::new`].
309+
/// Propagates errors from [`block_cipher::Decryptor::new`].
323310
#[cfg(any(feature = "aes", feature = "tdes"))]
324-
pub fn decryptor(self, key: &[u8], iv: &[u8]) -> Result<Decryptor> {
325-
Decryptor::new(self, key, iv)
311+
pub fn decryptor(self, key: &[u8], iv: &[u8]) -> Result<block_cipher::Decryptor> {
312+
block_cipher::Decryptor::new(self, key, iv)
326313
}
327314

328315
/// Encrypt the ciphertext in the `buffer` in-place using this cipher.
@@ -373,16 +360,16 @@ impl Cipher {
373360
}
374361
}
375362

376-
/// Get a stateful [`Encryptor`] for the given key and IV.
363+
/// Get a stateful [`block_cipher::Encryptor`] for the given key and IV.
377364
///
378365
/// Only applicable to unauthenticated modes (e.g. AES-CBC, AES-CTR). Not usable with
379366
/// authenticated modes which are inherently one-shot (AES-GCM, ChaCha20Poly1305).
380367
///
381368
/// # Errors
382-
/// Propagates errors from [`Encryptor::new`].
369+
/// Propagates errors from [`block_cipher::Encryptor::new`].
383370
#[cfg(any(feature = "aes", feature = "tdes"))]
384-
pub fn encryptor(self, key: &[u8], iv: &[u8]) -> Result<Encryptor> {
385-
Encryptor::new(self, key, iv)
371+
pub fn encryptor(self, key: &[u8], iv: &[u8]) -> Result<block_cipher::Encryptor> {
372+
block_cipher::Encryptor::new(self, key, iv)
386373
}
387374

388375
/// Check that the key and IV are the expected length for this cipher.

0 commit comments

Comments
 (0)