aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvgeny Grin (Karlson2k) <k2k@narod.ru>2022-01-18 12:41:32 +0300
committerEvgeny Grin (Karlson2k) <k2k@narod.ru>2022-01-18 12:41:32 +0300
commit17c22c2c3b8e2b56874ff701be58e7c10d1d41f4 (patch)
treeabaf7821718a77059f68f2bc4db88ce3c5de86e2
parent899e26205a2dfca9885eb87c460c02124922f493 (diff)
downloadlibmicrohttpd-17c22c2c3b8e2b56874ff701be58e7c10d1d41f4.tar.gz
libmicrohttpd-17c22c2c3b8e2b56874ff701be58e7c10d1d41f4.zip
digestauth: added macros for algorithms identifications
-rw-r--r--src/microhttpd/digestauth.c25
1 files changed, 20 insertions, 5 deletions
diff --git a/src/microhttpd/digestauth.c b/src/microhttpd/digestauth.c
index 7c22af6b..81ca2ac9 100644
--- a/src/microhttpd/digestauth.c
+++ b/src/microhttpd/digestauth.c
@@ -108,6 +108,20 @@
108 */ 108 */
109#define MAX_AUTH_RESPONSE_LENGTH 256 109#define MAX_AUTH_RESPONSE_LENGTH 256
110 110
111/**
112 * The token for MD5 algorithm.
113 */
114#define _MHD_MD5_TOKEN "MD5"
115
116/**
117 * The token for SHA-256 algorithm.
118 */
119#define _MHD_SHA256_TOKEN "SHA-256"
120
121/**
122 * The postfix token for "session" algorithms.
123 */
124#define _MHD_SESS_TOKEN "-sess"
111 125
112/** 126/**
113 * Context passed to functions that need to calculate 127 * Context passed to functions that need to calculate
@@ -128,7 +142,8 @@ struct DigestAlgorithm
128 void *ctx; 142 void *ctx;
129 143
130 /** 144 /**
131 * Name of the algorithm, "MD5" or "SHA-256" 145 * Name of the algorithm, "MD5" or "SHA-256".
146 * @sa #_MHD_MD5_TOKEN, #_MHD_SHA256_TOKEN
132 */ 147 */
133 const char *alg; 148 const char *alg;
134 149
@@ -218,9 +233,9 @@ digest_calc_ha1_from_digest (const char *alg,
218{ 233{
219 const unsigned int digest_size = da->digest_size; 234 const unsigned int digest_size = da->digest_size;
220 if ( (MHD_str_equal_caseless_ (alg, 235 if ( (MHD_str_equal_caseless_ (alg,
221 "MD5-sess")) || 236 _MHD_MD5_TOKEN _MHD_SESS_TOKEN)) ||
222 (MHD_str_equal_caseless_ (alg, 237 (MHD_str_equal_caseless_ (alg,
223 "SHA-256-sess")) ) 238 _MHD_SHA256_TOKEN _MHD_SESS_TOKEN)) )
224 { 239 {
225 uint8_t dig[VLA_ARRAY_LEN_DIGEST (digest_size)]; 240 uint8_t dig[VLA_ARRAY_LEN_DIGEST (digest_size)];
226 241
@@ -1197,7 +1212,7 @@ MHD_digest_auth_check (struct MHD_Connection *connection,
1197 case MHD_DIGEST_ALG_MD5: \ 1212 case MHD_DIGEST_ALG_MD5: \
1198 da.digest_size = MD5_DIGEST_SIZE; \ 1213 da.digest_size = MD5_DIGEST_SIZE; \
1199 da.ctx = &ctx.md5; \ 1214 da.ctx = &ctx.md5; \
1200 da.alg = "MD5"; \ 1215 da.alg = _MHD_MD5_TOKEN; \
1201 da.sessionkey = skey.md5; \ 1216 da.sessionkey = skey.md5; \
1202 da.init = &MHD_MD5Init; \ 1217 da.init = &MHD_MD5Init; \
1203 da.update = &MHD_MD5Update; \ 1218 da.update = &MHD_MD5Update; \
@@ -1208,7 +1223,7 @@ MHD_digest_auth_check (struct MHD_Connection *connection,
1208 case MHD_DIGEST_ALG_SHA256: \ 1223 case MHD_DIGEST_ALG_SHA256: \
1209 da.digest_size = SHA256_DIGEST_SIZE; \ 1224 da.digest_size = SHA256_DIGEST_SIZE; \
1210 da.ctx = &ctx.sha256; \ 1225 da.ctx = &ctx.sha256; \
1211 da.alg = "SHA-256"; \ 1226 da.alg = _MHD_SHA256_TOKEN; \
1212 da.sessionkey = skey.sha256; \ 1227 da.sessionkey = skey.sha256; \
1213 da.init = &MHD_SHA256_init; \ 1228 da.init = &MHD_SHA256_init; \
1214 da.update = &MHD_SHA256_update; \ 1229 da.update = &MHD_SHA256_update; \