aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorrhe <rhe@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-05-18 02:55:46 +0000
committerrhe <rhe@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-05-18 02:55:46 +0000
commit50272acc2c54875517e79e30eb664f8ddf200b30 (patch)
tree6ed6023194a4743a0aba139a0f66188d5f891d59 /test
parentaf65ee772dd5e1b04462dd2d282fbfb07ce5014d (diff)
downloadruby-50272acc2c54875517e79e30eb664f8ddf200b30.tar.gz
ext/openssl: refactor OpenSSL::PKey::EC::Point#mul
* ext/openssl/ossl_pkey_ec.c (ossl_ec_point_mul): Validate the arguments before passing to EC_POINT(s)_mul(). Add description of this method. [ruby-core:65152] [Bug #10268] * test/openssl/test_pkey_ec.rb (test_ec_point_mul): Test that OpenSSL::PKey::EC::Point#mul works. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55048 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/openssl/test_pkey_ec.rb45
1 files changed, 32 insertions, 13 deletions
diff --git a/test/openssl/test_pkey_ec.rb b/test/openssl/test_pkey_ec.rb
index fe128fd455..d3edcc47b4 100644
--- a/test/openssl/test_pkey_ec.rb
+++ b/test/openssl/test_pkey_ec.rb
@@ -190,19 +190,38 @@ class OpenSSL::TestEC < Test::Unit::TestCase
end
def test_ec_point_mul
- ec = OpenSSL::TestUtils::TEST_KEY_EC_P256V1
- p1 = ec.public_key
- bn1 = OpenSSL::BN.new('10')
- bn2 = OpenSSL::BN.new('20')
-
- p2 = p1.mul(bn1)
- assert(p1.group == p2.group)
- p2 = p1.mul(bn1, bn2)
- assert(p1.group == p2.group)
- p2 = p1.mul([bn1, bn2], [p1])
- assert(p1.group == p2.group)
- p2 = p1.mul([bn1, bn2], [p1], bn2)
- assert(p1.group == p2.group)
+ # y^2 = x^3 + 2x + 2 over F_17
+ # generator is (5, 1)
+ group = OpenSSL::PKey::EC::Group.new(:GFp, 17, 2, 2)
+ gen = OpenSSL::PKey::EC::Point.new(group, OpenSSL::BN.new("040501", 16))
+ group.set_generator(gen, 0, 0)
+
+ # 3 * (6, 3) = (16, 13)
+ point_a = OpenSSL::PKey::EC::Point.new(group, OpenSSL::BN.new("040603", 16))
+ result_a1 = point_a.mul(3.to_bn)
+ assert_equal("04100D", result_a1.to_bn.to_s(16))
+ # 3 * (6, 3) + 3 * (5, 1) = (7, 6)
+ result_a2 = point_a.mul(3.to_bn, 3.to_bn)
+ assert_equal("040706", result_a2.to_bn.to_s(16))
+ # 3 * point_a = 3 * (6, 3) = (16, 13)
+ result_b1 = point_a.mul([3.to_bn], [])
+ assert_equal("04100D", result_b1.to_bn.to_s(16))
+ # 3 * point_a + 2 * point_a = 3 * (6, 3) + 2 * (6, 3) = (7, 11)
+ result_b1 = point_a.mul([3.to_bn, 2.to_bn], [point_a])
+ assert_equal("04070B", result_b1.to_bn.to_s(16))
+ # 3 * point_a + 5 * point_a.group.generator = 3 * (6, 3) + 5 * (5, 1) = (13, 10)
+ result_b1 = point_a.mul([3.to_bn], [], 5)
+ assert_equal("040D0A", result_b1.to_bn.to_s(16))
+
+ p256_key = OpenSSL::TestUtils::TEST_KEY_EC_P256V1
+ p256_g = p256_key.group
+ assert_equal(p256_key.public_key, p256_g.generator.mul(p256_key.private_key))
+
+ # invalid argument
+ assert_raise(TypeError) { point_a.mul(nil) }
+ assert_raise(ArgumentError) { point_a.mul([1.to_bn], [point_a]) }
+ assert_raise(TypeError) { point_a.mul([1.to_bn], nil) }
+ assert_raise(TypeError) { point_a.mul([nil], []) }
end
# test Group: asn1_flag, point_conversion