aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_pkey_dsa.rb
diff options
context:
space:
mode:
authorKazuki Yamaguchi <k@rhe.jp>2016-10-16 14:48:51 +0900
committerKazuki Yamaguchi <k@rhe.jp>2016-10-16 14:48:51 +0900
commita9ef251697602d6ab419094ed64654c6cd7c17ac (patch)
tree2a7df3cc05dd7ffa2a67bb5a5bf3e68aedc9df46 /test/test_pkey_dsa.rb
parent8ff55aed5491c8bfdf18a1822c38066cb14dd92f (diff)
downloadruby-openssl-a9ef251697602d6ab419094ed64654c6cd7c17ac.tar.gz
test/test_pkey_*: refine sign/verify teststopic/test-static-test-vector
20a88ace0778 ("test: refactor PKey::PKey#{sign,verify} tests", 2016-07-07) was not a good idea in the sense of readability. So, let's revert it. Also, static test vectors generated by BouncyCastle are added to ensure #verify correctly accept valid signatures and reject invalid signatures.
Diffstat (limited to 'test/test_pkey_dsa.rb')
-rw-r--r--test/test_pkey_dsa.rb20
1 files changed, 20 insertions, 0 deletions
diff --git a/test/test_pkey_dsa.rb b/test/test_pkey_dsa.rb
index d0ba8ec0..a4ccd1d8 100644
--- a/test/test_pkey_dsa.rb
+++ b/test/test_pkey_dsa.rb
@@ -36,6 +36,26 @@ class OpenSSL::TestPKeyDSA < OpenSSL::PKeyTestCase
end
end
+ def test_sign_verify
+ data = "Sign me!"
+ if defined?(OpenSSL::Digest::DSS1)
+ signature = DSA512.sign(OpenSSL::Digest::DSS1.new, data)
+ assert_equal true, DSA512.verify(OpenSSL::Digest::DSS1.new, signature, data)
+ end
+
+ return if OpenSSL::OPENSSL_VERSION_NUMBER <= 0x010000000
+ signature = DSA512.sign("SHA1", data)
+ assert_equal true, DSA512.verify("SHA1", signature, data)
+
+ signature0 = (<<~'end;').unpack("m")[0]
+ MCwCFH5h40plgU5Fh0Z4wvEEpz0eE9SnAhRPbkRB8ggsN/vsSEYMXvJwjGg/
+ 6g==
+ end;
+ assert_equal true, DSA512.verify("SHA256", signature0, data)
+ signature1 = signature0.succ
+ assert_equal false, DSA512.verify("SHA256", signature1, data)
+ end
+
def test_sys_sign_verify
key = OpenSSL::TestUtils::TEST_KEY_DSA256
data = 'Sign me!'