Skip to content

Commit 41a3778

Browse files
committed
pkey/ec: deprecate OpenSSL::PKey::EC::Point#mul(ary, ary [, bn])
Deprecate it for future removal. However, I do not expect any application is affected by this. The other form of calling it, PKey::EC::Point#mul(bn [, bn]) remains untouched. PKey::EC::Point#mul calls EC_POINTs_mul(3) when multiple BNs are given as an array. LibreSSL 2.8.0 released on 2018-08 removed the feature and OpenSSL 3.0 which is planned to be released in 2020 will also deprecate the function as there is no real use-case.
1 parent 93213b2 commit 41a3778

File tree

2 files changed

+25
-13
lines changed

2 files changed

+25
-13
lines changed

ext/openssl/ossl_pkey_ec.c

+8
Original file line numberDiff line numberDiff line change
@@ -1505,6 +1505,10 @@ static VALUE ossl_ec_point_mul(int argc, VALUE *argv, VALUE self)
15051505
if (EC_POINT_mul(group, point_result, bn_g, point_self, bn, ossl_bn_ctx) != 1)
15061506
ossl_raise(eEC_POINT, NULL);
15071507
} else {
1508+
#if OPENSSL_VERSION_MAJOR+0 >= 3 || defined(LIBRESSL_VERSION_NUMBER)
1509+
rb_raise(rb_eNotImpError, "calling #mul with array arguments is not" \
1510+
"supported by this OpenSSL version");
1511+
#else
15081512
/*
15091513
* bignums | arg1[0] | arg1[1] | arg1[2] | ...
15101514
* points | self | arg2[0] | arg2[1] | ...
@@ -1519,6 +1523,9 @@ static VALUE ossl_ec_point_mul(int argc, VALUE *argv, VALUE self)
15191523
if (RARRAY_LEN(arg1) != RARRAY_LEN(arg2) + 1) /* arg2 must be 1 larger */
15201524
ossl_raise(rb_eArgError, "bns must be 1 longer than points; see the documentation");
15211525

1526+
rb_warn("OpenSSL::PKey::EC::Point#mul(array, array) is deprecated; " \
1527+
"use #mul(bn) form instead");
1528+
15221529
num = RARRAY_LEN(arg1);
15231530
bns_tmp = rb_ary_tmp_new(num);
15241531
bignums = ALLOCV_N(const BIGNUM *, tmp_b, num);
@@ -1544,6 +1551,7 @@ static VALUE ossl_ec_point_mul(int argc, VALUE *argv, VALUE self)
15441551

15451552
ALLOCV_END(tmp_b);
15461553
ALLOCV_END(tmp_p);
1554+
#endif
15471555
}
15481556

15491557
return result;

test/openssl/test_pkey_ec.rb

+17-13
Original file line numberDiff line numberDiff line change
@@ -349,21 +349,26 @@ def test_ec_point_mul
349349
# 3 * (6, 3) + 3 * (5, 1) = (7, 6)
350350
result_a2 = point_a.mul(3, 3)
351351
assert_equal B(%w{ 04 07 06 }), result_a2.to_octet_string(:uncompressed)
352-
# 3 * point_a = 3 * (6, 3) = (16, 13)
353-
result_b1 = point_a.mul([3], [])
354-
assert_equal B(%w{ 04 10 0D }), result_b1.to_octet_string(:uncompressed)
355-
# 3 * point_a + 2 * point_a = 3 * (6, 3) + 2 * (6, 3) = (7, 11)
356-
begin
352+
EnvUtil.suppress_warning do # Point#mul(ary, ary [, bn]) is deprecated
353+
begin
354+
result_b1 = point_a.mul([3], [])
355+
rescue NotImplementedError
356+
# LibreSSL and OpenSSL 3.0 do no longer support this form of calling
357+
next
358+
end
359+
360+
# 3 * point_a = 3 * (6, 3) = (16, 13)
361+
result_b1 = point_a.mul([3], [])
362+
assert_equal B(%w{ 04 10 0D }), result_b1.to_octet_string(:uncompressed)
363+
# 3 * point_a + 2 * point_a = 3 * (6, 3) + 2 * (6, 3) = (7, 11)
357364
result_b1 = point_a.mul([3, 2], [point_a])
358-
rescue OpenSSL::PKey::EC::Point::Error
359-
# LibreSSL doesn't support multiple entries in first argument
360-
raise if $!.message !~ /called a function you should not call/
361-
else
362365
assert_equal B(%w{ 04 07 0B }), result_b1.to_octet_string(:uncompressed)
366+
# 3 * point_a + 5 * point_a.group.generator = 3 * (6, 3) + 5 * (5, 1) = (13, 10)
367+
result_b1 = point_a.mul([3], [], 5)
368+
assert_equal B(%w{ 04 0D 0A }), result_b1.to_octet_string(:uncompressed)
369+
370+
assert_raise(ArgumentError) { point_a.mul([1], [point_a]) }
363371
end
364-
# 3 * point_a + 5 * point_a.group.generator = 3 * (6, 3) + 5 * (5, 1) = (13, 10)
365-
result_b1 = point_a.mul([3], [], 5)
366-
assert_equal B(%w{ 04 0D 0A }), result_b1.to_octet_string(:uncompressed)
367372
rescue OpenSSL::PKey::EC::Group::Error
368373
# CentOS patches OpenSSL to reject curves defined over Fp where p < 256 bits
369374
raise if $!.message !~ /unsupported field/
@@ -376,7 +381,6 @@ def test_ec_point_mul
376381
# invalid argument
377382
point = p256_key.public_key
378383
assert_raise(TypeError) { point.mul(nil) }
379-
assert_raise(ArgumentError) { point.mul([1], [point]) }
380384
assert_raise(TypeError) { point.mul([1], nil) }
381385
assert_raise(TypeError) { point.mul([nil], []) }
382386
end

0 commit comments

Comments
 (0)