@@ -577,22 +577,33 @@ BIGNUM_2c(gcd)
577577 */
578578BIGNUM_2c (mod_sqr )
579579
580+ #define BIGNUM_2cr (func ) \
581+ static VALUE \
582+ ossl_bn_ ##func (VALUE self, VALUE other) \
583+ { \
584+ BIGNUM *bn1, *bn2 = GetBNPtr(other), *result; \
585+ VALUE obj; \
586+ GetBN(self, bn1); \
587+ obj = NewBN(rb_obj_class(self)); \
588+ if (!(result = BN_##func(NULL, bn1, bn2, ossl_bn_ctx))) \
589+ ossl_raise(eBNError, NULL); \
590+ SetBN(obj, result); \
591+ return obj; \
592+ }
593+
580594/*
595+ * Document-method: OpenSSL::BN#mod_sqrt
596+ * call-seq:
597+ * bn.mod_sqrt(bn2) => aBN
598+ */
599+ BIGNUM_2cr (mod_sqrt )
600+
601+ /*
602+ * Document-method: OpenSSL::BN#mod_inverse
581603 * call-seq:
582604 * bn.mod_inverse(bn2) => aBN
583605 */
584- static VALUE
585- ossl_bn_mod_inverse (VALUE self , VALUE other )
586- {
587- BIGNUM * bn1 , * bn2 = GetBNPtr (other ), * result ;
588- VALUE obj ;
589- GetBN (self , bn1 );
590- obj = NewBN (rb_obj_class (self ));
591- if (!(result = BN_mod_inverse (NULL , bn1 , bn2 , ossl_bn_ctx )))
592- ossl_raise (eBNError , "BN_mod_inverse" );
593- SetBN (obj , result );
594- return obj ;
595- }
606+ BIGNUM_2cr (mod_inverse )
596607
597608/*
598609 * call-seq:
@@ -1234,6 +1245,7 @@ Init_ossl_bn(void)
12341245 rb_define_method (cBN , "mod_sub" , ossl_bn_mod_sub , 2 );
12351246 rb_define_method (cBN , "mod_mul" , ossl_bn_mod_mul , 2 );
12361247 rb_define_method (cBN , "mod_sqr" , ossl_bn_mod_sqr , 1 );
1248+ rb_define_method (cBN , "mod_sqrt" , ossl_bn_mod_sqrt , 1 );
12371249 rb_define_method (cBN , "**" , ossl_bn_exp , 1 );
12381250 rb_define_method (cBN , "mod_exp" , ossl_bn_mod_exp , 2 );
12391251 rb_define_method (cBN , "gcd" , ossl_bn_gcd , 1 );
0 commit comments