This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Experimentally cause 'use encoding' to fail.
[perl5.git] / hv_func.h
index 7678807..473ec46 100644 (file)
--- a/hv_func.h
+++ b/hv_func.h
@@ -93,7 +93,7 @@
  */
 
 #if (defined(__GNUC__) && defined(__i386__)) || defined(__WATCOMC__) \
-  || defined(_MSC_VER) || defined (__BORLANDC__) || defined (__TURBOC__)
+  || defined(_MSC_VER) || defined (__TURBOC__)
 #define U8TO16_LE(d) (*((const U16 *) (d)))
 #endif
 
 PERL_STATIC_INLINE U32
 S_perl_hash_siphash_2_4(const unsigned char * const seed, const unsigned char *in, const STRLEN inlen) {
   /* "somepseudorandomlygeneratedbytes" */
-  U64TYPE v0 = 0x736f6d6570736575ULL;
-  U64TYPE v1 = 0x646f72616e646f6dULL;
-  U64TYPE v2 = 0x6c7967656e657261ULL;
-  U64TYPE v3 = 0x7465646279746573ULL;
+  U64TYPE v0 = UINT64_C(0x736f6d6570736575);
+  U64TYPE v1 = UINT64_C(0x646f72616e646f6d);
+  U64TYPE v2 = UINT64_C(0x6c7967656e657261);
+  U64TYPE v3 = UINT64_C(0x7465646279746573);
 
   U64TYPE b;
   U64TYPE k0 = ((U64TYPE*)seed)[0];
@@ -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,13 +465,23 @@ 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++;
     }
     return hash;
 }
 
+/* - ONE_AT_A_TIME_HARD is the 5.17+ recommend ONE_AT_A_TIME algorithm
+ * - ONE_AT_A_TIME_OLD is the unmodified 5.16 and older algorithm
+ * - ONE_AT_A_TIME is a 5.17+ tweak of ONE_AT_A_TIME_OLD to
+ *   prevent strings of only \0 but different lengths from colliding
+ *
+ * Security-wise, from best to worst,
+ * ONE_AT_A_TIME_HARD > ONE_AT_A_TIME > ONE_AT_A_TIME_OLD
+ * There is a big drop-off in security between ONE_AT_A_TIME_HARD and
+ * ONE_AT_A_TIME
+ * */
 
 /* This is the "One-at-a-Time" algorithm by Bob Jenkins
  * from requirements by Colin Plumb.