Skip to content

Commit

Permalink
add BN#mod_sqrt
Browse files Browse the repository at this point in the history
  • Loading branch information
btoews committed Oct 17, 2022
1 parent 4d0971c commit 4619ab3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
8 changes: 8 additions & 0 deletions ext/openssl/ossl_bn.c
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,13 @@ BIGNUM_2c(mod_sqr)
return obj; \
}

/*
* Document-method: OpenSSL::BN#mod_sqrt
* call-seq:
* bn.mod_sqrt(bn2) => aBN
*/
BIGNUM_2cr(mod_sqrt)

/*
* call-seq:
* bn.mod_inverse(bn2) => aBN
Expand Down Expand Up @@ -1237,6 +1244,7 @@ Init_ossl_bn(void)
rb_define_method(cBN, "mod_sub", ossl_bn_mod_sub, 2);
rb_define_method(cBN, "mod_mul", ossl_bn_mod_mul, 2);
rb_define_method(cBN, "mod_sqr", ossl_bn_mod_sqr, 1);
rb_define_method(cBN, "mod_sqrt", ossl_bn_mod_sqrt, 1);
rb_define_method(cBN, "**", ossl_bn_exp, 1);
rb_define_method(cBN, "mod_exp", ossl_bn_mod_exp, 2);
rb_define_method(cBN, "gcd", ossl_bn_gcd, 1);
Expand Down
6 changes: 6 additions & 0 deletions test/openssl/test_bn.rb
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,12 @@ def test_mod_sqr
assert_equal(0, 59.to_bn.mod_sqr(59))
end

def test_mod_sqrt
assert_equal(3, 4.to_bn.mod_sqrt(5))
assert_equal(0, 5.to_bn.mod_sqrt(5))
assert_raise(OpenSSL::BNError) { 3.to_bn.mod_sqrt(5) }
end

def test_mod_inverse
assert_equal(2, 3.to_bn.mod_inverse(5))
assert_raise(OpenSSL::BNError) { 3.to_bn.mod_inverse(6) }
Expand Down

0 comments on commit 4619ab3

Please sign in to comment.