]> www.wagner.pp.ru Git - openssl-gost/engine.git/commitdiff
test_digest: Test old and new APIs
authorVitaly Chikunov <vt@altlinux.org>
Sat, 9 May 2020 20:02:25 +0000 (23:02 +0300)
committerDmitry Belyavskiy <beldmit@users.noreply.github.com>
Sun, 10 May 2020 14:11:21 +0000 (17:11 +0300)
Both HMAC (deprecated) and EVP_MAC (since 3.0).
Also, remove redundant test iteration in do_digest().

test_digest.c

index 7ad999ac2c167d55fc076858cf2fa887a335e392..c497044ff6aaa516b05c85a5faeea48b89f54355 100644 (file)
@@ -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;