[openssl-commits] [openssl] master update

Matt Caswell matt at openssl.org
Tue Apr 11 12:51:10 UTC 2017


The branch master has been updated
       via  524080c688cc55123250e48061a8c87f0d0ce1e7 (commit)
      from  05d775288effa21c39e9d6b4e1c82cf06cf9ba43 (commit)


- Log -----------------------------------------------------------------
commit 524080c688cc55123250e48061a8c87f0d0ce1e7
Author: Pauli <paul.dale at oracle.com>
Date:   Fri Apr 7 14:09:53 2017 +1000

    Update md2test to use the test infrastructure
    
    Reviewed-by: Rich Salz <rsalz at openssl.org>
    Reviewed-by: Matt Caswell <matt at openssl.org>
    (Merged from https://github.com/openssl/openssl/pull/3165)

-----------------------------------------------------------------------

Summary of changes:
 test/build.info |  2 +-
 test/md2test.c  | 65 ++++++++++++++++++---------------------------------------
 2 files changed, 21 insertions(+), 46 deletions(-)

diff --git a/test/build.info b/test/build.info
index 116262f..666cf53 100644
--- a/test/build.info
+++ b/test/build.info
@@ -75,7 +75,7 @@ IF[{- !$disabled{tests} -}]
   INCLUDE[ideatest]=../include
   DEPEND[ideatest]=../libcrypto
 
-  SOURCE[md2test]=md2test.c
+  SOURCE[md2test]=md2test.c testutil.c test_main.c
   INCLUDE[md2test]=../include
   DEPEND[md2test]=../libcrypto
 
diff --git a/test/md2test.c b/test/md2test.c
index cb667cb..81a1760 100644
--- a/test/md2test.c
+++ b/test/md2test.c
@@ -1,5 +1,5 @@
 /*
- * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 1995-2017 The OpenSSL Project Authors. All Rights Reserved.
  *
  * Licensed under the OpenSSL license (the "License").  You may not use
  * this file except in compliance with the License.  You can obtain a copy
@@ -7,19 +7,13 @@
  * https://www.openssl.org/source/license.html
  */
 
-#include <stdio.h>
-#include <stdlib.h>
 #include <string.h>
 
 #include "../e_os.h"
+#include "test_main.h"
+#include "testutil.h"
 
-#ifdef OPENSSL_NO_MD2
-int main(int argc, char *argv[])
-{
-    printf("No MD2 support\n");
-    return (0);
-}
-#else
+#ifndef OPENSSL_NO_MD2
 # include <openssl/evp.h>
 # include <openssl/md2.h>
 
@@ -35,7 +29,6 @@ static char *test[] = {
     "abcdefghijklmnopqrstuvwxyz",
     "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
     "12345678901234567890123456789012345678901234567890123456789012345678901234567890",
-    NULL,
 };
 
 static char *ret[] = {
@@ -48,45 +41,27 @@ static char *ret[] = {
     "d5976f79d83d3a0dc9806c3c66f3efd8",
 };
 
-static char *pt(unsigned char *md);
-int main(int argc, char *argv[])
+static int test_md2(int n)
 {
-    int i, err = 0;
-    char **P, **R;
-    char *p;
+    char buf[80];
     unsigned char md[MD2_DIGEST_LENGTH];
-
-    P = test;
-    R = ret;
-    i = 1;
-    while (*P != NULL) {
-        if (!EVP_Digest((unsigned char *)*P, strlen(*P), md, NULL, EVP_md2(),
-                        NULL)) {
-            printf("EVP Digest error.\n");
-            EXIT(1);
-        }
-        p = pt(md);
-        if (strcmp(p, *R) != 0) {
-            printf("error calculating MD2 on '%s'\n", *P);
-            printf("got %s instead of %s\n", p, *R);
-            err++;
-        } else
-            printf("test %d ok\n", i);
-        i++;
-        R++;
-        P++;
-    }
-    EXIT(err);
-    return err;
-}
-
-static char *pt(unsigned char *md)
-{
     int i;
-    static char buf[80];
+
+    if (!TEST_true(EVP_Digest((unsigned char *)test[n], strlen(test[n]),
+                                 md, NULL, EVP_md2(), NULL)))
+        return 0;
 
     for (i = 0; i < MD2_DIGEST_LENGTH; i++)
         sprintf(&(buf[i * 2]), "%02x", md[i]);
-    return (buf);
+    if (!TEST_str_eq(buf, ret[n]))
+        return 0;
+    return 1;
 }
 #endif
+
+void register_tests(void)
+{
+#ifndef OPENSSL_NO_MD2
+    ADD_ALL_TESTS(test_md2, OSSL_NELEM(test));
+#endif
+}


More information about the openssl-commits mailing list