diff options
author | Kazuki Yamaguchi <[email protected]> | 2017-03-18 22:34:19 +0900 |
---|---|---|
committer | Kazuki Yamaguchi <[email protected]> | 2021-03-16 19:16:11 +0900 |
commit | 9d3ffe09c47a1dfd722693965fbf7dba8571aa88 (patch) | |
tree | 69078a7ed04b682182538e384f5977eec2356fa6 /ext/openssl/lib | |
parent | fbadb01d6e0881ef6c6e5e105b8ac20fe663c817 (diff) |
[ruby/openssl] pkey: reimplement PKey::DH#compute_key and PKey::EC#dh_compute_key
Use the new OpenSSL::PKey::PKey#derive instead of the raw
{EC,}DH_compute_key(), mainly to reduce amount of the C code.
https://github.com/ruby/openssl/commit/28edf6bafc
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/4275
Diffstat (limited to 'ext/openssl/lib')
-rw-r--r-- | ext/openssl/lib/openssl/pkey.rb | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/ext/openssl/lib/openssl/pkey.rb b/ext/openssl/lib/openssl/pkey.rb index 9cc3276356..be60ac2beb 100644 --- a/ext/openssl/lib/openssl/pkey.rb +++ b/ext/openssl/lib/openssl/pkey.rb @@ -9,6 +9,24 @@ require_relative 'marshal' module OpenSSL::PKey class DH include OpenSSL::Marshal + + # :call-seq: + # dh.compute_key(pub_bn) -> string + # + # Returns a String containing a shared secret computed from the other + # party's public value. + # + # This method is provided for backwards compatibility, and calls #derive + # internally. + # + # === Parameters + # * _pub_bn_ is a OpenSSL::BN, *not* the DH instance returned by + # DH#public_key as that contains the DH parameters only. + def compute_key(pub_bn) + peer = dup + peer.set_key(pub_bn, nil) + derive(peer) + end end class DSA @@ -18,7 +36,22 @@ module OpenSSL::PKey if defined?(EC) class EC include OpenSSL::Marshal + + # :call-seq: + # ec.dh_compute_key(pubkey) -> string + # + # Derives a shared secret by ECDH. _pubkey_ must be an instance of + # OpenSSL::PKey::EC::Point and must belong to the same group. + # + # This method is provided for backwards compatibility, and calls #derive + # internally. + def dh_compute_key(pubkey) + peer = OpenSSL::PKey::EC.new(group) + peer.public_key = pubkey + derive(peer) + end end + class EC::Point # :call-seq: # point.to_bn([conversion_form]) -> OpenSSL::BN |