[前][次][番号順一覧][スレッド一覧]

ruby-changes:74057

From: Ben <ko1@a...>
Date: Mon, 17 Oct 2022 23:43:51 +0900 (JST)
Subject: [ruby-changes:74057] 149cb049f1 (master): [ruby/openssl] add BN#mod_sqrt

https://git.ruby-lang.org/ruby.git/commit/?id=149cb049f1

From 149cb049f1d7f5fd2edf5ab467c33037ec993a47 Mon Sep 17 00:00:00 2001
From: Ben Toews <benjamin.toews@g...>
Date: Mon, 17 Oct 2022 07:31:40 -0600
Subject: [ruby/openssl] add BN#mod_sqrt

https://github.com/ruby/openssl/commit/4619ab3e76
---
 ext/openssl/ossl_bn.c   | 8 ++++++++
 test/openssl/test_bn.rb | 6 ++++++
 2 files changed, 14 insertions(+)

diff --git a/ext/openssl/ossl_bn.c b/ext/openssl/ossl_bn.c
index 7eb1bc79a5..06647b5b62 100644
--- a/ext/openssl/ossl_bn.c
+++ b/ext/openssl/ossl_bn.c
@@ -591,6 +591,13 @@ BIGNUM_2c(mod_sqr) https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_bn.c#L591
 	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
@@ -1237,6 +1244,7 @@ Init_ossl_bn(void) https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_bn.c#L1244
     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);
diff --git a/test/openssl/test_bn.rb b/test/openssl/test_bn.rb
index 346602dada..77af14091e 100644
--- a/test/openssl/test_bn.rb
+++ b/test/openssl/test_bn.rb
@@ -174,6 +174,12 @@ class OpenSSL::TestBN < OpenSSL::TestCase https://github.com/ruby/ruby/blob/trunk/test/openssl/test_bn.rb#L174
     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) }
-- 
cgit v1.2.3


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]