rbnacl 3.0.0 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +3 -4
- data/CHANGES.md +9 -0
- data/README.md +21 -35
- data/bascule.gpg +52 -0
- data/lib/rbnacl/init.rb +5 -1
- data/lib/rbnacl/password_hash/scrypt.rb +70 -0
- data/lib/rbnacl/password_hash.rb +39 -0
- data/lib/rbnacl/rake_tasks.rb +2 -2
- data/lib/rbnacl/sodium.rb +5 -1
- data/lib/rbnacl/test_vectors.rb +11 -0
- data/lib/rbnacl/version.rb +1 -1
- data/lib/rbnacl.rb +4 -0
- data/spec/rbnacl/password_hash/scrypt_spec.rb +21 -0
- metadata +8 -4
- data/rbnacl.gpg +0 -30
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: da04c0339f10665de0880687721eb137edb0db2d
|
|
4
|
+
data.tar.gz: 4f149d92ee6701f70fa6f8715e6132357b6064fc
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7150574a248de534fa8f141eb891cc3db27a92988e319d55848d21f8323aa0f133416ffc5d4761c62b9d7dcaac7ef0ab70b7df2f45b42d540c857fc852b390a1
|
|
7
|
+
data.tar.gz: 08f8dfd718c3c75a436a826cc564beacb5533878f7b77d12ea0a057afc1750d421265b0c1172704e98953bece3c893926275aa991f6f86ba7d2d6ca2f85689b1
|
data/.travis.yml
CHANGED
|
@@ -3,18 +3,17 @@ script: "LD_LIBRARY_PATH=lib bundle exec rake ci"
|
|
|
3
3
|
rvm:
|
|
4
4
|
- 1.9.3
|
|
5
5
|
- 2.0.0
|
|
6
|
-
- 2.1.
|
|
6
|
+
- 2.1.1
|
|
7
7
|
- ruby-head
|
|
8
8
|
- jruby
|
|
9
9
|
- jruby-head
|
|
10
|
-
- rbx
|
|
11
|
-
- rbx-head
|
|
10
|
+
- rbx-2
|
|
12
11
|
|
|
13
12
|
matrix:
|
|
14
13
|
allow_failures:
|
|
15
14
|
- rvm: ruby-head
|
|
16
15
|
- rvm: jruby-head
|
|
17
|
-
- rvm: rbx-
|
|
16
|
+
- rvm: rbx-2
|
|
18
17
|
|
|
19
18
|
notifications:
|
|
20
19
|
irc: "irc.freenode.org#cryptosphere"
|
data/CHANGES.md
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
3.1.0 (2014-05-22)
|
|
2
|
+
------------------
|
|
3
|
+
* The scrypt password hashing function: RbNaCl::PasswordHash.scrypt
|
|
4
|
+
|
|
5
|
+
3.0.1 (2014-05-12)
|
|
6
|
+
------------------
|
|
7
|
+
* Load gem from RBNACL_LIBSODIUM_GEM_LIB_PATH if set. Used by rbnacl-libsodium
|
|
8
|
+
gem to use libsodium compiled from a gem.
|
|
9
|
+
|
|
1
10
|
3.0.0 (2014-04-22)
|
|
2
11
|
------------------
|
|
3
12
|
* Rename RandomNonceBox to SimpleBox (backwards compatibility preserved)
|
data/README.md
CHANGED
|
@@ -67,14 +67,10 @@ reports of successful Windows users.
|
|
|
67
67
|
|
|
68
68
|
### libsodium
|
|
69
69
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
so RbNaCl cannot take advantage of it via FFI. RbNaCl will support usage with
|
|
73
|
-
the upstream NaCl once it is able to compile a shared library.
|
|
70
|
+
**NOTE: Want to avoid the hassle of installing libsodium? Use the
|
|
71
|
+
[rbnacl-libsodium](https://github.com/cryptosphere/rbnacl-libsodium) gem**
|
|
74
72
|
|
|
75
|
-
|
|
76
|
-
of NaCl based upon the reference C code. Please see the libsodium project
|
|
77
|
-
for information regarding installation:
|
|
73
|
+
To use RbNaCl, you will need to install libsodium:
|
|
78
74
|
|
|
79
75
|
https://github.com/jedisct1/libsodium
|
|
80
76
|
|
|
@@ -82,6 +78,16 @@ For OS X users, libsodium is available via homebrew and can be installed with:
|
|
|
82
78
|
|
|
83
79
|
brew install libsodium
|
|
84
80
|
|
|
81
|
+
For FreeBSD users, libsodium is available both via pkgng and ports. To install
|
|
82
|
+
a binary package:
|
|
83
|
+
|
|
84
|
+
pkg install libsodium
|
|
85
|
+
|
|
86
|
+
To install from ports on FreeBSD, use your favorite ports front end (e.g.
|
|
87
|
+
portmaster or portupgrade), or use make as follows:
|
|
88
|
+
|
|
89
|
+
cd /usr/ports/security/libsodium; make install clean
|
|
90
|
+
|
|
85
91
|
### RbNaCl gem
|
|
86
92
|
|
|
87
93
|
Once you have libsodium installed, add this line to your application's Gemfile:
|
|
@@ -107,6 +113,7 @@ Inside of your Ruby program do:
|
|
|
107
113
|
RbNaCl's documentation can be found [in the Wiki][wiki]. The following features
|
|
108
114
|
are supported:
|
|
109
115
|
|
|
116
|
+
* [SimpleBox]: easy-to-use public-key or secret-key encryption "on Rails"
|
|
110
117
|
* [Secret-key Encryption][secretkey]: authenticated symmetric encryption using a
|
|
111
118
|
single key shared among parties
|
|
112
119
|
* [Public-key Encryption][publickey]: securely send messages to a given public
|
|
@@ -124,6 +131,7 @@ information.
|
|
|
124
131
|
[RDoc documentation][rdoc] is also available.
|
|
125
132
|
|
|
126
133
|
[wiki]: https://github.com/cryptosphere/rbnacl/wiki
|
|
134
|
+
[simplebox]: https://github.com/cryptosphere/rbnacl/wiki/SimpleBox
|
|
127
135
|
[secretkey]: https://github.com/cryptosphere/rbnacl/wiki/Secret-Key-Encryption
|
|
128
136
|
[publickey]: https://github.com/cryptosphere/rbnacl/wiki/Public-Key-Encryption
|
|
129
137
|
[signatures]: https://github.com/cryptosphere/rbnacl/wiki/Digital-Signatures
|
|
@@ -141,32 +149,6 @@ by professional cryptographers.
|
|
|
141
149
|
|
|
142
150
|
That said, it's probably still a million times better than OpenSSL...
|
|
143
151
|
|
|
144
|
-
## Using Signed Gems
|
|
145
|
-
|
|
146
|
-
The RbNaCl gem is signed by Tony Arcieri's certificate, which identifies
|
|
147
|
-
as `bascule@gmail.com`. You can obtain the official certificate with:
|
|
148
|
-
|
|
149
|
-
```
|
|
150
|
-
curl https://raw.github.com/cryptosphere/rbnacl/master/bascule.cert > /tmp/bascule.cert
|
|
151
|
-
gem cert -a /tmp/bascule.cert
|
|
152
|
-
```
|
|
153
|
-
|
|
154
|
-
You can verify the authenticity of bascule.cert by its SHA256 hash:
|
|
155
|
-
|
|
156
|
-
```
|
|
157
|
-
$ shasum -a 256 bascule.cert
|
|
158
|
-
6e8b7e53d347ca6c6d214efef2b923aadecdd7650565f0eb1d8d0419723ae20c bascule.cert
|
|
159
|
-
```
|
|
160
|
-
|
|
161
|
-
If you get a different number than `6e8b7e53...`, this is not the cert you are
|
|
162
|
-
looking for!
|
|
163
|
-
|
|
164
|
-
If you'd like to install the gem in high security mode, run:
|
|
165
|
-
|
|
166
|
-
```
|
|
167
|
-
gem install rbnacl-1.0.0.gem -P HighSecurity
|
|
168
|
-
```
|
|
169
|
-
|
|
170
152
|
## Reporting Security Problems
|
|
171
153
|
|
|
172
154
|
If you have discovered a bug in RbNaCl of a sensitive nature, i.e.
|
|
@@ -174,11 +156,11 @@ one which can compromise the security of RbNaCl users, you can
|
|
|
174
156
|
report it securely by sending a GPG encrypted message. Please use
|
|
175
157
|
the following key:
|
|
176
158
|
|
|
177
|
-
https://raw.github.com/cryptosphere/rbnacl/master/
|
|
159
|
+
https://raw.github.com/cryptosphere/rbnacl/master/bascule.gpg
|
|
178
160
|
|
|
179
161
|
The key fingerprint is (or should be):
|
|
180
162
|
|
|
181
|
-
`
|
|
163
|
+
`25C1 198A C8A1 8212 7D24 E665 666B AFA9 D77E E055`
|
|
182
164
|
|
|
183
165
|
## Learn More
|
|
184
166
|
|
|
@@ -208,6 +190,10 @@ Coursera offers from Stanford University Professor Dan Boneh:
|
|
|
208
190
|
|
|
209
191
|
Only if your military understands twisted Edwards curves
|
|
210
192
|
|
|
193
|
+
### Is it "Bank Grade™"?
|
|
194
|
+
|
|
195
|
+
No, that means 3DES, which this library doesn't support, sorry
|
|
196
|
+
|
|
211
197
|
### Does it have a lock with a checkmark?
|
|
212
198
|
|
|
213
199
|
Sure, here you go:
|
data/bascule.gpg
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
-----BEGIN PGP PUBLIC KEY BLOCK-----
|
|
2
|
+
Version: GnuPG v1
|
|
3
|
+
|
|
4
|
+
mQINBFNXTYEBEADG3Vk/ZLx6Uuw2e7SDZuyBCssszjQ+Zkkd4v1at0oinXMNBv7h
|
|
5
|
+
oRCUnx0xkHGKCeMYEWlpLKIQBQ8ngPpD1agsBlTB+dkcerADduUeiL0ftbc57lqu
|
|
6
|
+
Jss32JFQzoVybhfA1LPMnNndgNMCfKneCxftirsRIxOZg7tDvYBbRZIpFzcn8B6N
|
|
7
|
+
n3KgDqE4xZaR3N66lJhuW1exS0jHJiZ8l9IJv1zVtSinoFb5VdohPU3UnTG2rCw9
|
|
8
|
+
fIqic1ZPNFmBSMcowENulDxhfxywcJbXzGd2GA2959d3CgL+mSHNQk4etPM7Hnw1
|
|
9
|
+
rUWA84EQM+eSmI/fSNMIQKCc/Ds5JI0ZDm0ej0+LpZru6UpwDzpiviNFfIxx0ztJ
|
|
10
|
+
RQ04yRhOswpJAVNtarL6xVsXjyDqe1j+/RUkWQLAyKvasCUNAfEidI52uSG1NscB
|
|
11
|
+
dpqsj4D66FSnFKljdv9FkpcwfpkgyDh9dg134RzzpuWBZF2et0Gpu7T8SwbzfdaF
|
|
12
|
+
FdlIod9EE1gV/Ngc4mjy3Em+63mRXVcLa5cuLMh4N2rY4s//yz7dRV+J7xvyi/FH
|
|
13
|
+
QfOr+YcvrGrcuta3PZ0sEBBwD1ZoLv4mvtE8+V2DYA/ym7reuiBlJcLJnOX/Y4b4
|
|
14
|
+
+5oofRcZBdX8ts/nTGCp42ESm8by5mj1bjRBvJXpbvmDh0leTBWRHaLnkwARAQAB
|
|
15
|
+
tC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NNHuL9jnvzJcylscKJ
|
|
44
|
+
0u8uwk1StNtz/fwTsFV5s5ilg0dt+/hSB+TQbr7uI9PPgWPrGQIa1EzkjflaWYJd
|
|
45
|
+
hB4R44c5iYeRpGZoiXh5bm82yxGmIleRKJtRZ8OYJy/2QRFfhG1sS24FYZWojwve
|
|
46
|
+
0A7wguMB8SSfOj6cMo14sPe38h1w7XuDrvc4HshRNoB+7SYuqH2wQRd8GdkkX0SP
|
|
47
|
+
xfJy+3H9Mq1vGWHM5ZqVpA2QEEGArVuUh6TwjqB1gUvcoNFFZ5jLS4O06r7sNxrx
|
|
48
|
+
4udMZXdmYiztQzOak3rGI8bE4NwXRsJdiAnRC6pfhJmoVGI+y0dkkQfPaZEoiAHA
|
|
49
|
+
DGnZHqa7tnlSe7LcbC8FpCnSmaEEhx9blDv6z7vYZaCkNiGb3tIeHEeOm5wLsByC
|
|
50
|
+
8VqIziiGfWBn7c9CNBhHoBsTb/oK
|
|
51
|
+
=EFdK
|
|
52
|
+
-----END PGP PUBLIC KEY BLOCK-----
|
data/lib/rbnacl/init.rb
CHANGED
|
@@ -3,7 +3,11 @@ module RbNaCl
|
|
|
3
3
|
# Defines the libsodium init function
|
|
4
4
|
module Init
|
|
5
5
|
extend FFI::Library
|
|
6
|
-
|
|
6
|
+
if defined?(RBNACL_LIBSODIUM_GEM_LIB_PATH)
|
|
7
|
+
ffi_lib RBNACL_LIBSODIUM_GEM_LIB_PATH
|
|
8
|
+
else
|
|
9
|
+
ffi_lib 'sodium'
|
|
10
|
+
end
|
|
7
11
|
|
|
8
12
|
attach_function :sodium_init, [], :int
|
|
9
13
|
end
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# encoding: binary
|
|
2
|
+
module RbNaCl
|
|
3
|
+
module PasswordHash
|
|
4
|
+
# The scrypt sequential memory hard password hashing function
|
|
5
|
+
#
|
|
6
|
+
# scrypt is a password hash (or password based KDF). That is to say, where
|
|
7
|
+
# most hash functions are designed to be fast because hashing is often a
|
|
8
|
+
# bottleneck, scrypt is slow by design, because it's trying to "strengthen"
|
|
9
|
+
# the password by combining it with a random "salt" value then perform a
|
|
10
|
+
# series of operation on the result which are slow enough to defeat
|
|
11
|
+
# brute-force password cracking attempts.
|
|
12
|
+
#
|
|
13
|
+
# scrypt is similar to the bcrypt and pbkdf2 password hashes in that it's
|
|
14
|
+
# designed to strengthen passwords, but includes a new design element
|
|
15
|
+
# called "sequential memory hardness" which helps defeat attempts by
|
|
16
|
+
# attackers to compensate for their lack of memory (since they're typically
|
|
17
|
+
# on GPUs or FPGAs) with additional computation.
|
|
18
|
+
class SCrypt
|
|
19
|
+
extend Sodium
|
|
20
|
+
|
|
21
|
+
begin
|
|
22
|
+
sodium_type :pwhash
|
|
23
|
+
sodium_primitive :scryptxsalsa208sha256
|
|
24
|
+
|
|
25
|
+
sodium_constant :SALTBYTES
|
|
26
|
+
|
|
27
|
+
sodium_function :scrypt,
|
|
28
|
+
:crypto_pwhash_scryptxsalsa208sha256,
|
|
29
|
+
[:pointer, :ulong_long, :pointer, :ulong_long, :pointer, :ulong_long, :size_t]
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
# Create a new SCrypt password hash object
|
|
34
|
+
#
|
|
35
|
+
# @param [Integer] opslimit the CPU cost (e.g. 2**20)
|
|
36
|
+
# @param [Integer] memlimit the memory cost (e.g. 2**24)
|
|
37
|
+
#
|
|
38
|
+
# @return [RbNaCl::PasswordHash::SCrypt] An SCrypt password hasher object
|
|
39
|
+
def initialize(opslimit, memlimit, digest_size = 64)
|
|
40
|
+
# TODO: sanity check these parameters
|
|
41
|
+
@opslimit, @memlimit = opslimit, memlimit
|
|
42
|
+
|
|
43
|
+
# TODO: check digest size validity
|
|
44
|
+
#raise LengthError, "digest size too short" if @digest_size < BYTES_MIN
|
|
45
|
+
#raise LengthError, "digest size too long" if @digest_size > BYTES_MAX
|
|
46
|
+
|
|
47
|
+
@digest_size = digest_size
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# Calculate an scrypt digest for a given password and salt
|
|
51
|
+
#
|
|
52
|
+
# @param [String] password to be hashed
|
|
53
|
+
# @param [String] salt to make the digest unique
|
|
54
|
+
#
|
|
55
|
+
# @return [String] scrypt digest of the string as raw bytes
|
|
56
|
+
def digest(password, salt)
|
|
57
|
+
digest = Util.zeros(@digest_size)
|
|
58
|
+
salt = Util.check_string(salt, SALTBYTES, "salt")
|
|
59
|
+
|
|
60
|
+
self.class.scrypt(digest, @digest_size, password, password.bytesize, salt, @opslimit, @memlimit) || raise(CryptoError, "scrypt failed!")
|
|
61
|
+
digest
|
|
62
|
+
end
|
|
63
|
+
rescue FFI::NotFoundError
|
|
64
|
+
def initialize(opslimit, memlimit, digest_size = 64)
|
|
65
|
+
raise NotImplementedError, "scrypt not implemented in this version of libsodium"
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# encoding: binary
|
|
2
|
+
module RbNaCl
|
|
3
|
+
# Password hashing functions
|
|
4
|
+
#
|
|
5
|
+
# These hash functions are designed specifically for the purposes of securely
|
|
6
|
+
# storing passwords in a way that they can be checked against a supplied
|
|
7
|
+
# password but an attacker who obtains a hash cannot easily reverse them back
|
|
8
|
+
# into the original password.
|
|
9
|
+
#
|
|
10
|
+
# Unlike normal hash functions, which are intentionally designed to hash data
|
|
11
|
+
# as quickly as they can while remaining secure, password hashing functions
|
|
12
|
+
# are intentionally designed to be slow so they are hard for attackers to
|
|
13
|
+
# brute force.
|
|
14
|
+
#
|
|
15
|
+
# All password hashing functions take a "salt" value which should be randomly
|
|
16
|
+
# generated on a per-password basis (using RbNaCl::Random, accept no
|
|
17
|
+
# subsitutes)
|
|
18
|
+
#
|
|
19
|
+
# All of them also take a CPU work factor, which increases the amount of
|
|
20
|
+
# computation needed to produce the digest.
|
|
21
|
+
module PasswordHash
|
|
22
|
+
# scrypt: the original sequential memory hard password hashing function.
|
|
23
|
+
# This is also the only password hashing function supported by libsodium,
|
|
24
|
+
# but that's okay, because it's pretty awesome.
|
|
25
|
+
#
|
|
26
|
+
# @param [String] password to be hashed
|
|
27
|
+
# @param [String] salt to make the digest unique
|
|
28
|
+
# @param [Integer] opslimit the CPU cost (e.g. 2**20)
|
|
29
|
+
# @param [Integer] memlimit the memory cost (e.g. 2**24)
|
|
30
|
+
# @param [Integer] digest_size of the output
|
|
31
|
+
#
|
|
32
|
+
# @raise [CryptoError] If calculating the digest fails for some reason.
|
|
33
|
+
#
|
|
34
|
+
# @return [String] The scrypt digest as raw bytes
|
|
35
|
+
def self.scrypt(password, salt, opslimit, memlimit, digest_size = 64)
|
|
36
|
+
SCrypt.new(opslimit, memlimit, digest_size).digest(password, salt)
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
data/lib/rbnacl/rake_tasks.rb
CHANGED
|
@@ -3,8 +3,8 @@ require 'rake'
|
|
|
3
3
|
require 'rake/clean'
|
|
4
4
|
require 'digest/sha2'
|
|
5
5
|
|
|
6
|
-
LIBSODIUM_VERSION = "0.
|
|
7
|
-
LIBSODIUM_DIGEST = "
|
|
6
|
+
LIBSODIUM_VERSION = "0.5.0"
|
|
7
|
+
LIBSODIUM_DIGEST = "3ca0a0619199a2adb3449eb7f1bf6e1f4fb2ef8514da9133f7f043b8b5cdf9f0"
|
|
8
8
|
|
|
9
9
|
def sh_hidden(command)
|
|
10
10
|
STDERR.puts("*** Executing: #{command}")
|
data/lib/rbnacl/sodium.rb
CHANGED
data/lib/rbnacl/test_vectors.rb
CHANGED
|
@@ -85,6 +85,17 @@ module RbNaCl
|
|
|
85
85
|
:blake2b_keyed_digest => "142709d62e28fcccd0af97fad0f8465b971e82201dc51070faa0372aa43e9248" +
|
|
86
86
|
"4be1c1e73ba10906d5d1853db6a4106e0a7bf9800d373d6dee2d46d62ef2a461",
|
|
87
87
|
|
|
88
|
+
# scrypt test vectors
|
|
89
|
+
# Taken from http://tools.ietf.org/html/draft-josefsson-scrypt-kdf-01#page-14
|
|
90
|
+
:scrypt_password => "4a857e2ee8aa9b6056f2424e84d24a72473378906ee04a46cb05311502d5250b" +
|
|
91
|
+
"82ad86b83c8f20a23dbb74f6da60b0b6ecffd67134d45946ac8ebfb3064294bc" +
|
|
92
|
+
"097d43ced68642bfb8bbbdd0f50b30118f5e",
|
|
93
|
+
:scrypt_salt => "39d82eef32010b8b79cc5ba88ed539fbaba741100f2edbeca7cc171ffeabf258",
|
|
94
|
+
:scrypt_opslimit => 758010,
|
|
95
|
+
:scrypt_memlimit => 5432947,
|
|
96
|
+
:scrypt_digest => "bcc5c2fd785e4781d1201ed43d84925537e2a540d3de55f5812f29e9dd0a4a00" +
|
|
97
|
+
"451a5c8ddbb4862c03d45c75bf91b7fb49265feb667ad5c899fdbf2ca19eac67",
|
|
98
|
+
|
|
88
99
|
# Auth test vectors
|
|
89
100
|
# Taken from NaCl distribution
|
|
90
101
|
#
|
data/lib/rbnacl/version.rb
CHANGED
data/lib/rbnacl.rb
CHANGED
|
@@ -63,6 +63,10 @@ module RbNaCl
|
|
|
63
63
|
require "rbnacl/hash/sha512"
|
|
64
64
|
require "rbnacl/hash/blake2b"
|
|
65
65
|
|
|
66
|
+
# Password hash function: scrypt
|
|
67
|
+
require "rbnacl/password_hash"
|
|
68
|
+
require "rbnacl/password_hash/scrypt"
|
|
69
|
+
|
|
66
70
|
# HMAC: SHA256 and SHA512256
|
|
67
71
|
require "rbnacl/hmac/sha256"
|
|
68
72
|
require "rbnacl/hmac/sha512256"
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# encoding: binary
|
|
2
|
+
require 'spec_helper'
|
|
3
|
+
|
|
4
|
+
describe RbNaCl::PasswordHash::SCrypt do
|
|
5
|
+
let(:reference_password) { vector :scrypt_password }
|
|
6
|
+
let(:reference_salt) { vector :scrypt_salt }
|
|
7
|
+
let(:reference_opslimit) { RbNaCl::TestVectors[:scrypt_opslimit] }
|
|
8
|
+
let(:reference_memlimit) { RbNaCl::TestVectors[:scrypt_memlimit] }
|
|
9
|
+
let(:reference_digest) { vector :scrypt_digest }
|
|
10
|
+
|
|
11
|
+
it "calculates the correct diest for a reference password/salt" do
|
|
12
|
+
digest = RbNaCl::PasswordHash.scrypt(
|
|
13
|
+
reference_password,
|
|
14
|
+
reference_salt,
|
|
15
|
+
reference_opslimit,
|
|
16
|
+
reference_memlimit
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
expect(digest).to eq reference_digest
|
|
20
|
+
end
|
|
21
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rbnacl
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.
|
|
4
|
+
version: 3.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Tony Arcieri
|
|
@@ -10,7 +10,7 @@ autorequire:
|
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain:
|
|
12
12
|
- bascule.cert
|
|
13
|
-
date: 2014-
|
|
13
|
+
date: 2014-05-23 00:00:00.000000000 Z
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
16
16
|
name: ffi
|
|
@@ -88,6 +88,7 @@ files:
|
|
|
88
88
|
- README.md
|
|
89
89
|
- Rakefile
|
|
90
90
|
- bascule.cert
|
|
91
|
+
- bascule.gpg
|
|
91
92
|
- images/dragons.png
|
|
92
93
|
- images/ed25519.png
|
|
93
94
|
- images/hash.png
|
|
@@ -107,6 +108,8 @@ files:
|
|
|
107
108
|
- lib/rbnacl/init.rb
|
|
108
109
|
- lib/rbnacl/key_comparator.rb
|
|
109
110
|
- lib/rbnacl/one_time_auths/poly1305.rb
|
|
111
|
+
- lib/rbnacl/password_hash.rb
|
|
112
|
+
- lib/rbnacl/password_hash/scrypt.rb
|
|
110
113
|
- lib/rbnacl/rake_tasks.rb
|
|
111
114
|
- lib/rbnacl/random.rb
|
|
112
115
|
- lib/rbnacl/secret_boxes/xsalsa20poly1305.rb
|
|
@@ -122,7 +125,6 @@ files:
|
|
|
122
125
|
- lib/rbnacl/util.rb
|
|
123
126
|
- lib/rbnacl/version.rb
|
|
124
127
|
- rbnacl.gemspec
|
|
125
|
-
- rbnacl.gpg
|
|
126
128
|
- spec/rbnacl/authenticators/poly1305_spec.rb
|
|
127
129
|
- spec/rbnacl/boxes/curve25519xsalsa20poly1305/private_key_spec.rb
|
|
128
130
|
- spec/rbnacl/boxes/curve25519xsalsa20poly1305/public_key_spec.rb
|
|
@@ -132,6 +134,7 @@ files:
|
|
|
132
134
|
- spec/rbnacl/hash_spec.rb
|
|
133
135
|
- spec/rbnacl/hmac/sha256_spec.rb
|
|
134
136
|
- spec/rbnacl/hmac/sha512256_spec.rb
|
|
137
|
+
- spec/rbnacl/password_hash/scrypt_spec.rb
|
|
135
138
|
- spec/rbnacl/random_spec.rb
|
|
136
139
|
- spec/rbnacl/secret_box_spec.rb
|
|
137
140
|
- spec/rbnacl/signatures/ed25519/signing_key_spec.rb
|
|
@@ -166,7 +169,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
166
169
|
version: '0'
|
|
167
170
|
requirements: []
|
|
168
171
|
rubyforge_project:
|
|
169
|
-
rubygems_version: 2.2.
|
|
172
|
+
rubygems_version: 2.2.2
|
|
170
173
|
signing_key:
|
|
171
174
|
specification_version: 4
|
|
172
175
|
summary: The Networking and Cryptography (NaCl) library provides a high-level toolkit
|
|
@@ -181,6 +184,7 @@ test_files:
|
|
|
181
184
|
- spec/rbnacl/hash_spec.rb
|
|
182
185
|
- spec/rbnacl/hmac/sha256_spec.rb
|
|
183
186
|
- spec/rbnacl/hmac/sha512256_spec.rb
|
|
187
|
+
- spec/rbnacl/password_hash/scrypt_spec.rb
|
|
184
188
|
- spec/rbnacl/random_spec.rb
|
|
185
189
|
- spec/rbnacl/secret_box_spec.rb
|
|
186
190
|
- spec/rbnacl/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