argon2 0.1.4 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +5 -9
- data/.travis.yml +0 -1
- data/CONTRIBUTING.md +12 -0
- data/Changelog.md +10 -11
- data/README.md +23 -14
- data/ext/argon2_wrap/Makefile +8 -6
- data/ext/argon2_wrap/argon_wrap.c +23 -12
- data/ext/argon2_wrap/test.c +14 -42
- data/ext/phc-winner-argon2/.gitignore +5 -1
- data/ext/phc-winner-argon2/.travis.yml +14 -0
- data/ext/phc-winner-argon2/Makefile +33 -12
- data/ext/phc-winner-argon2/README.md +48 -19
- data/ext/phc-winner-argon2/argon2-specs.pdf +0 -0
- data/ext/phc-winner-argon2/{src → include}/argon2.h +137 -137
- data/ext/phc-winner-argon2/kats/argon2d +12290 -12290
- data/ext/phc-winner-argon2/kats/argon2d.shasum +1 -1
- data/ext/phc-winner-argon2/kats/argon2i +12290 -12290
- data/ext/phc-winner-argon2/kats/argon2i.shasum +1 -1
- data/ext/phc-winner-argon2/opt.o +0 -0
- data/ext/phc-winner-argon2/src/argon2.c +125 -145
- data/ext/phc-winner-argon2/src/bench.c +5 -5
- data/ext/phc-winner-argon2/src/core.c +15 -20
- data/ext/phc-winner-argon2/src/core.h +5 -2
- data/ext/phc-winner-argon2/src/encoding.c +45 -72
- data/ext/phc-winner-argon2/src/encoding.h +24 -0
- data/ext/phc-winner-argon2/src/genkat.c +2 -2
- data/ext/phc-winner-argon2/src/opt.c +19 -10
- data/ext/phc-winner-argon2/src/opt.h +5 -17
- data/ext/phc-winner-argon2/src/ref.c +12 -9
- data/ext/phc-winner-argon2/src/ref.h +4 -12
- data/ext/phc-winner-argon2/src/run.c +67 -42
- data/ext/phc-winner-argon2/src/test.c +131 -0
- data/lib/argon2.rb +6 -5
- data/lib/argon2/constants.rb +3 -2
- data/lib/argon2/engine.rb +1 -0
- data/lib/argon2/errors.rb +37 -36
- data/lib/argon2/ffi_engine.rb +10 -10
- data/lib/argon2/version.rb +2 -1
- metadata +7 -12
data/lib/argon2.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'argon2/constants'
|
2
3
|
require 'argon2/ffi_engine'
|
3
4
|
require 'argon2/version'
|
@@ -16,20 +17,20 @@ module Argon2
|
|
16
17
|
@secret = options[:secret]
|
17
18
|
end
|
18
19
|
|
19
|
-
def
|
20
|
+
def create(pass)
|
20
21
|
Argon2::Engine.hash_argon2i_encode(
|
21
22
|
pass, @salt, @t_cost, @m_cost, @secret)
|
22
23
|
end
|
23
24
|
|
24
|
-
#Helper class, just creates defaults and calls hash()
|
25
|
-
def self.
|
25
|
+
# Helper class, just creates defaults and calls hash()
|
26
|
+
def self.create(pass)
|
26
27
|
argon2 = Argon2::Password.new
|
27
|
-
argon2.
|
28
|
+
argon2.create(pass)
|
28
29
|
end
|
29
30
|
|
30
31
|
def self.verify_password(pass, hash, secret = nil)
|
31
32
|
raise ArgonHashFail, "Invalid hash" unless
|
32
|
-
/^\$argon2i\$.{,110}
|
33
|
+
/^\$argon2i\$.{,110}/ =~ hash
|
33
34
|
Argon2::Engine.argon2i_verify(pass, hash, secret)
|
34
35
|
end
|
35
36
|
end
|
data/lib/argon2/constants.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module Argon2
|
2
3
|
# Constants utilised in several parts of the Argon2 module
|
3
4
|
# SALT_LEN is a standard recommendation from the Argon2 spec.
|
4
5
|
module Constants
|
5
6
|
SALT_LEN = 16
|
6
|
-
OUT_LEN = 32 #Binary, unencoded output
|
7
|
-
ENCODE_LEN = 108 #Encoded output
|
7
|
+
OUT_LEN = 32 # Binary, unencoded output
|
8
|
+
ENCODE_LEN = 108 # Encoded output
|
8
9
|
end
|
9
10
|
end
|
data/lib/argon2/engine.rb
CHANGED
data/lib/argon2/errors.rb
CHANGED
@@ -1,41 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
# Defines an array of errors that matches the enum list of errors from
|
2
3
|
# argon2.h. This allows return values to propagate errors through the FFI.
|
3
4
|
module Argon2
|
4
5
|
class ArgonHashFail < StandardError; end
|
5
|
-
ERRORS =
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
6
|
+
ERRORS = %w(
|
7
|
+
ARGON2_OK
|
8
|
+
ARGON2_OUTPUT_PTR_NULL
|
9
|
+
ARGON2_OUTPUT_TOO_SHORT
|
10
|
+
ARGON2_OUTPUT_TOO_LONG
|
11
|
+
ARGON2_PWD_TOO_SHORT
|
12
|
+
ARGON2_PWD_TOO_LONG
|
13
|
+
ARGON2_SALT_TOO_SHORT
|
14
|
+
ARGON2_SALT_TOO_LONG
|
15
|
+
ARGON2_AD_TOO_SHORT
|
16
|
+
ARGON2_AD_TOO_LONG
|
17
|
+
ARGON2_SECRET_TOO_SHORT
|
18
|
+
ARGON2_SECRET_TOO_LONG
|
19
|
+
ARGON2_TIME_TOO_SMALL
|
20
|
+
ARGON2_TIME_TOO_LARGE
|
21
|
+
ARGON2_MEMORY_TOO_LITTLE
|
22
|
+
ARGON2_MEMORY_TOO_MUCH
|
23
|
+
ARGON2_LANES_TOO_FEW
|
24
|
+
ARGON2_LANES_TOO_MANY
|
25
|
+
ARGON2_PWD_PTR_MISMATCH
|
26
|
+
ARGON2_SALT_PTR_MISMATCH
|
27
|
+
ARGON2_SECRET_PTR_MISMATCH
|
28
|
+
ARGON2_AD_PTR_MISMATCH
|
29
|
+
ARGON2_MEMORY_ALLOCATION_ERROR
|
30
|
+
ARGON2_FREE_MEMORY_CBK_NULL
|
31
|
+
ARGON2_ALLOCATE_MEMORY_CBK_NULL
|
32
|
+
ARGON2_INCORRECT_PARAMETER
|
33
|
+
ARGON2_INCORRECT_TYPE
|
34
|
+
ARGON2_OUT_PTR_MISMATCH
|
35
|
+
ARGON2_THREADS_TOO_FEW
|
36
|
+
ARGON2_THREADS_TOO_MANY
|
37
|
+
ARGON2_MISSING_ARGS
|
38
|
+
ARGON2_ENCODING_FAIL
|
39
|
+
ARGON2_DECODING_FAIL
|
40
|
+
ARGON2_THREAD_FAIL
|
41
|
+
).freeze
|
41
42
|
end
|
data/lib/argon2/ffi_engine.rb
CHANGED
@@ -2,12 +2,12 @@ require 'ffi'
|
|
2
2
|
require 'ffi-compiler/loader'
|
3
3
|
|
4
4
|
module Argon2
|
5
|
-
#Direct external bindings. Call these methods via the Engine class to ensure points are dealt with
|
5
|
+
# Direct external bindings. Call these methods via the Engine class to ensure points are dealt with
|
6
6
|
module Ext
|
7
7
|
extend FFI::Library
|
8
8
|
ffi_lib FFI::Compiler::Loader.find('argon2_wrap')
|
9
9
|
|
10
|
-
#int argon2i_hash_raw(const uint32_t t_cost, const uint32_t m_cost,
|
10
|
+
# int argon2i_hash_raw(const uint32_t t_cost, const uint32_t m_cost,
|
11
11
|
# const uint32_t parallelism, const void *pwd,
|
12
12
|
# const size_t pwdlen, const void *salt,
|
13
13
|
# const size_t saltlen, void *hash, const size_t hashlen);
|
@@ -16,16 +16,16 @@ module Argon2
|
|
16
16
|
:uint, :uint, :uint, :pointer,
|
17
17
|
:size_t, :pointer, :size_t, :pointer, :size_t], :int, :blocking => true
|
18
18
|
|
19
|
-
#void argon2_wrap(uint8_t *out, char *pwd, size_it pwdlen,
|
20
|
-
#uint8_t *salt, uint32_t t_cost,
|
19
|
+
# void argon2_wrap(uint8_t *out, char *pwd, size_it pwdlen,
|
20
|
+
# uint8_t *salt, uint32_t t_cost,
|
21
21
|
# uint32_t m_cost, uint32_t lanes,
|
22
22
|
# uint8_t *secret, uint32_t secretlen)
|
23
23
|
attach_function :argon2_wrap, [
|
24
24
|
:pointer, :pointer, :size_t, :pointer, :uint,
|
25
25
|
:uint, :uint, :pointer, :size_t], :uint, :blocking => true
|
26
26
|
|
27
|
-
#int argon2i_verify(const char *encoded, const void *pwd,
|
28
|
-
#const size_t pwdlen);
|
27
|
+
# int argon2i_verify(const char *encoded, const void *pwd,
|
28
|
+
# const size_t pwdlen);
|
29
29
|
attach_function :wrap_argon2_verify, [:pointer, :pointer, :size_t,
|
30
30
|
:pointer, :size_t], :int, :blocking => true
|
31
31
|
end
|
@@ -39,7 +39,7 @@ module Argon2
|
|
39
39
|
ret = Ext.argon2i_hash_raw(t_cost, 1 << m_cost, 1, password,
|
40
40
|
password.length, salt, salt.length,
|
41
41
|
buffer, Constants::OUT_LEN)
|
42
|
-
raise ArgonHashFail, ERRORS[ret] unless ret == 0
|
42
|
+
raise ArgonHashFail, ERRORS[ret.abs] unless ret == 0
|
43
43
|
result = buffer.read_string(Constants::OUT_LEN)
|
44
44
|
end
|
45
45
|
result.unpack('H*').join
|
@@ -56,7 +56,7 @@ module Argon2
|
|
56
56
|
ret = Ext.argon2_wrap(buffer, password, passwordlen,
|
57
57
|
salt, t_cost, (1 << m_cost),
|
58
58
|
1, secret, secretlen)
|
59
|
-
raise ArgonHashFail, ERRORS[ret] unless ret == 0
|
59
|
+
raise ArgonHashFail, ERRORS[ret.abs] unless ret == 0
|
60
60
|
result = buffer.read_string(Constants::ENCODE_LEN)
|
61
61
|
end
|
62
62
|
result.delete "\0"
|
@@ -67,8 +67,8 @@ module Argon2
|
|
67
67
|
passwordlen = pwd.nil? ? 0 : pwd.bytesize
|
68
68
|
|
69
69
|
ret = Ext.wrap_argon2_verify(hash, pwd, passwordlen, secret, secretlen)
|
70
|
-
return false if ERRORS[ret] == 'ARGON2_DECODING_FAIL'
|
71
|
-
raise ArgonHashFail, ERRORS[ret] unless ret == 0
|
70
|
+
return false if ERRORS[ret.abs] == 'ARGON2_DECODING_FAIL'
|
71
|
+
raise ArgonHashFail, ERRORS[ret.abs] unless ret == 0
|
72
72
|
true
|
73
73
|
end
|
74
74
|
end
|
data/lib/argon2/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: argon2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Technion
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-03-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ffi
|
@@ -132,6 +132,7 @@ files:
|
|
132
132
|
- ".gitmodules"
|
133
133
|
- ".rubocop.yml"
|
134
134
|
- ".travis.yml"
|
135
|
+
- CONTRIBUTING.md
|
135
136
|
- Changelog.md
|
136
137
|
- Gemfile
|
137
138
|
- LICENSE.txt
|
@@ -148,47 +149,41 @@ files:
|
|
148
149
|
- ext/argon2_wrap/tests
|
149
150
|
- ext/phc-winner-argon2/.git
|
150
151
|
- ext/phc-winner-argon2/.gitignore
|
152
|
+
- ext/phc-winner-argon2/.travis.yml
|
151
153
|
- ext/phc-winner-argon2/CHANGELOG.md
|
152
154
|
- ext/phc-winner-argon2/LICENSE
|
153
155
|
- ext/phc-winner-argon2/Makefile
|
154
156
|
- ext/phc-winner-argon2/README.md
|
155
|
-
- ext/phc-winner-argon2/argon2
|
156
157
|
- ext/phc-winner-argon2/argon2-specs.pdf
|
158
|
+
- ext/phc-winner-argon2/include/argon2.h
|
157
159
|
- ext/phc-winner-argon2/kats/argon2d
|
158
160
|
- ext/phc-winner-argon2/kats/argon2d.shasum
|
159
161
|
- ext/phc-winner-argon2/kats/argon2i
|
160
162
|
- ext/phc-winner-argon2/kats/argon2i.shasum
|
161
163
|
- ext/phc-winner-argon2/kats/check-sums.sh
|
162
164
|
- ext/phc-winner-argon2/kats/test.sh
|
163
|
-
- ext/phc-winner-argon2/
|
164
|
-
- ext/phc-winner-argon2/libargon2.so
|
165
|
+
- ext/phc-winner-argon2/opt.o
|
165
166
|
- ext/phc-winner-argon2/src/argon2.c
|
166
|
-
- ext/phc-winner-argon2/src/argon2.h
|
167
|
-
- ext/phc-winner-argon2/src/argon2.o
|
168
167
|
- ext/phc-winner-argon2/src/bench.c
|
169
168
|
- ext/phc-winner-argon2/src/blake2/blake2-impl.h
|
170
169
|
- ext/phc-winner-argon2/src/blake2/blake2.h
|
171
170
|
- ext/phc-winner-argon2/src/blake2/blake2b.c
|
172
|
-
- ext/phc-winner-argon2/src/blake2/blake2b.o
|
173
171
|
- ext/phc-winner-argon2/src/blake2/blamka-round-opt.h
|
174
172
|
- ext/phc-winner-argon2/src/blake2/blamka-round-ref.h
|
175
173
|
- ext/phc-winner-argon2/src/core.c
|
176
174
|
- ext/phc-winner-argon2/src/core.h
|
177
|
-
- ext/phc-winner-argon2/src/core.o
|
178
175
|
- ext/phc-winner-argon2/src/encoding.c
|
179
176
|
- ext/phc-winner-argon2/src/encoding.h
|
180
|
-
- ext/phc-winner-argon2/src/encoding.o
|
181
177
|
- ext/phc-winner-argon2/src/genkat.c
|
182
178
|
- ext/phc-winner-argon2/src/genkat.h
|
183
179
|
- ext/phc-winner-argon2/src/opt.c
|
184
180
|
- ext/phc-winner-argon2/src/opt.h
|
185
181
|
- ext/phc-winner-argon2/src/ref.c
|
186
182
|
- ext/phc-winner-argon2/src/ref.h
|
187
|
-
- ext/phc-winner-argon2/src/ref.o
|
188
183
|
- ext/phc-winner-argon2/src/run.c
|
184
|
+
- ext/phc-winner-argon2/src/test.c
|
189
185
|
- ext/phc-winner-argon2/src/thread.c
|
190
186
|
- ext/phc-winner-argon2/src/thread.h
|
191
|
-
- ext/phc-winner-argon2/src/thread.o
|
192
187
|
- lib/argon2.rb
|
193
188
|
- lib/argon2/constants.rb
|
194
189
|
- lib/argon2/engine.rb
|