Skip to content
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

Add a test case for empty data in CBC mode #24

Merged
merged 1 commit into from
May 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions tests/aes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,19 @@ fn nist_verify_aes_256_cfb_128() {
assert_eq!(decrypted[..], plaintext[..]);
}

#[test]
fn empty_data() {
// Encrypt an input that is empty, i.e. zero bytes.
let key_128 = b"This is the key!"; // key is 16 bytes
let cipher = Cipher::new_128(key_128);
let plaintext = b""; // less than 16 bytes
let iv = b"This is 16 bytes";
let encrypted_128 = cipher.cbc_encrypt(iv, plaintext);
assert_eq!(encrypted_128.len(), 16); // Verify padding
let decrypted_128 = cipher.cbc_decrypt(iv, &encrypted_128[..]);
assert_eq!(decrypted_128, plaintext);
}

#[test]
fn small_data() {
// Encrypt and decrypt data that is smaller than 1 AES block size.
Expand Down