aboutsummaryrefslogtreecommitdiff
path: root/src/microhttpd/test_sha256.c
diff options
context:
space:
mode:
authorEvgeny Grin (Karlson2k) <k2k@narod.ru>2022-09-15 11:25:43 +0300
committerEvgeny Grin (Karlson2k) <k2k@narod.ru>2022-09-25 18:39:43 +0300
commiteef2d639f6f0a20b7768b3e521b0d0339957baeb (patch)
treef7793698ebe56eb2f86637339cf013da5dbc659a /src/microhttpd/test_sha256.c
parentb50bed1269be493f453c24de196bf89229abd2fd (diff)
downloadlibmicrohttpd-eef2d639f6f0a20b7768b3e521b0d0339957baeb.tar.gz
libmicrohttpd-eef2d639f6f0a20b7768b3e521b0d0339957baeb.zip
test_{md5,sha{256,512_256}}: re-use of the context structure
The context structure declaration was moved outside the loops, it should help to re-use the same memory area which may trigger more potential bugs.
Diffstat (limited to 'src/microhttpd/test_sha256.c')
-rw-r--r--src/microhttpd/test_sha256.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/microhttpd/test_sha256.c b/src/microhttpd/test_sha256.c
index a44ceedc..f287afd6 100644
--- a/src/microhttpd/test_sha256.c
+++ b/src/microhttpd/test_sha256.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of libmicrohttpd 2 This file is part of libmicrohttpd
3 Copyright (C) 2019 Karlson2k (Evgeny Grin) 3 Copyright (C) 2019-2022 Evgeny Grin (Karlson2k)
4 4
5 This test tool is free software; you can redistribute it and/or 5 This test tool is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License as 6 modify it under the terms of the GNU General Public License as
@@ -339,10 +339,10 @@ test1_str (void)
339{ 339{
340 int num_failed = 0; 340 int num_failed = 0;
341 unsigned int i; 341 unsigned int i;
342 struct Sha256Ctx ctx;
342 343
343 for (i = 0; i < units1_num; i++) 344 for (i = 0; i < units1_num; i++)
344 { 345 {
345 struct Sha256Ctx ctx;
346 uint8_t digest[SHA256_DIGEST_SIZE]; 346 uint8_t digest[SHA256_DIGEST_SIZE];
347 347
348 MHD_SHA256_init (&ctx); 348 MHD_SHA256_init (&ctx);
@@ -361,10 +361,10 @@ test1_bin (void)
361{ 361{
362 int num_failed = 0; 362 int num_failed = 0;
363 unsigned int i; 363 unsigned int i;
364 struct Sha256Ctx ctx;
364 365
365 for (i = 0; i < units2_num; i++) 366 for (i = 0; i < units2_num; i++)
366 { 367 {
367 struct Sha256Ctx ctx;
368 uint8_t digest[SHA256_DIGEST_SIZE]; 368 uint8_t digest[SHA256_DIGEST_SIZE];
369 369
370 MHD_SHA256_init (&ctx); 370 MHD_SHA256_init (&ctx);
@@ -384,10 +384,10 @@ test2_str (void)
384{ 384{
385 int num_failed = 0; 385 int num_failed = 0;
386 unsigned int i; 386 unsigned int i;
387 struct Sha256Ctx ctx;
387 388
388 for (i = 0; i < units1_num; i++) 389 for (i = 0; i < units1_num; i++)
389 { 390 {
390 struct Sha256Ctx ctx;
391 uint8_t digest[SHA256_DIGEST_SIZE]; 391 uint8_t digest[SHA256_DIGEST_SIZE];
392 size_t part_s = data_units1[i].str_l.len / 4; 392 size_t part_s = data_units1[i].str_l.len / 4;
393 393
@@ -413,10 +413,10 @@ test2_bin (void)
413{ 413{
414 int num_failed = 0; 414 int num_failed = 0;
415 unsigned int i; 415 unsigned int i;
416 struct Sha256Ctx ctx;
416 417
417 for (i = 0; i < units2_num; i++) 418 for (i = 0; i < units2_num; i++)
418 { 419 {
419 struct Sha256Ctx ctx;
420 uint8_t digest[SHA256_DIGEST_SIZE]; 420 uint8_t digest[SHA256_DIGEST_SIZE];
421 size_t part_s = data_units2[i].bin_l.len * 2 / 3; 421 size_t part_s = data_units2[i].bin_l.len * 2 / 3;
422 422
@@ -444,6 +444,7 @@ test_unaligned (void)
444 unsigned int offset; 444 unsigned int offset;
445 uint8_t *buf; 445 uint8_t *buf;
446 uint8_t *digest_buf; 446 uint8_t *digest_buf;
447 struct Sha256Ctx ctx;
447 448
448 const struct data_unit2 *const tdata = data_units2 + DATA_POS; 449 const struct data_unit2 *const tdata = data_units2 + DATA_POS;
449 450
@@ -454,7 +455,6 @@ test_unaligned (void)
454 455
455 for (offset = MAX_OFFSET; offset >= 1; --offset) 456 for (offset = MAX_OFFSET; offset >= 1; --offset)
456 { 457 {
457 struct Sha256Ctx ctx;
458 uint8_t *unaligned_digest; 458 uint8_t *unaligned_digest;
459 uint8_t *unaligned_buf; 459 uint8_t *unaligned_buf;
460 460