diff options
author | Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> | 2019-06-24 17:42:10 +0300 |
---|---|---|
committer | Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> | 2019-06-26 11:01:19 +0300 |
commit | 6b41d6ce9f18eac9673279db336f8c84bc839cac (patch) | |
tree | 482674a7ffe97d434477735fd3b9720ebf52101e | |
parent | de42342c24ba0d4f745a4a4ba29176bb79b1a9da (diff) | |
download | gnutls-6b41d6ce9f18eac9673279db336f8c84bc839cac.tar.gz |
crypto-selftests: add test for gnutls_hmac_copy()
Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
-rw-r--r-- | lib/crypto-selftests.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/crypto-selftests.c b/lib/crypto-selftests.c index 02e92849e9..200d98ee8d 100644 --- a/lib/crypto-selftests.c +++ b/lib/crypto-selftests.c @@ -1544,6 +1544,7 @@ static int test_mac(gnutls_mac_algorithm_t mac, int ret; size_t data_size; gnutls_hmac_hd_t hd; + gnutls_hmac_hd_t copy; for (i = 0; i < vectors_size; i++) { ret = gnutls_hmac_init(&hd, @@ -1560,6 +1561,14 @@ static int test_mac(gnutls_mac_algorithm_t mac, if (ret < 0) return gnutls_assert_val(GNUTLS_E_SELF_TEST_ERROR); + copy = gnutls_hmac_copy(hd); + /* Returning NULL is not an error here for the time being, but + * it might become one later */ +#if 0 + if (!copy) + return gnutls_assert_val(GNUTLS_E_SELF_TEST_ERROR); +#endif + ret = gnutls_hmac(hd, &vectors[i].plaintext[1], vectors[i].plaintext_size - 1); @@ -1582,6 +1591,25 @@ static int test_mac(gnutls_mac_algorithm_t mac, return gnutls_assert_val(GNUTLS_E_SELF_TEST_ERROR); } + + if (copy != NULL) { + ret = gnutls_hmac(copy, + &vectors[i].plaintext[1], + vectors[i].plaintext_size - 1); + if (ret < 0) + return gnutls_assert_val(GNUTLS_E_SELF_TEST_ERROR); + + memset(data, 0xaa, data_size); + gnutls_hmac_deinit(copy, data); + + if (memcmp(data, vectors[i].output, + vectors[i].output_size) != 0) { + _gnutls_debug_log + ("MAC-%s copy test vector %d failed!\n", + gnutls_mac_get_name(mac), i); + return gnutls_assert_val(GNUTLS_E_SELF_TEST_ERROR); + } + } } _gnutls_debug_log |