-
Notifications
You must be signed in to change notification settings - Fork 132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature request: add block_size method to BlockCipher #131
Comments
I think adding a Kind of curious what you're trying to do there specifically and if we could add some additional higher level methods to help. Do you specifically need (unauthenticated) AES-CBC encryption? |
Just transform golang to rust. 😂 In go, https://golang.org/pkg/crypto/cipher/#Block, provide a method |
Eventually they'll just be associated consts (after const generics land), but I agree for now having a method is easier than |
you mean something like this? pub trait BlockCipher {
const Size: usize;
fn block_size() -> usize {
Self::Size
}
fn new() -> Self;
}
pub struct Aes {}
impl BlockCipher for Aes {
const Size: usize = 1;
fn new() -> Self {
Self {}
}
}
pub struct Cbc<C: BlockCipher> {
cipher: C,
}
impl<C> Cbc<C>
where
C: BlockCipher,
{
fn encrypt(self, data: &str) {
for _ in 0..C::block_size() {
println!("data: {}", data);
}
}
fn new() -> Self {
Self { cipher: C::new() }
}
}
#[cfg(test)]
mod tests {
use super::*;
type AesCbc = Cbc<Aes>;
#[test]
pub fn test_size() {
println!("block_size: {}", Aes::block_size());
let encryptor = AesCbc::new();
encryptor.encrypt("hello");
}
} |
What I'm talking about involves changes to the Rust language. Here's a blog post I wrote on the topic: https://tonyarcieri.com/rust-in-2019-security-maturity-stability#const-generics-and-cryptography_2 |
Got it. ====== |
describe & question
BlockCipher.encrypt
work in-place, and no allocate. So I need to calculate the buffer size manually.my question :
block_size
method toBlockCipher
?my code
Cargo.toml
The text was updated successfully, but these errors were encountered: