diff options
Diffstat (limited to 'providers/implementations/encode_decode/decode_der2key.c')
-rw-r--r-- | providers/implementations/encode_decode/decode_der2key.c | 42 |
1 files changed, 37 insertions, 5 deletions
diff --git a/providers/implementations/encode_decode/decode_der2key.c b/providers/implementations/encode_decode/decode_der2key.c index 47fe2bad6b..74f462794a 100644 --- a/providers/implementations/encode_decode/decode_der2key.c +++ b/providers/implementations/encode_decode/decode_der2key.c @@ -137,9 +137,10 @@ struct keytype_desc_st { int selection_mask; /* For type specific decoders, we use the corresponding d2i */ - d2i_of_void *d2i_private_key; - d2i_of_void *d2i_public_key; - d2i_of_void *d2i_key_params; + d2i_of_void *d2i_private_key; /* From type-specific DER */ + d2i_of_void *d2i_public_key; /* From type-specific DER */ + d2i_of_void *d2i_key_params; /* From type-specific DER */ + d2i_of_void *d2i_PUBKEY; /* Wrapped in a SubjectPublicKeyInfo */ /* * For PKCS#8 decoders, we use EVP_PKEY extractors, EVP_PKEY_get1_{TYPE}() @@ -301,11 +302,14 @@ static int der2key_decode(void *vctx, OSSL_CORE_BIO *cin, int selection, goto next; } if (key == NULL - && ctx->desc->d2i_public_key != NULL + && (ctx->desc->d2i_PUBKEY != NULL || ctx->desc->d2i_public_key != NULL) && (selection & OSSL_KEYMGMT_SELECT_PUBLIC_KEY) != 0) { RESET_ERR_MARK(); derp = der; - key = ctx->desc->d2i_public_key(NULL, &derp, der_len); + if (ctx->desc->d2i_PUBKEY != NULL) + key = ctx->desc->d2i_PUBKEY(NULL, &derp, der_len); + else + key = ctx->desc->d2i_public_key(NULL, &derp, der_len); if (key == NULL && orig_selection != 0) goto next; } @@ -342,6 +346,10 @@ static int der2key_decode(void *vctx, OSSL_CORE_BIO *cin, int selection, &derp, der_len, libctx, NULL); } + /* + * As long as we have algos without a specific d2i_<TYPE>_PUBKEY, + * this code must remain... + */ if (pkey == NULL && (selection & OSSL_KEYMGMT_SELECT_PUBLIC_KEY) != 0) { RESET_ERR_MARK(); @@ -449,6 +457,7 @@ static int der2key_export_object(void *vctx, # define dh_d2i_private_key NULL # define dh_d2i_public_key NULL # define dh_d2i_key_params (d2i_of_void *)d2i_DHparams +# define dh_d2i_PUBKEY (d2i_of_void *)ossl_d2i_DH_PUBKEY # define dh_free (free_key_fn *)DH_free # define dh_check NULL @@ -462,6 +471,7 @@ static void dh_adjust(void *key, struct der2key_ctx_st *ctx) # define dhx_d2i_private_key NULL # define dhx_d2i_public_key NULL # define dhx_d2i_key_params (d2i_of_void *)d2i_DHxparams +# define dhx_d2i_PUBKEY (d2i_of_void *)ossl_d2i_DHx_PUBKEY # define dhx_free (free_key_fn *)DH_free # define dhx_check NULL # define dhx_adjust dh_adjust @@ -475,6 +485,7 @@ static void dh_adjust(void *key, struct der2key_ctx_st *ctx) # define dsa_d2i_private_key (d2i_of_void *)d2i_DSAPrivateKey # define dsa_d2i_public_key (d2i_of_void *)d2i_DSAPublicKey # define dsa_d2i_key_params (d2i_of_void *)d2i_DSAparams +# define dsa_d2i_PUBKEY (d2i_of_void *)d2i_DSA_PUBKEY # define dsa_free (free_key_fn *)DSA_free # define dsa_check NULL @@ -492,6 +503,7 @@ static void dsa_adjust(void *key, struct der2key_ctx_st *ctx) # define ec_d2i_private_key (d2i_of_void *)d2i_ECPrivateKey # define ec_d2i_public_key NULL # define ec_d2i_key_params (d2i_of_void *)d2i_ECParameters +# define ec_d2i_PUBKEY (d2i_of_void *)d2i_EC_PUBKEY # define ec_free (free_key_fn *)EC_KEY_free static int ec_check(void *key, struct der2key_ctx_st *ctx) @@ -523,6 +535,7 @@ static void ecx_key_adjust(void *key, struct der2key_ctx_st *ctx) # define ed25519_d2i_private_key NULL # define ed25519_d2i_public_key NULL # define ed25519_d2i_key_params NULL +# define ed25519_d2i_PUBKEY (d2i_of_void *)ossl_d2i_ED25519_PUBKEY # define ed25519_free (free_key_fn *)ossl_ecx_key_free # define ed25519_check NULL # define ed25519_adjust ecx_key_adjust @@ -532,6 +545,7 @@ static void ecx_key_adjust(void *key, struct der2key_ctx_st *ctx) # define ed448_d2i_private_key NULL # define ed448_d2i_public_key NULL # define ed448_d2i_key_params NULL +# define ed448_d2i_PUBKEY (d2i_of_void *)ossl_d2i_ED448_PUBKEY # define ed448_free (free_key_fn *)ossl_ecx_key_free # define ed448_check NULL # define ed448_adjust ecx_key_adjust @@ -541,6 +555,7 @@ static void ecx_key_adjust(void *key, struct der2key_ctx_st *ctx) # define x25519_d2i_private_key NULL # define x25519_d2i_public_key NULL # define x25519_d2i_key_params NULL +# define x25519_d2i_PUBKEY (d2i_of_void *)ossl_d2i_X25519_PUBKEY # define x25519_free (free_key_fn *)ossl_ecx_key_free # define x25519_check NULL # define x25519_adjust ecx_key_adjust @@ -550,6 +565,7 @@ static void ecx_key_adjust(void *key, struct der2key_ctx_st *ctx) # define x448_d2i_private_key NULL # define x448_d2i_public_key NULL # define x448_d2i_key_params NULL +# define x448_d2i_PUBKEY (d2i_of_void *)ossl_d2i_X448_PUBKEY # define x448_free (free_key_fn *)ossl_ecx_key_free # define x448_check NULL # define x448_adjust ecx_key_adjust @@ -560,6 +576,7 @@ static void ecx_key_adjust(void *key, struct der2key_ctx_st *ctx) # define sm2_d2i_private_key (d2i_of_void *)d2i_ECPrivateKey # define sm2_d2i_public_key NULL # define sm2_d2i_key_params (d2i_of_void *)d2i_ECParameters +# define sm2_d2i_PUBKEY (d2i_of_void *)d2i_EC_PUBKEY # define sm2_free (free_key_fn *)EC_KEY_free # define sm2_check ec_check # define sm2_adjust ec_adjust @@ -573,6 +590,7 @@ static void ecx_key_adjust(void *key, struct der2key_ctx_st *ctx) #define rsa_d2i_private_key (d2i_of_void *)d2i_RSAPrivateKey #define rsa_d2i_public_key (d2i_of_void *)d2i_RSAPublicKey #define rsa_d2i_key_params NULL +#define rsa_d2i_PUBKEY (d2i_of_void *)d2i_RSA_PUBKEY #define rsa_free (free_key_fn *)RSA_free static int rsa_check(void *key, struct der2key_ctx_st *ctx) @@ -598,6 +616,7 @@ static void rsa_adjust(void *key, struct der2key_ctx_st *ctx) #define rsapss_d2i_private_key (d2i_of_void *)d2i_RSAPrivateKey #define rsapss_d2i_public_key (d2i_of_void *)d2i_RSAPublicKey #define rsapss_d2i_key_params NULL +#define rsapss_d2i_PUBKEY (d2i_of_void *)d2i_RSA_PUBKEY #define rsapss_free (free_key_fn *)RSA_free #define rsapss_check rsa_check #define rsapss_adjust rsa_adjust @@ -615,6 +634,7 @@ static void rsa_adjust(void *key, struct der2key_ctx_st *ctx) keytype##_d2i_public_key, \ NULL, \ NULL, \ + NULL, \ keytype##_check, \ keytype##_adjust, \ keytype##_free @@ -626,6 +646,7 @@ static void rsa_adjust(void *key, struct der2key_ctx_st *ctx) keytype##_d2i_public_key, \ NULL, \ NULL, \ + NULL, \ keytype##_check, \ keytype##_adjust, \ keytype##_free @@ -637,6 +658,7 @@ static void rsa_adjust(void *key, struct der2key_ctx_st *ctx) NULL, \ NULL, \ NULL, \ + NULL, \ keytype##_check, \ keytype##_adjust, \ keytype##_free @@ -648,6 +670,7 @@ static void rsa_adjust(void *key, struct der2key_ctx_st *ctx) NULL, \ keytype##_d2i_key_params, \ NULL, \ + NULL, \ keytype##_check, \ keytype##_adjust, \ keytype##_free @@ -659,6 +682,7 @@ static void rsa_adjust(void *key, struct der2key_ctx_st *ctx) keytype##_d2i_public_key, \ keytype##_d2i_key_params, \ NULL, \ + NULL, \ keytype##_check, \ keytype##_adjust, \ keytype##_free @@ -671,6 +695,7 @@ static void rsa_adjust(void *key, struct der2key_ctx_st *ctx) NULL, \ keytype##_d2i_key_params, \ NULL, \ + NULL, \ keytype##_check, \ keytype##_adjust, \ keytype##_free @@ -681,6 +706,7 @@ static void rsa_adjust(void *key, struct der2key_ctx_st *ctx) NULL, \ NULL, \ NULL, \ + NULL, \ keytype##_evp_extract, \ keytype##_check, \ keytype##_adjust, \ @@ -692,6 +718,7 @@ static void rsa_adjust(void *key, struct der2key_ctx_st *ctx) NULL, \ NULL, \ NULL, \ + keytype##_d2i_PUBKEY, \ keytype##_evp_extract, \ keytype##_check, \ keytype##_adjust, \ @@ -704,6 +731,7 @@ static void rsa_adjust(void *key, struct der2key_ctx_st *ctx) NULL, \ keytype##_d2i_key_params, \ NULL, \ + NULL, \ keytype##_check, \ keytype##_adjust, \ keytype##_free @@ -715,6 +743,7 @@ static void rsa_adjust(void *key, struct der2key_ctx_st *ctx) NULL, \ keytype##_d2i_key_params, \ NULL, \ + NULL, \ keytype##_check, \ keytype##_adjust, \ keytype##_free @@ -726,6 +755,7 @@ static void rsa_adjust(void *key, struct der2key_ctx_st *ctx) keytype##_d2i_public_key, \ keytype##_d2i_key_params, \ NULL, \ + NULL, \ keytype##_check, \ keytype##_adjust, \ keytype##_free @@ -738,6 +768,7 @@ static void rsa_adjust(void *key, struct der2key_ctx_st *ctx) NULL, \ keytype##_d2i_key_params, \ NULL, \ + NULL, \ keytype##_check, \ keytype##_adjust, \ keytype##_free @@ -749,6 +780,7 @@ static void rsa_adjust(void *key, struct der2key_ctx_st *ctx) keytype##_d2i_public_key, \ NULL, \ NULL, \ + NULL, \ keytype##_check, \ keytype##_adjust, \ keytype##_free |