diff options
author | Kazuki Yamaguchi <k@rhe.jp> | 2016-07-07 11:32:06 +0900 |
---|---|---|
committer | Kazuki Yamaguchi <k@rhe.jp> | 2016-08-18 01:58:27 +0900 |
commit | feb8c261ad0ac6b4e85df48246681fe81cd8ece8 (patch) | |
tree | 8573d315ac241353393d469c2afaef24450ac4ba /test | |
parent | 01cf28145f7110b129a0faf699200a43adc08160 (diff) | |
download | ruby-openssl-feb8c261ad0ac6b4e85df48246681fe81cd8ece8.tar.gz |
test/test_pkey_dh: refine OpenSSL::PKey::DH::DEFAULT_* tests
Just comparing parameters does not make sense. Test that they have a
safe prime 'p' with appropriate length.
Diffstat (limited to 'test')
-rw-r--r-- | test/test_pkey_dh.rb | 37 |
1 files changed, 14 insertions, 23 deletions
diff --git a/test/test_pkey_dh.rb b/test/test_pkey_dh.rb index 4d84f7ad..78dedd1b 100644 --- a/test/test_pkey_dh.rb +++ b/test/test_pkey_dh.rb @@ -7,29 +7,20 @@ class OpenSSL::TestPKeyDH < OpenSSL::TestCase NEW_KEYLEN = 256 - def test_DEFAULT_1024 - params = <<-eop ------BEGIN DH PARAMETERS----- -MIGHAoGBAJ0lOVy0VIr/JebWn0zDwY2h+rqITFOpdNr6ugsgvkDXuucdcChhYExJ -AV/ZD2AWPbrTqV76mGRgJg4EddgT1zG0jq3rnFdMj2XzkBYx3BVvfR0Arnby0RHR -T4h7KZ/2zmjvV+eF8kBUHBJAojUlzxKj4QeO2x20FP9X5xmNUXeDAgEC ------END DH PARAMETERS----- - eop - assert_equal params, OpenSSL::PKey::DH::DEFAULT_1024.to_s - end - - def test_DEFAULT_2048 - params = <<-eop ------BEGIN DH PARAMETERS----- -MIIBCAKCAQEA7E6kBrYiyvmKAMzQ7i8WvwVk9Y/+f8S7sCTN712KkK3cqd1jhJDY -JbrYeNV3kUIKhPxWHhObHKpD1R84UpL+s2b55+iMd6GmL7OYmNIT/FccKhTcveab -VBmZT86BZKYyf45hUF9FOuUM9xPzuK3Vd8oJQvfYMCd7LPC0taAEljQLR4Edf8E6 -YoaOffgTf5qxiwkjnlVZQc3whgnEt9FpVMvQ9eknyeGB5KHfayAc3+hUAvI3/Cr3 -1bNveX5wInh5GDx1FGhKBZ+s1H+aedudCm7sCgRwv8lKWYGiHzObSma8A86KG+MD -7Lo5JquQ3DlBodj3IDyPrxIv96lvRPFtAwIBAg== ------END DH PARAMETERS----- - eop - assert_equal params, OpenSSL::PKey::DH::DEFAULT_2048.to_s + def test_DEFAULT_parameters + list = { + 1024 => OpenSSL::PKey::DH::DEFAULT_1024, + 2048 => OpenSSL::PKey::DH::DEFAULT_2048, + } + + list.each do |expected_size, dh| + assert_equal expected_size, dh.p.num_bits + assert_predicate dh.p, :prime? + result, remainder = (dh.p - 1) / 2 + assert_predicate result, :prime? + assert_equal 0, remainder + assert_no_key dh + end end def test_new |