Skip to content

Commit eab2629

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

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

ext/openssl/ossl_bn.c

Lines changed: 4 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
/*
@@ -689,6 +689,7 @@ BIGNUM_3c(mod_exp)
689689
ossl_bn_##func(VALUE self, VALUE bit) \
690690
{ \
691691
BIGNUM *bn; \
692+
rb_check_frozen(self); \
692693
GetBN(self, bn); \
693694
if (BN_##func(bn, NUM2INT(bit)) <= 0) { \
694695
ossl_raise(eBNError, NULL); \
@@ -778,6 +779,7 @@ BIGNUM_SHIFT(rshift)
778779
{ \
779780
BIGNUM *bn; \
780781
int b; \
782+
rb_check_frozen(self); \
781783
b = NUM2INT(bits); \
782784
GetBN(self, bn); \
783785
if (BN_##func(bn, bn, b) <= 0) \
@@ -1187,6 +1189,7 @@ ossl_bn_set_flags(VALUE self, VALUE arg)
11871189
BIGNUM *bn;
11881190
GetBN(self, bn);
11891191

1192+
rb_check_frozen(self);
11901193
BN_set_flags(bn, NUM2INT(arg));
11911194
return Qnil;
11921195
}

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)