-
-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR addresses issues related to connecting to legacy Cisco devices with no upgrade path (similar to issue #277). Changes Introduced • Refactored cipher/mod.rs: Make room to be able to implement CBC crypto support. • Updated cipher/block.rs: To provide an interface compatible with both streaming ciphers and CBC. • General Cipher Updates: Light modifications to other ciphers for compatibility with the new interface. Context I had trouble connecting to older Cisco devices which posed challenges due to their outdated cryptographic support. --------- Co-authored-by: Eugene <x@null.page>
- Loading branch information
Showing
8 changed files
with
153 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use aes::cipher::{ | ||
BlockCipher, BlockDecrypt, BlockDecryptMut, BlockEncrypt, BlockEncryptMut, InnerIvInit, Iv, | ||
IvSizeUser, | ||
}; | ||
use cbc::{Decryptor, Encryptor}; | ||
use digest::crypto_common::InnerUser; | ||
use generic_array::GenericArray; | ||
|
||
use super::block::BlockStreamCipher; | ||
|
||
pub struct CbcWrapper<C: BlockEncrypt + BlockCipher + BlockDecrypt> { | ||
encryptor: Encryptor<C>, | ||
decryptor: Decryptor<C>, | ||
} | ||
|
||
impl<C: BlockEncrypt + BlockCipher + BlockDecrypt> InnerUser for CbcWrapper<C> { | ||
type Inner = C; | ||
} | ||
|
||
impl<C: BlockEncrypt + BlockCipher + BlockDecrypt> IvSizeUser for CbcWrapper<C> { | ||
type IvSize = C::BlockSize; | ||
} | ||
|
||
impl<C: BlockEncrypt + BlockCipher + BlockDecrypt> BlockStreamCipher for CbcWrapper<C> { | ||
fn encrypt_data(&mut self, data: &mut [u8]) { | ||
for chunk in data.chunks_exact_mut(C::block_size()) { | ||
let mut block: GenericArray<u8, _> = GenericArray::clone_from_slice(chunk); | ||
self.encryptor.encrypt_block_mut(&mut block); | ||
chunk.clone_from_slice(&block); | ||
} | ||
} | ||
|
||
fn decrypt_data(&mut self, data: &mut [u8]) { | ||
for chunk in data.chunks_exact_mut(C::block_size()) { | ||
let mut block = GenericArray::clone_from_slice(chunk); | ||
self.decryptor.decrypt_block_mut(&mut block); | ||
chunk.clone_from_slice(&block); | ||
} | ||
} | ||
} | ||
|
||
impl<C: BlockEncrypt + BlockCipher + BlockDecrypt + Clone> InnerIvInit for CbcWrapper<C> | ||
where | ||
C: BlockEncryptMut + BlockCipher, | ||
{ | ||
#[inline] | ||
fn inner_iv_init(cipher: C, iv: &Iv<Self>) -> Self { | ||
Self { | ||
encryptor: Encryptor::inner_iv_init(cipher.clone(), iv), | ||
decryptor: Decryptor::inner_iv_init(cipher, iv), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters