Skip to content

Commit

Permalink
Address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
skmcgrail committed Nov 13, 2024
1 parent b062f0f commit 6f3a0e8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 30 deletions.
32 changes: 12 additions & 20 deletions aws-lc-rs/src/cipher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
//! # Ok(())
//! # }
//! ```
//!
//!
//! ### AES-128 CFB 128-bit mode
//!
//! ```rust
Expand Down Expand Up @@ -671,13 +671,12 @@ fn encrypt(
let block_len = algorithm.block_len();

match mode {
// TODO: Hopefully support CFB1, and CFB8
OperatingMode::CTR | OperatingMode::CFB128 => {}
_ => {
OperatingMode::CBC => {
if (in_out.len() % block_len) != 0 {
return Err(Unspecified);
}
}
_ => {}
}

match mode {
Expand Down Expand Up @@ -706,13 +705,12 @@ fn decrypt<'in_out>(
let block_len = algorithm.block_len();

match mode {
// TODO: Hopefully support CFB1, and CFB8
OperatingMode::CTR | OperatingMode::CFB128 => {}
_ => {
OperatingMode::CBC => {
if (in_out.len() % block_len) != 0 {
return Err(Unspecified);
}
}
_ => {}
}

match mode {
Expand Down Expand Up @@ -741,7 +739,7 @@ fn encrypt_aes_ctr_mode(
SymmetricCipherKey::Aes128 { enc_key, .. } | SymmetricCipherKey::Aes256 { enc_key, .. } => {
enc_key
}
_ => return Err(Unspecified),
_ => unreachable!(),
};

let mut iv = {
Expand Down Expand Up @@ -777,7 +775,7 @@ fn encrypt_aes_cbc_mode(
SymmetricCipherKey::Aes128 { enc_key, .. } | SymmetricCipherKey::Aes256 { enc_key, .. } => {
enc_key
}
_ => return Err(Unspecified),
_ => unreachable!(),
};

let mut iv = {
Expand All @@ -803,7 +801,7 @@ fn decrypt_aes_cbc_mode<'in_out>(
SymmetricCipherKey::Aes128 { dec_key, .. } | SymmetricCipherKey::Aes256 { dec_key, .. } => {
dec_key
}
_ => return Err(Unspecified),
_ => unreachable!(),
};

let mut iv = {
Expand All @@ -829,7 +827,7 @@ fn encrypt_aes_cfb_mode(
SymmetricCipherKey::Aes128 { enc_key, .. } | SymmetricCipherKey::Aes256 { enc_key, .. } => {
enc_key
}
_ => return Err(Unspecified),
_ => unreachable!(),
};

let mut iv = {
Expand All @@ -841,10 +839,7 @@ fn encrypt_aes_cfb_mode(
let cfb_encrypt: fn(&AES_KEY, &mut [u8], &mut [u8]) = match mode {
// TODO: Hopefully support CFB1, and CFB8
OperatingMode::CFB128 => aes_cfb128_encrypt,
_ => {
// this indicates a programming error and shouldn't happen
return Err(Unspecified);
}
_ => unreachable!(),
};

cfb_encrypt(key, &mut iv, in_out);
Expand All @@ -864,7 +859,7 @@ fn decrypt_aes_cfb_mode<'in_out>(
SymmetricCipherKey::Aes128 { enc_key, .. } | SymmetricCipherKey::Aes256 { enc_key, .. } => {
enc_key
}
_ => return Err(Unspecified),
_ => unreachable!(),
};

let mut iv = {
Expand All @@ -876,10 +871,7 @@ fn decrypt_aes_cfb_mode<'in_out>(
let cfb_decrypt: fn(&AES_KEY, &mut [u8], &mut [u8]) = match mode {
// TODO: Hopefully support CFB1, and CFB8
OperatingMode::CFB128 => aes_cfb128_decrypt,
_ => {
// this indicates a programming error and shouldn't happen
return Err(Unspecified);
}
_ => unreachable!(),
};

cfb_decrypt(key, &mut iv, in_out);
Expand Down
12 changes: 2 additions & 10 deletions aws-lc-rs/src/cipher/streaming.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,11 +470,7 @@ mod tests {
assert!(ciphertext.len() > plaintext.len());
assert!(ciphertext.len() <= plaintext.len() + alg.block_len());
}
OperatingMode::CTR => {
assert_eq!(ciphertext.len(), plaintext.len());
}
// TODO: Hopefully support CFB1, and CFB8
OperatingMode::CFB128 => {
_ => {
assert_eq!(ciphertext.len(), plaintext.len());
}
}
Expand Down Expand Up @@ -523,11 +519,7 @@ mod tests {
assert!(ciphertext.len() > plaintext.len());
assert!(ciphertext.len() <= plaintext.len() + alg.block_len());
}
OperatingMode::CTR => {
assert_eq!(ciphertext.len(), plaintext.len());
}
// TODO: Hopefully support CFB1, and CFB8
OperatingMode::CFB128 => {
_ => {
assert_eq!(ciphertext.len(), plaintext.len());
}
}
Expand Down

0 comments on commit 6f3a0e8

Please sign in to comment.