Skip to content

Commit

Permalink
Merge branch 'maint-3.1' into maint-3.2
Browse files Browse the repository at this point in the history
* maint-3.1:
  pkey: avoid calling i2d_PUBKEY family on an incomplete key
  Cleanup Gemfile
  test/openssl/test_ossl.rb: use clock_gettime for measuring time
  Backport changes related to extracted stdlibs in Ruby 3.4-3.5
  • Loading branch information
rhenium committed Jan 29, 2025
2 parents 2d7247e + c48bb75 commit e0ff759
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
14 changes: 6 additions & 8 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
source "https://rubygems.org"

group :development do
gem "rake"
gem "rake-compiler"
gem "test-unit", "~> 3.0", ">= 3.4.6"
gem "test-unit-ruby-core"
# In the case of Ruby whose rdoc is not a default gem.
gem "rdoc"
end
gem "rake"
gem "rake-compiler"
gem "test-unit", "~> 3.0", ">= 3.4.6"
gem "test-unit-ruby-core"
gem "prime"
gem "rdoc"
1 change: 1 addition & 0 deletions ext/openssl/ossl_pkey.c
Original file line number Diff line number Diff line change
Expand Up @@ -937,6 +937,7 @@ ossl_pkey_export_spki(VALUE self, int to_der)
BIO *bio;

GetPKey(self, pkey);
ossl_pkey_check_public_key(pkey);
bio = BIO_new(BIO_s_mem());
if (!bio)
ossl_raise(ePKeyError, "BIO_new");
Expand Down
12 changes: 8 additions & 4 deletions test/openssl/test_ossl.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# frozen_string_literal: true
require_relative "utils"

require 'benchmark'

if defined?(OpenSSL)

class OpenSSL::OSSL < OpenSSL::SSLTestCase
Expand Down Expand Up @@ -54,8 +52,14 @@ def test_memcmp_timing

a_b_time = a_c_time = 0
100.times do
a_b_time += Benchmark.measure { 100.times { OpenSSL.fixed_length_secure_compare(a, b) } }.real
a_c_time += Benchmark.measure { 100.times { OpenSSL.fixed_length_secure_compare(a, c) } }.real
t1 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
100.times { OpenSSL.fixed_length_secure_compare(a, b) }
t2 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
100.times { OpenSSL.fixed_length_secure_compare(a, c) }
t3 = Process.clock_gettime(Process::CLOCK_MONOTONIC)

a_b_time += t2 - t1
a_c_time += t3 - t2
end
assert_operator(a_b_time, :<, a_c_time * 10, "fixed_length_secure_compare timing test failed")
assert_operator(a_c_time, :<, a_b_time * 10, "fixed_length_secure_compare timing test failed")
Expand Down
6 changes: 6 additions & 0 deletions test/openssl/test_pkey_dsa.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ def test_new_break
end
end

def test_new_empty
key = OpenSSL::PKey::DSA.new
assert_nil(key.p)
assert_raise(OpenSSL::PKey::PKeyError) { key.to_der }
end

def test_generate
# DSA.generate used to call DSA_generate_parameters_ex(), which adjusts the
# size of q according to the size of p
Expand Down

0 comments on commit e0ff759

Please sign in to comment.