Return error if no cipher set for encrypted data type.
[oweals/openssl.git] / crypto / evp / pmeth_lib.c
index 49a8ee99cb20cff4f8f63b5b702f3a9838d79b6d..764271a36dd31dd9f2048fcde4334ff8b6f49dd7 100644 (file)
 typedef int sk_cmp_fn_type(const char * const *a, const char * const *b);
 STACK *app_pkey_methods = NULL;
 
-extern EVP_PKEY_METHOD rsa_pkey_meth, dh_pkey_meth, dsa_pkey_meth, ec_pkey_meth;
+extern const EVP_PKEY_METHOD rsa_pkey_meth, dh_pkey_meth, dsa_pkey_meth;
+extern const EVP_PKEY_METHOD ec_pkey_meth, hmac_pkey_meth;
 
 static const EVP_PKEY_METHOD *standard_methods[] =
        {
        &rsa_pkey_meth,
        &dh_pkey_meth,
        &dsa_pkey_meth,
-       &ec_pkey_meth
+       &ec_pkey_meth,
+       &hmac_pkey_meth,
        };
 
 static int pmeth_cmp(const EVP_PKEY_METHOD * const *a,
@@ -252,23 +254,21 @@ EVP_PKEY_CTX *EVP_PKEY_CTX_dup(EVP_PKEY_CTX *pctx)
 #endif
 
        if (pctx->pkey)
-               {
                CRYPTO_add(&pctx->pkey->references,1,CRYPTO_LOCK_EVP_PKEY);
-               rctx->pkey = pctx->pkey;
-               }
+
+       rctx->pkey = pctx->pkey;
 
        if (pctx->peerkey)
-               {
                CRYPTO_add(&pctx->peerkey->references,1,CRYPTO_LOCK_EVP_PKEY);
-               rctx->peerkey = pctx->peerkey;
-               }
+
+       rctx->peerkey = pctx->peerkey;
 
        rctx->data = NULL;
        rctx->app_data = NULL;
        rctx->operation = pctx->operation;
 
        if (pctx->pmeth->copy(rctx, pctx) > 0)
-               return pctx;
+               return rctx;
 
        EVP_PKEY_CTX_free(rctx);
        return NULL;
@@ -291,6 +291,8 @@ int EVP_PKEY_meth_add0(const EVP_PKEY_METHOD *pmeth)
 
 void EVP_PKEY_CTX_free(EVP_PKEY_CTX *ctx)
        {
+       if (ctx == NULL)
+               return;
        if (ctx->pmeth && ctx->pmeth->cleanup)
                ctx->pmeth->cleanup(ctx);
        if (ctx->pkey)
@@ -388,6 +390,11 @@ EVP_PKEY *EVP_PKEY_CTX_get0_pkey(EVP_PKEY_CTX *ctx)
        return ctx->pkey;
        }
 
+EVP_PKEY *EVP_PKEY_CTX_get0_peerkey(EVP_PKEY_CTX *ctx)
+       {
+       return ctx->peerkey;
+       }
+       
 void EVP_PKEY_CTX_set_app_data(EVP_PKEY_CTX *ctx, void *data)
        {
        ctx->app_data = data;