@@ -577,22 +577,33 @@ BIGNUM_2c(gcd)
577
577
*/
578
578
BIGNUM_2c (mod_sqr )
579
579
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
+
580
594
/*
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
581
603
* call-seq:
582
604
* bn.mod_inverse(bn2) => aBN
583
605
*/
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 )
596
607
597
608
/*
598
609
* call-seq:
@@ -1234,6 +1245,7 @@ Init_ossl_bn(void)
1234
1245
rb_define_method (cBN , "mod_sub" , ossl_bn_mod_sub , 2 );
1235
1246
rb_define_method (cBN , "mod_mul" , ossl_bn_mod_mul , 2 );
1236
1247
rb_define_method (cBN , "mod_sqr" , ossl_bn_mod_sqr , 1 );
1248
+ rb_define_method (cBN , "mod_sqrt" , ossl_bn_mod_sqrt , 1 );
1237
1249
rb_define_method (cBN , "**" , ossl_bn_exp , 1 );
1238
1250
rb_define_method (cBN , "mod_exp" , ossl_bn_mod_exp , 2 );
1239
1251
rb_define_method (cBN , "gcd" , ossl_bn_gcd , 1 );
0 commit comments