]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
crypto-selftests: exercise gnutls_hash_output(..., NULL)
authorDaiki Ueno <ueno@gnu.org>
Tue, 2 Dec 2025 00:33:22 +0000 (09:33 +0900)
committerDaiki Ueno <ueno@gnu.org>
Fri, 5 Dec 2025 11:41:43 +0000 (20:41 +0900)
This moves the test introduced in commit
7a7d3e44c0f769eb7bae6c6ee21a0a8a3f9e5144, from tests/slow/hash-large.c
to the library selftests, because the former is tailored for
excessively large input, ignoring SIGSEGV.

Signed-off-by: Daiki Ueno <ueno@gnu.org>
lib/crypto-selftests.c
tests/slow/hash-large.c

index e43c476291ad055cda15825215fba2bc6934a4df..f97e04ca948a21e4382916e3c8922817ba88bba4 100644 (file)
@@ -2396,6 +2396,46 @@ static int test_digest(gnutls_digest_algorithm_t dig,
                                        GNUTLS_E_SELF_TEST_ERROR);
                        }
                }
+
+               /* Exercise gnutls_hash_output(..., NULL), which
+                * resets the hash context
+                */
+               if (flags & GNUTLS_SELF_TEST_FLAG_ALL) {
+                       ret = gnutls_hash_init(&hd, dig);
+                       if (ret < 0) {
+                               _gnutls_debug_log("error initializing: %s\n",
+                                                 gnutls_digest_get_name(dig));
+                               return gnutls_assert_val(
+                                       GNUTLS_E_SELF_TEST_ERROR);
+                       }
+
+                       /* First feed dummy content */
+                       ret = gnutls_hash(hd, (void *)"dummy", 5);
+                       if (ret < 0)
+                               return gnutls_assert_val(
+                                       GNUTLS_E_SELF_TEST_ERROR);
+                       /* Reset the context */
+                       gnutls_hash_output(hd, NULL);
+
+                       /* Then feed the actual content */
+                       ret = gnutls_hash(hd, vectors[i].plaintext,
+                                         vectors[i].plaintext_size);
+                       if (ret < 0)
+                               return gnutls_assert_val(
+                                       GNUTLS_E_SELF_TEST_ERROR);
+
+                       memset(data, 0xbb, data_size);
+                       gnutls_hash_deinit(hd, data);
+
+                       if (memcmp(data, vectors[i].output,
+                                  vectors[i].output_size) != 0) {
+                               _gnutls_debug_log(
+                                       "%s reset test vector %d failed!\n",
+                                       gnutls_digest_get_name(dig), i);
+                               return gnutls_assert_val(
+                                       GNUTLS_E_SELF_TEST_ERROR);
+                       }
+               }
        }
 
        _gnutls_debug_log("%s self check succeeded\n",
index 6e99be86f19da81581485b39c3d25581a24ac7a3..385cbf55c93ad536d1bcc00fc57f5e22bb9de2d0 100644 (file)
@@ -116,10 +116,6 @@ void doit(void)
                fail("failed in %d\n", __LINE__);
        }
 
-       /* Test gnutls_hash_output(..., NULL) resets the context */
-       gnutls_hash(td, "foo", 3);
-       gnutls_hash_output(td, NULL);
-
        size2 = size;
        p = buf;
        while (size2 > 0) {