summaryrefslogtreecommitdiff
path: root/test/openssl/test_pkey_dh.rb
diff options
context:
space:
mode:
authorKazuki Yamaguchi <k@rhe.jp>2017-03-18 21:58:46 +0900
committerKazuki Yamaguchi <k@rhe.jp>2021-03-16 19:16:11 +0900
commitfbadb01d6e0881ef6c6e5e105b8ac20fe663c817 (patch)
tree59b9014cf8bf92e142cf9a29053e2ec10e433958 /test/openssl/test_pkey_dh.rb
parentb2dc4880f5d000c3e0117ecf9c57a273cbd713f9 (diff)
[ruby/openssl] pkey: add PKey::PKey#derive
Add OpenSSL::PKey::PKey#derive as the wrapper for EVP_PKEY_CTX_derive(). This is useful for pkey types that we don't have dedicated classes, such as X25519. https://github.com/ruby/openssl/commit/28f0059bea
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/4275
Diffstat (limited to 'test/openssl/test_pkey_dh.rb')
-rw-r--r--test/openssl/test_pkey_dh.rb13
1 files changed, 13 insertions, 0 deletions
diff --git a/test/openssl/test_pkey_dh.rb b/test/openssl/test_pkey_dh.rb
index 4a05626a12..9efc3ba68d 100644
--- a/test/openssl/test_pkey_dh.rb
+++ b/test/openssl/test_pkey_dh.rb
@@ -18,6 +18,19 @@ class OpenSSL::TestPKeyDH < OpenSSL::PKeyTestCase
end
end
+ def test_derive_key
+ dh1 = Fixtures.pkey("dh1024").generate_key!
+ dh2 = Fixtures.pkey("dh1024").generate_key!
+ dh1_pub = OpenSSL::PKey.read(dh1.public_to_der)
+ dh2_pub = OpenSSL::PKey.read(dh2.public_to_der)
+ z = dh1.g.mod_exp(dh1.priv_key, dh1.p).mod_exp(dh2.priv_key, dh1.p).to_s(2)
+ assert_equal z, dh1.derive(dh2_pub)
+ assert_equal z, dh2.derive(dh1_pub)
+
+ assert_equal z, dh1.compute_key(dh2.pub_key)
+ assert_equal z, dh2.compute_key(dh1.pub_key)
+ end
+
def test_DHparams
dh1024 = Fixtures.pkey("dh1024")
asn1 = OpenSSL::ASN1::Sequence([