argon2id 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1cbfe6e1fff46bce5e83b604a87c72e014df1e9884e08fc88847650a0bac0f82
4
- data.tar.gz: 25a079c7dbdbdb398c837f7363333eeb21c927899a5d1973150dab73935c3082
3
+ metadata.gz: 6f52b40e15650850965678538bc94eb2aa34da651e62e536da3bbca058e3d2c3
4
+ data.tar.gz: 852859c505d84f7ec6bfd0045d1c1bafe52c24e1c59ef52ccca5e997cfe48aa3
5
5
  SHA512:
6
- metadata.gz: ab1b69ae47a978396ceb06e1d03e775feca9ed5b87dd1acc837a1b9e7380356072256e954b70b8ee649a72de411f7932ca5868bf5a9c3ba216aa9fef65d4694e
7
- data.tar.gz: 71a2a80d4f68efd022348bfb1fa213cb77abb7411f41f6905f040b73b3bc38aa7f7fbd6ed2750442da653592ad62cb7de9d13e5c7a1c6ebf2c25357e1b1e1acc
6
+ metadata.gz: e89d4b69c0b98da64ff04c4dc15496ffe8cd11418fd4e466dcf382eca137b65b2301ad4c56f62a4387938067b4346269f7c6408d0ac498f6ef7359fe2224e3de
7
+ data.tar.gz: 9a31d89ff9bbd79294342c269c53ffd22574135ccde8c96c4efe99d772da1265a479964d031c0d6cd7e3b6923a383d0497dda78da6562faadc7f1af85f6ce1da
data/CHANGELOG.md CHANGED
@@ -5,6 +5,12 @@ 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.6.0] - 2024-11-05
9
+
10
+ ### Changed
11
+
12
+ - Move the internal API to `Argon2id::Password` and make it explicitly private
13
+
8
14
  ## [0.5.0] - 2024-11-02
9
15
 
10
16
  ### Removed
@@ -93,6 +99,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
93
99
  reference C implementation of Argon2, the password-hashing function that won
94
100
  the Password Hashing Competition.
95
101
 
102
+ [0.6.0]: https://github.com/mudge/argon2id/releases/tag/v0.6.0
96
103
  [0.5.0]: https://github.com/mudge/argon2id/releases/tag/v0.5.0
97
104
  [0.4.1]: https://github.com/mudge/argon2id/releases/tag/v0.4.1
98
105
  [0.4.0]: https://github.com/mudge/argon2id/releases/tag/v0.4.0
data/README.md CHANGED
@@ -5,7 +5,7 @@ Ruby bindings to [Argon2][], the password-hashing function that won the 2015
5
5
 
