test/recipes/30-test_afalg.t: set OPENSSL_ENGINES correctly
[openssl.git] / test / drbgtest.c
index b1fc751cd97cd36606ecc7303ae199f5678e151e..6e916c42cb62fe9f56965fd9c3f382ca82e199e8 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2011-2017 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2011-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
@@ -438,7 +438,7 @@ static int error_check(DRBG_SELFTEST_DATA *td)
         goto err;
 
     /* Standard says we have to check uninstantiate really zeroes */
-    if (!TEST_mem_eq(zero, sizeof(drbg->ctr), &drbg->ctr, sizeof(drbg->ctr)))
+    if (!TEST_mem_eq(zero, sizeof(drbg->data), &drbg->data, sizeof(drbg->data)))
         goto err;
 
     ret = 1;
@@ -573,6 +573,7 @@ static int test_drbg_reseed(int expect_success,
                            )
 {
     unsigned char buf[32];
+    time_t before_reseed, after_reseed;
     int expected_state = (expect_success ? DRBG_READY : DRBG_ERROR);
 
     /*
@@ -595,9 +596,11 @@ static int test_drbg_reseed(int expect_success,
      */
 
     /* Generate random output from the public and private DRBG */
+    before_reseed = expect_master_reseed == 1 ? time(NULL) : 0;
     if (!TEST_int_eq(RAND_bytes(buf, sizeof(buf)), expect_success)
         || !TEST_int_eq(RAND_priv_bytes(buf, sizeof(buf)), expect_success))
         return 0;
+    after_reseed = time(NULL);
 
 
     /*
@@ -633,6 +636,16 @@ static int test_drbg_reseed(int expect_success,
         if (!TEST_int_eq(public->reseed_counter, master->reseed_counter)
             || !TEST_int_eq(private->reseed_counter, master->reseed_counter))
             return 0;
+
+        /* Test whether reseed time of master DRBG is set correctly */
+        if (!TEST_time_t_le(before_reseed, master->reseed_time)
+            || !TEST_time_t_le(master->reseed_time, after_reseed))
+            return 0;
+
+        /* Test whether reseed times of child DRBGs are synchronized with master */
+        if (!TEST_time_t_ge(public->reseed_time, master->reseed_time)
+            || !TEST_time_t_ge(private->reseed_time, master->reseed_time))
+            return 0;
     } else {
         ERR_clear_error();
     }