Skip to content

Commit

Permalink
fips: verify that the RNG was restored after the self tests
Browse files Browse the repository at this point in the history
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Tim Hudson <tjh@openssl.org>
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
(Merged from #19510)
  • Loading branch information
paulidale committed Nov 1, 2022
1 parent 7057ddd commit 33290c5
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions providers/fips/self_test.c
Expand Up @@ -15,6 +15,7 @@
#include <openssl/fipskey.h>
#include <openssl/err.h>
#include <openssl/proverr.h>
#include <openssl/rand.h>
#include "internal/e_os.h"
#include "prov/providercommon.h"

Expand Down Expand Up @@ -307,6 +308,8 @@ int SELF_TEST_post(SELF_TEST_POST_PARAMS *st, int on_demand_test)
unsigned char *indicator_checksum = NULL;
int loclstate;
OSSL_SELF_TEST *ev = NULL;
EVP_RAND *testrand = NULL;
EVP_RAND_CTX *rng;

if (!RUN_ONCE(&fips_self_test_init, do_fips_self_test_init))
return 0;
Expand Down Expand Up @@ -417,8 +420,19 @@ int SELF_TEST_post(SELF_TEST_POST_PARAMS *st, int on_demand_test)
}
}

/* Verify that the RNG has been restored properly */
testrand = EVP_RAND_fetch(st->libctx, "TEST-RAND", NULL);
if (testrand == NULL
|| (rng = RAND_get0_private(st->libctx)) == NULL
|| strcmp(EVP_RAND_get0_name(EVP_RAND_CTX_get0_rand(rng)),
EVP_RAND_get0_name(testrand)) == 0) {
ERR_raise(ERR_LIB_PROV, PROV_R_SELF_TEST_KAT_FAILURE);
goto end;
}

ok = 1;
end:
EVP_RAND_free(testrand);
OSSL_SELF_TEST_free(ev);
OPENSSL_free(module_checksum);
OPENSSL_free(indicator_checksum);
Expand Down

0 comments on commit 33290c5

Please sign in to comment.