Skip to content

Commit 7343d3c

Browse files
committed
pkey/ec: remove deprecated PKey::EC::Point#mul(ary, ary [, bn]) form
The method has two forms, each corresponding to EC_POINT_mul() and EC_POINTs_mul(). The latter form does not work with any OpenSSL or LibreSSL versions that are still supported by upstream. The latter form has an extremely confusing behavior, too, and using it would print a deprecation warning since commit 812de42 in 2020, which went to 3.0.0. Let's remove it.
1 parent a1012fc commit 7343d3c

File tree

2 files changed

+15
-84
lines changed

2 files changed

+15
-84
lines changed

ext/openssl/ossl_pkey_ec.c

+12-62
Original file line numberDiff line numberDiff line change
@@ -1478,19 +1478,16 @@ static VALUE ossl_ec_point_add(VALUE self, VALUE other)
14781478
/*
14791479
* call-seq:
14801480
* point.mul(bn1 [, bn2]) => point
1481-
* point.mul(bns, points [, bn2]) => point
14821481
*
14831482
* Performs elliptic curve point multiplication.
14841483
*
14851484
* The first form calculates <tt>bn1 * point + bn2 * G</tt>, where +G+ is the
14861485
* generator of the group of _point_. _bn2_ may be omitted, and in that case,
14871486
* the result is just <tt>bn1 * point</tt>.
14881487
*
1489-
* The second form calculates <tt>bns[0] * point + bns[1] * points[0] + ...
1490-
* + bns[-1] * points[-1] + bn2 * G</tt>. _bn2_ may be omitted. _bns_ must be
1491-
* an array of OpenSSL::BN. _points_ must be an array of
1492-
* OpenSSL::PKey::EC::Point. Please note that <tt>points[0]</tt> is not
1493-
* multiplied by <tt>bns[0]</tt>, but <tt>bns[1]</tt>.
1488+
* Before version 4.0.0, and when compiled with OpenSSL 1.1.1 or older, this
1489+
* method allowed another form:
1490+
* point.mul(bns, points [, bn2]) => point
14941491
*/
14951492
static VALUE ossl_ec_point_mul(int argc, VALUE *argv, VALUE self)
14961493
{
@@ -1508,62 +1505,15 @@ static VALUE ossl_ec_point_mul(int argc, VALUE *argv, VALUE self)
15081505
GetECPoint(result, point_result);
15091506

15101507
rb_scan_args(argc, argv, "12", &arg1, &arg2, &arg3);
1511-
if (!RB_TYPE_P(arg1, T_ARRAY)) {
1512-
BIGNUM *bn = GetBNPtr(arg1);
1513-
1514-
if (!NIL_P(arg2))
1515-
bn_g = GetBNPtr(arg2);
1516-
if (EC_POINT_mul(group, point_result, bn_g, point_self, bn, ossl_bn_ctx) != 1)
1517-
ossl_raise(eEC_POINT, NULL);
1518-
} else {
1519-
#if (defined(OPENSSL_VERSION_MAJOR) && OPENSSL_VERSION_MAJOR >= 3) || defined(LIBRESSL_VERSION_NUMBER)
1520-
rb_raise(rb_eNotImpError, "calling #mul with arrays is not" \
1521-
"supported by this OpenSSL version");
1522-
#else
1523-
/*
1524-
* bignums | arg1[0] | arg1[1] | arg1[2] | ...
1525-
* points | self | arg2[0] | arg2[1] | ...
1526-
*/
1527-
long i, num;
1528-
VALUE bns_tmp, tmp_p, tmp_b;
1529-
const EC_POINT **points;
1530-
const BIGNUM **bignums;
1531-
1532-
Check_Type(arg1, T_ARRAY);
1533-
Check_Type(arg2, T_ARRAY);
1534-
if (RARRAY_LEN(arg1) != RARRAY_LEN(arg2) + 1) /* arg2 must be 1 larger */
1535-
ossl_raise(rb_eArgError, "bns must be 1 longer than points; see the documentation");
1536-
1537-
rb_warning("OpenSSL::PKey::EC::Point#mul(ary, ary) is deprecated; " \
1538-
"use #mul(bn) form instead");
1539-
1540-
num = RARRAY_LEN(arg1);
1541-
bns_tmp = rb_ary_tmp_new(num);
1542-
bignums = ALLOCV_N(const BIGNUM *, tmp_b, num);
1543-
for (i = 0; i < num; i++) {
1544-
VALUE item = RARRAY_AREF(arg1, i);
1545-
bignums[i] = GetBNPtr(item);
1546-
rb_ary_push(bns_tmp, item);
1547-
}
1548-
1549-
points = ALLOCV_N(const EC_POINT *, tmp_p, num);
1550-
points[0] = point_self; /* self */
1551-
for (i = 0; i < num - 1; i++)
1552-
GetECPoint(RARRAY_AREF(arg2, i), points[i + 1]);
1553-
1554-
if (!NIL_P(arg3))
1555-
bn_g = GetBNPtr(arg3);
1556-
1557-
if (EC_POINTs_mul(group, point_result, bn_g, num, points, bignums, ossl_bn_ctx) != 1) {
1558-
ALLOCV_END(tmp_b);
1559-
ALLOCV_END(tmp_p);
1560-
ossl_raise(eEC_POINT, NULL);
1561-
}
1562-
1563-
ALLOCV_END(tmp_b);
1564-
ALLOCV_END(tmp_p);
1565-
#endif
1566-
}
1508+
if (RB_TYPE_P(arg1, T_ARRAY) || argc > 2)
1509+
rb_raise(rb_eNotImpError, "OpenSSL::PKey::EC::Point#mul with arrays " \
1510+
"is no longer supported");
1511+
1512+
BIGNUM *bn = GetBNPtr(arg1);
1513+
if (!NIL_P(arg2))
1514+
bn_g = GetBNPtr(arg2);
1515+
if (EC_POINT_mul(group, point_result, bn_g, point_self, bn, ossl_bn_ctx) != 1)
1516+
ossl_raise(eEC_POINT, NULL);
15671517

15681518
return result;
15691519
}

