]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
crypto-selftests: add test for gnutls_hmac_copy()
authorDmitry Eremin-Solenikov <dbaryshkov@gmail.com>
Mon, 24 Jun 2019 14:42:10 +0000 (17:42 +0300)
committerDmitry Eremin-Solenikov <dbaryshkov@gmail.com>
Wed, 26 Jun 2019 08:01:19 +0000 (11:01 +0300)
Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
lib/crypto-selftests.c

index 02e92849e994c9a707c1acd4c92e5ab07d94d3a4..200d98ee8d81e33aef04736f22a136362e08c8ae 100644 (file)
@@ -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