Remove tests dependence on e_os.h
[openssl.git] / test / igetest.c
index fc80275495afa10841d93ddaf66835b70ba4f130..8a1db677047358064b85bb87580de50e2dfb7cb4 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2006-2016 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2006-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
@@ -12,7 +12,7 @@
 #include <openssl/rand.h>
 #include <stdio.h>
 #include <string.h>
-#include "e_os.h"
+#include <internal/nelem.h>
 #include "testutil.h"
 
 #define TEST_SIZE       128
@@ -27,19 +27,6 @@ static unsigned char rkey2[16];
 static unsigned char plaintext[BIG_TEST_SIZE];
 static unsigned char saved_iv[AES_BLOCK_SIZE * 4];
 
-static void hexdump(FILE *f, const char *title, const unsigned char *s, int l)
-{
-    int n = 0;
-
-    fprintf(f, "%s", title);
-    for (; n < l; ++n) {
-        if ((n % 16) == 0)
-            fprintf(f, "\n%04x", n);
-        fprintf(f, " %02x", s[n]);
-    }
-    fprintf(f, "\n");
-}
-
 #define MAX_VECTOR_SIZE 64
 
 struct ige_test {
@@ -174,9 +161,9 @@ static int test_ige_vectors(int n)
 
     if (!TEST_mem_eq(v->out, v->length, buf, v->length)) {
         TEST_info("IGE test vector %d failed", n);
-        hexdump(stderr, "key", v->key, sizeof v->key);
-        hexdump(stderr, "iv", v->iv, sizeof v->iv);
-        hexdump(stderr, "in", v->in, v->length);
+        test_output_memory("key", v->key, sizeof v->key);
+        test_output_memory("iv", v->iv, sizeof v->iv);
+        test_output_memory("in", v->in, v->length);
         testresult = 0;
     }
 
@@ -187,9 +174,9 @@ static int test_ige_vectors(int n)
 
     if (!TEST_mem_eq(v->out, v->length, buf, v->length)) {
         TEST_info("IGE test vector %d failed (with in == out)", n);
-        hexdump(stderr, "key", v->key, sizeof v->key);
-        hexdump(stderr, "iv", v->iv, sizeof v->iv);
-        hexdump(stderr, "in", v->in, v->length);
+        test_output_memory("key", v->key, sizeof v->key);
+        test_output_memory("iv", v->iv, sizeof v->iv);
+        test_output_memory("in", v->in, v->length);
         testresult = 0;
     }
 
@@ -218,10 +205,10 @@ static int test_bi_ige_vectors(int n)
                        v->encrypt);
 
     if (!TEST_mem_eq(v->out, v->length, buf, v->length)) {
-        hexdump(stderr, "key 1", v->key1, sizeof v->key1);
-        hexdump(stderr, "key 2", v->key2, sizeof v->key2);
-        hexdump(stderr, "iv", v->iv, sizeof v->iv);
-        hexdump(stderr, "in", v->in, v->length);
+        test_output_memory("key 1", v->key1, sizeof v->key1);
+        test_output_memory("key 2", v->key2, sizeof v->key2);
+        test_output_memory("iv", v->iv, sizeof v->iv);
+        test_output_memory("in", v->in, v->length);
         return 0;
     }
 
@@ -362,6 +349,7 @@ static int test_bi_ige_garble1(void)
     unsigned int n;
     size_t matches;
 
+    memcpy(iv, saved_iv, sizeof iv);
     AES_set_encrypt_key(rkey, 8 * sizeof rkey, &key);
     AES_set_encrypt_key(rkey2, 8 * sizeof rkey2, &key2);
     AES_ige_encrypt(plaintext, ciphertext, sizeof plaintext, &key, iv,
@@ -392,6 +380,7 @@ static int test_bi_ige_garble2(void)
     unsigned int n;
     size_t matches;
 
+    memcpy(iv, saved_iv, sizeof iv);
     AES_set_encrypt_key(rkey, 8 * sizeof rkey, &key);
     AES_set_encrypt_key(rkey2, 8 * sizeof rkey2, &key2);
     AES_ige_encrypt(plaintext, ciphertext, sizeof plaintext, &key, iv,
@@ -422,6 +411,7 @@ static int test_bi_ige_garble3(void)
     unsigned int n;
     size_t matches;
 
+    memcpy(iv, saved_iv, sizeof iv);
     AES_set_encrypt_key(rkey, 8 * sizeof rkey, &key);
     AES_set_encrypt_key(rkey2, 8 * sizeof rkey2, &key2);
     AES_ige_encrypt(plaintext, ciphertext, sizeof plaintext, &key, iv,
@@ -443,7 +433,7 @@ static int test_bi_ige_garble3(void)
     return TEST_size_t_le(matches, sizeof checktext / 100);
 }
 
-void register_tests(void)
+int setup_tests(void)
 {
     RAND_bytes(rkey, sizeof rkey);
     RAND_bytes(rkey2, sizeof rkey2);
@@ -460,4 +450,5 @@ void register_tests(void)
     ADD_TEST(test_bi_ige_garble3);
     ADD_ALL_TESTS(test_ige_vectors, OSSL_NELEM(ige_test_vectors));
     ADD_ALL_TESTS(test_bi_ige_vectors, OSSL_NELEM(bi_ige_test_vectors));
+    return 1;
 }