Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
nomoon committed May 7, 2012
2 parents 63bdf09 + 82ac1a2 commit 235a7e1
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 16 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -5,3 +5,5 @@ doc/*
ext/mri/*.bundle
*.o
.DS_Store

ext/mri/Makefile
4 changes: 4 additions & 0 deletions .travis.yml
@@ -0,0 +1,4 @@
language: ruby
rvm:
- 1.8.7
- 1.9.3
3 changes: 0 additions & 3 deletions CHANGELOG

This file was deleted.

4 changes: 4 additions & 0 deletions Gemfile.lock
Expand Up @@ -8,7 +8,10 @@ GEM
specs:
awesome_print (1.0.2)
diff-lcs (1.1.3)
json (1.7.0)
rake (0.9.2.2)
rdoc (3.12)
json (~> 1.4)
rspec (2.9.0)
rspec-core (~> 2.9.0)
rspec-expectations (~> 2.9.0)
Expand All @@ -24,5 +27,6 @@ PLATFORMS
DEPENDENCIES
awesome_print
rake (~> 0.9.2)
rdoc
rspec
scrypt!
2 changes: 1 addition & 1 deletion README.md
@@ -1,4 +1,4 @@
scrypt
scrypt [![Build Status](https://secure.travis-ci.org/pbhogan/scrypt.png)](http://travis-ci.org/pbhogan/scrypt)
======

The scrypt key derivation function is designed to be far more secure against hardware brute-force attacks than alternative functions such as PBKDF2 or bcrypt.
Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Expand Up @@ -14,7 +14,7 @@ rd = Rake::RDocTask.new do |rdoc|
rdoc.rdoc_dir = 'doc/rdoc'
rdoc.options << '--title' << 'scrypt-ruby' << '--line-numbers' << '--inline-source' << '--main' << 'README'
rdoc.template = ENV['TEMPLATE'] if ENV['TEMPLATE']
rdoc.rdoc_files.include('README', 'COPYING', 'CHANGELOG', 'lib/**/*.rb')
rdoc.rdoc_files.include('COPYING', 'lib/**/*.rb')
end


Expand Down
26 changes: 15 additions & 11 deletions lib/scrypt.rb
Expand Up @@ -17,24 +17,26 @@ class InvalidSecret < StandardError; end # The secret parameter provided is inv

class Engine
DEFAULTS = {
:key_len => 32,
:salt_size => 8,
:max_mem => 1024 * 1024,
:key_len => 32,
:salt_size => 8,
:max_mem => 1024 * 1024,
:max_memfrac => 0.5,
:max_time => 0.2
:max_time => 0.2
}

private_class_method :__sc_calibrate
private_class_method :__sc_crypt

def self.scrypt(secret, salt, *args, key_len)
if args.length == 1
#args is a cost-string
def self.scrypt(secret, salt, *args)
if args.length == 2
# args is [cost_string, key_len]
n, r, p = args[0].split('$').map{ |x| x.to_i(16) }
key_len = args[1]
__sc_crypt(secret, salt, n, r, p, key_len)
elsif args.length == 3
#args is n, r, p
elsif args.length == 4
# args is [n, r, p, key_len]
n, r, p = args[0, 3]
key_len = args[3]
__sc_crypt(secret, salt, n, r, p, key_len)
else
raise ArgumentError.new("invalid number of arguments (4 or 6)")
Expand All @@ -47,9 +49,11 @@ def self.hash_secret(secret, salt, key_len = DEFAULTS[:key_len])
if valid_salt?(salt)
cost = autodetect_cost(salt)
salt_only = salt[/\$([A-Za-z0-9]{16,64})$/, 1]
if salt_only.length == 40 #Old-style hash with 40-character salt
if salt_only.length == 40
# Old-style hash with 40-character salt
salt + "$" + Digest::SHA1.hexdigest(scrypt(secret.to_s, salt, cost, 256))
else #New-style hash
else
# New-style hash
salt_only = [salt_only].pack('H*')
salt + "$" + scrypt(secret.to_s, salt_only, cost, key_len).unpack('H*').first.rjust(key_len * 2, '0')
end
Expand Down
1 change: 1 addition & 0 deletions scrypt.gemspec
Expand Up @@ -17,6 +17,7 @@ Gem::Specification.new do |s|
EOF

s.add_development_dependency "rspec"
s.add_development_dependency "rdoc"
s.add_development_dependency "rake", "~> 0.9.2"
s.add_development_dependency "awesome_print"

Expand Down

0 comments on commit 235a7e1

Please sign in to comment.