Change RC5_32_set_key to return an int type
[openssl.git] / test / bftest.c
index 2bba06010087179d8a954e2c3e9f6c6e2d256769..5b489251c0cae5f6249e74f17fb6f038230883be 100644 (file)
@@ -1,7 +1,7 @@
 /*
- * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
  *
- * Licensed under the OpenSSL license (the "License").  You may not use
+ * Licensed under the Apache License 2.0 (the "License").  You may not use
  * this file except in compliance with the License.  You can obtain a copy
  * in the file LICENSE in the source distribution or at
  * https://www.openssl.org/source/license.html
 #include <string.h>
 #include <stdlib.h>
 #include <openssl/opensslconf.h> /* To see if OPENSSL_NO_BF is defined */
-
-#include "test_main_custom.h"
 #include "testutil.h"
 
-#include "../e_os.h"
+#include "internal/nelem.h"
 
-#ifdef OPENSSL_NO_BF
-int main(int argc, char *argv[])
-{
-    printf("No BF support\n");
-    return (0);
-}
-#else
+#ifndef OPENSSL_NO_BF
 # include <openssl/blowfish.h>
 
 # ifdef CHARSET_EBCDIC
@@ -294,7 +286,7 @@ static int print_test_data(void)
     for (j = 0; j < strlen(cbc_data) + 1; j++)
         printf("%02X", ofb64_ok[j]);
     printf("\n");
-    return (0);
+    return 0;
 }
 
 static int test_bf_ecb_raw(int n)
@@ -339,14 +331,14 @@ static int test_bf_ecb(int n)
 
 static int test_bf_set_key(int n)
 {
-    int i, ret = 1;
+    int ret = 1;
     BF_KEY key;
     unsigned char out[8];
 
     BF_set_key(&key, n+1, key_test);
     BF_ecb_encrypt(key_data, out, &key, BF_ENCRYPT);
     /* mips-sgi-irix6.5-gcc  vv  -mabi=64 bug workaround */
-    if (!TEST_mem_eq(out, 8, &(key_out[i = n][0]), 8))
+    if (!TEST_mem_eq(out, 8, &(key_out[n][0]), 8))
         ret = 0;
 
     return ret;
@@ -364,7 +356,7 @@ static int test_bf_cbc(void)
     BF_set_key(&key, 16, cbc_key);
     memset(cbc_in, 0, sizeof(cbc_in));
     memset(cbc_out, 0, sizeof(cbc_out));
-    memcpy(iv, cbc_iv, sizeof iv);
+    memcpy(iv, cbc_iv, sizeof(iv));
     BF_cbc_encrypt((unsigned char *)cbc_data, cbc_out, len,
                    &key, iv, BF_ENCRYPT);
     if (!TEST_mem_eq(cbc_out, 32, cbc_ok, 32))
@@ -440,31 +432,55 @@ static int test_bf_ofb64(void)
 
     return ret;
 }
+#endif
+
+typedef enum OPTION_choice {
+    OPT_ERR = -1,
+    OPT_EOF = 0,
+    OPT_PRINT,
+    OPT_TEST_ENUM
+} OPTION_CHOICE;
+
+const OPTIONS *test_get_options(void)
+{
+    static const OPTIONS test_options[] = {
+        OPT_TEST_OPTIONS_DEFAULT_USAGE,
+        { "print", OPT_PRINT, '-', "Output test tables instead of running tests"},
+        { NULL }
+    };
+    return test_options;
+}
 
-int test_main(int argc, char *argv[])
+int setup_tests(void)
 {
-    int ret;
+#ifndef OPENSSL_NO_BF
+    OPTION_CHOICE o;
 # ifdef CHARSET_EBCDIC
     int n;
-
     ebcdic2ascii(cbc_data, cbc_data, strlen(cbc_data));
     for (n = 0; n < 2; n++) {
         ebcdic2ascii(bf_key[n], bf_key[n], strlen(bf_key[n]));
     }
 # endif
 
+    while ((o = opt_next()) != OPT_EOF) {
+        switch(o) {
+        case OPT_PRINT:
+            print_test_data();
+            return 1;
+        case OPT_TEST_CASES:
+            break;
+        default:
+           return 0;
+        }
+    }
+
     ADD_ALL_TESTS(test_bf_ecb_raw, 2);
     ADD_ALL_TESTS(test_bf_ecb, NUM_TESTS);
     ADD_ALL_TESTS(test_bf_set_key, KEY_TEST_NUM-1);
     ADD_TEST(test_bf_cbc);
     ADD_TEST(test_bf_cfb64);
     ADD_TEST(test_bf_ofb64);
-
-    if (argc > 1)
-        ret = print_test_data();
-    else
-        ret = run_tests(argv[0]);
-
-    return ret;
-}
 #endif
+    return 1;
+}