Skip to content

Commit

Permalink
Make optional benchmark test in OpenSSL::OSSL#test_memcmp_timing
Browse files Browse the repository at this point in the history
  • Loading branch information
hsbt committed Aug 29, 2024
1 parent 1b66da1 commit 97285af
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 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 @@ -44,6 +42,12 @@ def test_secure_compare
end

def test_memcmp_timing
begin
require "benchmark"
rescue LoadError
pend "Benchmark is not available in this environment. Please install it with `gem install benchmark`."
end

# Ensure using fixed_length_secure_compare takes almost exactly the same amount of time to compare two different strings.
# Regular string comparison will short-circuit on the first non-matching character, failing this test.
# NOTE: this test may be susceptible to noise if the system running the tests is otherwise under load.
Expand Down

0 comments on commit 97285af

Please sign in to comment.