From: Jason Ish Date: Wed, 23 Dec 2020 22:24:23 +0000 (-0600) Subject: rust/hashing: method to SHA256 and finalize in one call X-Git-Tag: suricata-7.0.0-beta1~1888 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0f714be9f3997282eb0084a5ef70ab983d036fd8;p=thirdparty%2Fsuricata.git rust/hashing: method to SHA256 and finalize in one call Add SCSha256HashBuffer to hash a single buffer returning the result. --- diff --git a/rust/src/ffi/hashing.rs b/rust/src/ffi/hashing.rs index 3d0fef91e9..b49aa1131c 100644 --- a/rust/src/ffi/hashing.rs +++ b/rust/src/ffi/hashing.rs @@ -76,6 +76,20 @@ pub unsafe extern "C" fn SCSha256Free(hasher: &mut SCSha256) { let _: Box = Box::from_raw(hasher); } +#[no_mangle] +pub unsafe extern "C" fn SCSha256HashBuffer( + buf: *const u8, buf_len: u32, out: *mut u8, len: u32, +) -> bool { + if len as usize != SC_SHA256_LEN { + return false; + } + 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 = Sha256::new().chain(data).finalize(); + output.copy_from_slice(&hash); + return true; +} + // Start of SHA1 C bindings. pub struct SCSha1(Sha1);