From f16648dba7df20e153792bd05dd53d1a2000176e Mon Sep 17 00:00:00 2001 From: = Date: Wed, 18 Dec 2024 12:57:31 +0100 Subject: [PATCH] change smb3kdf --- rust/src/nasl/builtin/cryptographic/smb.rs | 17 ++++++++++++----- .../src/nasl/builtin/cryptographic/tests/smb.rs | 5 +++-- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/rust/src/nasl/builtin/cryptographic/smb.rs b/rust/src/nasl/builtin/cryptographic/smb.rs index d57c3fc81..030ba00db 100644 --- a/rust/src/nasl/builtin/cryptographic/smb.rs +++ b/rust/src/nasl/builtin/cryptographic/smb.rs @@ -62,11 +62,18 @@ fn smb3kdf( lvalue.to_string().as_str(), )); } - let concat = [label_bytes, ctx_bytes].concat(); - Mac::update(&mut mac_obj, &concat); - let output = mac_obj.finalize().into_bytes(); - let return_key = &output[..lvalue.min(output.len())]; - Ok(return_key.into()) + let buflen = 4 + label_bytes.len() + 1 + ctx_bytes.len(); + let mut buf = Vec::with_capacity(buflen); + + buf.extend_from_slice(&1u32.to_be_bytes()); + buf.extend_from_slice(label_bytes); + buf.push(0); + buf.extend_from_slice(ctx_bytes); + buf.extend_from_slice(&lvalue.to_be_bytes()); + mac_obj.update(&buf); + let result = mac_obj.finalize().into_bytes(); + let resultlen = (lvalue / 8) as usize; + Ok(result[..resultlen].into()) } pub struct Smb; diff --git a/rust/src/nasl/builtin/cryptographic/tests/smb.rs b/rust/src/nasl/builtin/cryptographic/tests/smb.rs index 6625650bf..d438e23dd 100644 --- a/rust/src/nasl/builtin/cryptographic/tests/smb.rs +++ b/rust/src/nasl/builtin/cryptographic/tests/smb.rs @@ -32,8 +32,9 @@ mod tests { } #[test] fn smb3kdf() { - let mut t = TestBuilder::default(); - t.run(r#"key = "1274637383948293";"#); + let mut t: TestBuilder = + TestBuilder::default(); + t.run(r#"key = "jfehfiuhf497hfiuhwf497g74gf97wh4u97hg";"#); t.run(r#"label = "1274637383948293";"#); t.run(r#"ctx = "28374928";"#); t.run(r#"lvalue = 128;"#);