Skip to content

Commit

Permalink
* ext/digest/lib/digest/hmac.rb (Digest::HMAC#initialize): faster
Browse files Browse the repository at this point in the history
  code.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24537 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
nobu committed Aug 14, 2009
1 parent 0ff3bf4 commit 69f1e59
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
@@ -1,3 +1,8 @@
Fri Aug 14 16:28:19 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>

* ext/digest/lib/digest/hmac.rb (Digest::HMAC#initialize): faster
code.

Fri Aug 14 14:31:33 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>

* configure.in (rubyhdrdir): fixed typo. [ruby-dev:39079]
Expand Down
10 changes: 5 additions & 5 deletions ext/digest/lib/digest/hmac.rb
Expand Up @@ -49,17 +49,17 @@ def initialize(key, digester)
key = @md.digest(key)
end

ipad = Array.new(block_len).fill(0x36)
opad = Array.new(block_len).fill(0x5c)
ipad = Array.new(block_len, 0x36)
opad = Array.new(block_len, 0x5c)

key.bytes.each_with_index { |c, i|
ipad[i] ^= c
opad[i] ^= c
}

@key = key.freeze
@ipad = ipad.inject('') { |s, c| s << c.chr }.freeze
@opad = opad.inject('') { |s, c| s << c.chr }.freeze
@ipad = ipad.pack('C*').freeze
@opad = opad.pack('C*').freeze
@md.update(@ipad)
end

Expand Down Expand Up @@ -102,7 +102,7 @@ def inspect
end

if $0 == __FILE__
eval DATA.read, nil, $0, __LINE__+4
eval DATA.gets(nil), nil, $0, DATA.lineno
end

__END__
Expand Down

0 comments on commit 69f1e59

Please sign in to comment.