mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
add fast xor, we need really fast xor to keep our password function honest.
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
# 3. It does not monkey patch string
|
||||
|
||||
require 'openssl'
|
||||
require 'xor'
|
||||
|
||||
class Pbkdf2
|
||||
|
||||
@@ -20,7 +21,7 @@ class Pbkdf2
|
||||
|
||||
2.upto(iterations) do
|
||||
u = prf(h, password, u)
|
||||
ret = xor(ret, u)
|
||||
ret.xor!(u)
|
||||
end
|
||||
|
||||
ret.bytes.map{|b| ("0" + b.to_s(16))[-2..-1]}.join("")
|
||||
@@ -28,6 +29,7 @@ class Pbkdf2
|
||||
|
||||
protected
|
||||
|
||||
# fallback xor in case we need it for jruby ... way slower
|
||||
def self.xor(x,y)
|
||||
x.bytes.zip(y.bytes).map{|x,y| x ^ y}.pack('c*')
|
||||
end
|
||||
|
Reference in New Issue
Block a user