Skip to content

Commit 4d0971c

Browse files
committed
define BIGNUM_2cr macro for BN function that takes context and
returns a BN
1 parent 2115cf3 commit 4d0971c

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

ext/openssl/ossl_bn.c

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -577,22 +577,25 @@ BIGNUM_2c(gcd)
577577
*/
578578
BIGNUM_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
/*
581595
* call-seq:
582596
* bn.mod_inverse(bn2) => aBN
583597
*/
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-
}
598+
BIGNUM_2cr(mod_inverse)
596599

597600
/*
598601
* call-seq:

0 commit comments

Comments
 (0)