From: Richard Levitte Date: Sat, 17 Oct 2020 09:44:43 +0000 (+0200) Subject: test/evp_libctx_test.c: use OSSL_ENCODER instead of i2d_PublicKey() X-Git-Tag: openssl-3.0.0-alpha9~121 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f49d486075e94a2b6387961c63436d59d5a988f4;p=thirdparty%2Fopenssl.git test/evp_libctx_test.c: use OSSL_ENCODER instead of i2d_PublicKey() Reviewed-by: Paul Dale (Merged from https://github.com/openssl/openssl/pull/13167) --- diff --git a/test/evp_libctx_test.c b/test/evp_libctx_test.c index e8d41ab2a7f..a1540dd4b98 100644 --- a/test/evp_libctx_test.c +++ b/test/evp_libctx_test.c @@ -25,8 +25,10 @@ #include #include #include +#include #include #include +#include #include "testutil.h" #include "internal/nelem.h" #include "crypto/bn_dh.h" /* _bignum_ffdhe2048_p */ @@ -448,19 +450,26 @@ static int rsa_keygen(int bits, EVP_PKEY **pub, EVP_PKEY **priv) EVP_PKEY_CTX *keygen_ctx = NULL; unsigned char *pub_der = NULL; const unsigned char *pp = NULL; - long len = 0; + size_t len = 0; + OSSL_ENCODER_CTX *ectx = NULL; if (!TEST_ptr(keygen_ctx = EVP_PKEY_CTX_new_from_name(libctx, "RSA", NULL)) || !TEST_int_gt(EVP_PKEY_keygen_init(keygen_ctx), 0) || !TEST_true(EVP_PKEY_CTX_set_rsa_keygen_bits(keygen_ctx, bits)) || !TEST_int_gt(EVP_PKEY_keygen(keygen_ctx, priv), 0) - || !TEST_int_gt(len = i2d_PublicKey(*priv, &pub_der), 0)) + || !TEST_ptr(ectx = + OSSL_ENCODER_CTX_new_by_EVP_PKEY(*priv, + EVP_PKEY_PUBLIC_KEY, + "DER", "type-specific", + libctx, NULL)) + || !TEST_true(OSSL_ENCODER_to_data(ectx, &pub_der, &len))) goto err; pp = pub_der; if (!TEST_ptr(d2i_PublicKey(EVP_PKEY_RSA, pub, &pp, len))) goto err; ret = 1; err: + OSSL_ENCODER_CTX_free(ectx); OPENSSL_free(pub_der); EVP_PKEY_CTX_free(keygen_ctx); return ret;