From 721dfe82c2edeb42db01fddd0f6f500e59eb7a7a Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Fri, 5 Sep 2014 15:02:10 -0400 Subject: [PATCH] add e_auth_hash_djb2 inline all eina hash functions are now useless for any case where the hashed value needs to be stored, so it's necessary for e to provide its own hash function to use for password storage --- src/bin/e_auth.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/bin/e_auth.h b/src/bin/e_auth.h index 7f989f23f..a106e079f 100644 --- a/src/bin/e_auth.h +++ b/src/bin/e_auth.h @@ -4,4 +4,17 @@ EAPI int e_auth_begin(char *passwd); EAPI char *e_auth_hostname_get(void); +static inline int +e_auth_hash_djb2(const char *key, int len) +{ + unsigned int hash_num = 5381; + const unsigned char *ptr; + + if (!key) return 0; + for (ptr = (unsigned char *)key; len; ptr++, len--) + hash_num = ((hash_num << 5) + hash_num) ^ *ptr; /* hash * 33 ^ c */ + + return (int)hash_num; +} + #endif