Skip to content

Commit

Permalink
change smb3kdf
Browse files Browse the repository at this point in the history
  • Loading branch information
puethenn committed Dec 18, 2024
1 parent aa0fa51 commit f16648d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
17 changes: 12 additions & 5 deletions rust/src/nasl/builtin/cryptographic/smb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions rust/src/nasl/builtin/cryptographic/tests/smb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ mod tests {
}
#[test]
fn smb3kdf() {
let mut t = TestBuilder::default();
t.run(r#"key = "1274637383948293";"#);
let mut t: TestBuilder<crate::nasl::NoOpLoader, crate::storage::DefaultDispatcher> =
TestBuilder::default();
t.run(r#"key = "jfehfiuhf497hfiuhwf497g74gf97wh4u97hg";"#);
t.run(r#"label = "1274637383948293";"#);
t.run(r#"ctx = "28374928";"#);
t.run(r#"lvalue = 128;"#);
Expand Down

0 comments on commit f16648d

Please sign in to comment.