argon2id 0.1.0-x64-mingw32 → 0.1.2-x64-mingw32
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/CHANGELOG.md +21 -0
- data/README.md +27 -12
- data/Rakefile +2 -4
- data/argon2id.gemspec +1 -0
- data/ext/argon2id/argon2id.c +18 -3
- data/lib/2.6/argon2id.so +0 -0
- data/lib/2.7/argon2id.so +0 -0
- data/lib/3.0/argon2id.so +0 -0
- data/lib/argon2id/password.rb +45 -0
- data/lib/argon2id/version.rb +1 -1
- data/lib/argon2id.rb +23 -1
- data/test/test_hash_encoded.rb +8 -40
- data/test/test_password.rb +14 -14
- data/test/test_verify.rb +17 -6
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e08dac3c5ae335fd51ca751fef00f6799d1fe54a0302d3c38fadd2b66ee9b03c
|
4
|
+
data.tar.gz: e06bca0bde28b2efdbffb6a585f532fa5b6217cb976396a7e3a1ba1c4bd2558d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c3fb37d7cea17b9dc0cc5de519922b501e65ccef9ae07370c5a082542eaf99d90382fb4d3d4a6ad1f850f2dce5445e018f4bdd1ab2fb16df208d5896ebbd8689
|
7
|
+
data.tar.gz: 1caa95453687c622a94cca9e2e05841ca9b877228a78b7d9a0b9fe724cee05f9edff956a00447b2a7186a8148f1da1c98c3c134f38a4b1df0431d0231804c99e
|
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,25 @@ All notable changes to this project will be documented in this file.
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
7
7
|
|
8
|
+
## [0.1.2] - 2024-11-01
|
9
|
+
|
10
|
+
### Fixed
|
11
|
+
|
12
|
+
- Validate that the encoded hash passed to Argon2id::Password.new is a
|
13
|
+
null-terminated C string, raising an ArgumentError if it contains extra null
|
14
|
+
bytes
|
15
|
+
|
16
|
+
## [0.1.1] - 2024-11-01
|
17
|
+
|
18
|
+
### Added
|
19
|
+
|
20
|
+
- RDoc documentation for the API
|
21
|
+
|
22
|
+
### Fixed
|
23
|
+
|
24
|
+
- Saved a superfluous extra byte when allocating the buffer for the encoded
|
25
|
+
hash
|
26
|
+
|
8
27
|
## [0.1.0] - 2024-10-31
|
9
28
|
|
10
29
|
### Added
|
@@ -13,4 +32,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
13
32
|
reference C implementation of Argon2, the password-hashing function that won
|
14
33
|
the Password Hashing Competition.
|
15
34
|
|
35
|
+
[0.1.2]: https://github.com/mudge/argon2id/releases/tag/v0.1.2
|
36
|
+
[0.1.1]: https://github.com/mudge/argon2id/releases/tag/v0.1.1
|
16
37
|
[0.1.0]: https://github.com/mudge/argon2id/releases/tag/v0.1.0
|
data/README.md
CHANGED
@@ -1,18 +1,22 @@
|
|
1
|
-
# Argon2id - Ruby bindings to the
|
1
|
+
# Argon2id - Ruby bindings to the OWASP recommended password-hashing function
|
2
2
|
|
3
3
|
Ruby bindings to the reference C implementation of [Argon2][], the password-hashing
|
4
4
|
function that won the 2015 [Password Hashing Competition][].
|
5
5
|
|
6
6
|
[](https://github.com/mudge/argon2id/actions)
|
7
7
|
|
8
|
-
**Current version:** 0.1.
|
8
|
+
**Current version:** 0.1.2
|
9
9
|
**Bundled Argon2 version:** libargon2.1 (20190702)
|
10
10
|
|
11
11
|
```ruby
|
12
12
|
Argon2::Password.create("opensesame").to_s
|
13
13
|
#=> "$argon2id$v=19$m=19456,t=2,p=1$ZS2nBFWBpnt28HjtzNOW4w$SQ+p+dIcWbpzWpZQ/ZZFj8IQkyhYZf127U4QdkRmKFU"
|
14
|
-
|
15
|
-
Argon2::Password.create("opensesame") == "
|
14
|
+
|
15
|
+
Argon2::Password.create("opensesame") == "opensesame"
|
16
|
+
#=> true
|
17
|
+
|
18
|
+
Argon2::Password.new("$argon2id$v=19$m=19456,t=2,p=1$ZS2nBFWBpnt28HjtzNOW4w$SQ+p+dIcWbpzWpZQ/ZZFj8IQkyhYZf127U4QdkRmKFU") == "opensesame"
|
19
|
+
#=> true
|
16
20
|
```
|
17
21
|
|
18
22
|
## Table of contents
|
@@ -156,16 +160,27 @@ This gem requires the following to run:
|
|
156
160
|
|
157
161
|
### Native gems
|
158
162
|
|
163
|
+
Where possible, a pre-compiled native gem will be provided for the following platforms:
|
164
|
+
|
165
|
+
* Linux
|
166
|
+
* `aarch64-linux` and `arm-linux` (requires [glibc](https://www.gnu.org/software/libc/) 2.29+)
|
167
|
+
* `x86-linux` and `x86_64-linux` (requires [glibc](https://www.gnu.org/software/libc/) 2.17+)
|
168
|
+
* [musl](https://musl.libc.org/)-based systems such as [Alpine](https://alpinelinux.org) are supported as long as a [glibc-compatible library is installed](https://wiki.alpinelinux.org/wiki/Running_glibc_programs)
|
169
|
+
* macOS `x86_64-darwin` and `arm64-darwin`
|
170
|
+
* Windows `x64-mingw32` and `x64-mingw-ucrt`
|
171
|
+
|
172
|
+
### Verifying the gems
|
173
|
+
|
159
174
|
SHA256 checksums are included in the [release
|
160
175
|
notes](https://github.com/mudge/argon2id/releases) for each version and can be
|
161
176
|
checked with `sha256sum`, e.g.
|
162
177
|
|
163
178
|
```console
|
164
|
-
$ gem fetch argon2id -v 0.1.
|
165
|
-
Fetching argon2id-0.1.
|
166
|
-
Downloaded argon2id-0.1.
|
167
|
-
$ sha256sum argon2id-0.1.
|
168
|
-
|
179
|
+
$ gem fetch argon2id -v 0.1.1
|
180
|
+
Fetching argon2id-0.1.1-arm64-darwin.gem
|
181
|
+
Downloaded argon2id-0.1.1-arm64-darwin
|
182
|
+
$ sha256sum argon2id-0.1.1-arm64-darwin.gem
|
183
|
+
8d47464edf847ca52c1d41cac1a9feff376e9a1e7c0a98ab58df846990caa1bb argon2id-0.1.1-arm64-darwin.gem
|
169
184
|
```
|
170
185
|
|
171
186
|
[GPG](https://www.gnupg.org/) signatures are attached to each release (the
|
@@ -175,8 +190,8 @@ from a public keyserver, e.g. `gpg --keyserver keyserver.ubuntu.com --recv-key
|
|
175
190
|
0x39AC3530070E0F75`):
|
176
191
|
|
177
192
|
```console
|
178
|
-
$ gpg --verify argon2id-0.1.
|
179
|
-
gpg: Signature made
|
193
|
+
$ gpg --verify argon2id-0.1.1-arm64-darwin.gem.sig argon2id-0.1.1-arm64-darwin.gem
|
194
|
+
gpg: Signature made Fri 1 Nov 07:24:16 2024 GMT
|
180
195
|
gpg: using RSA key 702609D9C790F45B577D7BEC39AC3530070E0F75
|
181
196
|
gpg: Good signature from "Paul Mucur <mudge@mudge.name>" [unknown]
|
182
197
|
gpg: aka "Paul Mucur <paul@ghostcassette.com>" [unknown]
|
@@ -229,7 +244,7 @@ Issues](https://github.com/mudge/argon2id/issues).
|
|
229
244
|
|
230
245
|
## License
|
231
246
|
|
232
|
-
This library is licensed under the BSD 3-Clause License, see `LICENSE
|
247
|
+
This library is licensed under the BSD 3-Clause License, see `LICENSE`.
|
233
248
|
|
234
249
|
Copyright © 2024, Paul Mucur.
|
235
250
|
|
data/Rakefile
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require "rake/extensiontask"
|
2
2
|
require "rake_compiler_dock"
|
3
|
-
require "
|
3
|
+
require "minitest/test_task"
|
4
4
|
|
5
5
|
CLEAN.add("lib/**/*.{o,so,bundle}", "pkg")
|
6
6
|
|
@@ -27,9 +27,7 @@ Rake::ExtensionTask.new("argon2id", gemspec) do |e|
|
|
27
27
|
e.cross_platform = cross_platforms
|
28
28
|
end
|
29
29
|
|
30
|
-
|
31
|
-
t.warning = true
|
32
|
-
end
|
30
|
+
Minitest::TestTask.create
|
33
31
|
|
34
32
|
begin
|
35
33
|
require "ruby_memcheck"
|
data/argon2id.gemspec
CHANGED
data/ext/argon2id/argon2id.c
CHANGED
@@ -7,6 +7,17 @@
|
|
7
7
|
|
8
8
|
VALUE mArgon2id, cArgon2idError;
|
9
9
|
|
10
|
+
/* call-seq: hash_encoded(t_cost, m_cost, parallelism, pwd, salt, output_len)
|
11
|
+
*
|
12
|
+
* Hashes a password with Argon2id, producing an encoded hash.
|
13
|
+
*
|
14
|
+
* - +t_cost+: number of iterations
|
15
|
+
* - +m_cost+: sets memory usage to +m_cost+ kibibytes
|
16
|
+
* - +parallelism+: number of threads and compute lanes
|
17
|
+
* - +pwd+: the password
|
18
|
+
* - +salt+: the salt
|
19
|
+
* - +output_len+: desired length of the hash in bytes
|
20
|
+
*/
|
10
21
|
static VALUE
|
11
22
|
rb_argon2id_hash_encoded(VALUE module, VALUE iterations, VALUE memory, VALUE threads, VALUE pwd, VALUE salt, VALUE hashlen)
|
12
23
|
{
|
@@ -24,7 +35,7 @@ rb_argon2id_hash_encoded(VALUE module, VALUE iterations, VALUE memory, VALUE thr
|
|
24
35
|
outlen = FIX2INT(hashlen);
|
25
36
|
|
26
37
|
encodedlen = argon2_encodedlen(t_cost, m_cost, parallelism, (uint32_t)RSTRING_LEN(salt), (uint32_t)outlen, Argon2_id);
|
27
|
-
encoded = malloc(encodedlen
|
38
|
+
encoded = malloc(encodedlen);
|
28
39
|
if (!encoded) {
|
29
40
|
rb_raise(rb_eNoMemError, "not enough memory to allocate for encoded password");
|
30
41
|
}
|
@@ -36,19 +47,23 @@ rb_argon2id_hash_encoded(VALUE module, VALUE iterations, VALUE memory, VALUE thr
|
|
36
47
|
rb_raise(cArgon2idError, "%s", argon2_error_message(result));
|
37
48
|
}
|
38
49
|
|
39
|
-
hash =
|
50
|
+
hash = rb_str_new_cstr(encoded);
|
40
51
|
free(encoded);
|
41
52
|
|
42
53
|
return hash;
|
43
54
|
}
|
44
55
|
|
56
|
+
/* call-seq: verify(encoded, pwd)
|
57
|
+
*
|
58
|
+
* Verifies a password against an encoded string.
|
59
|
+
*/
|
45
60
|
static VALUE
|
46
61
|
rb_argon2id_verify(VALUE module, VALUE encoded, VALUE pwd) {
|
47
62
|
int result;
|
48
63
|
|
49
64
|
UNUSED(module);
|
50
65
|
|
51
|
-
result = argon2id_verify(
|
66
|
+
result = argon2id_verify(StringValueCStr(encoded), StringValuePtr(pwd), RSTRING_LEN(pwd));
|
52
67
|
if (result == ARGON2_OK) {
|
53
68
|
return Qtrue;
|
54
69
|
}
|
data/lib/2.6/argon2id.so
CHANGED
Binary file
|
data/lib/2.7/argon2id.so
CHANGED
Binary file
|
data/lib/3.0/argon2id.so
CHANGED
Binary file
|
data/lib/argon2id/password.rb
CHANGED
@@ -3,9 +3,42 @@
|
|
3
3
|
require "openssl"
|
4
4
|
|
5
5
|
module Argon2id
|
6
|
+
# The Password class encapsulates an encoded Argon2id password hash.
|
7
|
+
#
|
8
|
+
# To hash a plain text password, use Argon2id::Password.create:
|
9
|
+
#
|
10
|
+
# password = Argon2id::Password.create("password")
|
11
|
+
# password.to_s
|
12
|
+
# #=> "$argon2id$v=19$m=19456,t=2,p=1$+Lrjry9Ifq0poLr15OGU1Q$utkDvejJB0ugwm4s9+a+vF6+1a/W+Y3CYa5Wte/85ig"
|
13
|
+
#
|
14
|
+
# To verify an encoded Argon2id password hash, use Argon2id::Password.new:
|
15
|
+
#
|
16
|
+
# password = Argon2id::Password.new("$argon2id$v=19$m=19456,t=2,p=1$+Lrjry9Ifq0poLr15OGU1Q$utkDvejJB0ugwm4s9+a+vF6+1a/W+Y3CYa5Wte/85ig")
|
17
|
+
# password == "password"
|
18
|
+
# #=> true
|
6
19
|
class Password
|
20
|
+
# The encoded password hash.
|
7
21
|
attr_reader :encoded
|
8
22
|
|
23
|
+
# Create a new Password object that hashes a given plain text password +pwd+.
|
24
|
+
#
|
25
|
+
# - +:t_cost+: integer (default 2) the "time cost" given as a number of iterations
|
26
|
+
# - +:m_cost+: integer (default 19456) the "memory cost" given in kibibytes
|
27
|
+
# - +:parallelism+: integer (default 1) the number of threads and compute lanes to use
|
28
|
+
# - +:salt_len+: integer (default 16) the salt size in bytes
|
29
|
+
# - +:output_len+: integer (default 32) the desired length of the hash in bytes
|
30
|
+
#
|
31
|
+
# For example, with the default configuration:
|
32
|
+
#
|
33
|
+
# password = Argon2id::Password.create("password")
|
34
|
+
# password.to_s
|
35
|
+
# #=> "$argon2id$v=19$m=19456,t=2,p=1$FI8yp1gXbthJCskBlpKPoQ$nOfCCpS2r+I8GRN71cZND4cskn7YKBNzuHUEO3YpY2s"
|
36
|
+
#
|
37
|
+
# When overriding the configuration:
|
38
|
+
#
|
39
|
+
# password = Argon2id::Password.create("password", t_cost: 3, m_cost: 12288)
|
40
|
+
# password.to_s
|
41
|
+
# #=> "$argon2id$v=19$m=12288,t=3,p=1$JigW7fFn+N3NImt+aWpuzw$eM5F1cKeIBALNTU6LuWra75Zi2nymGvQLWzJzVFv0Nc"
|
9
42
|
def self.create(pwd, t_cost: Argon2id.t_cost, m_cost: Argon2id.m_cost, parallelism: Argon2id.parallelism, salt_len: Argon2id.salt_len, output_len: Argon2id.output_len)
|
10
43
|
new(
|
11
44
|
Argon2id.hash_encoded(
|
@@ -19,14 +52,26 @@ module Argon2id
|
|
19
52
|
)
|
20
53
|
end
|
21
54
|
|
55
|
+
# call-seq: Argon2id::Password.new(encoded)
|
56
|
+
#
|
57
|
+
# Create a new Password with the given encoded password hash.
|
58
|
+
#
|
59
|
+
# password = Argon2id::Password.new("$argon2id$v=19$m=19456,t=2,p=1$FI8yp1gXbthJCskBlpKPoQ$nOfCCpS2r+I8GRN71cZND4cskn7YKBNzuHUEO3YpY2s")
|
22
60
|
def initialize(encoded)
|
23
61
|
@encoded = encoded
|
24
62
|
end
|
25
63
|
|
64
|
+
# Return the encoded password hash.
|
26
65
|
def to_s
|
27
66
|
encoded
|
28
67
|
end
|
29
68
|
|
69
|
+
# Compare the password with given plain text, returning true if it verifies
|
70
|
+
# successfully.
|
71
|
+
#
|
72
|
+
# password = Argon2id::Password.new("$argon2id$v=19$m=19456,t=2,p=1$FI8yp1gXbthJCskBlpKPoQ$nOfCCpS2r+I8GRN71cZND4cskn7YKBNzuHUEO3YpY2s")
|
73
|
+
# password == "password" #=> true
|
74
|
+
# password == "notpassword" #=> false
|
30
75
|
def ==(other)
|
31
76
|
Argon2id.verify(encoded, String(other))
|
32
77
|
end
|
data/lib/argon2id/version.rb
CHANGED
data/lib/argon2id.rb
CHANGED
@@ -11,10 +11,19 @@ require "argon2id/version"
|
|
11
11
|
require "argon2id/password"
|
12
12
|
|
13
13
|
module Argon2id
|
14
|
+
# The default "time cost" of 2 iterations recommended by OWASP.
|
14
15
|
DEFAULT_T_COST = 2
|
16
|
+
|
17
|
+
# The default "memory cost" of 19 mebibytes recommended by OWASP.
|
15
18
|
DEFAULT_M_COST = 19456
|
19
|
+
|
20
|
+
# The default 1 thread and compute lane recommended by OWASP.
|
16
21
|
DEFAULT_PARALLELISM = 1
|
22
|
+
|
23
|
+
# The default salt length of 16 bytes.
|
17
24
|
DEFAULT_SALT_LEN = 16
|
25
|
+
|
26
|
+
# The default desired hash length of 32 bytes.
|
18
27
|
DEFAULT_OUTPUT_LEN = 32
|
19
28
|
|
20
29
|
@t_cost = DEFAULT_T_COST
|
@@ -24,6 +33,19 @@ module Argon2id
|
|
24
33
|
@output_len = DEFAULT_OUTPUT_LEN
|
25
34
|
|
26
35
|
class << self
|
27
|
-
|
36
|
+
# The default number of iterations used by Argon2id::Password.create
|
37
|
+
attr_accessor :t_cost
|
38
|
+
|
39
|
+
# The default memory cost in kibibytes used by Argon2id::Password.create
|
40
|
+
attr_accessor :m_cost
|
41
|
+
|
42
|
+
# The default number of threads and compute lanes used by Argon2id::Password.create
|
43
|
+
attr_accessor :parallelism
|
44
|
+
|
45
|
+
# The default salt size in bytes used by Argon2id::Password.create
|
46
|
+
attr_accessor :salt_len
|
47
|
+
|
48
|
+
# The default desired length of the hash in bytes used by Argon2id::Password.create
|
49
|
+
attr_accessor :output_len
|
28
50
|
end
|
29
51
|
end
|
data/test/test_hash_encoded.rb
CHANGED
@@ -5,34 +5,28 @@ require "argon2id"
|
|
5
5
|
|
6
6
|
class TestHashEncoded < Minitest::Test
|
7
7
|
def test_valid_password_and_salt_encodes_successfully
|
8
|
-
encoded = Argon2id.hash_encoded(2,
|
8
|
+
encoded = Argon2id.hash_encoded(2, 256, 1, "password", "somesalt", 32)
|
9
9
|
|
10
|
-
|
10
|
+
assert_equal "$argon2id$v=19$m=256,t=2,p=1$c29tZXNhbHQ$nf65EOgLrQMR/uIPnA4rEsF5h7TKyQwu9U1bMCHGi/4", encoded
|
11
11
|
end
|
12
12
|
|
13
13
|
def test_valid_password_does_not_include_trailing_null_byte
|
14
|
-
encoded = Argon2id.hash_encoded(2,
|
14
|
+
encoded = Argon2id.hash_encoded(2, 256, 1, "password", "somesalt", 32)
|
15
15
|
|
16
16
|
refute encoded.end_with?("\x00")
|
17
17
|
end
|
18
18
|
|
19
19
|
def test_raises_with_too_short_output
|
20
20
|
error = assert_raises(Argon2id::Error) do
|
21
|
-
Argon2id.hash_encoded(2,
|
21
|
+
Argon2id.hash_encoded(2, 256, 1, "password", "somesalt", 1)
|
22
22
|
end
|
23
23
|
|
24
24
|
assert_equal "Output is too short", error.message
|
25
25
|
end
|
26
26
|
|
27
|
-
def test_raises_with_too_large_output
|
28
|
-
assert_raises(RangeError) do
|
29
|
-
Argon2id.hash_encoded(2, 19456, 1, "opensesame", OpenSSL::Random.random_bytes(16), 4294967296)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
27
|
def test_raises_with_too_few_lanes
|
34
28
|
error = assert_raises(Argon2id::Error) do
|
35
|
-
Argon2id.hash_encoded(2,
|
29
|
+
Argon2id.hash_encoded(2, 256, 0, "password", "somesalt", 32)
|
36
30
|
end
|
37
31
|
|
38
32
|
assert_equal "Too few lanes", error.message
|
@@ -40,51 +34,25 @@ class TestHashEncoded < Minitest::Test
|
|
40
34
|
|
41
35
|
def test_raises_with_too_small_memory_cost
|
42
36
|
error = assert_raises(Argon2id::Error) do
|
43
|
-
Argon2id.hash_encoded(2, 0, 1, "
|
37
|
+
Argon2id.hash_encoded(2, 0, 1, "password", "somesalt", 32)
|
44
38
|
end
|
45
39
|
|
46
40
|
assert_equal "Memory cost is too small", error.message
|
47
41
|
end
|
48
42
|
|
49
|
-
def test_raises_with_too_large_memory_cost
|
50
|
-
assert_raises(RangeError) do
|
51
|
-
Argon2id.hash_encoded(2, 4294967296, 1, "opensesame", OpenSSL::Random.random_bytes(16), 32)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
43
|
def test_raises_with_too_small_time_cost
|
56
44
|
error = assert_raises(Argon2id::Error) do
|
57
|
-
Argon2id.hash_encoded(0,
|
45
|
+
Argon2id.hash_encoded(0, 256, 1, "password", "somesalt", 32)
|
58
46
|
end
|
59
47
|
|
60
48
|
assert_equal "Time cost is too small", error.message
|
61
49
|
end
|
62
50
|
|
63
|
-
def test_raises_with_too_large_time_cost
|
64
|
-
assert_raises(RangeError) do
|
65
|
-
Argon2id.hash_encoded(4294967296, 19456, 1, "opensesame", OpenSSL::Random.random_bytes(16), 32)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
def test_raises_with_too_long_password
|
70
|
-
error = assert_raises(Argon2id::Error) do
|
71
|
-
Argon2id.hash_encoded(2, 19456, 1, "a" * 4294967296, OpenSSL::Random.random_bytes(16), 32)
|
72
|
-
end
|
73
|
-
|
74
|
-
assert_equal "Password is too long", error.message
|
75
|
-
end
|
76
|
-
|
77
51
|
def test_raises_with_too_short_salt
|
78
52
|
error = assert_raises(Argon2id::Error) do
|
79
|
-
Argon2id.hash_encoded(
|
53
|
+
Argon2id.hash_encoded(0, 256, 1, "password", "", 32)
|
80
54
|
end
|
81
55
|
|
82
56
|
assert_equal "Salt is too short", error.message
|
83
57
|
end
|
84
|
-
|
85
|
-
def test_raises_with_too_long_salt
|
86
|
-
assert_raises(RangeError) do
|
87
|
-
Argon2id.hash_encoded(2, 19456, 1, "opensesame", OpenSSL::Random.random_bytes(4294967296), 32)
|
88
|
-
end
|
89
|
-
end
|
90
58
|
end
|
data/test/test_password.rb
CHANGED
@@ -13,33 +13,33 @@ class TestPassword < Minitest::Test
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def test_create_options_can_override_parameters
|
16
|
-
password = Argon2id::Password.create("opensesame", t_cost:
|
16
|
+
password = Argon2id::Password.create("opensesame", t_cost: 2, m_cost: 256)
|
17
17
|
|
18
|
-
assert password.to_s.include?("t=
|
19
|
-
assert password.to_s.include?("m=
|
18
|
+
assert password.to_s.include?("t=2")
|
19
|
+
assert password.to_s.include?("m=256")
|
20
20
|
end
|
21
21
|
|
22
22
|
def test_create_uses_argon2id_configuration
|
23
|
-
Argon2id.
|
24
|
-
Argon2id.m_cost =
|
23
|
+
Argon2id.t_cost = 2
|
24
|
+
Argon2id.m_cost = 256
|
25
25
|
|
26
26
|
password = Argon2id::Password.create("opensesame")
|
27
27
|
|
28
|
-
assert password.to_s.include?("
|
29
|
-
assert password.to_s.include?("m=
|
28
|
+
assert password.to_s.include?("t=2")
|
29
|
+
assert password.to_s.include?("m=256")
|
30
30
|
ensure
|
31
|
-
Argon2id.
|
31
|
+
Argon2id.t_cost = Argon2id::DEFAULT_T_COST
|
32
32
|
Argon2id.m_cost = Argon2id::DEFAULT_M_COST
|
33
33
|
end
|
34
34
|
|
35
35
|
def test_create_coerces_pwd_to_string
|
36
|
-
password = Argon2id::Password.create(123)
|
36
|
+
password = Argon2id::Password.create(123, t_cost: 2, m_cost: 256)
|
37
37
|
|
38
38
|
assert password.to_s.start_with?("$argon2id$")
|
39
39
|
end
|
40
40
|
|
41
41
|
def test_create_coerces_costs_to_integer
|
42
|
-
password = Argon2id::Password.create("opensesame", t_cost: "
|
42
|
+
password = Argon2id::Password.create("opensesame", t_cost: "2", m_cost: "256", parallelism: "1", salt_len: "8", output_len: "32")
|
43
43
|
|
44
44
|
assert password.to_s.start_with?("$argon2id$")
|
45
45
|
end
|
@@ -51,25 +51,25 @@ class TestPassword < Minitest::Test
|
|
51
51
|
end
|
52
52
|
|
53
53
|
def test_equals_correct_password
|
54
|
-
password = Argon2id::Password.create("opensesame")
|
54
|
+
password = Argon2id::Password.create("opensesame", t_cost: 2, m_cost: 256)
|
55
55
|
|
56
56
|
assert password == "opensesame"
|
57
57
|
end
|
58
58
|
|
59
59
|
def test_does_not_equal_invalid_password
|
60
|
-
password = Argon2id::Password.create("opensesame")
|
60
|
+
password = Argon2id::Password.create("opensesame", t_cost: 2, m_cost: 256)
|
61
61
|
|
62
62
|
refute password == "notopensesame"
|
63
63
|
end
|
64
64
|
|
65
65
|
def test_is_password_returns_true_with_correct_password
|
66
|
-
password = Argon2id::Password.create("opensesame")
|
66
|
+
password = Argon2id::Password.create("opensesame", t_cost: 2, m_cost: 256)
|
67
67
|
|
68
68
|
assert password.is_password?("opensesame")
|
69
69
|
end
|
70
70
|
|
71
71
|
def test_is_password_returns_false_with_incorrect_password
|
72
|
-
password = Argon2id::Password.create("opensesame")
|
72
|
+
password = Argon2id::Password.create("opensesame", t_cost: 2, m_cost: 256)
|
73
73
|
|
74
74
|
refute password.is_password?("notopensesame")
|
75
75
|
end
|
data/test/test_verify.rb
CHANGED
@@ -5,15 +5,17 @@ require "argon2id"
|
|
5
5
|
|
6
6
|
class TestVerify < Minitest::Test
|
7
7
|
def test_returns_true_with_correct_password
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
assert Argon2id.verify(
|
9
|
+
"$argon2id$v=19$m=256,t=2,p=1$c29tZXNhbHQ$nf65EOgLrQMR/uIPnA4rEsF5h7TKyQwu9U1bMCHGi/4",
|
10
|
+
"password"
|
11
|
+
)
|
11
12
|
end
|
12
13
|
|
13
14
|
def test_returns_false_with_incorrect_password
|
14
|
-
|
15
|
-
|
16
|
-
|
15
|
+
refute Argon2id.verify(
|
16
|
+
"$argon2id$v=19$m=256,t=2,p=1$c29tZXNhbHQ$nf65EOgLrQMR/uIPnA4rEsF5h7TKyQwu9U1bMCHGi/4",
|
17
|
+
"not password"
|
18
|
+
)
|
17
19
|
end
|
18
20
|
|
19
21
|
def test_raises_if_given_invalid_encoded
|
@@ -21,4 +23,13 @@ class TestVerify < Minitest::Test
|
|
21
23
|
Argon2id.verify("", "opensesame")
|
22
24
|
end
|
23
25
|
end
|
26
|
+
|
27
|
+
def test_raises_if_given_encoded_with_null_byte
|
28
|
+
assert_raises(ArgumentError) do
|
29
|
+
Argon2id.verify(
|
30
|
+
"$argon2id$v=19$m=256,t=2,p=1$c29tZXNhbHQ$nf65EOgLrQMR/uIPnA4rEsF5h7TKyQwu9U1bMCHGi/4\x00foo",
|
31
|
+
"password"
|
32
|
+
)
|
33
|
+
end
|
34
|
+
end
|
24
35
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: argon2id
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: x64-mingw32
|
6
6
|
authors:
|
7
7
|
- Paul Mucur
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-11-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake-compiler
|
@@ -102,7 +102,9 @@ metadata:
|
|
102
102
|
source_code_uri: https://github.com/mudge/argon2id
|
103
103
|
rubygems_mfa_required: 'true'
|
104
104
|
post_install_message:
|
105
|
-
rdoc_options:
|
105
|
+
rdoc_options:
|
106
|
+
- "--main"
|
107
|
+
- README.md
|
106
108
|
require_paths:
|
107
109
|
- lib
|
108
110
|
required_ruby_version: !ruby/object:Gem::Requirement
|