gnunet-svn
[Top][All Lists]
Advanced

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

[libmicrohttpd] 09/09: check_nonce_nc(): sorted checks according to prob


From: gnunet
Subject: [libmicrohttpd] 09/09: check_nonce_nc(): sorted checks according to probability
Date: Sun, 01 May 2022 16:08:55 +0200

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

karlson2k pushed a commit to branch master
in repository libmicrohttpd.

commit 76b68f654f0984dfca834a9c8310af13885c6ce8
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
AuthorDate: Sun May 1 17:07:43 2022 +0300

    check_nonce_nc(): sorted checks according to probability
    
    The code should be more readable and it should give very minor
    performance improvement.
---
 src/microhttpd/digestauth.c | 38 ++++++++++++++++++++------------------
 1 file changed, 20 insertions(+), 18 deletions(-)

diff --git a/src/microhttpd/digestauth.c b/src/microhttpd/digestauth.c
index 2bfbf95e..78db203e 100644
--- a/src/microhttpd/digestauth.c
+++ b/src/microhttpd/digestauth.c
@@ -617,24 +617,7 @@ check_nonce_nc (struct MHD_Connection *connection,
   if ( (0 != memcmp (nn->nonce, nonce, noncelen)) ||
        (0 != nn->nonce[noncelen]) )
     ret = false;     /* Nonce does not match, fail */
-  else if (nc == nn->nc)
-    ret = false;     /* 'nc' was already used */
-  else if (nc < nn->nc)
-  {
-    /* Note that we use 64 here, as we do not store the
-       bit for 'nn->nc' itself in 'nn->nmask' */
-    if ( (nc + 64 >= nn->nc) &&
-         (0 == ((1LLU << (nn->nc - nc - 1)) & nn->nmask)) )
-    {
-      /* Out-of-order nonce, but within 64-bit bitmask, set bit */
-      nn->nmask |= (1LLU << (nn->nc - nc - 1));
-      ret = true;
-    }
-    else
-      /* 'nc' was already used or too old (more then 64 values ago) */
-      ret = false;
-  }
-  else
+  else if (nc > nn->nc)
   {
     /* 'nc' is larger, shift bitmask and bump limit */
     const uint64_t jump_size = nc - nn->nc;
@@ -652,6 +635,25 @@ check_nonce_nc (struct MHD_Connection *connection,
     nn->nc = nc;
     ret = true;
   }
+  else if (nc < nn->nc)
+  {
+    /* Note that we use 64 here, as we do not store the
+       bit for 'nn->nc' itself in 'nn->nmask' */
+    if ( (nc + 64 >= nn->nc) &&
+         (0 == ((UINT64_C (1) << (nn->nc - nc - 1)) & nn->nmask)) )
+    {
+      /* Out-of-order nonce, but within 64-bit bitmask, set bit */
+      nn->nmask |= (UINT64_C (1) << (nn->nc - nc - 1));
+      ret = true;
+    }
+    else
+      /* 'nc' was already used or too old (more then 64 values ago) */
+      ret = false;
+  }
+  else /* if (nc == nn->nc) */
+    /* 'nc' was already used */
+    ret = false;
+
   MHD_mutex_unlock_chk_ (&daemon->nnc_lock);
 #ifdef HAVE_MESSAGES
   if (! ret)

-- 
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]