Skip to content

Commit

Permalink
make bn shareable when frozen
Browse files Browse the repository at this point in the history
  • Loading branch information
HoneyryderChuck committed Nov 12, 2024
1 parent bd647c3 commit eab2629
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 4 additions & 1 deletion ext/openssl/ossl_bn.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ static const rb_data_type_t ossl_bn_type = {
{
0, ossl_bn_free,
},
0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED,
0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED | RUBY_TYPED_FROZEN_SHAREABLE,
};

/*
Expand Down Expand Up @@ -689,6 +689,7 @@ BIGNUM_3c(mod_exp)
ossl_bn_##func(VALUE self, VALUE bit) \
{ \
BIGNUM *bn; \
rb_check_frozen(self); \
GetBN(self, bn); \
if (BN_##func(bn, NUM2INT(bit)) <= 0) { \
ossl_raise(eBNError, NULL); \
Expand Down Expand Up @@ -778,6 +779,7 @@ BIGNUM_SHIFT(rshift)
{ \
BIGNUM *bn; \
int b; \
rb_check_frozen(self); \
b = NUM2INT(bits); \
GetBN(self, bn); \
if (BN_##func(bn, bn, b) <= 0) \
Expand Down Expand Up @@ -1187,6 +1189,7 @@ ossl_bn_set_flags(VALUE self, VALUE arg)
BIGNUM *bn;
GetBN(self, bn);

rb_check_frozen(self);
BN_set_flags(bn, NUM2INT(arg));
return Qnil;
}
Expand Down
2 changes: 2 additions & 0 deletions test/openssl/test_bn.rb
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,8 @@ def test_ractor
assert_include(128..255, Ractor.new { OpenSSL::BN.rand(8)}.take)
assert_include(0...2**32, Ractor.new { OpenSSL::BN.generate_prime(32) }.take)
assert_equal(0, Ractor.new { OpenSSL::BN.new(999).get_flags(OpenSSL::BN::CONSTTIME) }.take)
# test if shareable when frozen
assert Ractor.shareable?(@e1.freeze)
end
end
end
Expand Down

0 comments on commit eab2629

Please sign in to comment.