argon2 2.0.0 → 2.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/.github/workflows/ruby.yml +70 -0
- data/.rubocop.yml +178 -5
- data/Changelog.md +10 -0
- data/Gemfile +2 -0
- data/README.md +29 -17
- data/Rakefile +2 -0
- data/Steepfile +16 -0
- data/argon2.gemspec +13 -7
- data/bin/console +5 -4
- data/bin/setup +6 -2
- data/bin/test +10 -0
- data/ext/argon2_wrap/argon_wrap.c +6 -0
- data/ext/argon2_wrap/extconf.rb +1 -0
- data/ext/argon2_wrap/libargon2_wrap.so +0 -0
- data/ext/argon2_wrap/test.c +0 -1
- data/ext/phc-winner-argon2/.gitignore +1 -0
- data/ext/phc-winner-argon2/Argon2.sln +2 -4
- data/ext/phc-winner-argon2/LICENSE +2 -2
- data/ext/phc-winner-argon2/Makefile +86 -18
- data/ext/phc-winner-argon2/README.md +3 -1
- data/ext/phc-winner-argon2/include/argon2.h +3 -3
- data/ext/phc-winner-argon2/libargon2.pc.in +18 -0
- data/ext/phc-winner-argon2/src/argon2.c +2 -2
- data/ext/phc-winner-argon2/src/bench.c +4 -4
- data/ext/phc-winner-argon2/src/blake2/blake2-impl.h +3 -3
- data/ext/phc-winner-argon2/src/blake2/blake2.h +2 -2
- data/ext/phc-winner-argon2/src/blake2/blake2b.c +2 -2
- data/ext/phc-winner-argon2/src/blake2/blamka-round-opt.h +2 -2
- data/ext/phc-winner-argon2/src/blake2/blamka-round-ref.h +2 -2
- data/ext/phc-winner-argon2/src/core.c +20 -6
- data/ext/phc-winner-argon2/src/core.h +2 -2
- data/ext/phc-winner-argon2/src/encoding.c +2 -2
- data/ext/phc-winner-argon2/src/encoding.h +2 -2
- data/ext/phc-winner-argon2/src/genkat.c +9 -3
- data/ext/phc-winner-argon2/src/genkat.h +2 -2
- data/ext/phc-winner-argon2/src/opt.c +2 -2
- data/ext/phc-winner-argon2/src/ref.c +2 -2
- data/ext/phc-winner-argon2/src/run.c +2 -2
- data/ext/phc-winner-argon2/src/test.c +2 -2
- data/ext/phc-winner-argon2/src/thread.c +2 -2
- data/ext/phc-winner-argon2/src/thread.h +2 -2
- data/ext/phc-winner-argon2/vs2015/Argon2Opt/Argon2Opt.vcxproj +11 -6
- data/ext/phc-winner-argon2/vs2015/Argon2OptBench/Argon2OptBench.vcxproj +11 -6
- data/ext/phc-winner-argon2/vs2015/Argon2OptDll/Argon2OptDll.vcxproj +11 -6
- data/ext/phc-winner-argon2/vs2015/Argon2OptGenKAT/Argon2OptGenKAT.vcxproj +11 -6
- data/ext/phc-winner-argon2/vs2015/Argon2OptTestCI/Argon2OptTestCI.vcxproj +16 -8
- data/ext/phc-winner-argon2/vs2015/Argon2Ref/Argon2Ref.vcxproj +25 -8
- data/ext/phc-winner-argon2/vs2015/Argon2RefBench/Argon2RefBench.vcxproj +11 -6
- data/ext/phc-winner-argon2/vs2015/Argon2RefDll/Argon2RefDll.vcxproj +11 -6
- data/ext/phc-winner-argon2/vs2015/Argon2RefGenKAT/Argon2RefGenKAT.vcxproj +11 -6
- data/ext/phc-winner-argon2/vs2015/Argon2RefTestCI/Argon2RefTestCI.vcxproj +11 -6
- data/lib/argon2/ffi_engine.rb +49 -17
- data/lib/argon2/hash_format.rb +49 -0
- data/lib/argon2/version.rb +1 -1
- data/lib/argon2.rb +19 -8
- data/sig/argon2.rbs +16 -0
- data/sig/constants.rbs +8 -0
- data/sig/version.rbs +4 -0
- metadata +59 -39
- data/.travis.yml +0 -14
- data/ext/argon2_wrap/tests +0 -0
- data/ext/phc-winner-argon2/libargon2.pc +0 -16
@@ -32,43 +32,44 @@
|
|
32
32
|
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
|
33
33
|
</PropertyGroup>
|
34
34
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
35
|
+
<!-- Set DefaultPlatformToolset to v100 (VS2010) if not defined -->
|
36
|
+
<PropertyGroup Label="EmptyDefaultPlatformToolset">
|
37
|
+
<DefaultPlatformToolset Condition=" '$(DefaultPlatformToolset)' == '' ">v100</DefaultPlatformToolset>
|
38
|
+
</PropertyGroup>
|
39
|
+
<PropertyGroup Label="PlatformToolset">
|
40
|
+
<PlatformToolset>$(DefaultPlatformToolset)</PlatformToolset>
|
41
|
+
</PropertyGroup>
|
35
42
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
36
43
|
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
37
44
|
<UseDebugLibraries>true</UseDebugLibraries>
|
38
|
-
<PlatformToolset>v140</PlatformToolset>
|
39
45
|
<CharacterSet>MultiByte</CharacterSet>
|
40
46
|
</PropertyGroup>
|
41
47
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
42
48
|
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
43
49
|
<UseDebugLibraries>false</UseDebugLibraries>
|
44
|
-
<PlatformToolset>v140</PlatformToolset>
|
45
50
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
46
51
|
<CharacterSet>MultiByte</CharacterSet>
|
47
52
|
</PropertyGroup>
|
48
53
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseStatic|Win32'" Label="Configuration">
|
49
54
|
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
50
55
|
<UseDebugLibraries>false</UseDebugLibraries>
|
51
|
-
<PlatformToolset>v140</PlatformToolset>
|
52
56
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
53
57
|
<CharacterSet>MultiByte</CharacterSet>
|
54
58
|
</PropertyGroup>
|
55
59
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
56
60
|
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
57
61
|
<UseDebugLibraries>true</UseDebugLibraries>
|
58
|
-
<PlatformToolset>v140</PlatformToolset>
|
59
62
|
<CharacterSet>MultiByte</CharacterSet>
|
60
63
|
</PropertyGroup>
|
61
64
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
62
65
|
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
63
66
|
<UseDebugLibraries>false</UseDebugLibraries>
|
64
|
-
<PlatformToolset>v140</PlatformToolset>
|
65
67
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
66
68
|
<CharacterSet>MultiByte</CharacterSet>
|
67
69
|
</PropertyGroup>
|
68
70
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseStatic|x64'" Label="Configuration">
|
69
71
|
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
70
72
|
<UseDebugLibraries>false</UseDebugLibraries>
|
71
|
-
<PlatformToolset>v140</PlatformToolset>
|
72
73
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
73
74
|
<CharacterSet>MultiByte</CharacterSet>
|
74
75
|
</PropertyGroup>
|
@@ -154,6 +155,7 @@
|
|
154
155
|
<Link>
|
155
156
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
156
157
|
<OptimizeReferences>true</OptimizeReferences>
|
158
|
+
<GenerateDebugInformation>true</GenerateDebugInformation>
|
157
159
|
</Link>
|
158
160
|
</ItemDefinitionGroup>
|
159
161
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseStatic|Win32'">
|
@@ -169,6 +171,7 @@
|
|
169
171
|
<Link>
|
170
172
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
171
173
|
<OptimizeReferences>true</OptimizeReferences>
|
174
|
+
<GenerateDebugInformation>true</GenerateDebugInformation>
|
172
175
|
</Link>
|
173
176
|
</ItemDefinitionGroup>
|
174
177
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
@@ -183,6 +186,7 @@
|
|
183
186
|
<Link>
|
184
187
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
185
188
|
<OptimizeReferences>true</OptimizeReferences>
|
189
|
+
<GenerateDebugInformation>true</GenerateDebugInformation>
|
186
190
|
</Link>
|
187
191
|
</ItemDefinitionGroup>
|
188
192
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseStatic|x64'">
|
@@ -198,6 +202,7 @@
|
|
198
202
|
<Link>
|
199
203
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
200
204
|
<OptimizeReferences>true</OptimizeReferences>
|
205
|
+
<GenerateDebugInformation>true</GenerateDebugInformation>
|
201
206
|
</Link>
|
202
207
|
</ItemDefinitionGroup>
|
203
208
|
<ItemGroup>
|
@@ -32,43 +32,44 @@
|
|
32
32
|
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
|
33
33
|
</PropertyGroup>
|
34
34
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
35
|
+
<!-- Set DefaultPlatformToolset to v100 (VS2010) if not defined -->
|
36
|
+
<PropertyGroup Label="EmptyDefaultPlatformToolset">
|
37
|
+
<DefaultPlatformToolset Condition=" '$(DefaultPlatformToolset)' == '' ">v100</DefaultPlatformToolset>
|
38
|
+
</PropertyGroup>
|
39
|
+
<PropertyGroup Label="PlatformToolset">
|
40
|
+
<PlatformToolset>$(DefaultPlatformToolset)</PlatformToolset>
|
41
|
+
</PropertyGroup>
|
35
42
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
36
43
|
<ConfigurationType>Application</ConfigurationType>
|
37
44
|
<UseDebugLibraries>true</UseDebugLibraries>
|
38
|
-
<PlatformToolset>v140</PlatformToolset>
|
39
45
|
<CharacterSet>MultiByte</CharacterSet>
|
40
46
|
</PropertyGroup>
|
41
47
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
42
48
|
<ConfigurationType>Application</ConfigurationType>
|
43
49
|
<UseDebugLibraries>false</UseDebugLibraries>
|
44
|
-
<PlatformToolset>v140</PlatformToolset>
|
45
50
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
46
51
|
<CharacterSet>MultiByte</CharacterSet>
|
47
52
|
</PropertyGroup>
|
48
53
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseStatic|Win32'" Label="Configuration">
|
49
54
|
<ConfigurationType>Application</ConfigurationType>
|
50
55
|
<UseDebugLibraries>false</UseDebugLibraries>
|
51
|
-
<PlatformToolset>v140</PlatformToolset>
|
52
56
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
53
57
|
<CharacterSet>MultiByte</CharacterSet>
|
54
58
|
</PropertyGroup>
|
55
59
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
56
60
|
<ConfigurationType>Application</ConfigurationType>
|
57
61
|
<UseDebugLibraries>true</UseDebugLibraries>
|
58
|
-
<PlatformToolset>v140</PlatformToolset>
|
59
62
|
<CharacterSet>MultiByte</CharacterSet>
|
60
63
|
</PropertyGroup>
|
61
64
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
62
65
|
<ConfigurationType>Application</ConfigurationType>
|
63
66
|
<UseDebugLibraries>false</UseDebugLibraries>
|
64
|
-
<PlatformToolset>v140</PlatformToolset>
|
65
67
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
66
68
|
<CharacterSet>MultiByte</CharacterSet>
|
67
69
|
</PropertyGroup>
|
68
70
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseStatic|x64'" Label="Configuration">
|
69
71
|
<ConfigurationType>Application</ConfigurationType>
|
70
72
|
<UseDebugLibraries>false</UseDebugLibraries>
|
71
|
-
<PlatformToolset>v140</PlatformToolset>
|
72
73
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
73
74
|
<CharacterSet>MultiByte</CharacterSet>
|
74
75
|
</PropertyGroup>
|
@@ -154,6 +155,7 @@
|
|
154
155
|
<Link>
|
155
156
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
156
157
|
<OptimizeReferences>true</OptimizeReferences>
|
158
|
+
<GenerateDebugInformation>true</GenerateDebugInformation>
|
157
159
|
</Link>
|
158
160
|
</ItemDefinitionGroup>
|
159
161
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseStatic|Win32'">
|
@@ -169,6 +171,7 @@
|
|
169
171
|
<Link>
|
170
172
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
171
173
|
<OptimizeReferences>true</OptimizeReferences>
|
174
|
+
<GenerateDebugInformation>true</GenerateDebugInformation>
|
172
175
|
</Link>
|
173
176
|
</ItemDefinitionGroup>
|
174
177
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
@@ -183,6 +186,7 @@
|
|
183
186
|
<Link>
|
184
187
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
185
188
|
<OptimizeReferences>true</OptimizeReferences>
|
189
|
+
<GenerateDebugInformation>true</GenerateDebugInformation>
|
186
190
|
</Link>
|
187
191
|
</ItemDefinitionGroup>
|
188
192
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseStatic|x64'">
|
@@ -198,6 +202,7 @@
|
|
198
202
|
<Link>
|
199
203
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
200
204
|
<OptimizeReferences>true</OptimizeReferences>
|
205
|
+
<GenerateDebugInformation>true</GenerateDebugInformation>
|
201
206
|
</Link>
|
202
207
|
</ItemDefinitionGroup>
|
203
208
|
<ItemGroup>
|
@@ -32,43 +32,44 @@
|
|
32
32
|
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
|
33
33
|
</PropertyGroup>
|
34
34
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
35
|
+
<!-- Set DefaultPlatformToolset to v100 (VS2010) if not defined -->
|
36
|
+
<PropertyGroup Label="EmptyDefaultPlatformToolset">
|
37
|
+
<DefaultPlatformToolset Condition=" '$(DefaultPlatformToolset)' == '' ">v100</DefaultPlatformToolset>
|
38
|
+
</PropertyGroup>
|
39
|
+
<PropertyGroup Label="PlatformToolset">
|
40
|
+
<PlatformToolset>$(DefaultPlatformToolset)</PlatformToolset>
|
41
|
+
</PropertyGroup>
|
35
42
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
36
43
|
<ConfigurationType>Application</ConfigurationType>
|
37
44
|
<UseDebugLibraries>true</UseDebugLibraries>
|
38
|
-
<PlatformToolset>v140</PlatformToolset>
|
39
45
|
<CharacterSet>MultiByte</CharacterSet>
|
40
46
|
</PropertyGroup>
|
41
47
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
42
48
|
<ConfigurationType>Application</ConfigurationType>
|
43
49
|
<UseDebugLibraries>false</UseDebugLibraries>
|
44
|
-
<PlatformToolset>v140</PlatformToolset>
|
45
50
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
46
51
|
<CharacterSet>MultiByte</CharacterSet>
|
47
52
|
</PropertyGroup>
|
48
53
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseStatic|Win32'" Label="Configuration">
|
49
54
|
<ConfigurationType>Application</ConfigurationType>
|
50
55
|
<UseDebugLibraries>false</UseDebugLibraries>
|
51
|
-
<PlatformToolset>v140</PlatformToolset>
|
52
56
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
53
57
|
<CharacterSet>MultiByte</CharacterSet>
|
54
58
|
</PropertyGroup>
|
55
59
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
56
60
|
<ConfigurationType>Application</ConfigurationType>
|
57
61
|
<UseDebugLibraries>true</UseDebugLibraries>
|
58
|
-
<PlatformToolset>v140</PlatformToolset>
|
59
62
|
<CharacterSet>MultiByte</CharacterSet>
|
60
63
|
</PropertyGroup>
|
61
64
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
62
65
|
<ConfigurationType>Application</ConfigurationType>
|
63
66
|
<UseDebugLibraries>false</UseDebugLibraries>
|
64
|
-
<PlatformToolset>v140</PlatformToolset>
|
65
67
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
66
68
|
<CharacterSet>MultiByte</CharacterSet>
|
67
69
|
</PropertyGroup>
|
68
70
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseStatic|x64'" Label="Configuration">
|
69
71
|
<ConfigurationType>Application</ConfigurationType>
|
70
72
|
<UseDebugLibraries>false</UseDebugLibraries>
|
71
|
-
<PlatformToolset>v140</PlatformToolset>
|
72
73
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
73
74
|
<CharacterSet>MultiByte</CharacterSet>
|
74
75
|
</PropertyGroup>
|
@@ -154,6 +155,7 @@
|
|
154
155
|
<Link>
|
155
156
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
156
157
|
<OptimizeReferences>true</OptimizeReferences>
|
158
|
+
<GenerateDebugInformation>true</GenerateDebugInformation>
|
157
159
|
</Link>
|
158
160
|
</ItemDefinitionGroup>
|
159
161
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseStatic|Win32'">
|
@@ -169,6 +171,7 @@
|
|
169
171
|
<Link>
|
170
172
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
171
173
|
<OptimizeReferences>true</OptimizeReferences>
|
174
|
+
<GenerateDebugInformation>true</GenerateDebugInformation>
|
172
175
|
</Link>
|
173
176
|
</ItemDefinitionGroup>
|
174
177
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
@@ -183,6 +186,7 @@
|
|
183
186
|
<Link>
|
184
187
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
185
188
|
<OptimizeReferences>true</OptimizeReferences>
|
189
|
+
<GenerateDebugInformation>true</GenerateDebugInformation>
|
186
190
|
</Link>
|
187
191
|
</ItemDefinitionGroup>
|
188
192
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseStatic|x64'">
|
@@ -198,6 +202,7 @@
|
|
198
202
|
<Link>
|
199
203
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
200
204
|
<OptimizeReferences>true</OptimizeReferences>
|
205
|
+
<GenerateDebugInformation>true</GenerateDebugInformation>
|
201
206
|
</Link>
|
202
207
|
</ItemDefinitionGroup>
|
203
208
|
<ItemGroup>
|
data/lib/argon2/ffi_engine.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'ffi'
|
2
4
|
require 'ffi-compiler/loader'
|
3
5
|
|
@@ -5,29 +7,40 @@ module Argon2
|
|
5
7
|
# Direct external bindings. Call these methods via the Engine class to ensure points are dealt with
|
6
8
|
module Ext
|
7
9
|
extend FFI::Library
|
8
|
-
ffi_lib FFI::Compiler::Loader.find('argon2_wrap')
|
10
|
+
ffi_lib FFI::Compiler::Loader.find(FFI::Platform.windows? ? 'libargon2_wrap' : 'argon2_wrap')
|
9
11
|
|
10
12
|
# int argon2i_hash_raw(const uint32_t t_cost, const uint32_t m_cost,
|
11
13
|
# const uint32_t parallelism, const void *pwd,
|
12
14
|
# const size_t pwdlen, const void *salt,
|
13
15
|
# const size_t saltlen, void *hash, const size_t hashlen);
|
14
16
|
|
15
|
-
attach_function :argon2i_hash_raw, [
|
16
|
-
|
17
|
-
|
17
|
+
attach_function :argon2i_hash_raw, %i[
|
18
|
+
uint uint uint pointer
|
19
|
+
size_t pointer size_t pointer size_t
|
20
|
+
], :int, :blocking => true
|
21
|
+
|
22
|
+
# int argon2id_hash_raw(const uint32_t t_cost, const uint32_t m_cost,
|
23
|
+
# const uint32_t parallelism, const void *pwd,
|
24
|
+
# const size_t pwdlen, const void *salt,
|
25
|
+
# const size_t saltlen, void *hash, const size_t hashlen)
|
26
|
+
attach_function :argon2id_hash_raw, %i[
|
27
|
+
uint uint uint pointer
|
28
|
+
size_t pointer size_t pointer size_t
|
29
|
+
], :int, :blocking => true
|
18
30
|
|
19
31
|
# void argon2_wrap(uint8_t *out, char *pwd, size_t pwdlen,
|
20
32
|
# uint8_t *salt, uint32_t saltlen, uint32_t t_cost,
|
21
33
|
# uint32_t m_cost, uint32_t lanes,
|
22
34
|
# uint8_t *secret, uint32_t secretlen)
|
23
|
-
attach_function :argon2_wrap, [
|
24
|
-
|
25
|
-
|
35
|
+
attach_function :argon2_wrap, %i[
|
36
|
+
pointer pointer size_t pointer uint uint
|
37
|
+
uint uint pointer size_t
|
38
|
+
], :int, :blocking => true
|
26
39
|
|
27
40
|
# int argon2i_verify(const char *encoded, const void *pwd,
|
28
41
|
# const size_t pwdlen);
|
29
|
-
attach_function :wrap_argon2_verify, [
|
30
|
-
|
42
|
+
attach_function :wrap_argon2_verify, %i[pointer pointer size_t
|
43
|
+
pointer size_t], :int, :blocking => true
|
31
44
|
end
|
32
45
|
|
33
46
|
# The engine class shields users from the FFI interface.
|
@@ -36,29 +49,47 @@ module Argon2
|
|
36
49
|
def self.hash_argon2i(password, salt, t_cost, m_cost, out_len = nil)
|
37
50
|
out_len = (out_len || Constants::OUT_LEN).to_i
|
38
51
|
raise ArgonHashFail, "Invalid output length" if out_len < 1
|
52
|
+
|
39
53
|
result = ''
|
40
54
|
FFI::MemoryPointer.new(:char, out_len) do |buffer|
|
41
55
|
ret = Ext.argon2i_hash_raw(t_cost, 1 << m_cost, 1, password,
|
42
|
-
|
43
|
-
|
56
|
+
password.length, salt, salt.length,
|
57
|
+
buffer, out_len)
|
58
|
+
raise ArgonHashFail, ERRORS[ret.abs] unless ret.zero?
|
59
|
+
|
60
|
+
result = buffer.read_string(out_len)
|
61
|
+
end
|
62
|
+
result.unpack('H*').join
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.hash_argon2id(password, salt, t_cost, m_cost, p_cost, out_len = nil)
|
66
|
+
out_len = (out_len || Constants::OUT_LEN).to_i
|
67
|
+
raise ArgonHashFail, "Invalid output length" if out_len < 1
|
68
|
+
|
69
|
+
result = ''
|
70
|
+
FFI::MemoryPointer.new(:char, out_len) do |buffer|
|
71
|
+
ret = Ext.argon2id_hash_raw(t_cost, 1 << m_cost, p_cost, password,
|
72
|
+
password.length, salt, salt.length,
|
73
|
+
buffer, out_len)
|
44
74
|
raise ArgonHashFail, ERRORS[ret.abs] unless ret.zero?
|
75
|
+
|
45
76
|
result = buffer.read_string(out_len)
|
46
77
|
end
|
47
78
|
result.unpack('H*').join
|
48
79
|
end
|
49
80
|
|
50
|
-
def self.hash_argon2id_encode(password, salt, t_cost, m_cost, secret)
|
81
|
+
def self.hash_argon2id_encode(password, salt, t_cost, m_cost, p_cost, secret)
|
51
82
|
result = ''
|
52
83
|
secretlen = secret.nil? ? 0 : secret.bytesize
|
53
84
|
passwordlen = password.nil? ? 0 : password.bytesize
|
54
|
-
if salt.length != Constants::SALT_LEN
|
55
|
-
|
56
|
-
end
|
85
|
+
raise ArgonHashFail, "Invalid salt size" if salt.length != Constants::SALT_LEN
|
86
|
+
|
57
87
|
FFI::MemoryPointer.new(:char, Constants::ENCODE_LEN) do |buffer|
|
58
88
|
ret = Ext.argon2_wrap(buffer, password, passwordlen,
|
59
|
-
|
60
|
-
|
89
|
+
salt, salt.length, t_cost, (1 << m_cost),
|
90
|
+
p_cost, secret, secretlen)
|
61
91
|
raise ArgonHashFail, ERRORS[ret.abs] unless ret.zero?
|
92
|
+
|
62
93
|
result = buffer.read_string(Constants::ENCODE_LEN)
|
63
94
|
end
|
64
95
|
result.delete "\0"
|
@@ -71,6 +102,7 @@ module Argon2
|
|
71
102
|
ret = Ext.wrap_argon2_verify(hash, pwd, passwordlen, secret, secretlen)
|
72
103
|
return false if ERRORS[ret.abs] == 'ARGON2_DECODING_FAIL'
|
73
104
|
raise ArgonHashFail, ERRORS[ret.abs] unless ret.zero?
|
105
|
+
|
74
106
|
true
|
75
107
|
end
|
76
108
|
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Argon2
|
4
|
+
##
|
5
|
+
# Get the values from an Argon2 compatible string.
|
6
|
+
#
|
7
|
+
class HashFormat
|
8
|
+
attr_reader :variant, :version, :t_cost, :m_cost, :p_cost, :salt, :checksum
|
9
|
+
|
10
|
+
# FIXME: Reduce complexity/AbcSize
|
11
|
+
# rubocop:disable Metrics/AbcSize
|
12
|
+
def initialize(digest)
|
13
|
+
digest = digest.to_s unless digest.is_a?(String)
|
14
|
+
|
15
|
+
raise Argon2::ArgonHashFail, 'Invalid Argon2 hash' unless self.class.valid_hash?(digest)
|
16
|
+
|
17
|
+
_, variant, version, config, salt, checksum = digest.split('$')
|
18
|
+
# Regex magic to extract the values for each setting
|
19
|
+
version = /v=(\d+)/.match(version)
|
20
|
+
t_cost = /t=(\d+),/.match(config)
|
21
|
+
m_cost = /m=(\d+),/.match(config)
|
22
|
+
p_cost = /p=(\d+)/.match(config)
|
23
|
+
|
24
|
+
# Make sure none of the values are missing
|
25
|
+
raise Argon2::ArgonHashFail, 'Invalid Argon2 version' if version.nil?
|
26
|
+
raise Argon2::ArgonHashFail, 'Invalid Argon2 time cost' if t_cost.nil?
|
27
|
+
raise Argon2::ArgonHashFail, 'Invalid Argon2 memory cost' if m_cost.nil?
|
28
|
+
raise Argon2::ArgonHashFail, 'Invalid Argon2 parallelism cost' if p_cost.nil?
|
29
|
+
|
30
|
+
@variant = variant.to_str
|
31
|
+
@version = version[1].to_i
|
32
|
+
@t_cost = t_cost[1].to_i
|
33
|
+
@m_cost = m_cost[1].to_i
|
34
|
+
@p_cost = p_cost[1].to_i
|
35
|
+
@salt = salt.to_str
|
36
|
+
@checksum = checksum.to_str
|
37
|
+
end
|
38
|
+
# rubocop:enable Metrics/AbcSize
|
39
|
+
|
40
|
+
##
|
41
|
+
# Checks whether a given digest is a valid Argon2 hash.
|
42
|
+
#
|
43
|
+
# Supports 1 and argon2id formats.
|
44
|
+
#
|
45
|
+
def self.valid_hash?(digest)
|
46
|
+
/^\$argon2(id?|d).{,113}/ =~ digest
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/lib/argon2/version.rb
CHANGED
data/lib/argon2.rb
CHANGED
@@ -4,7 +4,8 @@ require 'argon2/constants'
|
|
4
4
|
require 'argon2/ffi_engine'
|
5
5
|
require 'argon2/version'
|
6
6
|
require 'argon2/errors'
|
7
|
-
require 'argon2/engine
|
7
|
+
require 'argon2/engine'
|
8
|
+
require 'argon2/hash_format'
|
8
9
|
|
9
10
|
module Argon2
|
10
11
|
# Front-end API for the Argon2 module.
|
@@ -12,9 +13,14 @@ module Argon2
|
|
12
13
|
def initialize(options = {})
|
13
14
|
@t_cost = options[:t_cost] || 2
|
14
15
|
raise ArgonHashFail, "Invalid t_cost" if @t_cost < 1 || @t_cost > 750
|
16
|
+
|
15
17
|
@m_cost = options[:m_cost] || 16
|
16
18
|
raise ArgonHashFail, "Invalid m_cost" if @m_cost < 1 || @m_cost > 31
|
17
|
-
|
19
|
+
|
20
|
+
@p_cost = options[:p_cost] || 1
|
21
|
+
raise ArgonHashFail, "Invalid p_cost" if @p_cost < 1 || @p_cost > 8
|
22
|
+
|
23
|
+
@insecure_salt = options[:salt_for_testing_purposes_only]
|
18
24
|
@secret = options[:secret]
|
19
25
|
end
|
20
26
|
|
@@ -22,20 +28,25 @@ module Argon2
|
|
22
28
|
raise ArgonHashFail, "Invalid password (expected string)" unless
|
23
29
|
pass.is_a?(String)
|
24
30
|
|
31
|
+
# Ensure salt is freshly generated unless it was intentionally supplied.
|
32
|
+
salt = @insecure_salt || Engine.saltgen
|
33
|
+
|
25
34
|
Argon2::Engine.hash_argon2id_encode(
|
26
|
-
|
35
|
+
pass, salt, @t_cost, @m_cost, @p_cost, @secret)
|
27
36
|
end
|
28
37
|
|
29
38
|
# Helper class, just creates defaults and calls hash()
|
30
|
-
def self.create(pass)
|
31
|
-
argon2 = Argon2::Password.new
|
39
|
+
def self.create(pass, options = {})
|
40
|
+
argon2 = Argon2::Password.new(options)
|
32
41
|
argon2.create(pass)
|
33
42
|
end
|
34
43
|
|
44
|
+
def self.valid_hash?(hash)
|
45
|
+
Argon2::HashFormat.valid_hash?(hash)
|
46
|
+
end
|
47
|
+
|
35
48
|
def self.verify_password(pass, hash, secret = nil)
|
36
|
-
|
37
|
-
raise ArgonHashFail, "Invalid hash" unless
|
38
|
-
/^\$argon2i.{,113}/ =~ hash
|
49
|
+
raise ArgonHashFail, "Invalid hash" unless valid_hash?(hash)
|
39
50
|
|
40
51
|
Argon2::Engine.argon2_verify(pass, hash, secret)
|
41
52
|
end
|
data/sig/argon2.rbs
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# Classes
|
2
|
+
module Argon2
|
3
|
+
class Password
|
4
|
+
@t_cost: Integer
|
5
|
+
@m_cost: Integer
|
6
|
+
@p_cost: Integer
|
7
|
+
@salt: nil | String
|
8
|
+
@secret: nil | String
|
9
|
+
|
10
|
+
def initialize: (?Hash[Symbol, Integer] options) -> (nil | String)
|
11
|
+
def create: (String pass) -> untyped
|
12
|
+
def self.create: (String pass) -> untyped
|
13
|
+
def self.valid_hash?: (string hash) -> Integer?
|
14
|
+
def self.verify_password: (untyped pass, untyped hash, ?nil secret) -> untyped
|
15
|
+
end
|
16
|
+
end
|
data/sig/constants.rbs
ADDED
data/sig/version.rbs
ADDED