From 1022b217ed0f3fae9096d91399ec3beed6253f0a Mon Sep 17 00:00:00 2001 From: Jason Ish Date: Tue, 22 Dec 2020 16:43:13 -0600 Subject: [PATCH] rust/hashing: a method to md5 hash a single buffer Add SCMd5HashBuffer as a replacement for NSS HASH_HashBuf as used in ja3 to hash a single buffer. --- rust/src/ffi/hashing.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/rust/src/ffi/hashing.rs b/rust/src/ffi/hashing.rs index c5c5b4166a..39fd6b017a 100644 --- a/rust/src/ffi/hashing.rs +++ b/rust/src/ffi/hashing.rs @@ -131,6 +131,14 @@ pub unsafe extern "C" fn SCMd5Free(hasher: &mut SCMd5) { let _: Box = Box::from_raw(hasher); } +#[no_mangle] +pub unsafe extern "C" fn SCMd5HashBuffer(buf: *const u8, buf_len: u32, out: *mut u8, len: u32) { + let data = std::slice::from_raw_parts(buf, buf_len as usize); + let output = std::slice::from_raw_parts_mut(out, len as usize); + let hash = Md5::new().chain(data).finalize(); + output.copy_from_slice(&hash); +} + // Functions that are generic over Digest. For the most part the C bindings are // just wrappers around these.