2020-02-16 15:21:29 +09:00
|
|
|
# frozen_string_literal: true
|
2003-07-23 16:12:24 +00:00
|
|
|
=begin
|
|
|
|
= Info
|
|
|
|
'OpenSSL for Ruby 2' project
|
|
|
|
Copyright (C) 2002 Michal Rokos <m.rokos@sh.cvut.cz>
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
= Licence
|
2015-04-20 03:55:09 +00:00
|
|
|
This program is licensed under the same licence as Ruby.
|
2003-07-23 16:12:24 +00:00
|
|
|
(See the file 'LICENCE'.)
|
|
|
|
=end
|
|
|
|
|
|
|
|
require 'openssl.so'
|
|
|
|
|
2020-02-16 15:21:29 +09:00
|
|
|
require_relative 'openssl/bn'
|
|
|
|
require_relative 'openssl/pkey'
|
|
|
|
require_relative 'openssl/cipher'
|
|
|
|
require_relative 'openssl/digest'
|
|
|
|
require_relative 'openssl/hmac'
|
|
|
|
require_relative 'openssl/x509'
|
|
|
|
require_relative 'openssl/ssl'
|
|
|
|
require_relative 'openssl/pkcs5'
|
2020-03-09 18:26:19 +09:00
|
|
|
require_relative 'openssl/version'
|
2020-02-16 15:21:29 +09:00
|
|
|
|
|
|
|
module OpenSSL
|
|
|
|
# call-seq:
|
|
|
|
# OpenSSL.secure_compare(string, string) -> boolean
|
|
|
|
#
|
|
|
|
# Constant time memory comparison. Inputs are hashed using SHA-256 to mask
|
|
|
|
# the length of the secret. Returns +true+ if the strings are identical,
|
|
|
|
# +false+ otherwise.
|
|
|
|
def self.secure_compare(a, b)
|
2020-04-19 11:14:36 -04:00
|
|
|
hashed_a = OpenSSL::Digest.digest('SHA256', a)
|
|
|
|
hashed_b = OpenSSL::Digest.digest('SHA256', b)
|
2020-02-16 15:21:29 +09:00
|
|
|
OpenSSL.fixed_length_secure_compare(hashed_a, hashed_b) && a == b
|
|
|
|
end
|
|
|
|
end
|