New pkey functions for keygen callbacks and retrieving operation type.
[openssl.git] / crypto / evp / pmeth_lib.c
index 6db6b17899570b9dea5ab43703ccf96b48635c13..fb07c00d897ae86b16ce87008c87933c5fd6c3df 100644 (file)
@@ -150,6 +150,7 @@ EVP_PKEY_METHOD* EVP_PKEY_meth_new(int id, int flags)
        pmeth->flags = flags | EVP_PKEY_FLAG_DYNAMIC;
 
        pmeth->init = 0;
+       pmeth->copy = 0;
        pmeth->cleanup = 0;
        pmeth->paramgen_init = 0;
        pmeth->paramgen = 0;
@@ -193,6 +194,41 @@ EVP_PKEY_CTX *EVP_PKEY_CTX_new_id(int id, ENGINE *e)
        return int_ctx_new(NULL, e, id);
        }
 
+EVP_PKEY_CTX *EVP_PKEY_CTX_dup(EVP_PKEY_CTX *pctx)
+       {
+       EVP_PKEY_CTX *rctx;
+       if (!pctx->pmeth || !pctx->pmeth->copy)
+               return NULL;
+       rctx = OPENSSL_malloc(sizeof(EVP_PKEY_CTX));
+       if (!rctx)
+               return NULL;
+
+       rctx->pmeth = pctx->pmeth;
+
+       if (pctx->pkey)
+               {
+               CRYPTO_add(&pctx->pkey->references,1,CRYPTO_LOCK_EVP_PKEY);
+               rctx->pkey = pctx->pkey;
+               }
+
+       if (pctx->peerkey)
+               {
+               CRYPTO_add(&pctx->peerkey->references,1,CRYPTO_LOCK_EVP_PKEY);
+               rctx->peerkey = pctx->peerkey;
+               }
+
+       rctx->data = NULL;
+       rctx->app_data = NULL;
+       rctx->operation = pctx->operation;
+
+       if (pctx->pmeth->copy(rctx, pctx) > 0)
+               return pctx;
+
+       EVP_PKEY_CTX_free(rctx);
+       return NULL;
+
+       }
+
 int EVP_PKEY_meth_add0(const EVP_PKEY_METHOD *pmeth)
        {
        if (app_pkey_methods == NULL)
@@ -274,6 +310,17 @@ int EVP_PKEY_CTX_ctrl_str(EVP_PKEY_CTX *ctx,
        return ctx->pmeth->ctrl_str(ctx, name, value);
        }
 
+int EVP_PKEY_CTX_get_operation(EVP_PKEY_CTX *ctx)
+       {
+       return ctx->operation;
+       }
+
+void EVP_PKEY_CTX_set0_keygen_info(EVP_PKEY_CTX *ctx, int *dat, int datlen)
+       {
+       ctx->keygen_info = dat;
+       ctx->keygen_info_count = datlen;
+       }
+
 void EVP_PKEY_CTX_set_data(EVP_PKEY_CTX *ctx, void *data)
        {
        ctx->data = data;
@@ -305,6 +352,12 @@ void EVP_PKEY_meth_set_init(EVP_PKEY_METHOD *pmeth,
        pmeth->init = init;
        }
 
+void EVP_PKEY_meth_set_copy(EVP_PKEY_METHOD *pmeth,
+       int (*copy)(EVP_PKEY_CTX *dst, EVP_PKEY_CTX *src))
+       {
+       pmeth->copy = copy;
+       }
+
 void EVP_PKEY_meth_set_cleanup(EVP_PKEY_METHOD *pmeth,
        void (*cleanup)(EVP_PKEY_CTX *ctx))
        {