diff options
author | Vitaly Chikunov <vt@altlinux.org> | 2020-05-09 23:02:25 +0300 |
---|---|---|
committer | Dmitry Belyavskiy <beldmit@users.noreply.github.com> | 2020-05-10 17:11:21 +0300 |
commit | e200e6195805d87303cc2157ba38a593013623d3 (patch) | |
tree | 1c3c2f7b7bf89ba3c4eccd1aaca71ca90ca26c7c | |
parent | cded1d0aa04a386faa3778d0b029c78abd996e93 (diff) | |
download | gost-engine-e200e6195805d87303cc2157ba38a593013623d3.zip gost-engine-e200e6195805d87303cc2157ba38a593013623d3.tar.gz gost-engine-e200e6195805d87303cc2157ba38a593013623d3.tar.bz2 |
test_digest: Test old and new APIs
Both HMAC (deprecated) and EVP_MAC (since 3.0).
Also, remove redundant test iteration in do_digest().
-rw-r--r-- | test_digest.c | 36 |
1 files 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 <openssl/rand.h> #include <openssl/err.h> #include <openssl/asn1.h> -#if OPENSSL_VERSION_MAJOR < 3 # include <openssl/hmac.h> -#else +#if OPENSSL_VERSION_MAJOR >= 3 # include <openssl/core_names.h> #endif #include <openssl/obj_mac.h> @@ -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; |