Skip to content

Commit

Permalink
Added test for smb_cmac_aes_signature and smb_gmac_aes_signature
Browse files Browse the repository at this point in the history
  • Loading branch information
puethenn committed Nov 27, 2024
1 parent dcdff4c commit aa35d1c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
6 changes: 3 additions & 3 deletions rust/src/nasl/builtin/cryptographic/smb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use nasl_function_proc_macro::nasl_function;
fn smb_cmac_aes_signature(key: &str, buf: &str) -> Result<NaslValue, FunctionErrorKind> {
let key_bytes = key.as_bytes();
let buf_bytes = buf.as_bytes();
let mut cmac = Cmac::<Aes128>::new_from_slice(&key_bytes)
let mut cmac = Cmac::<Aes128>::new_from_slice(key_bytes)
.map_err(|e| FunctionErrorKind::Diagnostic(e.to_string(), None))?;
cmac.update(buf_bytes);
let finish = cmac::Mac::finalize(cmac).into_bytes();
Expand All @@ -28,8 +28,8 @@ fn smb_gmac_aes_signature(key: &str, buf: &str, iv: &str) -> Result<NaslValue, F
let key_bytes = key.as_bytes();
let buf_bytes = buf.as_bytes();
let iv_bytes = iv.as_bytes();
let gmac = Aes128Gcm::new_from_slice(&key_bytes).unwrap();
let nonce = Nonce::from_slice(&iv_bytes);
let gmac = Aes128Gcm::new_from_slice(key_bytes).unwrap();
let nonce = Nonce::from_slice(iv_bytes);
let auth = gmac.encrypt(nonce, buf_bytes.as_ref()).unwrap();
Ok(auth.into())
}
Expand Down
17 changes: 17 additions & 0 deletions rust/src/nasl/builtin/cryptographic/tests/smb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,22 @@ mod tests {
#[test]
fn smb_cmac_aes_signature() {
let mut t = TestBuilder::default();
t.run(r#"key = "1274637383948293";"#);
t.run(r#"buf = "1274637383948293";"#);
t.ok(
r#"smb_cmac_aes_signature(key:key,buf:buf);"#,
NaslValue::Data(decode_hex("73C1B26E84FFC51037E057734B8AC8E2").unwrap()),
);
}
#[test]
fn smb_gmac_aes_signature() {
let mut t = TestBuilder::default();
t.run(r#"key = "1274637383948293";"#);
t.run(r#"buf = "1274637383948293";"#);
t.run(r#"iv = "28374928";"#);
t.ok(
r#"smb_gmac_aes_signature(key:key,buf:buf,iv:iv);"#,
NaslValue::Data(decode_hex("73C1B26E84FFC51037E057734B8AC8E2").unwrap()),
);
}
}

0 comments on commit aa35d1c

Please sign in to comment.