FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Use constant-time string comparison algorithm. by tylerhunt · Pull Request #43 · bcrypt-ruby/bcrypt-ruby · GitHub

Repository navigation

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .rb  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
Use constant-time string comparison algorithm.
This borrows the string comparison code from Devise to prevent timing
attacks (http://codahale.com/a-lesson-in-timing-attacks/).
  • Loading branch information
tylerhunt committed Jul 18, 2012
commit b26e4e3721302fe08085164d234159d33aa3c2af
8 changes: 7 additions & 1 deletion lib/bcrypt.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,13 @@ def initialize(raw_hash)

# Compares a potential secret against the hash. Returns true if the secret is the original secret, false otherwise.
def ==(secret)
super(BCrypt::Engine.hash_secret(secret, @salt))
hash = BCrypt::Engine.hash_secret(secret, @salt)
return false if self.empty? || hash.empty? || self.bytesize != hash.bytesize
l = self.unpack "C#{self.bytesize}"

res = 0
hash.each_byte { |byte| res |= byte ^ l.shift }
res == 0
end
alias_method :is_password?, :==

Expand Down

Back | FazBrowse Home | New Git URL