summaryrefslogtreecommitdiff
path: root/hv_func.h
diff options
context:
space:
mode:
authorYves Orton <demerphq@gmail.com>2014-04-13 12:54:12 +0200
committerYves Orton <demerphq@gmail.com>2014-06-02 00:33:19 +0200
commit54e07e2b21cb1f58c04d67bca2a311715ba8815e (patch)
tree362a330b97d3c3b1de32cbf9acf7eff49e2e3041 /hv_func.h
parent3ca75eca84b9d0987b69e271b2c50cae574df77e (diff)
downloadperl-54e07e2b21cb1f58c04d67bca2a311715ba8815e.tar.gz
hv_func.h - fix seed initialization in sdbm and djb2 hashing algorithms.
In a previous commit I added code to "mix in" the length of the string into the seed used by these functions, to avoid issues with zero seeds, and with the hope that it makes it harder to create multicollision attacks against these hash functions. Unfortunately when I restructured the seed logic for the inline functions in hv_func.h I messed it up, and these hash functions were broken. I never noticed because they are both such bad hash functions for our needs that I never built with them, and we have no infrastructure to make it easy to test building with non-standard hash functions so it never got automatically tested. Hopefully at some point someone will find a round-tuit and teach Configure about selecting alternate hash functions.
Diffstat (limited to 'hv_func.h')
-rw-r--r--hv_func.h4
1 files changed, 2 insertions, 2 deletions
diff --git a/hv_func.h b/hv_func.h
index 53230ae55c..473ec466a7 100644
--- a/hv_func.h
+++ b/hv_func.h
@@ -455,7 +455,7 @@ S_perl_hash_murmur3(const unsigned char * const seed, const unsigned char *ptr,
PERL_STATIC_INLINE U32
S_perl_hash_djb2(const unsigned char * const seed, const unsigned char *str, const STRLEN len) {
const unsigned char * const end = (const unsigned char *)str + len;
- U32 hash = *((U32*)seed + len);
+ U32 hash = *((U32*)seed) + len;
while (str < end) {
hash = ((hash << 5) + hash) + *str++;
}
@@ -465,7 +465,7 @@ S_perl_hash_djb2(const unsigned char * const seed, const unsigned char *str, con
PERL_STATIC_INLINE U32
S_perl_hash_sdbm(const unsigned char * const seed, const unsigned char *str, const STRLEN len) {
const unsigned char * const end = (const unsigned char *)str + len;
- U32 hash = *((U32*)seed + len);
+ U32 hash = *((U32*)seed) + len;
while (str < end) {
hash = (hash << 6) + (hash << 16) - hash + *str++;
}