]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
rust/hashing: a method to md5 hash a single buffer
authorJason Ish <jason.ish@oisf.net>
Tue, 22 Dec 2020 22:43:13 +0000 (16:43 -0600)
committerVictor Julien <victor@inliniac.net>
Tue, 12 Jan 2021 20:17:29 +0000 (21:17 +0100)
Add SCMd5HashBuffer as a replacement for NSS HASH_HashBuf as
used in ja3 to hash a single buffer.

rust/src/ffi/hashing.rs

index c5c5b4166a9884f49f48d95c8f96d25a5b3b73a0..39fd6b017a40d4ed253f4a3978e93196bc08c523 100644 (file)
@@ -131,6 +131,14 @@ pub unsafe extern "C" fn SCMd5Free(hasher: &mut SCMd5) {
     let _: Box<SCMd5> = 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.