File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2626#include <linux/phy.h>
2727#include <linux/platform_device.h>
2828#include <linux/refcount.h>
29+ #include <linux/siphash.h>
2930#include <linux/sched.h>
3031#include <linux/slab.h>
3132#include <linux/wait.h>
Original file line number Diff line number Diff line change 2424#include "rcu.c"
2525#include "refcount.c"
2626#include "signal.c"
27+ #include "siphash.c"
2728#include "slab.c"
2829#include "spinlock.c"
2930#include "task.c"
Original file line number Diff line number Diff line change 1+ // SPDX-License-Identifier: GPL-2.0
2+
3+ #include <linux/siphash.h>
4+
5+ u64 rust_helper_siphash (const void * data , size_t len ,
6+ const siphash_key_t * key )
7+ {
8+ return siphash (data , len , key );
9+ }
Original file line number Diff line number Diff line change @@ -64,6 +64,7 @@ pub mod prelude;
6464pub mod print;
6565pub mod rbtree;
6666pub mod revocable;
67+ pub mod siphash;
6768pub mod sizes;
6869mod static_assert;
6970#[ 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+ // SAFETY: Safe to call on a valid slice
38+ self . state = unsafe { bindings:: siphash ( bytes. as_ptr ( ) as * const _ , bytes. len ( ) , & key) } ;
39+ }
40+ }
You can’t perform that action at this time.
0 commit comments