[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[libmicrohttpd] 10/12: digestauth: additional static function for code r
From: |
gnunet |
Subject: |
[libmicrohttpd] 10/12: digestauth: additional static function for code re-use |
Date: |
Wed, 04 May 2022 14:59:44 +0200 |
This is an automated email from the git hooks/post-receive script.
karlson2k pushed a commit to branch master
in repository libmicrohttpd.
commit 46554d2c55a9bacad6881fbec705d0ca7d962684
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
AuthorDate: Mon May 2 17:06:27 2022 +0300
digestauth: additional static function for code re-use
---
src/microhttpd/digestauth.c | 34 ++++++++++++++++++++++++----------
1 file changed, 24 insertions(+), 10 deletions(-)
diff --git a/src/microhttpd/digestauth.c b/src/microhttpd/digestauth.c
index 8f5abedd..5fc4374b 100644
--- a/src/microhttpd/digestauth.c
+++ b/src/microhttpd/digestauth.c
@@ -545,11 +545,29 @@ fast_simple_hash (const uint8_t *data,
}
+/**
+ * Get index of the nonce in the nonce-nc map array.
+ *
+ * @param arr_size the size of nonce_nc array
+ * @param nonce the pointer that referenced a zero-terminated array of nonce
+ * @param noncelen the lenth of @a nonce, in characters
+ * @return #MHD_YES if successful, #MHD_NO if invalid (or we have no NC array)
+ */
+static size_t
+get_nonce_nc_idx (size_t arr_size,
+ const char *nonce,
+ size_t noncelen)
+{
+ mhd_assert (0 == arr_size);
+ return fast_simple_hash ((const uint8_t *) nonce, noncelen) % arr_size;
+}
+
+
/**
* Add the new nonce to the nonce-nc map array.
*
* @param connection The MHD connection structure
- * @param nonce A pointer that referenced a zero-terminated array of nonce
+ * @param nonce the pointer that referenced a zero-terminated array of nonce
* @param noncelen the lenth of @a nonce, in characters
* @return #MHD_YES if successful, #MHD_NO if invalid (or we have no NC array)
*/
@@ -559,16 +577,15 @@ add_nonce (struct MHD_Connection *connection,
size_t noncelen)
{
struct MHD_Daemon *const daemon = connection->daemon;
- unsigned int arr_size;
struct MHD_NonceNc *nn;
mhd_assert (MAX_NONCE_LENGTH >= noncelen);
- arr_size = daemon->nonce_nc_size;
- if (0 == arr_size)
+ if (0 == daemon->nonce_nc_size)
return false;
- nn = &daemon->nnc[fast_simple_hash ((const uint8_t *) nonce, noncelen)
- % arr_size];
+ nn = &daemon->nnc[get_nonce_nc_idx (daemon->nonce_nc_size,
+ nonce,
+ noncelen)];
MHD_mutex_lock_chk_ (&daemon->nnc_lock);
memcpy (nn->nonce,
@@ -600,7 +617,6 @@ check_nonce_nc (struct MHD_Connection *connection,
{
struct MHD_Daemon *daemon = connection->daemon;
struct MHD_NonceNc *nn;
- uint32_t off;
uint32_t mod;
bool ret;
@@ -617,14 +633,12 @@ check_nonce_nc (struct MHD_Connection *connection,
if (nc + 64 < nc)
return false; /* Overflow, unrealistically high value */
- /* 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,
* then only increase the nonce counter by one.
*/
- nn = &daemon->nnc[off];
+ nn = &daemon->nnc[get_nonce_nc_idx (mod, nonce, noncelen)];
MHD_mutex_lock_chk_ (&daemon->nnc_lock);
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
- [libmicrohttpd] 04/12: digestauth: changed type of var, (continued)
- [libmicrohttpd] 04/12: digestauth: changed type of var, gnunet, 2022/05/04
- [libmicrohttpd] 01/12: internal.h: fixed doxy, gnunet, 2022/05/04
- [libmicrohttpd] 02/12: .gitignore: Updated, gnunet, 2022/05/04
- [libmicrohttpd] 05/12: digestauth: additional assert, gnunet, 2022/05/04
- [libmicrohttpd] 08/12: digestauth: use mseconds for timestamp, gnunet, 2022/05/04
- [libmicrohttpd] 09/12: digestauth: additional macros for readability, gnunet, 2022/05/04
- [libmicrohttpd] 07/12: digestauth: increased timestamp to 48 bits, gnunet, 2022/05/04
- [libmicrohttpd] 06/12: digestauth: added run-time checks for algo value, gnunet, 2022/05/04
- [libmicrohttpd] 11/12: digestauth: added management of nonce-nc map array slots, gnunet, 2022/05/04
- [libmicrohttpd] 03/12: digestauth: use 7 bit shift for fast "hash", gnunet, 2022/05/04
- [libmicrohttpd] 10/12: digestauth: additional static function for code re-use,
gnunet <=
- [libmicrohttpd] 12/12: digestauth: re-used static function, gnunet, 2022/05/04