scrypt 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/.rspec +2 -0
- data/CHANGELOG +3 -0
- data/COPYING +28 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +24 -0
- data/README +19 -0
- data/Rakefile +42 -0
- data/Rakefile.old +104 -0
- data/autotest/discover.rb +1 -0
- data/ext/mri/Makefile +157 -0
- data/ext/mri/crypto_scrypt-ref.c +284 -0
- data/ext/mri/crypto_scrypt.h +46 -0
- data/ext/mri/extconf.rb +4 -0
- data/ext/mri/memlimit.c +302 -0
- data/ext/mri/memlimit.h +42 -0
- data/ext/mri/scrypt_calibrate.c +104 -0
- data/ext/mri/scrypt_calibrate.h +19 -0
- data/ext/mri/scrypt_ext.bundle +0 -0
- data/ext/mri/scrypt_ext.c +126 -0
- data/ext/mri/scrypt_platform.h +4 -0
- data/ext/mri/scryptenc_cpuperf.c +185 -0
- data/ext/mri/scryptenc_cpuperf.h +39 -0
- data/ext/mri/sha256.c +412 -0
- data/ext/mri/sha256.h +62 -0
- data/ext/mri/sysendian.h +140 -0
- data/lib/scrypt.rb +171 -0
- data/lib/scrypt/version.rb +3 -0
- data/scrypt.gemspec +27 -0
- data/spec/scrypt/engine_spec.rb +58 -0
- data/spec/scrypt/password_spec.rb +62 -0
- data/spec/spec_helper.rb +4 -0
- metadata +101 -0
@@ -0,0 +1,62 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "..", "spec_helper"))
|
2
|
+
|
3
|
+
describe "Creating a hashed password" do
|
4
|
+
before :each do
|
5
|
+
@password = SCrypt::Password.create("s3cr3t", :max_time => 0.25)
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should return a SCrypt::Password" do
|
9
|
+
@password.should be_an_instance_of(SCrypt::Password)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should return a valid bcrypt password" do
|
13
|
+
lambda { SCrypt::Password.new(@password) }.should_not raise_error
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should behave normally if the secret is not a string" do
|
17
|
+
lambda { SCrypt::Password.create(nil) }.should_not raise_error(SCrypt::Errors::InvalidSecret)
|
18
|
+
lambda { SCrypt::Password.create({:woo => "yeah"}) }.should_not raise_error(SCrypt::Errors::InvalidSecret)
|
19
|
+
lambda { SCrypt::Password.create(false) }.should_not raise_error(SCrypt::Errors::InvalidSecret)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should tolerate empty string secrets" do
|
23
|
+
lambda { SCrypt::Password.create( "\n".chop ) }.should_not raise_error
|
24
|
+
lambda { SCrypt::Password.create( "" ) }.should_not raise_error
|
25
|
+
lambda { SCrypt::Password.create( String.new ) }.should_not raise_error
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
describe "Reading a hashed password" do
|
31
|
+
before :each do
|
32
|
+
@secret = "my secret"
|
33
|
+
@hash = "400$8$d$173a8189751c095a29b933789560b73bf17b2e01$9bf66d74bd6f3ebcf99da3b379b689b89db1cb07"
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should read the cost, salt, and hash" do
|
37
|
+
password = SCrypt::Password.new(@hash)
|
38
|
+
password.cost.should == "400$8$d$"
|
39
|
+
password.salt.should == "173a8189751c095a29b933789560b73bf17b2e01"
|
40
|
+
password.to_s.should == @hash
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should raise an InvalidHashError when given an invalid hash" do
|
44
|
+
lambda { SCrypt::Password.new('not a valid hash') }.should raise_error(SCrypt::Errors::InvalidHash)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
|
49
|
+
describe "Comparing a hashed password with a secret" do
|
50
|
+
before :each do
|
51
|
+
@secret = "s3cr3t"
|
52
|
+
@password = SCrypt::Password.create(@secret)
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should compare successfully to the original secret" do
|
56
|
+
(@password == @secret).should be(true)
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should compare unsuccessfully to anything besides original secret" do
|
60
|
+
(@password == "@secret").should be(false)
|
61
|
+
end
|
62
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: scrypt
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
version: 1.0.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Patrick Hogan
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-12-16 00:00:00 -06:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: " The scrypt key derivation function is designed to be far \n more secure against hardware brute-force attacks than \n alternative functions such as PBKDF2 or bcrypt.\n"
|
23
|
+
email:
|
24
|
+
- pbhogan@gmail.com
|
25
|
+
executables: []
|
26
|
+
|
27
|
+
extensions:
|
28
|
+
- ext/mri/extconf.rb
|
29
|
+
extra_rdoc_files: []
|
30
|
+
|
31
|
+
files:
|
32
|
+
- .gitignore
|
33
|
+
- .rspec
|
34
|
+
- CHANGELOG
|
35
|
+
- COPYING
|
36
|
+
- Gemfile
|
37
|
+
- Gemfile.lock
|
38
|
+
- README
|
39
|
+
- Rakefile
|
40
|
+
- Rakefile.old
|
41
|
+
- autotest/discover.rb
|
42
|
+
- ext/mri/Makefile
|
43
|
+
- ext/mri/crypto_scrypt-ref.c
|
44
|
+
- ext/mri/crypto_scrypt.h
|
45
|
+
- ext/mri/extconf.rb
|
46
|
+
- ext/mri/memlimit.c
|
47
|
+
- ext/mri/memlimit.h
|
48
|
+
- ext/mri/scrypt_calibrate.c
|
49
|
+
- ext/mri/scrypt_calibrate.h
|
50
|
+
- ext/mri/scrypt_ext.bundle
|
51
|
+
- ext/mri/scrypt_ext.c
|
52
|
+
- ext/mri/scrypt_platform.h
|
53
|
+
- ext/mri/scryptenc_cpuperf.c
|
54
|
+
- ext/mri/scryptenc_cpuperf.h
|
55
|
+
- ext/mri/sha256.c
|
56
|
+
- ext/mri/sha256.h
|
57
|
+
- ext/mri/sysendian.h
|
58
|
+
- lib/scrypt.rb
|
59
|
+
- lib/scrypt/version.rb
|
60
|
+
- scrypt.gemspec
|
61
|
+
- spec/scrypt/engine_spec.rb
|
62
|
+
- spec/scrypt/password_spec.rb
|
63
|
+
- spec/spec_helper.rb
|
64
|
+
has_rdoc: true
|
65
|
+
homepage: ""
|
66
|
+
licenses: []
|
67
|
+
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options: []
|
70
|
+
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
hash: 3
|
79
|
+
segments:
|
80
|
+
- 0
|
81
|
+
version: "0"
|
82
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
hash: 3
|
88
|
+
segments:
|
89
|
+
- 0
|
90
|
+
version: "0"
|
91
|
+
requirements: []
|
92
|
+
|
93
|
+
rubyforge_project: scrypt
|
94
|
+
rubygems_version: 1.3.7
|
95
|
+
signing_key:
|
96
|
+
specification_version: 3
|
97
|
+
summary: scrypt password hashing algorithm.
|
98
|
+
test_files:
|
99
|
+
- spec/scrypt/engine_spec.rb
|
100
|
+
- spec/scrypt/password_spec.rb
|
101
|
+
- spec/spec_helper.rb
|