argon2 0.0.1 → 0.0.2
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/.gitignore +4 -0
- data/.travis.yml +2 -0
- data/README.md +25 -9
- data/argon2.gemspec +10 -2
- data/bin/console +1 -1
- data/bin/setup +3 -0
- data/ext/argon2_wrap/Makefile +72 -0
- data/ext/argon2_wrap/argon_wrap.c +65 -0
- data/ext/argon2_wrap/extconf.rb +1 -0
- data/ext/argon2_wrap/test.c +67 -0
- data/ext/phc-winner-argon2/.gitignore +7 -0
- data/ext/phc-winner-argon2/LICENSE +31 -0
- data/ext/phc-winner-argon2/Makefile +102 -0
- data/ext/phc-winner-argon2/README.md +193 -0
- data/ext/phc-winner-argon2/argon2-specs.pdf +0 -0
- data/ext/phc-winner-argon2/kats/argon2d +12302 -0
- data/ext/phc-winner-argon2/kats/argon2d.shasum +1 -0
- data/ext/phc-winner-argon2/kats/argon2i +12302 -0
- data/ext/phc-winner-argon2/kats/argon2i.shasum +1 -0
- data/ext/phc-winner-argon2/kats/check-sums.sh +13 -0
- data/ext/phc-winner-argon2/kats/test.sh +47 -0
- data/ext/phc-winner-argon2/src/argon2.c +360 -0
- data/ext/phc-winner-argon2/src/argon2.h +298 -0
- data/ext/phc-winner-argon2/src/bench.c +111 -0
- data/ext/phc-winner-argon2/src/blake2/blake2-impl.h +143 -0
- data/ext/phc-winner-argon2/src/blake2/blake2.h +74 -0
- data/ext/phc-winner-argon2/src/blake2/blake2b.c +372 -0
- data/ext/phc-winner-argon2/src/blake2/blamka-round-opt.h +162 -0
- data/ext/phc-winner-argon2/src/blake2/blamka-round-ref.h +39 -0
- data/ext/phc-winner-argon2/src/core.c +662 -0
- data/ext/phc-winner-argon2/src/core.h +226 -0
- data/ext/phc-winner-argon2/src/genkat.c +194 -0
- data/ext/phc-winner-argon2/src/genkat.h +45 -0
- data/ext/phc-winner-argon2/src/opt.c +173 -0
- data/ext/phc-winner-argon2/src/opt.h +49 -0
- data/ext/phc-winner-argon2/src/ref.c +175 -0
- data/ext/phc-winner-argon2/src/ref.h +49 -0
- data/ext/phc-winner-argon2/src/run.c +223 -0
- data/ext/phc-winner-argon2/src/thread.c +36 -0
- data/ext/phc-winner-argon2/src/thread.h +46 -0
- data/lib/argon2.rb +15 -32
- data/lib/argon2/constants.rb +6 -0
- data/lib/argon2/engine.rb +10 -0
- data/lib/argon2/errors.rb +36 -0
- data/lib/argon2/ffi_engine.rb +47 -0
- data/lib/argon2/version.rb +1 -1
- metadata +75 -11
@@ -0,0 +1,36 @@
|
|
1
|
+
#include "thread.h"
|
2
|
+
#if defined(_WIN32)
|
3
|
+
#include <Windows.h>
|
4
|
+
#endif
|
5
|
+
|
6
|
+
int argon2_thread_create(argon2_thread_handle_t *handle,
|
7
|
+
argon2_thread_func_t func, void *args) {
|
8
|
+
if (NULL == handle || func == NULL) {
|
9
|
+
return -1;
|
10
|
+
}
|
11
|
+
#if defined(_WIN32)
|
12
|
+
*handle = _beginthreadex(NULL, 0, func, args, 0, NULL);
|
13
|
+
return *handle != 0 ? 0 : -1;
|
14
|
+
#else
|
15
|
+
return pthread_create(handle, NULL, func, args);
|
16
|
+
#endif
|
17
|
+
}
|
18
|
+
|
19
|
+
int argon2_thread_join(argon2_thread_handle_t handle) {
|
20
|
+
#if defined(_WIN32)
|
21
|
+
if (WaitForSingleObject((HANDLE)handle, INFINITE) == WAIT_OBJECT_0) {
|
22
|
+
return CloseHandle((HANDLE)handle) != 0 ? 0 : -1;
|
23
|
+
}
|
24
|
+
return -1;
|
25
|
+
#else
|
26
|
+
return pthread_join(handle, NULL);
|
27
|
+
#endif
|
28
|
+
}
|
29
|
+
|
30
|
+
void argon2_thread_exit(void) {
|
31
|
+
#if defined(_WIN32)
|
32
|
+
_endthreadex(0);
|
33
|
+
#else
|
34
|
+
pthread_exit(NULL);
|
35
|
+
#endif
|
36
|
+
}
|
@@ -0,0 +1,46 @@
|
|
1
|
+
#ifndef ARGON2_THREAD_H
|
2
|
+
#define ARGON2_THREAD_H
|
3
|
+
/*
|
4
|
+
Here we implement an abstraction layer for the simpĺe requirements
|
5
|
+
of the Argon2 code. We only require 3 primitives---thread creation,
|
6
|
+
joining, and termination---so full emulation of the pthreads API
|
7
|
+
is unwarranted. Currently we wrap pthreads and Win32 threads.
|
8
|
+
|
9
|
+
The API defines 2 types: the function pointer type,
|
10
|
+
argon2_thread_func_t,
|
11
|
+
and the type of the thread handle---argon2_thread_handle_t.
|
12
|
+
*/
|
13
|
+
#if defined(_WIN32)
|
14
|
+
#include <process.h>
|
15
|
+
typedef unsigned(__stdcall *argon2_thread_func_t)(void *);
|
16
|
+
typedef uintptr_t argon2_thread_handle_t;
|
17
|
+
#else
|
18
|
+
#include <pthread.h>
|
19
|
+
typedef void *(*argon2_thread_func_t)(void *);
|
20
|
+
typedef pthread_t argon2_thread_handle_t;
|
21
|
+
#endif
|
22
|
+
|
23
|
+
/* Creates a thread
|
24
|
+
* @param handle pointer to a thread handle, which is the output of this
|
25
|
+
* function. Must not be NULL.
|
26
|
+
* @param func A function pointer for the thread's entry point. Must not be
|
27
|
+
* NULL.
|
28
|
+
* @param args Pointer that is passed as an argument to @func. May be NULL.
|
29
|
+
* @return 0 if @handle and @func are valid pointers and a thread is successfuly
|
30
|
+
* created.
|
31
|
+
*/
|
32
|
+
int argon2_thread_create(argon2_thread_handle_t *handle,
|
33
|
+
argon2_thread_func_t func, void *args);
|
34
|
+
|
35
|
+
/* Waits for a thread to terminate
|
36
|
+
* @param handle Handle to a thread created with argon2_thread_create.
|
37
|
+
* @return 0 if @handle is a valid handle, and joining completed successfully.
|
38
|
+
*/
|
39
|
+
int argon2_thread_join(argon2_thread_handle_t handle);
|
40
|
+
|
41
|
+
/* Terminate the current thread. Must be run inside a thread created by
|
42
|
+
* argon2_thread_create.
|
43
|
+
*/
|
44
|
+
void argon2_thread_exit(void);
|
45
|
+
|
46
|
+
#endif
|
data/lib/argon2.rb
CHANGED
@@ -1,38 +1,21 @@
|
|
1
|
-
require
|
2
|
-
require '
|
1
|
+
require 'argon2/constants'
|
2
|
+
require 'argon2/ffi_engine'
|
3
|
+
require 'argon2/version'
|
4
|
+
require 'argon2/errors'
|
5
|
+
require 'argon2/engine.rb'
|
3
6
|
|
4
7
|
module Argon2
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
# * @param in Pointer to the input (password)
|
13
|
-
# * @param inlen Input length in bytes
|
14
|
-
# * @param salt Pointer to the salt
|
15
|
-
# * @param saltlen Salt length in bytes
|
16
|
-
# * @pre @a out must have at least @a outlen bytes allocated
|
17
|
-
# * @pre @a in must be at least @inlen bytes long
|
18
|
-
# * @pre @a saltlen must be at least @saltlen bytes long
|
19
|
-
# * @return Zero if successful, 1 otherwise.
|
20
|
-
# */
|
21
|
-
#int hash_argon2i(void *out, size_t outlen, const void *in, size_t inlen,
|
22
|
-
# const void *salt, size_t saltlen, unsigned int t_cost,
|
23
|
-
# unsigned int m_cost);
|
24
|
-
|
25
|
-
attach_function :hash_argon2i, [:pointer, :size_t, :pointer, :size_t,
|
26
|
-
:pointer, :size_t, :uint, :uint ], :int, :blocking => true
|
27
|
-
end
|
8
|
+
class Password
|
9
|
+
def initialize(options = {})
|
10
|
+
#TODO: Verify inputs
|
11
|
+
@t_cost = options[:t_cost] || 2
|
12
|
+
@m_cost = options[:m_cost] || 16
|
13
|
+
@salt = options[:salt_do_not_supply] || Engine.saltgen
|
14
|
+
end
|
28
15
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
ret = Ext.hash_argon2i(buffer, 32, password, password.length, salt, salt.length, 2, (1<<16))
|
33
|
-
fail "Hash failed" unless ret == 0
|
34
|
-
result = buffer.read_string(32)
|
16
|
+
def hash(pass)
|
17
|
+
Argon2::Engine.hash_argon2i_encode(
|
18
|
+
pass, @salt, @t_cost, @m_cost)
|
35
19
|
end
|
36
|
-
result.unpack('H*').join
|
37
20
|
end
|
38
21
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Argon2
|
2
|
+
class ArgonHashFail < StandardError; end
|
3
|
+
ERRORS = [
|
4
|
+
'ARGON2_OK',
|
5
|
+
'ARGON2_OUTPUT_PTR_NULL',
|
6
|
+
'ARGON2_OUTPUT_TOO_SHORT',
|
7
|
+
'ARGON2_OUTPUT_TOO_LONG',
|
8
|
+
'ARGON2_PWD_TOO_SHORT',
|
9
|
+
'ARGON2_PWD_TOO_LONG',
|
10
|
+
'ARGON2_SALT_TOO_SHORT',
|
11
|
+
'ARGON2_SALT_TOO_LONG',
|
12
|
+
'ARGON2_AD_TOO_SHORT',
|
13
|
+
'ARGON2_AD_TOO_LONG',
|
14
|
+
'ARGON2_SECRET_TOO_SHORT',
|
15
|
+
'ARGON2_SECRET_TOO_LONG',
|
16
|
+
'ARGON2_TIME_TOO_SMALL',
|
17
|
+
'ARGON2_TIME_TOO_LARGE',
|
18
|
+
'ARGON2_MEMORY_TOO_LITTLE',
|
19
|
+
'ARGON2_MEMORY_TOO_MUCH',
|
20
|
+
'ARGON2_LANES_TOO_FEW',
|
21
|
+
'ARGON2_LANES_TOO_MANY',
|
22
|
+
'ARGON2_PWD_PTR_MISMATCH',
|
23
|
+
'ARGON2_SALT_PTR_MISMATCH',
|
24
|
+
'ARGON2_SECRET_PTR_MISMATCH',
|
25
|
+
'ARGON2_AD_PTR_MISMATCH',
|
26
|
+
'ARGON2_MEMORY_ALLOCATION_ERROR',
|
27
|
+
'ARGON2_FREE_MEMORY_CBK_NULL',
|
28
|
+
'ARGON2_ALLOCATE_MEMORY_CBK_NULL',
|
29
|
+
'ARGON2_INCORRECT_PARAMETER',
|
30
|
+
'ARGON2_INCORRECT_TYPE',
|
31
|
+
'ARGON2_OUT_PTR_MISMATCH',
|
32
|
+
'ARGON2_THREADS_TOO_FEW',
|
33
|
+
'ARGON2_THREADS_TOO_MANY',
|
34
|
+
'ARGON2_MISSING_ARGS'
|
35
|
+
]
|
36
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'ffi'
|
2
|
+
require 'ffi-compiler/loader'
|
3
|
+
|
4
|
+
module Argon2
|
5
|
+
module Ext
|
6
|
+
extend FFI::Library
|
7
|
+
ffi_lib FFI::Compiler::Loader.find('argon2_wrap')
|
8
|
+
#int hash_argon2i(void *out, size_t outlen, const void *in, size_t inlen,
|
9
|
+
# const void *salt, size_t saltlen, unsigned int t_cost,
|
10
|
+
# unsigned int m_cost);
|
11
|
+
|
12
|
+
attach_function :hash_argon2i, [:pointer, :size_t, :pointer, :size_t,
|
13
|
+
:pointer, :size_t, :uint, :uint ], :int, :blocking => true
|
14
|
+
|
15
|
+
#void argon2_wrap(uint8_t *out, char *pwd, uint8_t *salt, uint32_t t_cost,
|
16
|
+
# uint32_t m_cost, uint32_t lanes);
|
17
|
+
attach_function :argon2_wrap, [:pointer, :pointer, :pointer, :uint, :uint, :uint], :uint, :blocking => true
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
class Engine
|
22
|
+
# The engine class shields users from the FFI interface.
|
23
|
+
# It is generally not advised to directly use this class.
|
24
|
+
def self.hash_argon2i(password, salt, t_cost, m_cost)
|
25
|
+
result = ''
|
26
|
+
FFI::MemoryPointer.new(:char, Constants::OUT_LEN) do |buffer|
|
27
|
+
ret = Ext.hash_argon2i(buffer, Constants::OUT_LEN, password, password.length, salt, salt.length, t_cost, (1<<m_cost))
|
28
|
+
raise ArgonHashFail.new(ERRORS[ret]) unless ret == 0
|
29
|
+
result = buffer.read_string(Constants::OUT_LEN)
|
30
|
+
end
|
31
|
+
result.unpack('H*').join
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.hash_argon2i_encode(password, salt, t_cost, m_cost)
|
35
|
+
result = ''
|
36
|
+
if salt.length != Constants::SALT_LEN
|
37
|
+
raise ArgonHashFail.new("Invalid salt size")
|
38
|
+
end
|
39
|
+
FFI::MemoryPointer.new(:char, 300) do |buffer|
|
40
|
+
ret = Ext.argon2_wrap(buffer, password, salt, t_cost, (1<<m_cost), 1)
|
41
|
+
raise ArgonHashFail.new(ERRORS[ret]) unless ret == 0
|
42
|
+
result = buffer.read_string(300)
|
43
|
+
end
|
44
|
+
result.gsub("\0", '')
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/lib/argon2/version.rb
CHANGED
metadata
CHANGED
@@ -1,29 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: argon2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Technion
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-11-
|
11
|
+
date: 2015-11-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: ffi
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.9'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.9'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: ffi-compiler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
16
30
|
requirements:
|
17
|
-
- - "
|
31
|
+
- - "~>"
|
18
32
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
33
|
+
version: '0.1'
|
20
34
|
type: :runtime
|
21
35
|
prerelease: false
|
22
36
|
version_requirements: !ruby/object:Gem::Requirement
|
23
37
|
requirements:
|
24
|
-
- - "
|
38
|
+
- - "~>"
|
25
39
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
40
|
+
version: '0.1'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: bundler
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -56,21 +70,22 @@ dependencies:
|
|
56
70
|
name: minitest
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
58
72
|
requirements:
|
59
|
-
- - "
|
73
|
+
- - "~>"
|
60
74
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
75
|
+
version: '5'
|
62
76
|
type: :development
|
63
77
|
prerelease: false
|
64
78
|
version_requirements: !ruby/object:Gem::Requirement
|
65
79
|
requirements:
|
66
|
-
- - "
|
80
|
+
- - "~>"
|
67
81
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
82
|
+
version: '5'
|
69
83
|
description: Not remotely finished Argon2 binding
|
70
84
|
email:
|
71
85
|
- technion@lolware.net
|
72
86
|
executables: []
|
73
|
-
extensions:
|
87
|
+
extensions:
|
88
|
+
- ext/argon2_wrap/extconf.rb
|
74
89
|
extra_rdoc_files: []
|
75
90
|
files:
|
76
91
|
- ".gitignore"
|
@@ -83,7 +98,56 @@ files:
|
|
83
98
|
- argon2.gemspec
|
84
99
|
- bin/console
|
85
100
|
- bin/setup
|
101
|
+
- ext/argon2_wrap/Makefile
|
102
|
+
- ext/argon2_wrap/argon_wrap.c
|
103
|
+
- ext/argon2_wrap/extconf.rb
|
104
|
+
- ext/argon2_wrap/libargon2_wrap.so
|
105
|
+
- ext/argon2_wrap/test.c
|
106
|
+
- ext/argon2_wrap/tests
|
107
|
+
- ext/phc-winner-argon2/.git
|
108
|
+
- ext/phc-winner-argon2/.gitignore
|
109
|
+
- ext/phc-winner-argon2/LICENSE
|
110
|
+
- ext/phc-winner-argon2/Makefile
|
111
|
+
- ext/phc-winner-argon2/README.md
|
112
|
+
- ext/phc-winner-argon2/argon2
|
113
|
+
- ext/phc-winner-argon2/argon2-specs.pdf
|
114
|
+
- ext/phc-winner-argon2/kats/argon2d
|
115
|
+
- ext/phc-winner-argon2/kats/argon2d.shasum
|
116
|
+
- ext/phc-winner-argon2/kats/argon2i
|
117
|
+
- ext/phc-winner-argon2/kats/argon2i.shasum
|
118
|
+
- ext/phc-winner-argon2/kats/check-sums.sh
|
119
|
+
- ext/phc-winner-argon2/kats/test.sh
|
120
|
+
- ext/phc-winner-argon2/libargon2.a
|
121
|
+
- ext/phc-winner-argon2/libargon2.so
|
122
|
+
- ext/phc-winner-argon2/src/argon2.c
|
123
|
+
- ext/phc-winner-argon2/src/argon2.h
|
124
|
+
- ext/phc-winner-argon2/src/argon2.o
|
125
|
+
- ext/phc-winner-argon2/src/bench.c
|
126
|
+
- ext/phc-winner-argon2/src/blake2/blake2-impl.h
|
127
|
+
- ext/phc-winner-argon2/src/blake2/blake2.h
|
128
|
+
- ext/phc-winner-argon2/src/blake2/blake2b.c
|
129
|
+
- ext/phc-winner-argon2/src/blake2/blake2b.o
|
130
|
+
- ext/phc-winner-argon2/src/blake2/blamka-round-opt.h
|
131
|
+
- ext/phc-winner-argon2/src/blake2/blamka-round-ref.h
|
132
|
+
- ext/phc-winner-argon2/src/core.c
|
133
|
+
- ext/phc-winner-argon2/src/core.h
|
134
|
+
- ext/phc-winner-argon2/src/core.o
|
135
|
+
- ext/phc-winner-argon2/src/genkat.c
|
136
|
+
- ext/phc-winner-argon2/src/genkat.h
|
137
|
+
- ext/phc-winner-argon2/src/opt.c
|
138
|
+
- ext/phc-winner-argon2/src/opt.h
|
139
|
+
- ext/phc-winner-argon2/src/ref.c
|
140
|
+
- ext/phc-winner-argon2/src/ref.h
|
141
|
+
- ext/phc-winner-argon2/src/ref.o
|
142
|
+
- ext/phc-winner-argon2/src/run.c
|
143
|
+
- ext/phc-winner-argon2/src/thread.c
|
144
|
+
- ext/phc-winner-argon2/src/thread.h
|
145
|
+
- ext/phc-winner-argon2/src/thread.o
|
86
146
|
- lib/argon2.rb
|
147
|
+
- lib/argon2/constants.rb
|
148
|
+
- lib/argon2/engine.rb
|
149
|
+
- lib/argon2/errors.rb
|
150
|
+
- lib/argon2/ffi_engine.rb
|
87
151
|
- lib/argon2/version.rb
|
88
152
|
homepage: https://github.com/technion/ruby-argon2
|
89
153
|
licenses:
|