Browse files

Documentation of new options in `scrypt.rb` and `README.md`

  • Loading branch information...
1 parent 235a7e1 commit 3409dbf24a41d21d63eb6d806de91974efb0a1f2 @nomoon nomoon committed May 6, 2012
Showing with 8 additions and 6 deletions.
  1. +3 −1 README.md
  2. +5 −5 lib/scrypt.rb
View
4 README.md
@@ -41,8 +41,10 @@ include "scrypt"
@db_password == "a paltry guess" #=> false
```
-Password.create takes three options which will determine the cost limits of the computation:
+Password.create takes five options which will determine the key length and salt size, as well as the cost limits of the computation:
+* `:key_len` specifies the length in bytes of the key you want to generate. The default is 32 bytes (256 bits). Minimum is 16 bytes (128 bits). Maximum is 512 bytes (4096 bits).
+* `:salt_size` specifies the size in bytes of the random salt you want to generate. The default and minimum is 8 bytes (64 bits). Maximum is 32 bytes (256 bits).
* `:max_time` specifies the maximum number of seconds the computation should take.
* `: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.
* `: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.
View
10 lib/scrypt.rb
@@ -49,10 +49,10 @@ 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
+ if salt_only.length == 40
# Old-style hash with 40-character salt
salt + "$" + Digest::SHA1.hexdigest(scrypt(secret.to_s, salt, cost, 256))
- else
+ 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')
@@ -152,9 +152,9 @@ class Password < String
class << self
# Hashes a secret, returning a SCrypt::Password instance.
- # Takes four options (optional), which will determine the salt/key's length and the cost limits of the computation.
- # <tt>:key_len</tt> specifies the length in bytes of the key you want to generate. The default is 32 bytes (256 bits). Minimum is 16 bytes (128 bits). Maximum us 512 bytes (4096 bits).
- # <tt>:salt_size</tt> specifies the size in bytes of the salt you want to generate. The default/minimum is 8 bytes (64 bits). Maximum is 32 bytes (256 bits).
+ # Takes five options (optional), which will determine the salt/key's length and the cost limits of the computation.
+ # <tt>:key_len</tt> specifies the length in bytes of the key you want to generate. The default is 32 bytes (256 bits). Minimum is 16 bytes (128 bits). Maximum is 512 bytes (4096 bits).
+ # <tt>:salt_size</tt> specifies the size in bytes of the random salt you want to generate. The default and minimum is 8 bytes (64 bits). Maximum is 32 bytes (256 bits).
# <tt>:max_time</tt> specifies the maximum number of seconds the computation should take.
# <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.
# <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.

0 comments on commit 3409dbf

Please sign in to comment.