From ffb1ac674c8294bf519add26fb37d94b7afeceb4 Mon Sep 17 00:00:00 2001 From: "Dr. Stephen Henson" Date: Thu, 13 Apr 2006 20:16:56 +0000 Subject: Complete key derivation support. --- crypto/dh/dh_pmeth.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'crypto/dh/dh_pmeth.c') diff --git a/crypto/dh/dh_pmeth.c b/crypto/dh/dh_pmeth.c index d2e6aaff1e..aaf32804b8 100644 --- a/crypto/dh/dh_pmeth.c +++ b/crypto/dh/dh_pmeth.c @@ -115,11 +115,16 @@ static int pkey_dh_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2) dctx->generator = p1; return 1; + case EVP_PKEY_CTRL_PEER_KEY: + /* Default behaviour is OK */ + return 1; + default: return -2; } } + static int pkey_dh_ctrl_str(EVP_PKEY_CTX *ctx, const char *type, const char *value) @@ -182,6 +187,22 @@ static int pkey_dh_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey) return DH_generate_key(pkey->pkey.dh); } +static int pkey_dh_derive(EVP_PKEY_CTX *ctx, unsigned char *key, int *keylen) + { + int ret; + if (!ctx->pkey || !ctx->peerkey) + { + DHerr(DH_F_PKEY_DH_DERIVE, DH_R_KEYS_NOT_SET); + return 0; + } + ret = DH_compute_key(key, ctx->peerkey->pkey.dh->pub_key, + ctx->pkey->pkey.dh); + if (ret < 0) + return ret; + *keylen = ret; + return 1; + } + const EVP_PKEY_METHOD dh_pkey_meth = { EVP_PKEY_DH, @@ -209,7 +230,8 @@ const EVP_PKEY_METHOD dh_pkey_meth = 0,0, - 0,0, + 0, + pkey_dh_derive, pkey_dh_ctrl, pkey_dh_ctrl_str -- cgit v1.2.3