Allow DH_set0_key with only private key.
authorDavid Benjamin <davidben@google.com>
Mon, 18 Sep 2017 15:58:24 +0000 (11:58 -0400)
committerBernd Edlinger <bernd.edlinger@hotmail.de>
Wed, 27 Sep 2017 15:28:24 +0000 (17:28 +0200)
commiteffdcf6c2a10afea8041addb8ccce2367ecaac0d
tree66245a14d86697ae72ce2a076a4d4d6555829852
parenta8e047a819b8f8bf8699e0bbfc838e1f23e82051
Allow DH_set0_key with only private key.

The pub_key field for DH isn't actually used in DH_compute_key at all.
(Note the peer public key is passed in as as BIGNUM.) It's mostly there
so the caller may extract it from DH_generate_key. It doesn't
particularly need to be present if filling in a DH from external
parameters.

The check in DH_set0_key conflicts with adding OpenSSL 1.1.0 to Node.
Their public API is a thin wrapper over the old OpenSSL one:
https://nodejs.org/api/crypto.html#crypto_class_diffiehellman

They have separate setPrivateKey and setPublicKey methods, so the public
key may be set last or not at all. In 1.0.2, either worked fine since
operations on DH objects generally didn't use the public key.  (Like
with OpenSSL, Node's setPublicKey method is also largely a no-op, but so
it goes.) In 1.1.0, DH_set0_key prevents create a private-key-only DH
object.

(cherry picked from commit d58ad9a2a287d1c0bc99ba63c997eed88cc161b5)

Reviewed-by: Rich Salz <rsalz@openssl.org>
Reviewed-by: Bernd Edlinger <bernd.edlinger@hotmail.de>
(Merged from https://github.com/openssl/openssl/pull/4425)
crypto/dh/dh_lib.c
doc/crypto/DH_get0_pqg.pod
test/dhtest.c