Explorar el Código

misc/hashfun.h: add badvpn_djb2_hash_bin()

ambrop7 hace 13 años
padre
commit
aafa614ea8
Se han modificado 1 ficheros con 12 adiciones y 0 borrados
  1. 12 0
      misc/hashfun.h

+ 12 - 0
misc/hashfun.h

@@ -45,4 +45,16 @@ static size_t badvpn_djb2_hash (const uint8_t *str)
     return hash;
 }
 
+static size_t badvpn_djb2_hash_bin (const uint8_t *str, size_t str_len)
+{
+    size_t hash = 5381;
+    
+    while (str_len-- > 0) {
+        int c = *str++;
+        hash = ((hash << 5) + hash) + c;
+    }
+    
+    return hash;
+}
+
 #endif