diff options
author | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2022-09-16 13:41:28 +0300 |
---|---|---|
committer | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2022-09-25 18:39:44 +0300 |
commit | 281b22da0e60e642a5ad528e5a25ff7ae9b2d7ed (patch) | |
tree | 7282b6cf27c9f5279762eed8fc694bc2596844e2 | |
parent | ebe7f8d26c67d218dbb08788b0d07b01d824c12a (diff) | |
download | libmicrohttpd-281b22da0e60e642a5ad528e5a25ff7ae9b2d7ed.tar.gz libmicrohttpd-281b22da0e60e642a5ad528e5a25ff7ae9b2d7ed.zip |
digestauth: refactored hashing asserts
-rw-r--r-- | src/microhttpd/digestauth.c | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/src/microhttpd/digestauth.c b/src/microhttpd/digestauth.c index bc466d87..88668d1d 100644 --- a/src/microhttpd/digestauth.c +++ b/src/microhttpd/digestauth.c | |||
@@ -336,7 +336,7 @@ struct DigestAlgorithm | |||
336 | #if _DEBUG | 336 | #if _DEBUG |
337 | bool setup; /**< The structure was set-up */ | 337 | bool setup; /**< The structure was set-up */ |
338 | bool inited; /**< The calculation was initialised */ | 338 | bool inited; /**< The calculation was initialised */ |
339 | bool digest_calculated; /**< The digest was calculated */ | 339 | bool hashing; /**< Some data has been hashed, but digest is not yet finalised */ |
340 | #endif /* _DEBUG */ | 340 | #endif /* _DEBUG */ |
341 | }; | 341 | }; |
342 | 342 | ||
@@ -381,7 +381,7 @@ digest_setup (struct DigestAlgorithm *da, | |||
381 | #ifdef _DEBUG | 381 | #ifdef _DEBUG |
382 | da->setup = false; | 382 | da->setup = false; |
383 | da->inited = false; | 383 | da->inited = false; |
384 | da->digest_calculated = false; | 384 | da->hashing = false; |
385 | #endif /* _DEBUG */ | 385 | #endif /* _DEBUG */ |
386 | if (false | 386 | if (false |
387 | #ifdef MHD_MD5_SUPPORT | 387 | #ifdef MHD_MD5_SUPPORT |
@@ -413,9 +413,8 @@ _MHD_static_inline void | |||
413 | digest_init (struct DigestAlgorithm *da) | 413 | digest_init (struct DigestAlgorithm *da) |
414 | { | 414 | { |
415 | mhd_assert (da->setup); | 415 | mhd_assert (da->setup); |
416 | #ifdef _DEBUG | 416 | mhd_assert (! da->hashing); |
417 | da->digest_calculated = false; | 417 | mhd_assert (! da->inited); |
418 | #endif | ||
419 | #ifdef MHD_MD5_SUPPORT | 418 | #ifdef MHD_MD5_SUPPORT |
420 | if (MHD_DIGEST_BASE_ALGO_MD5 == da->algo) | 419 | if (MHD_DIGEST_BASE_ALGO_MD5 == da->algo) |
421 | { | 420 | { |
@@ -467,7 +466,6 @@ digest_update (struct DigestAlgorithm *da, | |||
467 | size_t length) | 466 | size_t length) |
468 | { | 467 | { |
469 | mhd_assert (da->inited); | 468 | mhd_assert (da->inited); |
470 | mhd_assert (! da->digest_calculated); | ||
471 | #ifdef MHD_MD5_SUPPORT | 469 | #ifdef MHD_MD5_SUPPORT |
472 | if (MHD_DIGEST_BASE_ALGO_MD5 == da->algo) | 470 | if (MHD_DIGEST_BASE_ALGO_MD5 == da->algo) |
473 | MHD_MD5_update (&da->ctx.md5_ctx, (const uint8_t *) data, length); | 471 | MHD_MD5_update (&da->ctx.md5_ctx, (const uint8_t *) data, length); |
@@ -485,6 +483,9 @@ digest_update (struct DigestAlgorithm *da, | |||
485 | else | 483 | else |
486 | #endif /* MHD_SHA512_256_SUPPORT */ | 484 | #endif /* MHD_SHA512_256_SUPPORT */ |
487 | mhd_assert (0); /* May not happen */ | 485 | mhd_assert (0); /* May not happen */ |
486 | #ifdef _DEBUG | ||
487 | da->hashing = true; | ||
488 | #endif | ||
488 | } | 489 | } |
489 | 490 | ||
490 | 491 | ||
@@ -525,7 +526,6 @@ _MHD_static_inline void | |||
525 | digest_calc_hash (struct DigestAlgorithm *da, uint8_t *digest) | 526 | digest_calc_hash (struct DigestAlgorithm *da, uint8_t *digest) |
526 | { | 527 | { |
527 | mhd_assert (da->inited); | 528 | mhd_assert (da->inited); |
528 | mhd_assert (! da->digest_calculated); | ||
529 | #ifdef MHD_MD5_SUPPORT | 529 | #ifdef MHD_MD5_SUPPORT |
530 | if (MHD_DIGEST_BASE_ALGO_MD5 == da->algo) | 530 | if (MHD_DIGEST_BASE_ALGO_MD5 == da->algo) |
531 | MHD_MD5_finish (&da->ctx.md5_ctx, digest); | 531 | MHD_MD5_finish (&da->ctx.md5_ctx, digest); |
@@ -543,7 +543,8 @@ digest_calc_hash (struct DigestAlgorithm *da, uint8_t *digest) | |||
543 | #endif /* MHD_SHA512_256_SUPPORT */ | 543 | #endif /* MHD_SHA512_256_SUPPORT */ |
544 | mhd_assert (0); /* May not happen */ | 544 | mhd_assert (0); /* May not happen */ |
545 | #ifdef _DEBUG | 545 | #ifdef _DEBUG |
546 | da->digest_calculated = true; | 546 | da->hashing = false; |
547 | da->inited = false; | ||
547 | #endif | 548 | #endif |
548 | } | 549 | } |
549 | 550 | ||