Skip to content

Commit 4619ab3

Browse files
committed
add BN#mod_sqrt
1 parent 4d0971c commit 4619ab3

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

ext/openssl/ossl_bn.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,13 @@ BIGNUM_2c(mod_sqr)
591591
return obj; \
592592
}
593593

594+
/*
595+
* Document-method: OpenSSL::BN#mod_sqrt
596+
* call-seq:
597+
* bn.mod_sqrt(bn2) => aBN
598+
*/
599+
BIGNUM_2cr(mod_sqrt)
600+
594601
/*
595602
* call-seq:
596603
* bn.mod_inverse(bn2) => aBN
@@ -1237,6 +1244,7 @@ Init_ossl_bn(void)
12371244
rb_define_method(cBN, "mod_sub", ossl_bn_mod_sub, 2);
12381245
rb_define_method(cBN, "mod_mul", ossl_bn_mod_mul, 2);
12391246
rb_define_method(cBN, "mod_sqr", ossl_bn_mod_sqr, 1);
1247+
rb_define_method(cBN, "mod_sqrt", ossl_bn_mod_sqrt, 1);
12401248
rb_define_method(cBN, "**", ossl_bn_exp, 1);
12411249
rb_define_method(cBN, "mod_exp", ossl_bn_mod_exp, 2);
12421250
rb_define_method(cBN, "gcd", ossl_bn_gcd, 1);

test/openssl/test_bn.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,12 @@ def test_mod_sqr
174174
assert_equal(0, 59.to_bn.mod_sqr(59))
175175
end
176176

177+
def test_mod_sqrt
178+
assert_equal(3, 4.to_bn.mod_sqrt(5))
179+
assert_equal(0, 5.to_bn.mod_sqrt(5))
180+
assert_raise(OpenSSL::BNError) { 3.to_bn.mod_sqrt(5) }
181+
end
182+
177183
def test_mod_inverse
178184
assert_equal(2, 3.to_bn.mod_inverse(5))
179185
assert_raise(OpenSSL::BNError) { 3.to_bn.mod_inverse(6) }

0 commit comments

Comments
 (0)