From e200e6195805d87303cc2157ba38a593013623d3 Mon Sep 17 00:00:00 2001 From: Vitaly Chikunov Date: Sat, 9 May 2020 23:02:25 +0300 Subject: [PATCH] test_digest: Test old and new APIs Both HMAC (deprecated) and EVP_MAC (since 3.0). Also, remove redundant test iteration in do_digest(). --- test_digest.c | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/test_digest.c b/test_digest.c index 7ad999a..c497044 100644 --- a/test_digest.c +++ b/test_digest.c @@ -13,9 +13,8 @@ #include #include #include -#if OPENSSL_VERSION_MAJOR < 3 # include -#else +#if OPENSSL_VERSION_MAJOR >= 3 # include #endif #include @@ -54,6 +53,9 @@ else \ printf(cGREEN " Test passed\n" cNORM);} +/* To test older APIs. */ +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" + /* * Test keys from both GOST R 34.12-2015 and GOST R 34.13-2015, * for 128-bit cipher (A.1). @@ -451,8 +453,7 @@ static void hexdump(const void *ptr, size_t len) printf("\n"); } -#if OPENSSL_VERSION_MAJOR < 3 -static int do_hmac(const EVP_MD *type, const char *plaintext, +static int do_hmac_old(const EVP_MD *type, const char *plaintext, unsigned int psize, const char *etalon, int mdsize, const char *key, unsigned int key_size) { @@ -476,8 +477,8 @@ static int do_hmac(const EVP_MD *type, const char *plaintext, } return 0; } -#else -static int do_hmac(const EVP_MD *type, const char *plaintext, +#if OPENSSL_VERSION_MAJOR >= 3 +static int do_hmac_prov(const EVP_MD *type, const char *plaintext, unsigned int psize, const char *etalon, int mdsize, const char *key, unsigned int key_size) { @@ -513,6 +514,21 @@ static int do_hmac(const EVP_MD *type, const char *plaintext, } #endif +static int do_hmac(const EVP_MD *type, const char *plaintext, + unsigned int psize, const char *etalon, int mdsize, + const char *key, unsigned int key_size) +{ + int ret; + + /* Test old (deprecated) and (too) new APIs. */ + ret = do_hmac_old(type, plaintext, psize, etalon, mdsize, key, key_size); +#if OPENSSL_VERSION_MAJOR >= 3 + ret |= do_hmac_prov(type, plaintext, psize, etalon, mdsize, key, key_size); +#endif + + return ret; +} + static int do_digest(const EVP_MD *type, const char *plaintext, unsigned int psize, const char *etalon, int mdsize, int truncate, const char *key, unsigned int key_size, int acpkm, int acpkm_t, @@ -570,14 +586,6 @@ static int do_test(const struct hash_testvec *tv) const char *name = EVP_MD_name(type); printf(cBLUE "%s Test %s: %s: " cNORM, tv->hmac? "HMAC" : "MD", name, tv->name); - fflush(stdout); - if (tv->hmac) - ret |= do_hmac(type, tv->plaintext, tv->psize, tv->hmac, - tv->mdsize, tv->key, tv->key_size); - else - ret |= do_digest(type, tv->plaintext, tv->psize, tv->digest, - tv->mdsize, tv->truncate, tv->key, tv->key_size, tv->acpkm, - tv->acpkm_t, tv->block_size); /* Test alignment problems. */ int shifts = 32; -- 2.39.2