aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKazuki Yamaguchi <k@rhe.jp>2020-02-16 20:56:48 +0900
committerGitHub <noreply@github.com>2020-02-16 20:56:48 +0900
commit941c08e77042b4404a10ee161f142a95ae9cfbba (patch)
tree49a92521346455613aecf157c2e6534a98d46e81
parentcecc89aa844ede0cdc2f40be340789cb4b9c73b3 (diff)
parent36740fe410c27f8abdcef32ae40d4edef50c52ba (diff)
downloadruby-openssl-941c08e77042b4404a10ee161f142a95ae9cfbba.tar.gz
Merge pull request #332 from mame/make-fixed_length_secure_compare-test-tolerant
Make OpenSSL::OSSL#test_memcmp_timing robust
-rw-r--r--test/test_ossl.rb11
1 files changed, 7 insertions, 4 deletions
diff --git a/test/test_ossl.rb b/test/test_ossl.rb
index f517b1d8..f83e8136 100644
--- a/test/test_ossl.rb
+++ b/test/test_ossl.rb
@@ -52,10 +52,13 @@ class OpenSSL::OSSL < OpenSSL::SSLTestCase
c = "y#{a}"
a = "#{a}x"
- n = 10_000
- a_b_time = Benchmark.measure { n.times { OpenSSL.fixed_length_secure_compare(a, b) } }.real
- a_c_time = Benchmark.measure { n.times { OpenSSL.fixed_length_secure_compare(a, c) } }.real
- assert_in_delta(a_b_time, a_c_time, 1, "fixed_length_secure_compare timing test failed")
+ 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
+ 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")
end
end