diff options
author | Kazuki Yamaguchi <k@rhe.jp> | 2020-05-13 18:07:06 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-13 18:07:06 +0900 |
commit | d669d7158266c7943d191be9dd39f3be2df7cf57 (patch) | |
tree | ad243a8e2c8eb67bbb6222959ff08a96326abca4 /lib | |
parent | 2cb67d71f6276875186096cfcddad3b9e4de6e8f (diff) | |
parent | 28edf6bafcfd8c80e2cb52c498db8930f8517fd1 (diff) | |
download | ruby-openssl-d669d7158266c7943d191be9dd39f3be2df7cf57.tar.gz |
Merge pull request #329 from rhenium/ky/pkey-generic-operations
pkey: add more support for 'generic' pkey types
Diffstat (limited to 'lib')
-rw-r--r-- | lib/openssl/pkey.rb | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/openssl/pkey.rb b/lib/openssl/pkey.rb index 9cc32763..be60ac2b 100644 --- a/lib/openssl/pkey.rb +++ b/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 |