include (untested) hash
This commit is contained in:
29
c/hash.c
Normal file
29
c/hash.c
Normal file
@@ -0,0 +1,29 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0 */
|
||||
|
||||
/* inspired from kernel's <fs/namei.h>
|
||||
*/
|
||||
#include "hash.h"
|
||||
|
||||
/* Return the hash of a string of known length */
|
||||
unsigned int full_name_hash(const void *salt, const char *name, unsigned int len)
|
||||
{
|
||||
unsigned long hash = init_name_hash(salt);
|
||||
while (len--)
|
||||
hash = partial_name_hash((unsigned char)*name++, hash);
|
||||
return end_name_hash(hash);
|
||||
}
|
||||
|
||||
/* Return the "hash_len" (hash and length) of a null-terminated string */
|
||||
u64 hashlen_string(const void *salt, const char *name)
|
||||
{
|
||||
unsigned long hash = init_name_hash(salt);
|
||||
unsigned long len = 0, c;
|
||||
|
||||
c = (unsigned char)*name;
|
||||
while (c) {
|
||||
len++;
|
||||
hash = partial_name_hash(c, hash);
|
||||
c = (unsigned char)name[len];
|
||||
}
|
||||
return hashlen_create(end_name_hash(hash), len);
|
||||
}
|
Reference in New Issue
Block a user