test/openssl/test_pkey_ec.rb

+3-22
Original file line numberDiff line numberDiff line change
@@ -425,28 +425,6 @@ def test_ec_point_mul
425425
# 3 * (6, 3) + 3 * (5, 1) = (7, 6)
426426
result_a2 = point_a.mul(3, 3)
427427
assert_equal B(%w{ 04 07 06 }), result_a2.to_octet_string(:uncompressed)
428-
EnvUtil.suppress_warning do # Point#mul(ary, ary [, bn]) is deprecated
429-
begin
430-
result_b1 = point_a.mul([3], [])
431-
rescue NotImplementedError
432-
# LibreSSL and OpenSSL 3.0 do no longer support this form of calling
433-
next
434-
end
435-
436-
# 3 * point_a = 3 * (6, 3) = (16, 13)
437-
result_b1 = point_a.mul([3], [])
438-
assert_equal B(%w{ 04 10 0D }), result_b1.to_octet_string(:uncompressed)
439-
# 3 * point_a + 2 * point_a = 3 * (6, 3) + 2 * (6, 3) = (7, 11)
440-
result_b1 = point_a.mul([3, 2], [point_a])
441-
assert_equal B(%w{ 04 07 0B }), result_b1.to_octet_string(:uncompressed)
442-
# 3 * point_a + 5 * point_a.group.generator = 3 * (6, 3) + 5 * (5, 1) = (13, 10)
443-
result_b1 = point_a.mul([3], [], 5)
444-
assert_equal B(%w{ 04 0D 0A }), result_b1.to_octet_string(:uncompressed)
445-
446-
assert_raise(ArgumentError) { point_a.mul([1], [point_a]) }
447-
assert_raise(TypeError) { point_a.mul([1], nil) }
448-
assert_raise(TypeError) { point_a.mul([nil], []) }
449-
end
450428
rescue OpenSSL::PKey::EC::Group::Error
451429
# CentOS patches OpenSSL to reject curves defined over Fp where p < 256 bits
452430
raise if $!.message !~ /unsupported field/
@@ -459,6 +437,9 @@ def test_ec_point_mul
459437
# invalid argument
460438
point = p256_key.public_key
461439
assert_raise(TypeError) { point.mul(nil) }
440+
441+
# mul with arrays was removed in version 4.0.0
442+
assert_raise(NotImplementedError) { point.mul([1], []) }
462443
end
463444

464445
# test Group: asn1_flag, point_conversion

0 commit comments

Comments
 (0)