diff options
author | Dr. Stephen Henson <steve@openssl.org> | 2017-09-21 15:40:15 +0100 |
---|---|---|
committer | Dr. Stephen Henson <steve@openssl.org> | 2017-10-12 02:40:30 +0100 |
commit | f4403a1fa9335b0fe2db27031d2352a8652a345a (patch) | |
tree | 1335c22e9ab0a82ee1d81b6d5cd21ffcefcd3758 /crypto/dh | |
parent | 9b82c8b1c1823f2c1a0502a6f8eb1622714145f6 (diff) |
Add pad support
Reviewed-by: Andy Polyakov <appro@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/4485)
Diffstat (limited to 'crypto/dh')
-rw-r--r-- | crypto/dh/dh_pmeth.c | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/crypto/dh/dh_pmeth.c b/crypto/dh/dh_pmeth.c index 9b492169a0..bd8b8cc614 100644 --- a/crypto/dh/dh_pmeth.c +++ b/crypto/dh/dh_pmeth.c @@ -26,6 +26,7 @@ typedef struct { int generator; int use_dsa; int subprime_len; + int pad; /* message digest used for parameter generation */ const EVP_MD *md; int rfc5114_param; @@ -86,6 +87,7 @@ static int pkey_dh_copy(EVP_PKEY_CTX *dst, EVP_PKEY_CTX *src) dctx->subprime_len = sctx->subprime_len; dctx->generator = sctx->generator; dctx->use_dsa = sctx->use_dsa; + dctx->pad = sctx->pad; dctx->md = sctx->md; dctx->rfc5114_param = sctx->rfc5114_param; dctx->param_nid = sctx->param_nid; @@ -121,6 +123,10 @@ static int pkey_dh_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2) dctx->subprime_len = p1; return 1; + case EVP_PKEY_CTRL_DH_PAD: + dctx->pad = p1; + return 1; + case EVP_PKEY_CTRL_DH_PARAMGEN_GENERATOR: if (dctx->use_dsa) return -2; @@ -255,6 +261,11 @@ static int pkey_dh_ctrl_str(EVP_PKEY_CTX *ctx, typ = atoi(value); return EVP_PKEY_CTX_set_dh_paramgen_type(ctx, typ); } + if (strcmp(type, "dh_pad") == 0) { + int pad; + pad = atoi(value); + return EVP_PKEY_CTX_set_dh_pad(ctx, pad); + } return -2; } @@ -423,7 +434,10 @@ static int pkey_dh_derive(EVP_PKEY_CTX *ctx, unsigned char *key, *keylen = DH_size(dh); return 1; } - ret = DH_compute_key(key, dhpub, dh); + if (dctx->pad) + ret = DH_compute_key_padded(key, dhpub, dh); + else + ret = DH_compute_key(key, dhpub, dh); if (ret < 0) return ret; *keylen = ret; |