File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2929#include <linux/platform_device.h>
3030#include <linux/refcount.h>
3131#include <linux/wait.h>
32+ #include <linux/siphash.h>
3233#include <linux/sched.h>
3334#include <linux/soc/apple/rtkit.h>
3435#include <linux/timekeeping.h>
Original file line number Diff line number Diff line change 3434#include <linux/platform_device.h>
3535#include <linux/refcount.h>
3636#include <linux/mutex.h>
37+ #include <linux/siphash.h>
3738#include <linux/spinlock.h>
3839#include <linux/sched/signal.h>
3940#include <linux/wait.h>
@@ -151,6 +152,13 @@ const char *rust_helper_errname(int err)
151152}
152153EXPORT_SYMBOL_GPL (rust_helper_errname );
153154
155+ u64 rust_helper_siphash (const void * data , size_t len ,
156+ const siphash_key_t * key )
157+ {
158+ return siphash (data , len , key );
159+ }
160+ EXPORT_SYMBOL_GPL (rust_helper_siphash );
161+
154162void rust_helper_xa_init_flags (struct xarray * xa , gfp_t flags )
155163{
156164 xa_init_flags (xa , flags );
Original file line number Diff line number Diff line change @@ -57,6 +57,7 @@ pub mod of;
5757pub mod platform;
5858pub mod prelude;
5959pub mod print;
60+ pub mod siphash;
6061pub mod soc;
6162mod static_assert;
6263#[ doc( hidden) ]
Original file line number Diff line number Diff line change 1+ // SPDX-License-Identifier: GPL-2.0
2+
3+ //! A core::hash::Hasher wrapper for the kernel siphash implementation.
4+ //!
5+ //! This module allows Rust code to use the kernel's siphash implementation
6+ //! to hash Rust objects.
7+
8+ use core:: hash:: Hasher ;
9+
10+ /// A Hasher implementation that uses the kernel siphash implementation.
11+ #[ derive( Default ) ]
12+ pub struct SipHasher {
13+ // SipHash state is 4xu64, but the Linux implementation
14+ // doesn't expose incremental hashing so let's just chain
15+ // individual SipHash calls for now, which return a u64
16+ // hash.
17+ state : u64 ,
18+ }
19+
20+ impl SipHasher {
21+ /// Create a new SipHasher with zeroed state.
22+ pub fn new ( ) -> Self {
23+ SipHasher { state : 0 }
24+ }
25+ }
26+
27+ impl Hasher for SipHasher {
28+ fn finish ( & self ) -> u64 {
29+ self . state
30+ }
31+
32+ fn write ( & mut self , bytes : & [ u8 ] ) {
33+ let key = bindings:: siphash_key_t {
34+ key : [ self . state , 0 ] ,
35+ } ;
36+
37+ self . state = unsafe { bindings:: siphash ( bytes. as_ptr ( ) as * const _ , bytes. len ( ) , & key) } ;
38+ }
39+ }
You can’t perform that action at this time.
0 commit comments