Re: [PATCH RFC 04/11] rust: siphash: Add a simple siphash abstraction

From: Martin Rodriguez Reboredo
Date: Fri Jul 14 2023 - 16:37:42 EST


On 7/14/23 06:13, Asahi Lina wrote:
This simple wrapper allows Rust code to use the Hasher interface with
the kernel siphash implementation. No fancy features supported for now,
just basic bag-of-bytes hashing. No guarantee that hash outputs will
remain stable in the future either.

Signed-off-by: Asahi Lina <lina@xxxxxxxxxxxxx>
---
[...]
--- /dev/null
+++ b/rust/kernel/siphash.rs
@@ -0,0 +1,39 @@
+// SPDX-License-Identifier: GPL-2.0
+
+//! A core::hash::Hasher wrapper for the kernel siphash implementation.
+//!
+//! This module allows Rust code to use the kernel's siphash implementation
+//! to hash Rust objects.
+
+use core::hash::Hasher;
+
+/// A Hasher implementation that uses the kernel siphash implementation.
+#[derive(Default)]
+pub struct SipHasher {
+ // SipHash state is 4xu64, but the Linux implementation
+ // doesn't expose incremental hashing so let's just chain
+ // individual SipHash calls for now, which return a u64
+ // hash.

Isn't this detail relevant to mention in the doc comment? At least to
explain the difference between them.

+ state: u64,
+}
[...]