scrypt 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,5 +1,7 @@
1
1
  pkg/*
2
+ doc/*
2
3
  *.gem
3
4
  .bundle
5
+ ext/mri/*.bundle
4
6
  *.o
5
7
  .DS_Store
data/README CHANGED
@@ -7,13 +7,36 @@ The scrypt key derivation function is designed to be far more secure against har
7
7
 
8
8
  == Why you should use scrypt
9
9
 
10
- Coming soon.
10
+ The designers of scrypt estimate that on modern (2009) hardware, if 5 seconds are spent computing a derived key, the cost of a hardware brute-force attack against scrypt is roughly 4000 times greater than the cost of a similar attack against bcrypt (to find the same password), and 20000 times greater than a similar attack against PBKDF2.
11
11
 
12
- == How to install bcrypt
12
+ == How to install scrypt
13
13
 
14
14
  gem install scrypt
15
15
 
16
16
  == How to use scrypt
17
17
 
18
- Coming soon. It works pretty similarly to ruby-bcrypt.
18
+ It works pretty similarly to ruby-bcrypt with a few minor differences, especially where the cost factor is concerned.
19
19
 
20
+ include "scrypt"
21
+
22
+ # hash a user's password
23
+ @password = Password.create("my grand secret")
24
+ @password #=> "2000$8$1$f5f2fa5fe5484a7091f1299768fbe92b5a7fbc77$6a385f22c54d92c314b71a4fd5ef33967c93d679"
25
+
26
+ # store it safely
27
+ @user.update_attribute(:password, @password)
28
+
29
+ # read it back
30
+ @user.reload!
31
+ @db_password = Password.new(@user.password)
32
+
33
+ # compare it after retrieval
34
+ @db_password == "my grand secret" #=> true
35
+ @db_password == "a paltry guess" #=> false
36
+
37
+ Password.create takes three options which will determine the cost limits of the computation.
38
+ * :max_time specifies the maximum number of seconds the computation should take.
39
+ * :max_mem specifies the maximum number of bytes the computation should take. A value of 0 specifies no upper limit. The minimum is always 1 MB.
40
+ * :max_memfrac specifies the maximum memory in a fraction of available resources to use. Any value equal to 0 or greater than 0.5 will result in 0.5 being used.
41
+
42
+ Default options will result in calculation time of approx. 200 ms with 1 MB memory use.
data/lib/scrypt.rb CHANGED
@@ -8,6 +8,7 @@ require "scanf"
8
8
 
9
9
 
10
10
  module SCrypt
11
+
11
12
  module Errors
12
13
  class InvalidSalt < StandardError; end # The salt parameter provided is invalid.
13
14
  class InvalidHash < StandardError; end # The hash parameter provided is invalid.
@@ -63,14 +64,16 @@ module SCrypt
63
64
 
64
65
  # Returns the cost value which will result in computation limits less than the given options.
65
66
  #
67
+ # Options:
68
+ # <tt>:max_time</tt> specifies the maximum number of seconds the computation should take.
69
+ # <tt>:max_mem</tt> specifies the maximum number of bytes the computation should take. A value of 0 specifies no upper limit. The minimum is always 1 MB.
70
+ # <tt>:max_memfrac</tt> specifies the maximum memory in a fraction of available resources to use. Any value equal to 0 or greater than 0.5 will result in 0.5 being used.
71
+ #
66
72
  # Example:
67
73
  #
68
74
  # # should take less than 200ms
69
75
  # SCrypt.calibrate(:max_time => 0.2)
70
76
  #
71
- # # should take less than 1000ms
72
- # SCrypt.calibrate(:max_time => 1)
73
- #
74
77
  def self.calibrate(options = {})
75
78
  options = DEFAULTS.merge(options)
76
79
  __sc_calibrate(options[:max_mem], options[:max_memfrac], options[:max_time])
@@ -129,6 +132,7 @@ module SCrypt
129
132
  #
130
133
  # Example:
131
134
  # @password = SCrypt::Password.create("my secret", :max_time => 0.25)
135
+ #
132
136
  def create(secret, options = {})
133
137
  options = SCrypt::Engine::DEFAULTS.merge(options)
134
138
  salt = SCrypt::Engine.generate_salt(options)
@@ -1,3 +1,3 @@
1
1
  module SCrypt
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scrypt
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 0
10
- version: 1.0.0
9
+ - 1
10
+ version: 1.0.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Patrick Hogan
@@ -47,7 +47,6 @@ files:
47
47
  - ext/mri/memlimit.h
48
48
  - ext/mri/scrypt_calibrate.c
49
49
  - ext/mri/scrypt_calibrate.h
50
- - ext/mri/scrypt_ext.bundle
51
50
  - ext/mri/scrypt_ext.c
52
51
  - ext/mri/scrypt_platform.h
53
52
  - ext/mri/scryptenc_cpuperf.c
Binary file