argon2 1.1.1 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +7 -4
- data/Changelog.md +3 -0
- data/README.md +2 -0
- data/argon2.gemspec +1 -1
- data/ext/argon2_wrap/Makefile +6 -0
- data/ext/argon2_wrap/argon_wrap.c +1 -7
- data/ext/phc-winner-argon2/.gitignore +1 -0
- data/ext/phc-winner-argon2/Argon2.sln +64 -2
- data/ext/phc-winner-argon2/CHANGELOG.md +8 -1
- data/ext/phc-winner-argon2/LICENSE +301 -18
- data/ext/phc-winner-argon2/Makefile +85 -20
- data/ext/phc-winner-argon2/README.md +73 -30
- data/ext/phc-winner-argon2/argon2-specs.pdf +0 -0
- data/ext/phc-winner-argon2/include/argon2.h +73 -10
- data/ext/phc-winner-argon2/kats/argon2id +12304 -0
- data/ext/phc-winner-argon2/kats/argon2id.shasum +1 -0
- data/ext/phc-winner-argon2/kats/argon2id_v16 +12304 -0
- data/ext/phc-winner-argon2/kats/argon2id_v16.shasum +1 -0
- data/ext/phc-winner-argon2/kats/test.ps1 +1 -1
- data/ext/phc-winner-argon2/kats/test.sh +1 -1
- data/ext/phc-winner-argon2/latex/IEEEtran.cls +6347 -0
- data/ext/phc-winner-argon2/latex/argon2-spec.tex +920 -0
- data/ext/phc-winner-argon2/latex/pics/argon2-par.pdf +0 -0
- data/ext/phc-winner-argon2/latex/pics/compression.pdf +0 -0
- data/ext/phc-winner-argon2/latex/pics/generic.pdf +0 -0
- data/ext/phc-winner-argon2/latex/pics/power-distribution.jpg +0 -0
- data/ext/phc-winner-argon2/latex/tradeoff.bib +822 -0
- data/ext/phc-winner-argon2/libargon2.pc +16 -0
- data/ext/phc-winner-argon2/man/argon2.1 +13 -3
- data/ext/phc-winner-argon2/src/argon2.c +112 -68
- data/ext/phc-winner-argon2/src/bench.c +44 -27
- data/ext/phc-winner-argon2/src/blake2/blake2-impl.h +18 -5
- data/ext/phc-winner-argon2/src/blake2/blake2.h +17 -0
- data/ext/phc-winner-argon2/src/blake2/blake2b.c +25 -7
- data/ext/phc-winner-argon2/src/blake2/blamka-round-opt.h +17 -0
- data/ext/phc-winner-argon2/src/blake2/blamka-round-ref.h +17 -0
- data/ext/phc-winner-argon2/src/core.c +138 -110
- data/ext/phc-winner-argon2/src/core.h +41 -26
- data/ext/phc-winner-argon2/src/encoding.c +79 -55
- data/ext/phc-winner-argon2/src/encoding.h +25 -8
- data/ext/phc-winner-argon2/src/genkat.c +35 -39
- data/ext/phc-winner-argon2/src/genkat.h +11 -7
- data/ext/phc-winner-argon2/src/opt.c +65 -99
- data/ext/phc-winner-argon2/src/opt.h +15 -32
- data/ext/phc-winner-argon2/src/ref.c +50 -93
- data/ext/phc-winner-argon2/src/ref.h +15 -31
- data/ext/phc-winner-argon2/src/run.c +73 -30
- data/ext/phc-winner-argon2/src/test.c +33 -2
- data/ext/phc-winner-argon2/src/thread.c +21 -0
- data/ext/phc-winner-argon2/src/thread.h +21 -0
- data/ext/phc-winner-argon2/vs2015/Argon2Opt/Argon2Opt.vcxproj +69 -1
- data/ext/phc-winner-argon2/vs2015/Argon2OptBench/Argon2OptBench.vcxproj +69 -1
- data/ext/phc-winner-argon2/vs2015/Argon2OptDll/Argon2OptDll.vcxproj +225 -0
- data/ext/phc-winner-argon2/vs2015/Argon2OptDll/Argon2OptDll.vcxproj.filters +66 -0
- data/ext/phc-winner-argon2/vs2015/Argon2OptGenKAT/Argon2OptGenKAT.vcxproj +73 -1
- data/ext/phc-winner-argon2/vs2015/Argon2OptTestCI/Argon2OptTestCI.vcxproj +69 -1
- data/ext/phc-winner-argon2/vs2015/Argon2Ref/Argon2Ref.vcxproj +69 -1
- data/ext/phc-winner-argon2/vs2015/Argon2RefBench/Argon2RefBench.vcxproj +69 -1
- data/ext/phc-winner-argon2/vs2015/Argon2RefDll/Argon2RefDll.vcxproj +225 -0
- data/ext/phc-winner-argon2/vs2015/Argon2RefDll/Argon2RefDll.vcxproj.filters +66 -0
- data/ext/phc-winner-argon2/vs2015/Argon2RefGenKAT/Argon2RefGenKAT.vcxproj +69 -1
- data/ext/phc-winner-argon2/vs2015/Argon2RefTestCI/Argon2RefTestCI.vcxproj +69 -1
- data/lib/argon2.rb +3 -3
- data/lib/argon2/ffi_engine.rb +3 -3
- data/lib/argon2/version.rb +1 -1
- metadata +21 -5
@@ -1,16 +1,27 @@
|
|
1
1
|
#
|
2
|
-
# Argon2 source code package
|
3
|
-
#
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
# this
|
2
|
+
# Argon2 reference source code package - reference C implementations
|
3
|
+
#
|
4
|
+
# Copyright 2015
|
5
|
+
# Daniel Dinu, Dmitry Khovratovich, Jean-Philippe Aumasson, and Samuel Neves
|
6
|
+
#
|
7
|
+
# You may use this work under the terms of a Creative Commons CC0 1.0
|
8
|
+
# License/Waiver or the Apache Public License 2.0, at your option. The terms of
|
9
|
+
# these licenses can be found at:
|
10
|
+
#
|
11
|
+
# - CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0
|
12
|
+
# - Apache 2.0 : http://www.apache.org/licenses/LICENSE-2.0
|
13
|
+
#
|
14
|
+
# You should have received a copy of both of these licenses along with this
|
15
|
+
# software. If not, they may be obtained at the above URLs.
|
8
16
|
#
|
9
17
|
|
10
18
|
RUN = argon2
|
11
19
|
BENCH = bench
|
12
20
|
GENKAT = genkat
|
13
21
|
|
22
|
+
# Increment on an ABI breaking change
|
23
|
+
ABI_VERSION = 0
|
24
|
+
|
14
25
|
DIST = phc-winner-argon2
|
15
26
|
|
16
27
|
SRC = src/argon2.c src/core.c src/blake2/blake2b.c src/thread.c src/encoding.c
|
@@ -19,17 +30,27 @@ SRC_BENCH = src/bench.c
|
|
19
30
|
SRC_GENKAT = src/genkat.c
|
20
31
|
OBJ = $(SRC:.c=.o)
|
21
32
|
|
22
|
-
CFLAGS += -std=c89 -
|
33
|
+
CFLAGS += -std=c89 -O3 -Wall -g -Iinclude -Isrc
|
34
|
+
|
35
|
+
ifeq ($(NO_THREADS), 1)
|
36
|
+
CFLAGS += -DARGON2_NO_THREADS
|
37
|
+
else
|
38
|
+
CFLAGS += -pthread
|
39
|
+
endif
|
40
|
+
|
23
41
|
CI_CFLAGS := $(CFLAGS) -Werror=declaration-after-statement -D_FORTIFY_SOURCE=2 \
|
24
42
|
-Wextra -Wno-type-limits -Werror -coverage -DTEST_LARGE_RAM
|
25
43
|
|
26
|
-
|
44
|
+
OPTTARGET ?= native
|
45
|
+
OPTTEST := $(shell $(CC) -Iinclude -Isrc -march=$(OPTTARGET) src/opt.c -c \
|
27
46
|
-o /dev/null 2>/dev/null; echo $$?)
|
28
47
|
# Detect compatible platform
|
29
48
|
ifneq ($(OPTTEST), 0)
|
49
|
+
$(info Building without optimizations)
|
30
50
|
SRC += src/ref.c
|
31
51
|
else
|
32
|
-
|
52
|
+
$(info Building with optimizations for $(OPTTARGET))
|
53
|
+
CFLAGS += -march=$(OPTTARGET)
|
33
54
|
SRC += src/opt.c
|
34
55
|
endif
|
35
56
|
|
@@ -38,17 +59,23 @@ KERNEL_NAME := $(shell uname -s)
|
|
38
59
|
|
39
60
|
LIB_NAME=argon2
|
40
61
|
ifeq ($(KERNEL_NAME), Linux)
|
41
|
-
LIB_EXT := so
|
62
|
+
LIB_EXT := so.$(ABI_VERSION)
|
42
63
|
LIB_CFLAGS := -shared -fPIC -fvisibility=hidden -DA2_VISCTL=1
|
43
|
-
SO_LDFLAGS := -Wl,-soname,
|
64
|
+
SO_LDFLAGS := -Wl,-soname,lib$(LIB_NAME).$(LIB_EXT)
|
65
|
+
LINKED_LIB_EXT := so
|
44
66
|
endif
|
45
|
-
ifeq ($(KERNEL_NAME), NetBSD)
|
67
|
+
ifeq ($(KERNEL_NAME), $(filter $(KERNEL_NAME),FreeBSD NetBSD OpenBSD))
|
46
68
|
LIB_EXT := so
|
47
69
|
LIB_CFLAGS := -shared -fPIC
|
48
70
|
endif
|
49
71
|
ifeq ($(KERNEL_NAME), Darwin)
|
50
|
-
LIB_EXT := dylib
|
72
|
+
LIB_EXT := $(ABI_VERSION).dylib
|
51
73
|
LIB_CFLAGS := -dynamiclib -install_name @rpath/lib$(LIB_NAME).$(LIB_EXT)
|
74
|
+
LINKED_LIB_EXT := dylib
|
75
|
+
endif
|
76
|
+
ifeq ($(findstring CYGWIN, $(KERNEL_NAME)), CYGWIN)
|
77
|
+
LIB_EXT := dll
|
78
|
+
LIB_CFLAGS := -shared -Wl,--out-implib,lib$(LIB_NAME).$(LIB_EXT).a
|
52
79
|
endif
|
53
80
|
ifeq ($(findstring MINGW, $(KERNEL_NAME)), MINGW)
|
54
81
|
LIB_EXT := dll
|
@@ -58,7 +85,9 @@ ifeq ($(findstring MSYS, $(KERNEL_NAME)), MSYS)
|
|
58
85
|
LIB_EXT := dll
|
59
86
|
LIB_CFLAGS := -shared -Wl,--out-implib,lib$(LIB_NAME).$(LIB_EXT).a
|
60
87
|
endif
|
61
|
-
ifeq ($(KERNEL_NAME),
|
88
|
+
ifeq ($(KERNEL_NAME), SunOS)
|
89
|
+
CC := gcc
|
90
|
+
CFLAGS += -D_REENTRANT
|
62
91
|
LIB_EXT := so
|
63
92
|
LIB_CFLAGS := -shared -fPIC
|
64
93
|
endif
|
@@ -72,10 +101,30 @@ endif
|
|
72
101
|
LIB_SH := lib$(LIB_NAME).$(LIB_EXT)
|
73
102
|
LIB_ST := lib$(LIB_NAME).a
|
74
103
|
|
75
|
-
|
104
|
+
ifdef LINKED_LIB_EXT
|
105
|
+
LINKED_LIB_SH := lib$(LIB_NAME).$(LINKED_LIB_EXT)
|
106
|
+
endif
|
107
|
+
|
108
|
+
|
109
|
+
LIBRARIES = $(LIB_SH) $(LIB_ST)
|
110
|
+
HEADERS = include/argon2.h
|
111
|
+
|
112
|
+
INSTALL = install
|
113
|
+
|
114
|
+
DESTDIR =
|
115
|
+
PREFIX = /usr
|
116
|
+
INCLUDE_REL = include
|
117
|
+
LIBRARY_REL = lib
|
118
|
+
BINARY_REL = bin
|
76
119
|
|
77
|
-
|
78
|
-
|
120
|
+
INST_INCLUDE = $(DESTDIR)$(PREFIX)/$(INCLUDE_REL)
|
121
|
+
INST_LIBRARY = $(DESTDIR)$(PREFIX)/$(LIBRARY_REL)
|
122
|
+
INST_BINARY = $(DESTDIR)$(PREFIX)/$(BINARY_REL)
|
123
|
+
|
124
|
+
.PHONY: clean dist format $(GENKAT) all install
|
125
|
+
|
126
|
+
all: clean $(RUN) libs
|
127
|
+
libs: $(LIBRARIES)
|
79
128
|
|
80
129
|
$(RUN): $(SRC) $(SRC_RUN)
|
81
130
|
$(CC) $(CFLAGS) $(LDFLAGS) $^ -o $@
|
@@ -94,7 +143,7 @@ $(LIB_ST): $(OBJ)
|
|
94
143
|
|
95
144
|
clean:
|
96
145
|
rm -f $(RUN) $(BENCH) $(GENKAT)
|
97
|
-
rm -f $(LIB_SH) $(LIB_ST) kat-argon2*
|
146
|
+
rm -f $(LIB_SH) $(LIB_ST) kat-argon2*
|
98
147
|
rm -f testcase
|
99
148
|
rm -rf *.dSYM
|
100
149
|
cd src/ && rm -f *.o
|
@@ -105,12 +154,12 @@ dist:
|
|
105
154
|
cd ..; \
|
106
155
|
tar -c --exclude='.??*' -z -f $(DIST)-`date "+%Y%m%d"`.tgz $(DIST)/*
|
107
156
|
|
108
|
-
test:
|
157
|
+
test: $(SRC) src/test.c
|
109
158
|
$(CC) $(CFLAGS) -Wextra -Wno-type-limits $^ -o testcase
|
110
159
|
@sh kats/test.sh
|
111
160
|
./testcase
|
112
161
|
|
113
|
-
testci:
|
162
|
+
testci: $(SRC) src/test.c
|
114
163
|
$(CC) $(CI_CFLAGS) $^ -o testcase
|
115
164
|
@sh kats/test.sh
|
116
165
|
./testcase
|
@@ -120,3 +169,19 @@ testci: $(SRC) src/test.c
|
|
120
169
|
format:
|
121
170
|
clang-format -style="{BasedOnStyle: llvm, IndentWidth: 4}" \
|
122
171
|
-i include/*.h src/*.c src/*.h src/blake2/*.c src/blake2/*.h
|
172
|
+
|
173
|
+
install: $(RUN) libs
|
174
|
+
$(INSTALL) -d $(INST_INCLUDE)
|
175
|
+
$(INSTALL) -m 0644 $(HEADERS) $(INST_INCLUDE)
|
176
|
+
$(INSTALL) -d $(INST_LIBRARY)
|
177
|
+
$(INSTALL) $(LIBRARIES) $(INST_LIBRARY)
|
178
|
+
ifdef LINKED_LIB_SH
|
179
|
+
cd $(INST_LIBRARY) && ln -s $(notdir $(LIB_SH) $(LINKED_LIB_SH))
|
180
|
+
endif
|
181
|
+
$(INSTALL) -d $(INST_BINARY)
|
182
|
+
$(INSTALL) $(RUN) $(INST_BINARY)
|
183
|
+
|
184
|
+
uninstall:
|
185
|
+
cd $(INST_INCLUDE) && rm -f $(notdir $(HEADERS))
|
186
|
+
cd $(INST_LIBRARY) && rm -f $(notdir $(LIBRARIES) $(LINKED_LIB_SH))
|
187
|
+
cd $(INST_BINARY) && rm -f $(notdir $(RUN))
|
@@ -17,15 +17,19 @@ effective use of multiple computing units, while still providing defense
|
|
17
17
|
against tradeoff attacks (by exploiting the cache and memory organization
|
18
18
|
of the recent processors).
|
19
19
|
|
20
|
-
Argon2 has
|
21
|
-
uses data-depending memory access, which makes it highly resistant
|
20
|
+
Argon2 has three variants: Argon2i, Argon2d, and Argon2id. Argon2d is faster
|
21
|
+
and uses data-depending memory access, which makes it highly resistant
|
22
22
|
against GPU cracking attacks and suitable for applications with no threats
|
23
23
|
from side-channel timing attacks (eg. cryptocurrencies). Argon2i instead
|
24
24
|
uses data-independent memory access, which is preferred for password
|
25
25
|
hashing and password-based key derivation, but it is slower as it makes
|
26
|
-
more passes over the memory to protect from tradeoff attacks.
|
26
|
+
more passes over the memory to protect from tradeoff attacks. Argon2id is a
|
27
|
+
hybrid of Argon2i and Argon2d, using a combination of data-depending and
|
28
|
+
data-independent memory accesses, which gives some of Argon2i's resistance to
|
29
|
+
side-channel cache timing attacks and much of Argon2d's resistance to GPU
|
30
|
+
cracking attacks.
|
27
31
|
|
28
|
-
Argon2i and
|
32
|
+
Argon2i, Argon2d, and Argon2id are parametrized by:
|
29
33
|
|
30
34
|
* A **time** cost, which defines the amount of computation realized and
|
31
35
|
therefore the execution time, given in number of iterations
|
@@ -42,31 +46,35 @@ Please report bugs as issues on this repository.
|
|
42
46
|
`make` builds the executable `argon2`, the static library `libargon2.a`,
|
43
47
|
and the shared library `libargon2.so` (or `libargon2.dylib` on OSX).
|
44
48
|
Make sure to run `make test` to verify that your build produces valid
|
45
|
-
results.
|
49
|
+
results. `make install PREFIX=/usr` installs it to your system.
|
46
50
|
|
47
51
|
### Command-line utility
|
48
52
|
|
49
53
|
`argon2` is a command-line utility to test specific Argon2 instances
|
50
54
|
on your system. To show usage instructions, run
|
51
|
-
`./argon2`
|
55
|
+
`./argon2 -h` as
|
52
56
|
```
|
53
|
-
Usage: ./argon2 salt [-d] [-t iterations] [-m memory] [-p parallelism] [-
|
57
|
+
Usage: ./argon2 [-h] salt [-i|-d|-id] [-t iterations] [-m memory] [-p parallelism] [-l hash length] [-e|-r] [-v (10|13)]
|
54
58
|
Password is read from stdin
|
55
59
|
Parameters:
|
56
|
-
salt The salt to use, at least 8 characters
|
57
|
-
-
|
60
|
+
salt The salt to use, at least 8 characters
|
61
|
+
-i Use Argon2i (this is the default)
|
62
|
+
-d Use Argon2d instead of Argon2i
|
63
|
+
-id Use Argon2id instead of Argon2i
|
58
64
|
-t N Sets the number of iterations to N (default = 3)
|
59
65
|
-m N Sets the memory usage of 2^N KiB (default 12)
|
60
66
|
-p N Sets parallelism to N threads (default 1)
|
61
|
-
-
|
67
|
+
-l N Sets hash output length to N bytes (default 32)
|
62
68
|
-e Output only encoded hash
|
63
69
|
-r Output only the raw bytes of the hash
|
70
|
+
-v (10|13) Argon2 version (defaults to the most recent version, currently 13)
|
71
|
+
-h Print argon2 usage
|
64
72
|
```
|
65
73
|
For example, to hash "password" using "somesalt" as a salt and doing 2
|
66
74
|
iterations, consuming 64 MiB, using four parallel threads and an output hash
|
67
75
|
of 24 bytes
|
68
76
|
```
|
69
|
-
$ echo -n "password" | ./argon2 somesalt -t 2 -m 16 -p 4 -
|
77
|
+
$ echo -n "password" | ./argon2 somesalt -t 2 -m 16 -p 4 -l 24
|
70
78
|
Type: Argon2i
|
71
79
|
Iterations: 2
|
72
80
|
Memory: 65536 KiB
|
@@ -84,10 +92,33 @@ for using Argon2.
|
|
84
92
|
|
85
93
|
The example program below hashes the string "password" with Argon2i
|
86
94
|
using the high-level API and then using the low-level API. While the
|
87
|
-
high-level API
|
88
|
-
|
89
|
-
|
90
|
-
|
95
|
+
high-level API takes the three cost parameters (time, memory, and
|
96
|
+
parallelism), the password input buffer, the salt input buffer, and the
|
97
|
+
output buffers, the low-level API takes in these and additional parameters
|
98
|
+
, as defined in [`include/argon2.h`](include/argon2.h).
|
99
|
+
|
100
|
+
There are many additional parameters, but we will highlight three of them here.
|
101
|
+
|
102
|
+
1. The `secret` parameter, which is used for [keyed hashing](
|
103
|
+
https://en.wikipedia.org/wiki/Hash-based_message_authentication_code).
|
104
|
+
This allows a secret key to be input at hashing time (from some external
|
105
|
+
location) and be folded into the value of the hash. This means that even if
|
106
|
+
your salts and hashes are compromized, an attacker cannot brute-force to find
|
107
|
+
the password without the key.
|
108
|
+
|
109
|
+
2. The `ad` parameter, which is used to fold any additional data into the hash
|
110
|
+
value. Functionally, this behaves almost exactly like the `secret` or `salt`
|
111
|
+
parameters; the `ad` parameter is folding into the value of the hash.
|
112
|
+
However, this parameter is used for different data. The `salt` should be a
|
113
|
+
random string stored alongside your password. The `secret` should be a random
|
114
|
+
key only usable at hashing time. The `ad` is for any other data.
|
115
|
+
|
116
|
+
3. The `flags` parameter, which determines which memory should be securely
|
117
|
+
erased. This is useful if you want to securly delete the `pwd` or `secret`
|
118
|
+
fields right after they are used. To do this set `flags` to either
|
119
|
+
`ARGON2_FLAG_CLEAR_PASSWORD` or `ARGON2_FLAG_CLEAR_SECRET`. To change how
|
120
|
+
internal memory is cleared, change the global flag
|
121
|
+
`FLAG_clear_internal_memory` (defaults to clearing internal memory).
|
91
122
|
|
92
123
|
Here the time cost `t_cost` is set to 2 iterations, the
|
93
124
|
memory cost `m_cost` is set to 2<sup>16</sup> kibibytes (64 mebibytes),
|
@@ -137,7 +168,8 @@ int main(void)
|
|
137
168
|
t_cost, m_cost, parallelism, parallelism,
|
138
169
|
ARGON2_VERSION_13, /* algorithm version */
|
139
170
|
NULL, NULL, /* custom memory allocation / deallocation functions */
|
140
|
-
|
171
|
+
/* by default only internal memory is cleared (pwd is not wiped) */
|
172
|
+
ARGON2_DEFAULT_FLAGS
|
141
173
|
};
|
142
174
|
|
143
175
|
int rc = argon2i_ctx( &context );
|
@@ -161,10 +193,12 @@ int main(void)
|
|
161
193
|
|
162
194
|
To use Argon2d instead of Argon2i call `argon2d_hash` instead of
|
163
195
|
`argon2i_hash` using the high-level API, and `argon2d` instead of
|
164
|
-
`argon2i` using the low-level API.
|
196
|
+
`argon2i` using the low-level API. Similarly for Argon2id, call `argond2id_hash`
|
197
|
+
and `argon2id`.
|
165
198
|
|
166
199
|
To produce the crypt-like encoding rather than the raw hash, call
|
167
|
-
`argon2i_hash_encoded` for Argon2i
|
200
|
+
`argon2i_hash_encoded` for Argon2i, `argon2d_hash_encoded` for Argon2d, and
|
201
|
+
`argon2id_hash_encoded` for Argon2id
|
168
202
|
|
169
203
|
See [`include/argon2.h`](include/argon2.h) for API details.
|
170
204
|
|
@@ -209,19 +243,26 @@ Argon2i 1 iterations 4096 MiB 4 threads: 2.72 cpb 11124.86 Mcycles
|
|
209
243
|
Bindings are available for the following languages (make sure to read
|
210
244
|
their documentation):
|
211
245
|
|
246
|
+
* [Elixir](https://github.com/riverrun/argon2_elixir) by [@riverrun](https://github.com/riverrun)
|
212
247
|
* [Go](https://github.com/tvdburgt/go-argon2) by [@tvdburgt](https://github.com/tvdburgt)
|
213
248
|
* [Haskell](https://hackage.haskell.org/package/argon2-1.0.0/docs/Crypto-Argon2.html) by [@ocharles](https://github.com/ocharles)
|
214
|
-
* [JavaScript](https://github.com/ranisalt/node-argon2), by [@ranisalt](https://github.com/ranisalt)
|
215
|
-
* [JavaScript](https://github.com/
|
249
|
+
* [JavaScript (native)](https://github.com/ranisalt/node-argon2), by [@ranisalt](https://github.com/ranisalt)
|
250
|
+
* [JavaScript (native)](https://github.com/jdconley/argon2themax), by [@jdconley](https://github.com/jdconley)
|
251
|
+
* [JavaScript (ffi)](https://github.com/cjlarose/argon2-ffi), by [@cjlarose](https://github.com/cjlarose)
|
252
|
+
* [JavaScript (browser)](https://github.com/antelle/argon2-browser), by [@antelle](https://github.com/antelle)
|
216
253
|
* [JVM](https://github.com/phxql/argon2-jvm) by [@phXql](https://github.com/phxql)
|
217
|
-
* [Lua](https://github.com/thibaultCha/lua-argon2) by [@thibaultCha](https://github.com/thibaultCha)
|
254
|
+
* [Lua (native)](https://github.com/thibaultCha/lua-argon2) by [@thibaultCha](https://github.com/thibaultCha)
|
255
|
+
* [Lua (ffi)](https://github.com/thibaultCha/lua-argon2-ffi) by [@thibaultCha](https://github.com/thibaultCha)
|
218
256
|
* [OCaml](https://github.com/Khady/ocaml-argon2) by [@Khady](https://github.com/Khady)
|
219
|
-
* [Python](https://pypi.python.org/pypi/argon2), by [@flamewow](https://github.com/flamewow)
|
220
|
-
* [Python](https://pypi.python.org/pypi/argon2_cffi), by [@hynek](https://github.com/hynek)
|
257
|
+
* [Python (native)](https://pypi.python.org/pypi/argon2), by [@flamewow](https://github.com/flamewow)
|
258
|
+
* [Python (ffi)](https://pypi.python.org/pypi/argon2_cffi), by [@hynek](https://github.com/hynek)
|
221
259
|
* [Ruby](https://github.com/technion/ruby-argon2) by [@technion](https://github.com/technion)
|
222
260
|
* [Rust](https://github.com/quininer/argon2-rs) by [@quininer](https://github.com/quininer)
|
261
|
+
* [C#/.NET CoreCLR](https://github.com/kmaragon/Konscious.Security.Cryptography) by [@kmaragon](https://github.com/kmaragon)
|
262
|
+
* [Perl](https://github.com/Leont/crypt-argon2) by [@leont](https://github.com/Leont)
|
263
|
+
|
223
264
|
|
224
|
-
## Test
|
265
|
+
## Test suite
|
225
266
|
|
226
267
|
There are two sets of test suites. One is a low level test for the hash
|
227
268
|
function, the other tests the higher level API. Both of these are built and
|
@@ -233,15 +274,17 @@ executed by running:
|
|
233
274
|
|
234
275
|
Except for the components listed below, the Argon2 code in this
|
235
276
|
repository is copyright (c) 2015 Daniel Dinu, Dmitry Khovratovich (main
|
236
|
-
authors), Jean-Philippe Aumasson and Samuel Neves, and under
|
237
|
-
[CC0
|
277
|
+
authors), Jean-Philippe Aumasson and Samuel Neves, and dual licensed under the
|
278
|
+
[CC0 License](https://creativecommons.org/about/cc0) and the
|
279
|
+
[Apache 2.0 License](http://www.apache.org/licenses/LICENSE-2.0). For more info
|
280
|
+
see the LICENSE file.
|
238
281
|
|
239
282
|
The string encoding routines in [`src/encoding.c`](src/encoding.c) are
|
240
|
-
copyright (c) 2015 Thomas Pornin, and under
|
241
|
-
|
283
|
+
copyright (c) 2015 Thomas Pornin, and under
|
284
|
+
[CC0 License](https://creativecommons.org/about/cc0).
|
242
285
|
|
243
286
|
The BLAKE2 code in [`src/blake2/`](src/blake2) is copyright (c) Samuel
|
244
|
-
Neves, 2013-2015, and under
|
245
|
-
|
287
|
+
Neves, 2013-2015, and under
|
288
|
+
[CC0 License](https://creativecommons.org/about/cc0).
|
246
289
|
|
247
290
|
All licenses are therefore GPL-compatible.
|
Binary file
|
@@ -1,13 +1,18 @@
|
|
1
1
|
/*
|
2
|
-
* Argon2 source code package
|
2
|
+
* Argon2 reference source code package - reference C implementations
|
3
3
|
*
|
4
|
-
*
|
4
|
+
* Copyright 2015
|
5
|
+
* Daniel Dinu, Dmitry Khovratovich, Jean-Philippe Aumasson, and Samuel Neves
|
5
6
|
*
|
6
|
-
*
|
7
|
+
* You may use this work under the terms of a Creative Commons CC0 1.0
|
8
|
+
* License/Waiver or the Apache Public License 2.0, at your option. The terms of
|
9
|
+
* these licenses can be found at:
|
7
10
|
*
|
8
|
-
*
|
9
|
-
*
|
10
|
-
*
|
11
|
+
* - CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0
|
12
|
+
* - Apache 2.0 : http://www.apache.org/licenses/LICENSE-2.0
|
13
|
+
*
|
14
|
+
* You should have received a copy of both of these licenses along with this
|
15
|
+
* software. If not, they may be obtained at the above URLs.
|
11
16
|
*/
|
12
17
|
|
13
18
|
#ifndef ARGON2_H
|
@@ -24,6 +29,8 @@ extern "C" {
|
|
24
29
|
/* Symbols visibility control */
|
25
30
|
#ifdef A2_VISCTL
|
26
31
|
#define ARGON2_PUBLIC __attribute__((visibility("default")))
|
32
|
+
#elif _MSC_VER
|
33
|
+
#define ARGON2_PUBLIC __declspec(dllexport)
|
27
34
|
#else
|
28
35
|
#define ARGON2_PUBLIC
|
29
36
|
#endif
|
@@ -77,10 +84,14 @@ extern "C" {
|
|
77
84
|
#define ARGON2_MIN_SECRET UINT32_C(0)
|
78
85
|
#define ARGON2_MAX_SECRET UINT32_C(0xFFFFFFFF)
|
79
86
|
|
87
|
+
/* Flags to determine which fields are securely wiped (default = no wipe). */
|
88
|
+
#define ARGON2_DEFAULT_FLAGS UINT32_C(0)
|
80
89
|
#define ARGON2_FLAG_CLEAR_PASSWORD (UINT32_C(1) << 0)
|
81
90
|
#define ARGON2_FLAG_CLEAR_SECRET (UINT32_C(1) << 1)
|
82
|
-
|
83
|
-
|
91
|
+
|
92
|
+
/* Global flag to determine if we are wiping internal memory buffers. This flag
|
93
|
+
* is defined in core.c and deafults to 1 (wipe internal memory). */
|
94
|
+
extern int FLAG_clear_internal_memory;
|
84
95
|
|
85
96
|
/* Error codes */
|
86
97
|
typedef enum Argon2_ErrorCodes {
|
@@ -204,7 +215,11 @@ typedef struct Argon2_Context {
|
|
204
215
|
} argon2_context;
|
205
216
|
|
206
217
|
/* Argon2 primitive type */
|
207
|
-
typedef enum Argon2_type {
|
218
|
+
typedef enum Argon2_type {
|
219
|
+
Argon2_d = 0,
|
220
|
+
Argon2_i = 1,
|
221
|
+
Argon2_id = 2
|
222
|
+
} argon2_type;
|
208
223
|
|
209
224
|
/* Version of the algorithm */
|
210
225
|
typedef enum Argon2_version {
|
@@ -213,6 +228,14 @@ typedef enum Argon2_version {
|
|
213
228
|
ARGON2_VERSION_NUMBER = ARGON2_VERSION_13
|
214
229
|
} argon2_version;
|
215
230
|
|
231
|
+
/*
|
232
|
+
* Function that gives the string representation of an argon2_type.
|
233
|
+
* @param type The argon2_type that we want the string for
|
234
|
+
* @param uppercase Whether the string should have the first letter uppercase
|
235
|
+
* @return NULL if invalid type, otherwise the string representation.
|
236
|
+
*/
|
237
|
+
ARGON2_PUBLIC const char *argon2_type2string(argon2_type type, int uppercase);
|
238
|
+
|
216
239
|
/*
|
217
240
|
* Function that performs memory-hard hashing with certain degree of parallelism
|
218
241
|
* @param context Pointer to the Argon2 internal structure
|
@@ -278,6 +301,21 @@ ARGON2_PUBLIC int argon2d_hash_raw(const uint32_t t_cost, const uint32_t m_cost,
|
|
278
301
|
const size_t saltlen, void *hash,
|
279
302
|
const size_t hashlen);
|
280
303
|
|
304
|
+
ARGON2_PUBLIC int argon2id_hash_encoded(const uint32_t t_cost,
|
305
|
+
const uint32_t m_cost,
|
306
|
+
const uint32_t parallelism,
|
307
|
+
const void *pwd, const size_t pwdlen,
|
308
|
+
const void *salt, const size_t saltlen,
|
309
|
+
const size_t hashlen, char *encoded,
|
310
|
+
const size_t encodedlen);
|
311
|
+
|
312
|
+
ARGON2_PUBLIC int argon2id_hash_raw(const uint32_t t_cost,
|
313
|
+
const uint32_t m_cost,
|
314
|
+
const uint32_t parallelism, const void *pwd,
|
315
|
+
const size_t pwdlen, const void *salt,
|
316
|
+
const size_t saltlen, void *hash,
|
317
|
+
const size_t hashlen);
|
318
|
+
|
281
319
|
/* generic function underlying the above ones */
|
282
320
|
ARGON2_PUBLIC int argon2_hash(const uint32_t t_cost, const uint32_t m_cost,
|
283
321
|
const uint32_t parallelism, const void *pwd,
|
@@ -300,6 +338,9 @@ ARGON2_PUBLIC int argon2i_verify(const char *encoded, const void *pwd,
|
|
300
338
|
ARGON2_PUBLIC int argon2d_verify(const char *encoded, const void *pwd,
|
301
339
|
const size_t pwdlen);
|
302
340
|
|
341
|
+
ARGON2_PUBLIC int argon2id_verify(const char *encoded, const void *pwd,
|
342
|
+
const size_t pwdlen);
|
343
|
+
|
303
344
|
/* generic function underlying the above ones */
|
304
345
|
ARGON2_PUBLIC int argon2_verify(const char *encoded, const void *pwd,
|
305
346
|
const size_t pwdlen, argon2_type type);
|
@@ -324,6 +365,17 @@ ARGON2_PUBLIC int argon2d_ctx(argon2_context *context);
|
|
324
365
|
*/
|
325
366
|
ARGON2_PUBLIC int argon2i_ctx(argon2_context *context);
|
326
367
|
|
368
|
+
/**
|
369
|
+
* Argon2id: Version of Argon2 where the first half-pass over memory is
|
370
|
+
* password-independent, the rest are password-dependent (on the password and
|
371
|
+
* salt). OK against side channels (they reduce to 1/2-pass Argon2i), and
|
372
|
+
* better with w.r.t. tradeoff attacks (similar to Argon2d).
|
373
|
+
*****
|
374
|
+
* @param context Pointer to current Argon2 context
|
375
|
+
* @return Zero if successful, a non zero error code otherwise
|
376
|
+
*/
|
377
|
+
ARGON2_PUBLIC int argon2id_ctx(argon2_context *context);
|
378
|
+
|
327
379
|
/**
|
328
380
|
* Verify if a given password is correct for Argon2d hashing
|
329
381
|
* @param context Pointer to current Argon2 context
|
@@ -342,6 +394,16 @@ ARGON2_PUBLIC int argon2d_verify_ctx(argon2_context *context, const char *hash);
|
|
342
394
|
*/
|
343
395
|
ARGON2_PUBLIC int argon2i_verify_ctx(argon2_context *context, const char *hash);
|
344
396
|
|
397
|
+
/**
|
398
|
+
* Verify if a given password is correct for Argon2id hashing
|
399
|
+
* @param context Pointer to current Argon2 context
|
400
|
+
* @param hash The password hash to verify. The length of the hash is
|
401
|
+
* specified by the context outlen member
|
402
|
+
* @return Zero if successful, a non zero error code otherwise
|
403
|
+
*/
|
404
|
+
ARGON2_PUBLIC int argon2id_verify_ctx(argon2_context *context,
|
405
|
+
const char *hash);
|
406
|
+
|
345
407
|
/* generic function underlying the above ones */
|
346
408
|
ARGON2_PUBLIC int argon2_verify_ctx(argon2_context *context, const char *hash,
|
347
409
|
argon2_type type);
|
@@ -359,11 +421,12 @@ ARGON2_PUBLIC const char *argon2_error_message(int error_code);
|
|
359
421
|
* @param parallelism Number of threads; used to compute lanes
|
360
422
|
* @param saltlen Salt size in bytes
|
361
423
|
* @param hashlen Hash size in bytes
|
424
|
+
* @param type The argon2_type that we want the encoded length for
|
362
425
|
* @return The encoded hash length in bytes
|
363
426
|
*/
|
364
427
|
ARGON2_PUBLIC size_t argon2_encodedlen(uint32_t t_cost, uint32_t m_cost,
|
365
428
|
uint32_t parallelism, uint32_t saltlen,
|
366
|
-
uint32_t hashlen);
|
429
|
+
uint32_t hashlen, argon2_type type);
|
367
430
|
|
368
431
|
#if defined(__cplusplus)
|
369
432
|
}
|