From 0a8a6afdfb71e42962921980b51942cea8632697 Mon Sep 17 00:00:00 2001 From: "Dr. David von Oheimb" Date: Mon, 29 Mar 2021 19:42:33 +0200 Subject: Add quick one-shot EVP_Q_mac() and deprecation compensation decls for MAC functions This helps compensating for deprecated functions such as HMAC() and reduces clutter in the crypto lib, apps, and tests. Also fixes memory leaks in generate_cookie_callback() of apps/lib/s_cb.c. and replaces 'B<...>' by 'I<...>' where appropriate in HMAC.pod Partially fixes #14628. Reviewed-by: Paul Dale (Merged from https://github.com/openssl/openssl/pull/14664) --- test/hmactest.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'test') diff --git a/test/hmactest.c b/test/hmactest.c index babfb0e1a7..918ae0b005 100644 --- a/test/hmactest.c +++ b/test/hmactest.c @@ -100,10 +100,7 @@ static int test_hmac_md5(int idx) test[idx].data, test[idx].data_len, NULL, NULL), MD5_DIGEST_LENGTH); - if (!TEST_str_eq(p, test[idx].digest)) - return 0; - - return 1; + return TEST_ptr(p) && TEST_str_eq(p, test[idx].digest); } # endif @@ -151,7 +148,7 @@ static int test_hmac_run(void) goto err; p = pt(buf, len); - if (!TEST_str_eq(p, test[4].digest)) + if (!TEST_ptr(p) || !TEST_str_eq(p, test[4].digest)) goto err; if (!TEST_false(HMAC_Init_ex(ctx, NULL, 0, EVP_sha256(), NULL))) @@ -164,7 +161,7 @@ static int test_hmac_run(void) goto err; p = pt(buf, len); - if (!TEST_str_eq(p, test[5].digest)) + if (!TEST_ptr(p) || !TEST_str_eq(p, test[5].digest)) goto err; if (!TEST_true(HMAC_Init_ex(ctx, test[6].key, test[6].key_len, NULL, NULL)) @@ -172,7 +169,7 @@ static int test_hmac_run(void) || !TEST_true(HMAC_Final(ctx, buf, &len))) goto err; p = pt(buf, len); - if (!TEST_str_eq(p, test[6].digest)) + if (!TEST_ptr(p) || !TEST_str_eq(p, test[6].digest)) goto err; /* Test reusing a key */ @@ -181,7 +178,7 @@ static int test_hmac_run(void) || !TEST_true(HMAC_Final(ctx, buf, &len))) goto err; p = pt(buf, len); - if (!TEST_str_eq(p, test[6].digest)) + if (!TEST_ptr(p) || !TEST_str_eq(p, test[6].digest)) goto err; /* @@ -193,7 +190,7 @@ static int test_hmac_run(void) || !TEST_true(HMAC_Final(ctx, buf, &len))) goto err; p = pt(buf, len); - if (!TEST_str_eq(p, test[6].digest)) + if (!TEST_ptr(p) || !TEST_str_eq(p, test[6].digest)) goto err; ret = 1; @@ -207,10 +204,10 @@ static int test_hmac_single_shot(void) { char *p; - /* Test single-shot with an empty key. */ + /* Test single-shot with NULL key. */ p = pt(HMAC(EVP_sha1(), NULL, 0, test[4].data, test[4].data_len, NULL, NULL), SHA_DIGEST_LENGTH); - if (!TEST_str_eq(p, test[4].digest)) + if (!TEST_ptr(p) || !TEST_str_eq(p, test[4].digest)) return 0; return 1; @@ -237,7 +234,7 @@ static int test_hmac_copy(void) goto err; p = pt(buf, len); - if (!TEST_str_eq(p, test[7].digest)) + if (!TEST_ptr(p) || !TEST_str_eq(p, test[7].digest)) goto err; ret = 1; @@ -253,6 +250,8 @@ static char *pt(unsigned char *md, unsigned int len) unsigned int i; static char buf[80]; + if (md == NULL) + return NULL; for (i = 0; i < len; i++) sprintf(&(buf[i * 2]), "%02x", md[i]); return buf; -- cgit v1.2.3