Address review feedback (to be squashed)
authorRich Salz <rsalz@openssl.org>
Wed, 12 Apr 2017 13:27:33 +0000 (09:27 -0400)
committerRich Salz <rsalz@openssl.org>
Wed, 12 Apr 2017 15:20:48 +0000 (11:20 -0400)
Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/3189)

test/casttest.c
test/x509aux.c

index 17faf9273ab86ac0ed89e1998eef0ede94a41a0a..175085824d42d349203d9ccc3ffe53d0fe0a6b34 100644 (file)
@@ -65,30 +65,29 @@ static unsigned char c_b[16] = {
 
 static int cast_test(void)
 {
-    static char *hex = "0123456789ABCDEF";
     long l;
-    int i, z, testresult = 1;
+    int z, testresult = 1;
     CAST_KEY key, key_b;
     unsigned char out_a[16], out_b[16];
 
     for (z = 0; z < 3; z++) {
         CAST_set_key(&key, k_len[z], k);
         CAST_ecb_encrypt(in, out, &key, CAST_ENCRYPT);
-        if (!TEST_mem_eq(out, sizeof(c[z]), c[z], sizeof(c[z])))
+        if (!TEST_mem_eq(out, sizeof(c[z]), c[z], sizeof(c[z]))) {
+            TEST_info("CAST_ENCRYPT iteration %d failed (len=%d)", z, k_len[z]);
             testresult = 0;
+        }
 
         CAST_ecb_encrypt(out, out, &key, CAST_DECRYPT);
-        if (!TEST_mem_eq(out, sizeof(in), in, sizeof(in)))
+        if (!TEST_mem_eq(out, sizeof(in), in, sizeof(in))) {
+            TEST_info("CAST_DECRYPT iteration %d failed (len=%d)", z, k_len[z]);
             testresult = 0;
+        }
     }
-    if (testresult)
-        TEST_info("ecb cast5 ok");
-
 
     memcpy(out_a, in_a, sizeof(in_a));
     memcpy(out_b, in_b, sizeof(in_b));
 
-    i = 1;
     for (l = 0; l < 1000000L; l++) {
         CAST_set_key(&key_b, 16, out_b);
         CAST_ecb_encrypt(&(out_a[0]), &(out_a[0]), &key_b, CAST_ENCRYPT);
@@ -96,10 +95,6 @@ static int cast_test(void)
         CAST_set_key(&key, 16, out_a);
         CAST_ecb_encrypt(&(out_b[0]), &(out_b[0]), &key, CAST_ENCRYPT);
         CAST_ecb_encrypt(&(out_b[8]), &(out_b[8]), &key, CAST_ENCRYPT);
-        if ((l & 0xffff) == 0xffff) {
-            TEST_info("%c", hex[i & 0x0f]);
-            i++;
-        }
     }
 
     if (!TEST_mem_eq(out_a, sizeof(c_a), c_a, sizeof(c_a))
index 2ad7b6d1cd78d4f66c647d834c7d82042e99a809..7030a13365fe9c6c11fe3365edbb281cc31dc8d9 100644 (file)
 #include "test_main_custom.h"
 #include "testutil.h"
 
-static int test_certs(BIO *fp)
+
+/* List of files, from argv */
+static char **files;
+
+static int test_certs(int num)
 {
     int count;
     char *name = 0;
@@ -31,6 +35,10 @@ static int test_certs(BIO *fp)
     typedef X509 *(*d2i_X509_t)(X509 **, const unsigned char **, long);
     typedef int (*i2d_X509_t)(X509 *, unsigned char **);
     int err = 0;
+    BIO *fp = BIO_new_file(files[num], "r");
+
+    if (!TEST_ptr(fp))
+        return 0;
 
     for (count = 0;
          !err && PEM_read_bio(fp, &name, &header, &data, &len);
@@ -140,6 +148,7 @@ static int test_certs(BIO *fp)
        OPENSSL_free(header);
        OPENSSL_free(data);
     }
+    BIO_free(fp);
 
     if (ERR_GET_REASON(ERR_peek_last_error()) == PEM_R_NO_START_LINE) {
         /* Reached end of PEM file */
@@ -155,26 +164,12 @@ static int test_certs(BIO *fp)
 
 int test_main(int argc, char *argv[])
 {
-    BIO *bio_err;
-    int ret = 1;
-
-    if (argc < 2)
+    if (argc < 2) {
         TEST_error("usage: %s certfile...", argv[0]);
-
-    bio_err = BIO_new_fp(stderr, BIO_NOCLOSE | BIO_FP_TEXT);
-
-    for (argv++; *argv; argv++) {
-        BIO *f = BIO_new_file(*argv, "r");
-        int ok;
-
-        TEST_check(f != NULL);
-        ok = test_certs(f);
-        BIO_free(f);
-
-        if (!TEST_int_eq(ok, 1))
-            break;
-        ret = 0;
+        return 0;
     }
-    BIO_free(bio_err);
-    return ret;
+
+    files = &argv[1];
+    ADD_ALL_TESTS(test_certs, argc - 1);
+    return run_tests(argv[0]);
 }