X-Git-Url: https://git.openssl.org/gitweb/?p=openssl.git;a=blobdiff_plain;f=test%2Fsiphash_internal_test.c;h=573c15d254206dea469b6d3578a3d08cf3eade1f;hp=0114af18d08e87b3dbe48acee0d2c7ee04f3f65b;hb=58094ab60ff51918a248dc6bd977d48f981fe2c1;hpb=a9c6d221055c3a85edb23b1364cd60baafed4b9f diff --git a/test/siphash_internal_test.c b/test/siphash_internal_test.c index 0114af18d0..573c15d254 100644 --- a/test/siphash_internal_test.c +++ b/test/siphash_internal_test.c @@ -1,5 +1,5 @@ /* - * Copyright 2016-2017 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2016-2018 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 @@ -16,10 +16,7 @@ #include "testutil.h" #include "internal/siphash.h" #include "../crypto/siphash/siphash_local.h" -#include "e_os.h" - -static BIO* b_stderr = NULL; -static BIO* b_stdout = NULL; +#include "internal/nelem.h" typedef struct { size_t size; @@ -37,47 +34,6 @@ typedef struct { * ***/ -static int benchmark_siphash(void) -{ -# ifdef OPENSSL_CPUID_OBJ - SIPHASH siphash; - unsigned char key[SIPHASH_KEY_SIZE]; - unsigned char buf[8192]; - unsigned long long stopwatch; - unsigned long long OPENSSL_rdtsc(); - unsigned int i; - - memset (buf,0x55,sizeof(buf)); - memset (key,0xAA,sizeof(key)); - - (void)SipHash_Init(&siphash, key, 0, 0, 0); - - for (i=0;i<100000;i++) - SipHash_Update(&siphash, buf, sizeof(buf)); - - stopwatch = OPENSSL_rdtsc(); - for (i=0;i<10000;i++) - SipHash_Update(&siphash, buf, sizeof(buf)); - stopwatch = OPENSSL_rdtsc() - stopwatch; - - BIO_printf(b_stdout, "%g\n",stopwatch/(double)(i*sizeof(buf))); - - stopwatch = OPENSSL_rdtsc(); - for (i=0;i<10000;i++) { - (void)SipHash_Init(&siphash, key, 0, 0, 0); - SipHash_Update(&siphash, buf, 16); - (void)SipHash_Final(&siphash, buf, SIPHASH_MAX_DIGEST_SIZE); - } - stopwatch = OPENSSL_rdtsc() - stopwatch; - - BIO_printf(b_stdout, "%g\n",stopwatch/(double)(i)); -# else - BIO_printf(b_stderr, - "Benchmarking of siphash isn't available on this platform\n"); -# endif - return 1; -} - /* From C reference: https://131002.net/siphash/ */ static TESTDATA tests[] = { @@ -235,10 +191,10 @@ static int test_siphash(int idx) /* key and in data are 00 01 02 ... */ for (i = 0; i < sizeof(key); i++) - key[i] = i; + key[i] = (unsigned char)i; for (i = 0; i < inlen; i++) - in[i] = i; + in[i] = (unsigned char)i; if (!TEST_true(SipHash_Init(&siphash, key, expectedlen, 0, 0))) return 0; @@ -319,41 +275,9 @@ static int test_siphash_basic(void) && TEST_true(SipHash_Final(&siphash, output, 16)); } -int test_main(int argc, char **argv) +int setup_tests(void) { - int result = 0; - int iter_argv; - int benchmark = 0; - - b_stderr = BIO_new_fp(stderr, BIO_NOCLOSE | BIO_FP_TEXT); - b_stdout = BIO_new_fp(stdout, BIO_NOCLOSE | BIO_FP_TEXT); -#ifdef OPENSSL_SYS_VMS - b_stderr = BIO_push(BIO_new(BIO_f_linebuffer()), b_stderr); - b_stdout = BIO_push(BIO_new(BIO_f_linebuffer()), b_stdout); -#endif - - for (iter_argv = 1; iter_argv < argc; iter_argv++) { - if (strcmp(argv[iter_argv], "-b") == 0) - benchmark = 1; - else if (strcmp(argv[iter_argv], "-h") == 0) - goto help; - } - ADD_TEST(test_siphash_basic); ADD_ALL_TESTS(test_siphash, OSSL_NELEM(tests)); - if (benchmark) - ADD_TEST(benchmark_siphash); - - result = run_tests(argv[0]); - goto out; - - help: - BIO_printf(b_stdout, "-h\tThis help\n"); - BIO_printf(b_stdout, "-b\tBenchmark in addition to the tests\n"); - - out: - BIO_free(b_stdout); - BIO_free(b_stderr); - - return result; + return 1; }