Skip to content

Commit

Permalink
style: fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Taowyoo committed Oct 26, 2023
1 parent 634b7bc commit 8b3c9b5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 39 deletions.
21 changes: 5 additions & 16 deletions mbedtls/src/cipher/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,13 +458,11 @@ fn aes_kwp() {
assert_eq!(p, &p_out[..out_len]);
}


#[test]
fn aes_gcm() {
let k = [
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e,
0x4f, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d,
0x4e, 0x4f,
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x40, 0x41, 0x42, 0x43,
0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
];
let iv = [0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16];

Expand All @@ -475,23 +473,14 @@ fn aes_gcm() {
let mut p_out = [0u8; 4];
let mut c_out = [0u8; 8];

let cipher = Cipher::<Encryption, Authenticated, Fresh>::new(
raw::CipherId::Aes,
raw::CipherMode::GCM,
(k.len() * 8) as _,
)
.unwrap();
let cipher =
Cipher::<Encryption, Authenticated, Fresh>::new(raw::CipherId::Aes, raw::CipherMode::GCM, (k.len() * 8) as _).unwrap();
let cipher = cipher.set_key_iv(&k, &iv).unwrap();

cipher.encrypt_auth(&ad, &p, &mut c_out, 4).unwrap();
assert_eq!(c, c_out[0..4]);
assert_eq!(t, c_out[4..8]);
let cipher = Cipher::<_, Authenticated, _>::new(
raw::CipherId::Aes,
raw::CipherMode::GCM,
(k.len() * 8) as _,
)
.unwrap();
let cipher = Cipher::<_, Authenticated, _>::new(raw::CipherId::Aes, raw::CipherMode::GCM, (k.len() * 8) as _).unwrap();
let cipher = cipher.set_key_iv(&k, &iv).unwrap();
cipher.decrypt_auth(&ad, &c_out, &mut p_out, 4).unwrap();
assert_eq!(p, p_out);
Expand Down
27 changes: 4 additions & 23 deletions mbedtls/src/cipher/raw/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,13 +330,7 @@ impl Cipher {
self.do_crypto(cipher, plain)
}

pub fn encrypt_auth(
&mut self,
ad: &[u8],
plain: &[u8],
cipher_and_tag: &mut [u8],
tag_len: usize,
) -> Result<usize> {
pub fn encrypt_auth(&mut self, ad: &[u8], plain: &[u8], cipher_and_tag: &mut [u8], tag_len: usize) -> Result<usize> {
if cipher_and_tag
.len()
.checked_sub(tag_len)
Expand Down Expand Up @@ -402,12 +396,7 @@ impl Cipher {
Ok(plain_len)
}

pub fn encrypt_auth_inplace(
&mut self,
ad: &[u8],
data: &mut [u8],
tag: &mut [u8],
) -> Result<usize> {
pub fn encrypt_auth_inplace(&mut self, ad: &[u8], data: &mut [u8], tag: &mut [u8]) -> Result<usize> {
let iv = self.inner.iv;
let iv_len = self.inner.iv_size;
let mut olen = data.len();
Expand All @@ -431,12 +420,7 @@ impl Cipher {
Ok(olen)
}

pub fn decrypt_auth_inplace(
&mut self,
ad: &[u8],
data: &mut [u8],
tag: &[u8],
) -> Result<usize> {
pub fn decrypt_auth_inplace(&mut self, ad: &[u8], data: &mut [u8], tag: &[u8]) -> Result<usize> {
let iv = self.inner.iv;
let iv_len = self.inner.iv_size;
let mut plain_len = data.len();
Expand Down Expand Up @@ -538,8 +522,5 @@ fn cmac_test() {
&mut out,
)
.expect("Success in CMAC");
assert_eq!(
&out,
b"\x38\x7b\x36\x22\x8b\xa7\x77\x44\x5b\xaf\xa0\x36\x45\xb9\x40\x10"
);
assert_eq!(&out, b"\x38\x7b\x36\x22\x8b\xa7\x77\x44\x5b\xaf\xa0\x36\x45\xb9\x40\x10");
}

0 comments on commit 8b3c9b5

Please sign in to comment.