6
6
  [![Build Status](https://github.com/mudge/argon2id/actions/workflows/tests.yml/badge.svg?branch=main)](https://github.com/mudge/argon2id/actions)
7
7
 
8
- **Current version:** 0.5.0
8
+ **Current version:** 0.6.0
9
9
  **Bundled Argon2 version:** libargon2.1 (20190702)
10
10
 
11
11
  ```ruby
@@ -201,11 +201,11 @@ notes](https://github.com/mudge/argon2id/releases) for each version and can be
201
201
  checked with `sha256sum`, e.g.
202
202
 
203
203
  ```console
204
- $ gem fetch argon2id -v 0.4.1
205
- Fetching argon2id-0.4.1-arm64-darwin.gem
206
- Downloaded argon2id-0.4.1-arm64-darwin
207
- $ sha256sum argon2id-0.4.1-arm64-darwin.gem
208
- c74c06c2c4ce70d6c3822f05d83bab4ea431dd16ec086c9c856da3c6e0d9bbe9 argon2id-0.4.1-arm64-darwin.gem
204
+ $ gem fetch argon2id -v 0.5.0
205
+ Fetching argon2id-0.5.0-arm64-darwin.gem
206
+ Downloaded argon2id-0.5.0-arm64-darwin
207
+ $ sha256sum argon2id-0.5.0-arm64-darwin.gem
208
+ 871e9d9bcad09e75620ce9ddd32cd99a4ebc3a6db1516e487680787faa7368a3 argon2id-0.5.0-arm64-darwin.gem
209
209
  ```
210
210
 
211
211
  [GPG](https://www.gnupg.org/) signatures are attached to each release (the
@@ -215,8 +215,8 @@ from a public keyserver, e.g. `gpg --keyserver keyserver.ubuntu.com --recv-key
215
215
  0x39AC3530070E0F75`):
216
216
 
217
217
  ```console
218
- $ gpg --verify argon2id-0.4.1-arm64-darwin.gem.sig argon2id-0.4.1-arm64-darwin.gem
219
- gpg: Signature made Sat 2 Nov 20:50:54 2024 GMT
218
+ $ gpg --verify argon2id-0.5.0-arm64-darwin.gem.sig argon2id-0.5.0-arm64-darwin.gem
219
+ gpg: Signature made Sat 2 Nov 21:09:51 2024 GMT
220
220
  gpg: using RSA key 702609D9C790F45B577D7BEC39AC3530070E0F75
221
221
  gpg: Good signature from "Paul Mucur <mudge@mudge.name>" [unknown]
222
222
  gpg: aka "Paul Mucur <paul@ghostcassette.com>" [unknown]
data/Rakefile CHANGED
@@ -20,16 +20,20 @@ ENV["RUBY_CC_VERSION"] = %w[3.3.0 3.2.0 3.1.0 3.0.0 2.7.0 2.6.0].join(":")
20
20
 
21
21
  gemspec = Gem::Specification.load("argon2id.gemspec")
22
22
 
23
- if RUBY_PLATFORM == "java"
24
- gemspec.files.reject! { |path| File.fnmatch?("ext/*", path) }
25
- gemspec.extensions.clear
26
- gemspec.platform = Gem::Platform.new("java")
27
- gemspec.required_ruby_version = ">= 3.1.0"
28
- end
29
-
30
23
  Gem::PackageTask.new(gemspec).define
31
24
 
25
+ namespace :java do
26
+ java_gemspec = gemspec.dup
27
+ java_gemspec.files.reject! { |path| File.fnmatch?("ext/*", path) }
28
+ java_gemspec.extensions.clear
29
+ java_gemspec.platform = Gem::Platform.new("java")
30
+ java_gemspec.required_ruby_version = ">= 3.1.0"
31
+
32
+ Gem::PackageTask.new(java_gemspec).define
33
+ end
34
+
32
35
  Rake::ExtensionTask.new("argon2id", gemspec) do |e|
36
+ e.lib_dir = "lib/argon2id"
33
37
  e.cross_compile = true
34
38
  e.cross_platform = cross_platforms
35
39
  end
@@ -57,15 +61,6 @@ namespace :gem do
57
61
  SCRIPT
58
62
  end
59
63
  end
60
-
61
- desc "Compile gem for JRuby"
62
- task :jruby do
63
- RakeCompilerDock.sh <<~SCRIPT, rubyvm: "jruby", platform: "jruby", verbose: true
64
- gem install bundler --no-document &&
65
- bundle &&
66
- bundle exec rake gem
67
- SCRIPT
68
- end
69
64
  end
70
65
 
71
66
  task default: [:compile, :test]
data/argon2id.gemspec CHANGED
@@ -45,11 +45,10 @@ Gem::Specification.new do |s|
45
45
  "ext/argon2id/libargon2/thread.c",
46
46
  "ext/argon2id/libargon2/thread.h",
47
47
  "lib/argon2id.rb",
48
+ "lib/argon2id/extension.rb",
48
49
  "lib/argon2id/password.rb",
49
50
  "lib/argon2id/version.rb",
50
- "test/test_hash_encoded.rb",
51
- "test/test_password.rb",
52
- "test/test_verify.rb"
51
+ "test/test_password.rb"
53
52
  ]
54
53
  s.rdoc_options = ["--main", "README.md"]
55
54
 
@@ -5,21 +5,11 @@
5
5
 
6
6
  #define UNUSED(x) (void)(x)
7
7
 
8
- VALUE mArgon2id, cArgon2idError;
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
- */
8
+ VALUE mArgon2id, cArgon2idError, cArgon2idPassword;
9
+ ID id_encoded;
10
+
21
11
  static VALUE
22
- rb_argon2id_hash_encoded(VALUE module, VALUE iterations, VALUE memory, VALUE threads, VALUE pwd, VALUE salt, VALUE hashlen)
12
+ rb_argon2id_hash_encoded(VALUE klass, VALUE iterations, VALUE memory, VALUE threads, VALUE pwd, VALUE salt, VALUE hashlen)
23
13
  {
24
14
  uint32_t t_cost, m_cost, parallelism;
25
15
  size_t encodedlen, outlen;
@@ -27,7 +17,7 @@ rb_argon2id_hash_encoded(VALUE module, VALUE iterations, VALUE memory, VALUE thr
27
17
  int result;
28
18
  VALUE hash;
29
19
 
30
- UNUSED(module);
20
+ UNUSED(klass);
31
21
 
32
22
  t_cost = FIX2INT(iterations);
33
23
  m_cost = FIX2INT(memory);
@@ -53,16 +43,12 @@ rb_argon2id_hash_encoded(VALUE module, VALUE iterations, VALUE memory, VALUE thr
53
43
  return hash;
54
44
  }
55
45
 
56
- /* call-seq: verify(encoded, pwd)
57
- *
58
- * Verifies a password against an encoded string.
59
- */
60
46
  static VALUE
61
- rb_argon2id_verify(VALUE module, VALUE encoded, VALUE pwd) {
47
+ rb_argon2id_verify(VALUE self, VALUE pwd) {
62
48
  int result;
49
+ VALUE encoded;
63
50
 
64
- UNUSED(module);
65
-
51
+ encoded = rb_ivar_get(self, id_encoded);
66
52
  result = argon2id_verify(StringValueCStr(encoded), StringValuePtr(pwd), RSTRING_LEN(pwd));
67
53
  if (result == ARGON2_OK) {
68
54
  return Qtrue;
@@ -80,8 +66,11 @@ rb_argon2id_verify(VALUE module, VALUE encoded, VALUE pwd) {
80
66
  void
81
67
  Init_argon2id(void)
82
68
  {
69
+ id_encoded = rb_intern("@encoded");
70
+
83
71
  mArgon2id = rb_define_module("Argon2id");
84
72
  cArgon2idError = rb_define_class_under(mArgon2id, "Error", rb_eStandardError);
85
- rb_define_singleton_method(mArgon2id, "hash_encoded", rb_argon2id_hash_encoded, 6);
86
- rb_define_singleton_method(mArgon2id, "verify", rb_argon2id_verify, 2);
73
+ cArgon2idPassword = rb_define_class_under(mArgon2id, "Password", rb_cObject);
74
+ rb_define_private_method(rb_singleton_class(cArgon2idPassword), "hash_encoded", rb_argon2id_hash_encoded, 6);
75
+ rb_define_private_method(cArgon2idPassword, "verify", rb_argon2id_verify, 1);
87
76
  }
@@ -14,4 +14,4 @@ $CPPFLAGS << " " << "-I$(srcdir)/libargon2"
14
14
  have_header("stdint.h")
15
15
  have_header("argon2.h")
16
16
 
17
- create_makefile "argon2id"
17
+ create_makefile "argon2id/argon2id"
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+
3
+ if RUBY_PLATFORM == "java"
4
+ require "java"
5
+ require "openssl"
6
+
7
+ module Argon2id
8
+ Error = Class.new(StandardError)
9
+
10
+ class Password
11
+ def self.hash_encoded(t_cost, m_cost, parallelism, pwd, salt, hashlen)
12
+ raise Error, "Salt is too short" if salt.empty?
13
+
14
+ salt_bytes = salt.to_java_bytes
15
+ output = Java::byte[hashlen].new
16
+ params = Java::OrgBouncycastleCryptoParams::Argon2Parameters::Builder
17
+ .new(Java::OrgBouncycastleCryptoParams::Argon2Parameters::ARGON2_id)
18
+ .with_salt(salt_bytes)
19
+ .with_parallelism(parallelism)
20
+ .with_memory_as_kb(m_cost)
21
+ .with_iterations(t_cost)
22
+ .build
23
+ generator = Java::OrgBouncycastleCryptoGenerators::Argon2BytesGenerator.new
24
+
25
+ generator.init(params)
26
+ generator.generate_bytes(pwd.to_java_bytes, output)
27
+
28
+ encoder = Java::JavaUtil::Base64.get_encoder.without_padding
29
+ encoded_salt = encoder.encode_to_string(salt_bytes)
30
+ encoded_output = encoder.encode_to_string(output)
31
+
32
+ "$argon2id$v=19$m=#{m_cost},t=#{t_cost},p=#{parallelism}" \
33
+ "$#{encoded_salt}$#{encoded_output}"
34
+ rescue Java::JavaLang::IllegalStateException => e
35
+ raise Error, e.message
36
+ end
37
+
38
+ private_class_method :hash_encoded
39
+
40
+ private
41
+
42
+ def verify(pwd)
43
+ other_output = Java::byte[output.bytesize].new
44
+ params = Java::OrgBouncycastleCryptoParams::Argon2Parameters::Builder
45
+ .new(Java::OrgBouncycastleCryptoParams::Argon2Parameters::ARGON2_id)
46
+ .with_salt(salt.to_java_bytes)
47
+ .with_parallelism(parallelism)
48
+ .with_memory_as_kb(m_cost)
49
+ .with_iterations(t_cost)
50
+ .build
51
+ generator = Java::OrgBouncycastleCryptoGenerators::Argon2BytesGenerator.new
52
+ generator.init(params)
53
+ generator.generate_bytes(pwd.to_java_bytes, other_output)
54
+
55
+ Java::OrgBouncycastleUtil::Arrays.constant_time_are_equal?(
56
+ output.to_java_bytes,
57
+ other_output
58
+ )
59
+ end
60
+ end
61
+ end
62
+ else
63
+ begin
64
+ ::RUBY_VERSION =~ /(\d+\.\d+)/
65
+ require_relative "#{Regexp.last_match(1)}/argon2id"
66
+ rescue LoadError
67
+ require "argon2id/argon2id"
68
+ end
69
+ end
@@ -89,7 +89,7 @@ module Argon2id
89
89
  # #=> "$argon2id$v=19$m=12288,t=3,p=1$JigW7fFn+N3NImt+aWpuzw$eM5F1cKeIBALNTU6LuWra75Zi2nymGvQLWzJzVFv0Nc"
90
90
  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)
91
91
  new(
92
- Argon2id.hash_encoded(
92
+ hash_encoded(
93
93
  Integer(t_cost),
94
94
  Integer(m_cost),
95
95
  Integer(parallelism),
@@ -127,7 +127,7 @@ module Argon2id
127
127
  # password == "password" #=> true
128
128
  # password == "notpassword" #=> false
129
129
  def ==(other)
130
- Argon2id.verify(encoded, String(other))
130
+ verify(String(other))
131
131
  end
132
132
 
133
133
  alias_method :is_password?, :==
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Argon2id
4
- VERSION = "0.5.0"
4
+ VERSION = "0.6.0"
5
5
  end
data/lib/argon2id.rb CHANGED
@@ -1,18 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- if RUBY_PLATFORM == "java"
4
- require "openssl"
5
- else
6
- begin
7
- ::RUBY_VERSION =~ /(\d+\.\d+)/
8
- require_relative "#{Regexp.last_match(1)}/argon2id.so"
9
- rescue LoadError
10
- require "argon2id.so"
11
- end
12
- end
13
-
14
- require "argon2id/version"
3
+ require "argon2id/extension"
15
4
  require "argon2id/password"
5
+ require "argon2id/version"
16
6
 
17
7
  module Argon2id
18
8
  # The default "time cost" of 2 iterations recommended by OWASP.
@@ -52,57 +42,4 @@ module Argon2id
52
42
  # The default desired length of the hash in bytes used by Argon2id::Password.create
53
43
  attr_accessor :output_len
54
44
  end
55
-
56
- if RUBY_PLATFORM == "java"
57
- Error = Class.new(StandardError)
58
-
59
- def self.hash_encoded(t_cost, m_cost, parallelism, pwd, salt, hashlen)
60
- output = hash_raw(t_cost, m_cost, parallelism, pwd, salt, hashlen)
61
-
62
- encoder = Java::JavaUtil::Base64.get_encoder.without_padding
63
- encoded_salt = encoder.encode_to_string(salt.to_java_bytes)
64
- encoded_output = encoder.encode_to_string(output)
65
-
66
- "$argon2id$v=19$m=#{Integer(m_cost)},t=#{Integer(t_cost)}," \
67
- "p=#{Integer(parallelism)}$#{encoded_salt}$#{encoded_output}"
68
- end
69
-
70
- def self.verify(encoded, pwd)
71
- password = Password.new(encoded)
72
- other_raw = hash_raw(
73
- password.t_cost,
74
- password.m_cost,
75
- password.parallelism,
76
- String(pwd),
77
- password.salt,
78
- password.output.bytesize
79
- )
80
-
81
- Java::OrgBouncycastleUtil::Arrays.constant_time_are_equal(
82
- password.output.to_java_bytes,
83
- other_raw
84
- )
85
- end
86
-
87
- def self.hash_raw(t_cost, m_cost, parallelism, pwd, salt, hashlen)
88
- raise Error, "Salt is too short" if String(salt).empty?
89
-
90
- hash = Java::byte[Integer(hashlen)].new
91
- params = Java::OrgBouncycastleCryptoParams::Argon2Parameters::Builder
92
- .new(Java::OrgBouncycastleCryptoParams::Argon2Parameters::ARGON2_id)
93
- .with_salt(String(salt).to_java_bytes)
94
- .with_parallelism(Integer(parallelism))
95
- .with_memory_as_kb(Integer(m_cost))
96
- .with_iterations(Integer(t_cost))
97
- .build
98
- generator = Java::OrgBouncycastleCryptoGenerators::Argon2BytesGenerator.new
99
-
100
- generator.init(params)
101
- generator.generate_bytes(String(pwd).to_java_bytes, hash)
102
-
103
- hash
104
- rescue Java::JavaLang::IllegalStateException => e
105
- raise Error, e.message
106
- end
107
- end
108
45
  end
@@ -98,6 +98,12 @@ class TestPassword < Minitest::Test
98
98
  end
99
99
  end
100
100
 
101
+ def test_raises_for_hashes_with_null_bytes
102
+ assert_raises(ArgumentError) do
103
+ Argon2id::Password.new("$argon2id$v=19$m=256,t=2,p=1$c29tZXNhbHQ$nf65EOgLrQMR/uIPnA4rEsF5h7TKyQwu9U1bMCHGi/4\x00foo")
104
+ end
105
+ end
106
+
101
107
  def test_raises_for_non_argon2id_hashes
102
108
  assert_raises(ArgumentError) do
103
109
  Argon2id::Password.new("$argon2i$v=19$m=256,t=2,p=1$c29tZXNhbHQ$iekCn0Y3spW+sCcFanM2xBT63UP2sghkUoHLIUpWRS8")
@@ -169,4 +175,58 @@ class TestPassword < Minitest::Test
169
175
 
170
176
  assert_equal "\x9D\xFE\xB9\x10\xE8\v\xAD\x03\x11\xFE\xE2\x0F\x9C\x0E+\x12\xC1y\x87\xB4\xCA\xC9\f.\xF5M[0!\xC6\x8B\xFE".b, password.output
171
177
  end
178
+
179
+ def test_libargon2_test_case_1
180
+ password = Argon2id::Password.new("$argon2id$v=19$m=256,t=2,p=1$c29tZXNhbHQ$nf65EOgLrQMR/uIPnA4rEsF5h7TKyQwu9U1bMCHGi/4")
181
+
182
+ assert password == "password"
183
+ end
184
+
185
+ def test_libargon2_test_case_1_returns_false_with_incorrect_password
186
+ password = Argon2id::Password.new("$argon2id$v=19$m=256,t=2,p=1$c29tZXNhbHQ$nf65EOgLrQMR/uIPnA4rEsF5h7TKyQwu9U1bMCHGi/4")
187
+
188
+ refute password == "not password"
189
+ end
190
+
191
+ def test_libargon2_test_case_2
192
+ password = Argon2id::Password.new("$argon2id$v=19$m=256,t=2,p=2$c29tZXNhbHQ$bQk8UB/VmZZF4Oo79iDXuL5/0ttZwg2f/5U52iv1cDc")
193
+
194
+ assert password == "password"
195
+ end
196
+
197
+ def test_encoded_password_does_not_include_trailing_null_byte
198
+ password = Argon2id::Password.create("password", t_cost: 2, m_cost: 256, salt_len: 8)
199
+
200
+ refute password.to_s.end_with?("\x00")
201
+ end
202
+
203
+ def test_raises_with_too_short_output
204
+ assert_raises(Argon2id::Error) do
205
+ Argon2id::Password.create("password", t_cost: 2, m_cost: 256, salt_len: 8, output_len: 1)
206
+ end
207
+ end
208
+
209
+ def test_raises_with_too_few_threads_and_compute_lanes
210
+ assert_raises(Argon2id::Error) do
211
+ Argon2id::Password.create("password", t_cost: 2, m_cost: 256, parallelism: 0, salt_len: 8)
212
+ end
213
+ end
214
+
215
+ def test_raises_with_too_small_memory_cost
216
+ assert_raises(Argon2id::Error) do
217
+ Argon2id::Password.create("password", t_cost: 2, m_cost: 0, salt_len: 8)
218
+ end
219
+ end
220
+
221
+ def test_raises_with_too_small_time_cost
222
+ assert_raises(Argon2id::Error) do
223
+ Argon2id::Password.create("password", t_cost: 0, m_cost: 256, salt_len: 8)
224
+ end
225
+ end
226
+
227
+ def test_raises_with_too_short_salt
228
+ assert_raises(Argon2id::Error) do
229
+ Argon2id::Password.create("password", t_cost: 2, m_cost: 256, salt_len: 0)
230
+ end
231
+ end
172
232
  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.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Mucur
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-11-02 00:00:00.000000000 Z
11
+ date: 2024-11-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler
@@ -84,11 +84,10 @@ files:
84
84
  - ext/argon2id/libargon2/thread.c
85
85
  - ext/argon2id/libargon2/thread.h
86
86
  - lib/argon2id.rb
87
+ - lib/argon2id/extension.rb
87
88
  - lib/argon2id/password.rb
88
89
  - lib/argon2id/version.rb
89
- - test/test_hash_encoded.rb
90
90
  - test/test_password.rb
91
- - test/test_verify.rb
92
91
  homepage: https://github.com/mudge/argon2id
93
92
  licenses:
94
93
  - BSD-3-Clause
@@ -1,54 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "minitest/autorun"
4
- require "argon2id"
5
-
6
- class TestHashEncoded < Minitest::Test
7
- def test_valid_password_and_salt_encodes_successfully
8
- encoded = Argon2id.hash_encoded(2, 256, 1, "password", "somesalt", 32)
9
-
10
- assert_equal "$argon2id$v=19$m=256,t=2,p=1$c29tZXNhbHQ$nf65EOgLrQMR/uIPnA4rEsF5h7TKyQwu9U1bMCHGi/4", encoded
11
- end
12
-
13
- def test_password_with_parallelism_of_two
14
- encoded = Argon2id.hash_encoded(2, 256, 2, "password", "somesalt", 32)
15
-
16
- assert_equal "$argon2id$v=19$m=256,t=2,p=2$c29tZXNhbHQ$bQk8UB/VmZZF4Oo79iDXuL5/0ttZwg2f/5U52iv1cDc", encoded
17
- end
18
-
19
- def test_valid_password_does_not_include_trailing_null_byte
20
- encoded = Argon2id.hash_encoded(2, 256, 1, "password", "somesalt", 32)
21
-
22
- refute encoded.end_with?("\x00")
23
- end
24
-
25
- def test_raises_with_too_short_output
26
- assert_raises(Argon2id::Error) do
27
- Argon2id.hash_encoded(2, 256, 1, "password", "somesalt", 1)
28
- end
29
- end
30
-
31
- def test_raises_with_too_few_lanes
32
- assert_raises(Argon2id::Error) do
33
- Argon2id.hash_encoded(2, 256, 0, "password", "somesalt", 32)
34
- end
35
- end
36
-
37
- def test_raises_with_too_small_memory_cost
38
- assert_raises(Argon2id::Error) do
39
- Argon2id.hash_encoded(2, 0, 1, "password", "somesalt", 32)
40
- end
41
- end
42
-
43
- def test_raises_with_too_small_time_cost
44
- assert_raises(Argon2id::Error) do
45
- Argon2id.hash_encoded(0, 256, 1, "password", "somesalt", 32)
46
- end
47
- end
48
-
49
- def test_raises_with_too_short_salt
50
- assert_raises(Argon2id::Error) do
51
- Argon2id.hash_encoded(2, 256, 1, "password", "", 32)
52
- end
53
- end
54
- end
data/test/test_verify.rb DELETED
@@ -1,35 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "minitest/autorun"
4
- require "argon2id"
5
-
6
- class TestVerify < Minitest::Test
7
- def test_returns_true_with_correct_password
8
- assert Argon2id.verify(
9
- "$argon2id$v=19$m=256,t=2,p=1$c29tZXNhbHQ$nf65EOgLrQMR/uIPnA4rEsF5h7TKyQwu9U1bMCHGi/4",
10
- "password"
11
- )
12
- end
13
-
14
- def test_returns_false_with_incorrect_password
15
- refute Argon2id.verify(
16
- "$argon2id$v=19$m=256,t=2,p=1$c29tZXNhbHQ$nf65EOgLrQMR/uIPnA4rEsF5h7TKyQwu9U1bMCHGi/4",
17
- "not password"
18
- )
19
- end
20
-
21
- def test_raises_if_given_invalid_encoded
22
- assert_raises(ArgumentError) do
23
- Argon2id.verify("", "opensesame")
24
- end
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
35
- end