Skip to content

Commit d3c8e66

Browse files
make bn shareable when frozen
1 parent bd647c3 commit d3c8e66

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

ext/openssl/ossl_bn.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ static const rb_data_type_t ossl_bn_type = {
3737
{
3838
0, ossl_bn_free,
3939
},
40-
0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED,
40+
0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED | RUBY_TYPED_FROZEN_SHAREABLE,
4141
};
4242

4343
/*
@@ -259,6 +259,7 @@ ossl_bn_initialize(int argc, VALUE *argv, VALUE self)
259259
ossl_raise(rb_eArgError, "invalid argument");
260260
}
261261

262+
rb_check_frozen(self);
262263
if (RB_INTEGER_TYPE_P(str)) {
263264
GetBN(self, bn);
264265
integer_to_bnptr(str, bn);
@@ -689,6 +690,7 @@ BIGNUM_3c(mod_exp)
689690
ossl_bn_##func(VALUE self, VALUE bit) \
690691
{ \
691692
BIGNUM *bn; \
693+
rb_check_frozen(self); \
692694
GetBN(self, bn); \
693695
if (BN_##func(bn, NUM2INT(bit)) <= 0) { \
694696
ossl_raise(eBNError, NULL); \
@@ -778,6 +780,7 @@ BIGNUM_SHIFT(rshift)
778780
{ \
779781
BIGNUM *bn; \
780782
int b; \
783+
rb_check_frozen(self); \
781784
b = NUM2INT(bits); \
782785
GetBN(self, bn); \
783786
if (BN_##func(bn, bn, b) <= 0) \
@@ -1187,6 +1190,7 @@ ossl_bn_set_flags(VALUE self, VALUE arg)
11871190
BIGNUM *bn;
11881191
GetBN(self, bn);
11891192

1193+
rb_check_frozen(self);
11901194
BN_set_flags(bn, NUM2INT(arg));
11911195
return Qnil;
11921196
}

test/openssl/test_bn.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,8 @@ def test_ractor
365365
assert_include(128..255, Ractor.new { OpenSSL::BN.rand(8)}.take)
366366
assert_include(0...2**32, Ractor.new { OpenSSL::BN.generate_prime(32) }.take)
367367
assert_equal(0, Ractor.new { OpenSSL::BN.new(999).get_flags(OpenSSL::BN::CONSTTIME) }.take)
368+
# test if shareable when frozen
369+
assert Ractor.shareable?(@e1.freeze)
368370
end
369371
end
370372
end

0 commit comments

Comments
 (0)