From 4227e504c894db14d06be7180d0b4e7f6fe4ac2c Mon Sep 17 00:00:00 2001 From: Richard Levitte Date: Sat, 17 Oct 2020 08:55:39 +0200 Subject: Adapt libcrypto functionality to specify the desired output structure This also modifies i2d_PublicKey() and i2d_KeyParams() to support provided keys. Reviewed-by: Paul Dale (Merged from https://github.com/openssl/openssl/pull/13167) --- crypto/pem/pem_local.h | 10 +++++++++- crypto/pem/pem_pk8.c | 4 ++-- 2 files changed, 11 insertions(+), 3 deletions(-) (limited to 'crypto/pem') diff --git a/crypto/pem/pem_local.h b/crypto/pem/pem_local.h index f9575d4988..10761b03d3 100644 --- a/crypto/pem/pem_local.h +++ b/crypto/pem/pem_local.h @@ -32,12 +32,20 @@ # define PEM_SELECTION_PrivateKey EVP_PKEY_KEYPAIR # define PEM_SELECTION_Parameters EVP_PKEY_KEY_PARAMETERS +/* + * Properties, named according to the ASN.1 names used throughout libcrypto. + */ +# define PEM_STRUCTURE_PUBKEY "SubjectPublicKeyInfo" +# define PEM_STRUCTURE_PrivateKey "pkcs8" +# define PEM_STRUCTURE_Parameters "type-specific" + /* Alternative IMPLEMENT macros for provided encoders */ # define IMPLEMENT_PEM_provided_write_body_vars(type, asn1) \ int ret = 0; \ OSSL_ENCODER_CTX *ctx = \ - OSSL_ENCODER_CTX_new_by_##type(x, "PEM", PEM_SELECTION_##asn1, \ + OSSL_ENCODER_CTX_new_by_##type(x, PEM_SELECTION_##asn1, \ + "PEM", PEM_STRUCTURE_##asn1, \ NULL, NULL); \ \ if (OSSL_ENCODER_CTX_get_num_encoders(ctx) == 0) { \ diff --git a/crypto/pem/pem_pk8.c b/crypto/pem/pem_pk8.c index 2abf687cbd..797c9881d8 100644 --- a/crypto/pem/pem_pk8.c +++ b/crypto/pem/pem_pk8.c @@ -74,8 +74,8 @@ static int do_pk8pkey(BIO *bp, const EVP_PKEY *x, int isder, int nid, int ret = 0; const char *outtype = isder ? "DER" : "PEM"; OSSL_ENCODER_CTX *ctx = - OSSL_ENCODER_CTX_new_by_EVP_PKEY(x, outtype, OSSL_KEYMGMT_SELECT_ALL, - libctx, propq); + OSSL_ENCODER_CTX_new_by_EVP_PKEY(x, OSSL_KEYMGMT_SELECT_ALL, + outtype, "pkcs8", libctx, propq); if (ctx == NULL) return 0; -- cgit v1.2.3