From b38cf104f0d010fb46c0cc639c1465cc3106a3b6 Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Fri, 9 Jun 2017 13:30:28 +0200 Subject: [PATCH] move prng-tests away from cipher_hash_test() --- tests/cipher_hash_test.c | 29 ----------------------------- tests/prng_test.c | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 30 deletions(-) diff --git a/tests/cipher_hash_test.c b/tests/cipher_hash_test.c index abb2648f..20cd0d16 100644 --- a/tests/cipher_hash_test.c +++ b/tests/cipher_hash_test.c @@ -5,9 +5,6 @@ int cipher_hash_test(void) { int x; - unsigned char buf[4096]; - unsigned long n, one; - prng_state nprng; /* test ciphers */ for (x = 0; cipher_descriptor[x].name != NULL; x++) { @@ -33,32 +30,6 @@ int cipher_hash_test(void) /* SHAKE128 + SHAKE256 tests are a bit special */ DOX(sha3_shake_test(), "sha3_shake"); - /* test prngs (test, import/export */ - for (x = 0; prng_descriptor[x].name != NULL; x++) { - DOX(prng_descriptor[x].test(), prng_descriptor[x].name); - DOX(prng_descriptor[x].start(&nprng), prng_descriptor[x].name); - DOX(prng_descriptor[x].add_entropy((unsigned char *)"helloworld12", 12, &nprng), prng_descriptor[x].name); - DOX(prng_descriptor[x].ready(&nprng), prng_descriptor[x].name); - n = sizeof(buf); - if (strcmp(prng_descriptor[x].name, "sprng")) { - one = 1; - if (prng_descriptor[x].pexport(buf, &one, &nprng) != CRYPT_BUFFER_OVERFLOW) { - fprintf(stderr, "Error testing pexport with a short buffer (%s)\n", prng_descriptor[x].name); - return CRYPT_ERROR; - } - } - DOX(prng_descriptor[x].pexport(buf, &n, &nprng), prng_descriptor[x].name); - prng_descriptor[x].done(&nprng); - DOX(prng_descriptor[x].pimport(buf, n, &nprng), prng_descriptor[x].name); - DOX(prng_descriptor[x].pimport(buf, 4096, &nprng), prng_descriptor[x].name); /* try to import larger data */ - DOX(prng_descriptor[x].ready(&nprng), prng_descriptor[x].name); - if (prng_descriptor[x].read(buf, 100, &nprng) != 100) { - fprintf(stderr, "Error reading from imported PRNG (%s)!\n", prng_descriptor[x].name); - return CRYPT_ERROR; - } - prng_descriptor[x].done(&nprng); - } - return 0; } diff --git a/tests/prng_test.c b/tests/prng_test.c index 15d953d4..a05fe81d 100644 --- a/tests/prng_test.c +++ b/tests/prng_test.c @@ -20,7 +20,12 @@ static unsigned long my_test_rng(unsigned char *buf, unsigned long len, int prng_test(void) { - int err = CRYPT_NOP; + int err = CRYPT_NOP; + int x; + unsigned char buf[4096]; + unsigned long n, one; + prng_state nprng; + #ifdef LTC_PRNG_ENABLE_LTC_RNG unsigned long before; @@ -41,5 +46,33 @@ int prng_test(void) ltc_rng = previous; #endif + + /* test prngs (test, import/export) */ + for (x = 0; prng_descriptor[x].name != NULL; x++) { + if(strcmp(prng_descriptor[x].name, "no_prng") == 0) continue; + err = CRYPT_OK; + DOX(prng_descriptor[x].test(), prng_descriptor[x].name); + DOX(prng_descriptor[x].start(&nprng), prng_descriptor[x].name); + DOX(prng_descriptor[x].add_entropy((unsigned char *)"helloworld12", 12, &nprng), prng_descriptor[x].name); + DOX(prng_descriptor[x].ready(&nprng), prng_descriptor[x].name); + n = sizeof(buf); + if (strcmp(prng_descriptor[x].name, "sprng")) { + one = 1; + if (prng_descriptor[x].pexport(buf, &one, &nprng) != CRYPT_BUFFER_OVERFLOW) { + fprintf(stderr, "Error testing pexport with a short buffer (%s)\n", prng_descriptor[x].name); + return CRYPT_ERROR; + } + } + DOX(prng_descriptor[x].pexport(buf, &n, &nprng), prng_descriptor[x].name); + prng_descriptor[x].done(&nprng); + DOX(prng_descriptor[x].pimport(buf, n, &nprng), prng_descriptor[x].name); + DOX(prng_descriptor[x].pimport(buf, 4096, &nprng), prng_descriptor[x].name); /* try to import larger data */ + DOX(prng_descriptor[x].ready(&nprng), prng_descriptor[x].name); + if (prng_descriptor[x].read(buf, 100, &nprng) != 100) { + fprintf(stderr, "Error reading from imported PRNG (%s)!\n", prng_descriptor[x].name); + return CRYPT_ERROR; + } + prng_descriptor[x].done(&nprng); + } return err; }