rust-crypto icon indicating copy to clipboard operation
rust-crypto copied to clipboard

assertion failed: dst.len() * 4 == input.len()

Open lamualfa opened this issue 4 years ago • 0 comments

Dependencies

rand="0.7.2"
rust-crypto = "0.2.36"
rustc-serialize = "0.3.24"
use rand;
use crypto::aessafe::AesSafe128Encryptor;
use crypto::symmetriccipher::BlockEncryptor;

fn encrypt(key: &[u8], input: &[u8], output: &mut [u8]) {
    let encryptor = AesSafe128Encryptor::new(key);

    encryptor.encrypt_block(input, output);
}

fn main() {
    let mut key = [0u8; 128 / 8];

    for v in key.iter_mut() {
        *v = rand::random();
    }

    let mut output = Vec::<u8>::new();

    encrypt(&key, "hello".as_bytes(), &mut output);
}

Output:

user@user:~/Projects/rust/encrypt-file$ cargo run
   Compiling encrypt-file v0.1.0 (/home/user/Projects/rust/encrypt-file)
    Finished dev [unoptimized + debuginfo] target(s) in 0.48s
     Running `target/debug/encrypt-file`
thread 'main' panicked at 'assertion failed: dst.len() * 4 == input.len()', /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/rust-crypto-0.2.36/src/cryptoutil.rs:143:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.

lamualfa avatar Sep 24 '19 07:09 lamualfa