gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[libmicrohttpd] 05/05: digestauth: moved "hash" calculation to separate


From: gnunet
Subject: [libmicrohttpd] 05/05: digestauth: moved "hash" calculation to separate function
Date: Thu, 28 Apr 2022 18:09:48 +0200

This is an automated email from the git hooks/post-receive script.

karlson2k pushed a commit to branch master
in repository libmicrohttpd.

commit 0effaaad3ef06ce2fad2dd493d3064c259b3fe52
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
AuthorDate: Thu Apr 28 18:19:00 2022 +0300

    digestauth: moved "hash" calculation to separate function
---
 src/microhttpd/digestauth.c | 40 ++++++++++++++++++++++++++++++----------
 1 file changed, 30 insertions(+), 10 deletions(-)

diff --git a/src/microhttpd/digestauth.c b/src/microhttpd/digestauth.c
index b40e1fc2..25cae280 100644
--- a/src/microhttpd/digestauth.c
+++ b/src/microhttpd/digestauth.c
@@ -31,6 +31,7 @@
 #include "mhd_mono_clock.h"
 #include "mhd_str.h"
 #include "mhd_compat.h"
+#include "mhd_bithelpers.h"
 #include "mhd_assert.h"
 
 #if defined(MHD_W32_MUTEX_)
@@ -503,6 +504,33 @@ lookup_sub_value (char *dest,
 }
 
 
+/**
+ * Super-fast xor-based "hash" function
+ *
+ * @param data the data to calculate hash for
+ * @param data_size the size of the data in bytes
+ * @return the "hash"
+ */
+static uint32_t
+fast_simple_hash (const uint8_t *data,
+                  size_t data_size)
+{
+  uint32_t hash;
+
+  if (0 != data_size)
+  {
+    size_t i;
+    hash = data[0];
+    for (i = 1; i < data_size; i++)
+      hash = _MHD_ROTL32 (hash, 8) ^ data[i];
+  }
+  else
+    hash = 0;
+
+  return hash;
+}
+
+
 /**
  * Check nonce-nc map array with either new nonce counter
  * or a whole new nonce.
@@ -521,7 +549,6 @@ check_nonce_nc (struct MHD_Connection *connection,
   struct MHD_NonceNc *nn;
   uint32_t off;
   uint32_t mod;
-  const char *np;
   size_t noncelen;
   enum MHD_Result ret;
   bool stale;
@@ -536,15 +563,8 @@ check_nonce_nc (struct MHD_Connection *connection,
   mod = daemon->nonce_nc_size;
   if (0 == mod)
     return MHD_NO; /* no array! */
-  /* super-fast xor-based "hash" function for HT lookup in nonce array */
-  off = 0;
-  np = nonce;
-  while ('\0' != *np)
-  {
-    off = (off << 8) | (((uint8_t) *np) ^ (off >> 24));
-    np++;
-  }
-  off = off % mod;
+  /* HT lookup in nonce array */
+  off = fast_simple_hash ((const uint8_t *) nonce, noncelen) % mod;
   /*
    * Look for the nonce, if it does exist and its corresponding
    * nonce counter is less than the current nonce counter by 1,

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]