File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 3030#include <linux/poll.h>
3131#include <linux/property.h>
3232#include <linux/refcount.h>
33+ #include <linux/siphash.h>
3334#include <linux/sched.h>
3435#include <linux/security.h>
3536#include <linux/slab.h>
Original file line number Diff line number Diff line change 2929#include "refcount.c"
3030#include "security.c"
3131#include "signal.c"
32+ #include "siphash.c"
3233#include "slab.c"
3334#include "spinlock.c"
3435#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 @@ -76,6 +76,7 @@ pub mod rbtree;
7676pub mod revocable;
7777pub mod security;
7878pub mod seq_file;
79+ pub mod siphash;
7980pub mod sizes;
8081mod static_assert;
8182#[ 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