X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=test%2Fevp_extra_test.c;h=1876bdcf11be84254c1421d16130ac3ec1e66d6a;hb=HEAD;hp=7f07ab738e1b3a9729715eedfd7022d3619ea43a;hpb=29c49b2534fbd60338f61e94c2893d774f9361a9;p=oweals%2Fopenssl.git diff --git a/test/evp_extra_test.c b/test/evp_extra_test.c index 7f07ab738e..1876bdcf11 100644 --- a/test/evp_extra_test.c +++ b/test/evp_extra_test.c @@ -471,6 +471,35 @@ static EVP_PKEY *load_example_hmac_key(void) return pkey; } +static int test_EVP_set_default_properties(void) +{ + OPENSSL_CTX *ctx; + EVP_MD *md = NULL; + int res = 0; + + if (!TEST_ptr(ctx = OPENSSL_CTX_new()) + || !TEST_ptr(md = EVP_MD_fetch(ctx, "sha256", NULL))) + goto err; + EVP_MD_free(md); + md = NULL; + + if (!TEST_true(EVP_set_default_properties(ctx, "provider=fizzbang")) + || !TEST_ptr_null(md = EVP_MD_fetch(ctx, "sha256", NULL)) + || !TEST_ptr(md = EVP_MD_fetch(ctx, "sha256", "-provider"))) + goto err; + EVP_MD_free(md); + md = NULL; + + if (!TEST_true(EVP_set_default_properties(ctx, NULL)) + || !TEST_ptr(md = EVP_MD_fetch(ctx, "sha256", NULL))) + goto err; + res = 1; +err: + EVP_MD_free(md); + OPENSSL_CTX_free(ctx); + return res; +} + static int test_EVP_Enveloped(void) { int ret = 0; @@ -1741,6 +1770,37 @@ static int test_pkey_ctx_fail_without_provider(int tst) return ret; } +static int test_rand_agglomeration(void) +{ + EVP_RAND *rand; + EVP_RAND_CTX *ctx; + OSSL_PARAM params[3], *p = params; + int res; + unsigned int step = 7; + static unsigned char seed[] = "It does not matter how slowly you go " + "as long as you do not stop."; + unsigned char out[sizeof(seed)]; + + if (!TEST_int_ne(sizeof(seed) % step, 0) + || !TEST_ptr(rand = EVP_RAND_fetch(NULL, "TEST-RAND", NULL))) + return 0; + ctx = EVP_RAND_CTX_new(rand, NULL); + EVP_RAND_free(rand); + if (!TEST_ptr(ctx)) + return 0; + + memset(out, 0, sizeof(out)); + *p++ = OSSL_PARAM_construct_octet_string(OSSL_RAND_PARAM_TEST_ENTROPY, + seed, sizeof(seed)); + *p++ = OSSL_PARAM_construct_uint(OSSL_DRBG_PARAM_MAX_REQUEST, &step); + *p = OSSL_PARAM_construct_end(); + res = TEST_true(EVP_RAND_set_ctx_params(ctx, params)) + && TEST_true(EVP_RAND_generate(ctx, out, sizeof(out), 0, 1, NULL, 0)) + && TEST_mem_eq(seed, sizeof(seed), out, sizeof(out)); + EVP_RAND_CTX_free(ctx); + return res; +} + int setup_tests(void) { testctx = OPENSSL_CTX_new(); @@ -1748,6 +1808,7 @@ int setup_tests(void) if (!TEST_ptr(testctx)) return 0; + ADD_TEST(test_EVP_set_default_properties); ADD_ALL_TESTS(test_EVP_DigestSignInit, 9); ADD_TEST(test_EVP_DigestVerifyInit); ADD_TEST(test_EVP_Enveloped); @@ -1793,6 +1854,8 @@ int setup_tests(void) ADD_ALL_TESTS(test_keygen_with_empty_template, 2); ADD_ALL_TESTS(test_pkey_ctx_fail_without_provider, 2); + ADD_TEST(test_rand_agglomeration); + return 1; }