X-Git-Url: https://git.openssl.org/gitweb/?p=openssl.git;a=blobdiff_plain;f=fips%2Frand%2Ffips_rand_selftest.c;h=ff5780abe0e9accde6d368b3b7bf0ca5a832b42f;hp=f352cc6cd785e6c2ab90b601f8d56d70e32ef171;hb=706735aea34218c811beaaa34fe6199556aa4837;hpb=14ae26f2e4f83b9ec0cbb02976e08a69bc5e5ba4 diff --git a/fips/rand/fips_rand_selftest.c b/fips/rand/fips_rand_selftest.c index f352cc6cd7..ff5780abe0 100644 --- a/fips/rand/fips_rand_selftest.c +++ b/fips/rand/fips_rand_selftest.c @@ -54,6 +54,7 @@ #include #include #include +#include "fips_locl.h" #ifdef OPENSSL_FIPS @@ -324,50 +325,55 @@ static AES_PRNG_TV aes_256_tv[] = { }; -void FIPS_corrupt_rng() - { - aes_192_tv[0].V[0]++; - } +#define fips_x931_test(key, tv) \ + do_x931_test(key, sizeof key, tv, sizeof(tv)/sizeof(AES_PRNG_TV)) -#define fips_rand_test(key, tv) \ - do_rand_test(key, sizeof key, tv, sizeof(tv)/sizeof(AES_PRNG_TV)) - -static int do_rand_test(unsigned char *key, int keylen, +static int do_x931_test(unsigned char *key, int keylen, AES_PRNG_TV *tv, int ntv) { unsigned char R[16]; - int i; - if (!FIPS_rand_set_key(key, keylen)) + int i, rv = 1; + if (!FIPS_x931_set_key(key, keylen)) return 0; for (i = 0; i < ntv; i++) { - FIPS_rand_seed(tv[i].V, 16); - FIPS_rand_set_dt(tv[i].DT); - FIPS_rand_bytes(R, 16); + if (!fips_post_started(FIPS_TEST_X931, keylen, NULL)) + return 1; + if (!fips_post_corrupt(FIPS_TEST_X931, keylen, NULL)) + tv[i].V[0]++; + FIPS_x931_seed(tv[i].V, 16); + FIPS_x931_set_dt(tv[i].DT); + FIPS_x931_bytes(R, 16); if (memcmp(R, tv[i].R, 16)) + { + fips_post_failed(FIPS_TEST_X931, keylen, NULL); + rv = 0; + } + else if (!fips_post_success(FIPS_TEST_X931, keylen, NULL)) return 0; } - return 1; + return rv; } - -int FIPS_selftest_rng() +int FIPS_selftest_x931() { - FIPS_rand_reset(); - if (!FIPS_rand_test_mode()) - { - FIPSerr(FIPS_F_FIPS_SELFTEST_RNG,FIPS_R_SELFTEST_FAILED); - return 0; - } - if (!fips_rand_test(aes_128_key,aes_128_tv) - || !fips_rand_test(aes_192_key, aes_192_tv) - || !fips_rand_test(aes_256_key, aes_256_tv)) + int rv = 1; + FIPS_x931_reset(); + if (!FIPS_x931_test_mode()) { - FIPSerr(FIPS_F_FIPS_SELFTEST_RNG,FIPS_R_SELFTEST_FAILED); + FIPSerr(FIPS_F_FIPS_SELFTEST_X931,FIPS_R_SELFTEST_FAILED); return 0; } - FIPS_rand_reset(); - return 1; + if (!fips_x931_test(aes_128_key,aes_128_tv)) + rv = 0; + if (!fips_x931_test(aes_192_key, aes_192_tv)) + rv = 0; + if (!fips_x931_test(aes_256_key, aes_256_tv)) + rv = 0; + FIPS_x931_reset(); + if (!rv) + FIPSerr(FIPS_F_FIPS_SELFTEST_X931,FIPS_R_SELFTEST_FAILED); + return rv; } #endif