aboutsummaryrefslogtreecommitdiff
path: root/src/microhttpd/digestauth.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/microhttpd/digestauth.c')
-rw-r--r--src/microhttpd/digestauth.c62
1 files changed, 18 insertions, 44 deletions
diff --git a/src/microhttpd/digestauth.c b/src/microhttpd/digestauth.c
index 81ca2ac9..0d7a62e6 100644
--- a/src/microhttpd/digestauth.c
+++ b/src/microhttpd/digestauth.c
@@ -184,32 +184,6 @@ struct DigestAlgorithm
184 184
185 185
186/** 186/**
187 * convert bin to hex
188 *
189 * @param bin binary data
190 * @param len number of bytes in bin
191 * @param hex pointer to len*2+1 bytes
192 */
193static void
194cvthex (const unsigned char *bin,
195 size_t len,
196 char *hex)
197{
198 size_t i;
199 unsigned int j;
200
201 for (i = 0; i < len; ++i)
202 {
203 j = (bin[i] >> 4) & 0x0f;
204 hex[i * 2] = (char) ((j <= 9) ? (j + '0') : (j - 10 + 'a'));
205 j = bin[i] & 0x0f;
206 hex[i * 2 + 1] = (char) ((j <= 9) ? (j + '0') : (j - 10 + 'a'));
207 }
208 hex[len * 2] = '\0';
209}
210
211
212/**
213 * calculate H(A1) from given hash as per RFC2617 spec 187 * calculate H(A1) from given hash as per RFC2617 spec
214 * and store the * result in 'sessionkey'. 188 * and store the * result in 'sessionkey'.
215 * 189 *
@@ -258,15 +232,15 @@ digest_calc_ha1_from_digest (const char *alg,
258 strlen (cnonce)); 232 strlen (cnonce));
259 da->digest (da->ctx, 233 da->digest (da->ctx,
260 dig); 234 dig);
261 cvthex (dig, 235 MHD_bin_to_hex (dig,
262 digest_size, 236 digest_size,
263 da->sessionkey); 237 da->sessionkey);
264 } 238 }
265 else 239 else
266 { 240 {
267 cvthex (digest, 241 MHD_bin_to_hex (digest,
268 digest_size, 242 digest_size,
269 da->sessionkey); 243 da->sessionkey);
270 } 244 }
271} 245}
272 246
@@ -383,9 +357,9 @@ digest_calc_response (const char *ha1,
383#endif 357#endif
384 da->digest (da->ctx, 358 da->digest (da->ctx,
385 ha2); 359 ha2);
386 cvthex (ha2, 360 MHD_bin_to_hex (ha2,
387 digest_size, 361 digest_size,
388 da->sessionkey); 362 da->sessionkey);
389 da->init (da->ctx); 363 da->init (da->ctx);
390 /* calculate response */ 364 /* calculate response */
391 da->update (da->ctx, 365 da->update (da->ctx,
@@ -426,9 +400,9 @@ digest_calc_response (const char *ha1,
426 digest_size * 2); 400 digest_size * 2);
427 da->digest (da->ctx, 401 da->digest (da->ctx,
428 resphash); 402 resphash);
429 cvthex (resphash, 403 MHD_bin_to_hex (resphash,
430 digest_size, 404 digest_size,
431 da->sessionkey); 405 da->sessionkey);
432} 406}
433 407
434 408
@@ -736,12 +710,12 @@ calculate_nonce (uint32_t nonce_time,
736 strlen (realm)); 710 strlen (realm));
737 da->digest (da->ctx, 711 da->digest (da->ctx,
738 tmpnonce); 712 tmpnonce);
739 cvthex (tmpnonce, 713 MHD_bin_to_hex (tmpnonce,
740 digest_size, 714 digest_size,
741 nonce); 715 nonce);
742 cvthex (timestamp, 716 MHD_bin_to_hex (timestamp,
743 sizeof (timestamp), 717 sizeof (timestamp),
744 nonce + digest_size * 2); 718 nonce + digest_size * 2);
745} 719}
746 720
747 721