sorcery-argon2 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +0 -2
  3. data/.rubocop.yml +34 -2
  4. data/CHANGELOG.md +4 -0
  5. data/MAINTAINING.md +8 -3
  6. data/bin/setup +3 -0
  7. data/ext/phc-winner-argon2/.gitattributes +10 -0
  8. data/ext/phc-winner-argon2/.gitignore +22 -0
  9. data/ext/phc-winner-argon2/.travis.yml +25 -0
  10. data/ext/phc-winner-argon2/Argon2.sln +158 -0
  11. data/ext/phc-winner-argon2/CHANGELOG.md +32 -0
  12. data/ext/phc-winner-argon2/LICENSE +314 -0
  13. data/ext/phc-winner-argon2/Makefile +255 -0
  14. data/ext/phc-winner-argon2/Package.swift +46 -0
  15. data/ext/phc-winner-argon2/README.md +303 -0
  16. data/ext/phc-winner-argon2/appveyor.yml +25 -0
  17. data/ext/phc-winner-argon2/argon2-specs.pdf +0 -0
  18. data/ext/phc-winner-argon2/export.sh +7 -0
  19. data/ext/phc-winner-argon2/include/argon2.h +437 -0
  20. data/ext/phc-winner-argon2/kats/argon2d +12304 -0
  21. data/ext/phc-winner-argon2/kats/argon2d.shasum +1 -0
  22. data/ext/phc-winner-argon2/kats/argon2d_v16 +12304 -0
  23. data/ext/phc-winner-argon2/kats/argon2d_v16.shasum +1 -0
  24. data/ext/phc-winner-argon2/kats/argon2i +12304 -0
  25. data/ext/phc-winner-argon2/kats/argon2i.shasum +1 -0
  26. data/ext/phc-winner-argon2/kats/argon2i_v16 +12304 -0
  27. data/ext/phc-winner-argon2/kats/argon2i_v16.shasum +1 -0
  28. data/ext/phc-winner-argon2/kats/argon2id +12304 -0
  29. data/ext/phc-winner-argon2/kats/argon2id.shasum +1 -0
  30. data/ext/phc-winner-argon2/kats/argon2id_v16 +12304 -0
  31. data/ext/phc-winner-argon2/kats/argon2id_v16.shasum +1 -0
  32. data/ext/phc-winner-argon2/kats/check-sums.ps1 +42 -0
  33. data/ext/phc-winner-argon2/kats/check-sums.sh +13 -0
  34. data/ext/phc-winner-argon2/kats/test.ps1 +50 -0
  35. data/ext/phc-winner-argon2/kats/test.sh +49 -0
  36. data/ext/phc-winner-argon2/latex/IEEEtran.cls +6347 -0
  37. data/ext/phc-winner-argon2/latex/Makefile +18 -0
  38. data/ext/phc-winner-argon2/latex/argon2-specs.tex +920 -0
  39. data/ext/phc-winner-argon2/latex/pics/argon2-par.pdf +0 -0
  40. data/ext/phc-winner-argon2/latex/pics/compression.pdf +0 -0
  41. data/ext/phc-winner-argon2/latex/pics/generic.pdf +0 -0
  42. data/ext/phc-winner-argon2/latex/pics/power-distribution.jpg +0 -0
  43. data/ext/phc-winner-argon2/latex/tradeoff.bib +822 -0
  44. data/ext/phc-winner-argon2/libargon2.pc.in +18 -0
  45. data/ext/phc-winner-argon2/man/argon2.1 +57 -0
  46. data/ext/phc-winner-argon2/src/argon2.c +452 -0
  47. data/ext/phc-winner-argon2/src/bench.c +111 -0
  48. data/ext/phc-winner-argon2/src/blake2/blake2-impl.h +156 -0
  49. data/ext/phc-winner-argon2/src/blake2/blake2.h +89 -0
  50. data/ext/phc-winner-argon2/src/blake2/blake2b.c +390 -0
  51. data/ext/phc-winner-argon2/src/blake2/blamka-round-opt.h +471 -0
  52. data/ext/phc-winner-argon2/src/blake2/blamka-round-ref.h +56 -0
  53. data/ext/phc-winner-argon2/src/core.c +648 -0
  54. data/ext/phc-winner-argon2/src/core.h +228 -0
  55. data/ext/phc-winner-argon2/src/encoding.c +463 -0
  56. data/ext/phc-winner-argon2/src/encoding.h +57 -0
  57. data/ext/phc-winner-argon2/src/genkat.c +213 -0
  58. data/ext/phc-winner-argon2/src/genkat.h +51 -0
  59. data/ext/phc-winner-argon2/src/opt.c +283 -0
  60. data/ext/phc-winner-argon2/src/ref.c +194 -0
  61. data/ext/phc-winner-argon2/src/run.c +337 -0
  62. data/ext/phc-winner-argon2/src/test.c +289 -0
  63. data/ext/phc-winner-argon2/src/thread.c +57 -0
  64. data/ext/phc-winner-argon2/src/thread.h +67 -0
  65. data/ext/phc-winner-argon2/vs2015/Argon2Opt/Argon2Opt.vcxproj +231 -0
  66. data/ext/phc-winner-argon2/vs2015/Argon2Opt/Argon2Opt.vcxproj.filters +69 -0
  67. data/ext/phc-winner-argon2/vs2015/Argon2OptBench/Argon2OptBench.vcxproj +231 -0
  68. data/ext/phc-winner-argon2/vs2015/Argon2OptBench/Argon2OptBench.vcxproj.filters +69 -0
  69. data/ext/phc-winner-argon2/vs2015/Argon2OptDll/Argon2OptDll.vcxproj +230 -0
  70. data/ext/phc-winner-argon2/vs2015/Argon2OptDll/Argon2OptDll.vcxproj.filters +66 -0
  71. data/ext/phc-winner-argon2/vs2015/Argon2OptGenKAT/Argon2OptGenKAT.vcxproj +244 -0
  72. data/ext/phc-winner-argon2/vs2015/Argon2OptGenKAT/Argon2OptGenKAT.vcxproj.filters +72 -0
  73. data/ext/phc-winner-argon2/vs2015/Argon2OptTestCI/Argon2OptTestCI.vcxproj +235 -0
  74. data/ext/phc-winner-argon2/vs2015/Argon2OptTestCI/Argon2OptTestCI.vcxproj.filters +69 -0
  75. data/ext/phc-winner-argon2/vs2015/Argon2Ref/Argon2Ref.vcxproj +243 -0
  76. data/ext/phc-winner-argon2/vs2015/Argon2Ref/Argon2Ref.vcxproj.filters +69 -0
  77. data/ext/phc-winner-argon2/vs2015/Argon2RefBench/Argon2RefBench.vcxproj +231 -0
  78. data/ext/phc-winner-argon2/vs2015/Argon2RefBench/Argon2RefBench.vcxproj.filters +69 -0
  79. data/ext/phc-winner-argon2/vs2015/Argon2RefDll/Argon2RefDll.vcxproj +230 -0
  80. data/ext/phc-winner-argon2/vs2015/Argon2RefDll/Argon2RefDll.vcxproj.filters +66 -0
  81. data/ext/phc-winner-argon2/vs2015/Argon2RefGenKAT/Argon2RefGenKAT.vcxproj +232 -0
  82. data/ext/phc-winner-argon2/vs2015/Argon2RefGenKAT/Argon2RefGenKAT.vcxproj.filters +72 -0
  83. data/ext/phc-winner-argon2/vs2015/Argon2RefTestCI/Argon2RefTestCI.vcxproj +231 -0
  84. data/ext/phc-winner-argon2/vs2015/Argon2RefTestCI/Argon2RefTestCI.vcxproj.filters +69 -0
  85. data/lib/argon2/ffi_engine.rb +4 -4
  86. data/lib/argon2/password.rb +11 -3
  87. data/lib/argon2/version.rb +1 -1
  88. metadata +84 -3
@@ -0,0 +1,255 @@
1
+ #
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 : https://creativecommons.org/publicdomain/zero/1.0
12
+ # - Apache 2.0 : https://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.
16
+ #
17
+
18
+ RUN = argon2
19
+ BENCH = bench
20
+ GENKAT = genkat
21
+ ARGON2_VERSION ?= ZERO
22
+
23
+ # installation parameters for staging area and final installation path
24
+ # Note; if Linux and not Debian/Ubuntu version also add lib override to make command-line
25
+ # for RedHat/Fedora, add: LIBRARY_REL=lib64
26
+ DESTDIR ?=
27
+ PREFIX ?= /usr
28
+
29
+ # Increment on an ABI breaking change
30
+ ABI_VERSION = 1
31
+
32
+ DIST = phc-winner-argon2
33
+
34
+ SRC = src/argon2.c src/core.c src/blake2/blake2b.c src/thread.c src/encoding.c
35
+ SRC_RUN = src/run.c
36
+ SRC_BENCH = src/bench.c
37
+ SRC_GENKAT = src/genkat.c
38
+ OBJ = $(SRC:.c=.o)
39
+
40
+ CFLAGS += -std=c89 -O3 -Wall -g -Iinclude -Isrc
41
+
42
+ ifeq ($(NO_THREADS), 1)
43
+ CFLAGS += -DARGON2_NO_THREADS
44
+ else
45
+ CFLAGS += -pthread
46
+ endif
47
+
48
+ CI_CFLAGS := $(CFLAGS) -Werror=declaration-after-statement -D_FORTIFY_SOURCE=2 \
49
+ -Wextra -Wno-type-limits -Werror -coverage -DTEST_LARGE_RAM
50
+
51
+ OPTTARGET ?= native
52
+ OPTTEST := $(shell $(CC) -Iinclude -Isrc -march=$(OPTTARGET) src/opt.c -c \
53
+ -o /dev/null 2>/dev/null; echo $$?)
54
+ # Detect compatible platform
55
+ ifneq ($(OPTTEST), 0)
56
+ $(info Building without optimizations)
57
+ SRC += src/ref.c
58
+ else
59
+ $(info Building with optimizations for $(OPTTARGET))
60
+ CFLAGS += -march=$(OPTTARGET)
61
+ SRC += src/opt.c
62
+ endif
63
+
64
+ BUILD_PATH := $(shell pwd)
65
+ KERNEL_NAME := $(shell uname -s)
66
+ MACHINE_NAME := $(shell uname -m)
67
+
68
+ LIB_NAME = argon2
69
+ PC_NAME = lib$(LIB_NAME).pc
70
+ PC_SRC = $(PC_NAME).in
71
+
72
+ ifeq ($(KERNEL_NAME), Linux)
73
+ LIB_EXT := so.$(ABI_VERSION)
74
+ LIB_CFLAGS := -shared -fPIC -fvisibility=hidden -DA2_VISCTL=1
75
+ SO_LDFLAGS := -Wl,-soname,lib$(LIB_NAME).$(LIB_EXT)
76
+ LINKED_LIB_EXT := so
77
+ PC_EXTRA_LIBS ?= -lrt -ldl
78
+ endif
79
+ ifeq ($(KERNEL_NAME), $(filter $(KERNEL_NAME),DragonFly FreeBSD NetBSD OpenBSD))
80
+ LIB_EXT := so
81
+ LIB_CFLAGS := -shared -fPIC
82
+ PC_EXTRA_LIBS ?=
83
+ endif
84
+ ifeq ($(KERNEL_NAME), Darwin)
85
+ LIB_EXT := $(ABI_VERSION).dylib
86
+ LIB_CFLAGS = -dynamiclib -install_name $(PREFIX)/$(LIBRARY_REL)/lib$(LIB_NAME).$(LIB_EXT)
87
+ LINKED_LIB_EXT := dylib
88
+ PC_EXTRA_LIBS ?=
89
+ endif
90
+ ifeq ($(findstring CYGWIN, $(KERNEL_NAME)), CYGWIN)
91
+ LIB_EXT := dll
92
+ LIB_CFLAGS := -shared -Wl,--out-implib,lib$(LIB_NAME).$(LIB_EXT).a
93
+ PC_EXTRA_LIBS ?=
94
+ endif
95
+ ifeq ($(findstring MINGW, $(KERNEL_NAME)), MINGW)
96
+ LIB_EXT := dll
97
+ LIB_CFLAGS := -shared -Wl,--out-implib,lib$(LIB_NAME).$(LIB_EXT).a
98
+ PC_EXTRA_LIBS ?=
99
+ endif
100
+ ifeq ($(findstring MSYS, $(KERNEL_NAME)), MSYS)
101
+ LIB_EXT := dll
102
+ LIB_CFLAGS := -shared -Wl,--out-implib,lib$(LIB_NAME).$(LIB_EXT).a
103
+ PC_EXTRA_LIBS ?=
104
+ endif
105
+ ifeq ($(KERNEL_NAME), SunOS)
106
+ CC := gcc
107
+ CFLAGS += -D_REENTRANT
108
+ LIB_EXT := so
109
+ LIB_CFLAGS := -shared -fPIC
110
+ PC_EXTRA_LIBS ?=
111
+ endif
112
+
113
+ ifeq ($(KERNEL_NAME), Linux)
114
+ ifeq ($(CC), clang)
115
+ CI_CFLAGS += -fsanitize=address -fsanitize=undefined
116
+ endif
117
+ endif
118
+
119
+ LIB_SH := lib$(LIB_NAME).$(LIB_EXT)
120
+ LIB_ST := lib$(LIB_NAME).a
121
+
122
+ ifdef LINKED_LIB_EXT
123
+ LINKED_LIB_SH := lib$(LIB_NAME).$(LINKED_LIB_EXT)
124
+ endif
125
+
126
+ # Some systems don't provide an unprefixed ar when cross-compiling.
127
+ AR=ar
128
+
129
+ LIBRARIES = $(LIB_SH) $(LIB_ST)
130
+ HEADERS = include/argon2.h
131
+
132
+ INSTALL = install
133
+
134
+ # relative paths for different OS
135
+ ifeq ($(KERNEL_NAME), $(filter $(KERNEL_NAME),DragonFly FreeBSD))
136
+
137
+ # default for FreeBSD
138
+ BINARY_REL ?= bin
139
+ INCLUDE_REL ?= include
140
+ LIBRARY_REL ?= lib
141
+ PKGCONFIG_REL ?= libdata
142
+
143
+ else ifeq ($(KERNEL_NAME)-$(MACHINE_NAME), Linux-x86_64)
144
+
145
+ # default for Debian/Ubuntu x86_64
146
+ BINARY_REL ?= bin
147
+ INCLUDE_REL ?= include
148
+ LIBRARY_REL ?= lib/x86_64-linux-gnu
149
+ PKGCONFIG_REL ?= $(LIBRARY_REL)
150
+
151
+ else
152
+
153
+ # NetBSD, ... and Linux64/Linux32 variants that use plain lib directory
154
+ BINARY_REL ?= bin
155
+ INCLUDE_REL ?= include
156
+ LIBRARY_REL ?= lib
157
+ PKGCONFIG_REL ?= $(LIBRARY_REL)
158
+
159
+ endif
160
+
161
+ # absolute paths to staging area
162
+ INST_INCLUDE = $(DESTDIR)$(PREFIX)/$(INCLUDE_REL)
163
+ INST_LIBRARY = $(DESTDIR)$(PREFIX)/$(LIBRARY_REL)
164
+ INST_BINARY = $(DESTDIR)$(PREFIX)/$(BINARY_REL)
165
+ INST_PKGCONFIG = $(DESTDIR)$(PREFIX)/$(PKGCONFIG_REL)/pkgconfig
166
+
167
+ # main target
168
+ .PHONY: all
169
+ all: $(RUN) libs
170
+
171
+ .PHONY: libs
172
+ libs: $(LIBRARIES) $(PC_NAME)
173
+
174
+ $(RUN): $(SRC) $(SRC_RUN)
175
+ $(CC) $(CFLAGS) $(LDFLAGS) $^ -o $@
176
+
177
+ $(BENCH): $(SRC) $(SRC_BENCH)
178
+ $(CC) $(CFLAGS) $^ -o $@
179
+
180
+ $(GENKAT): $(SRC) $(SRC_GENKAT)
181
+ $(CC) $(CFLAGS) $^ -o $@ -DGENKAT
182
+
183
+ $(LIB_SH): $(SRC)
184
+ $(CC) $(CFLAGS) $(LIB_CFLAGS) $(LDFLAGS) $(SO_LDFLAGS) $^ -o $@
185
+
186
+ $(LIB_ST): $(OBJ)
187
+ $(AR) rcs $@ $^
188
+
189
+ .PHONY: clean
190
+ clean:
191
+ rm -f '$(RUN)' '$(BENCH)' '$(GENKAT)'
192
+ rm -f '$(LIB_SH)' '$(LIB_ST)' kat-argon2* '$(PC_NAME)'
193
+ rm -f testcase
194
+ rm -rf *.dSYM
195
+ cd src/ && rm -f *.o
196
+ cd src/blake2/ && rm -f *.o
197
+ cd kats/ && rm -f kat-* diff* run_* make_*
198
+
199
+
200
+ # all substitutions to pc template
201
+ SED_COMMANDS = /^\#\#.*$$/d;
202
+ SED_COMMANDS += s\#@PREFIX@\#$(PREFIX)\#g;
203
+ SED_COMMANDS += s\#@EXTRA_LIBS@\#$(PC_EXTRA_LIBS)\#g;
204
+ SED_COMMANDS += s\#@UPSTREAM_VER@\#$(ARGON2_VERSION)\#g;
205
+ SED_COMMANDS += s\#@HOST_MULTIARCH@\#$(LIBRARY_REL)\#g;
206
+ SED_COMMANDS += s\#@INCLUDE@\#$(INCLUDE_REL)\#g;
207
+
208
+ # substitute PREFIX and PC_EXTRA_LIBS into pkgconfig pc file
209
+ $(PC_NAME): $(PC_SRC)
210
+ sed '$(SED_COMMANDS)' < '$(PC_SRC)' > '$@'
211
+
212
+
213
+ .PHONY: dist
214
+ dist:
215
+ cd ..; \
216
+ tar -c --exclude='.??*' -z -f $(DIST)-`date "+%Y%m%d"`.tgz $(DIST)/*
217
+
218
+ .PHONY: test
219
+ test: $(SRC) src/test.c
220
+ $(CC) $(CFLAGS) -Wextra -Wno-type-limits $^ -o testcase
221
+ @sh kats/test.sh
222
+ ./testcase
223
+
224
+ .PHONY: testci
225
+ testci: $(SRC) src/test.c
226
+ $(CC) $(CI_CFLAGS) $^ -o testcase
227
+ @sh kats/test.sh
228
+ ./testcase
229
+
230
+
231
+ .PHONY: format
232
+ format:
233
+ clang-format -style="{BasedOnStyle: llvm, IndentWidth: 4}" \
234
+ -i include/*.h src/*.c src/*.h src/blake2/*.c src/blake2/*.h
235
+
236
+ .PHONY: install
237
+ install: $(RUN) libs
238
+ $(INSTALL) -d $(INST_INCLUDE)
239
+ $(INSTALL) -m 0644 $(HEADERS) $(INST_INCLUDE)
240
+ $(INSTALL) -d $(INST_LIBRARY)
241
+ $(INSTALL) -m 0644 $(LIBRARIES) $(INST_LIBRARY)
242
+ ifdef LINKED_LIB_SH
243
+ cd $(INST_LIBRARY) && ln -sf $(notdir $(LIB_SH) $(LINKED_LIB_SH))
244
+ endif
245
+ $(INSTALL) -d $(INST_BINARY)
246
+ $(INSTALL) $(RUN) $(INST_BINARY)
247
+ $(INSTALL) -d $(INST_PKGCONFIG)
248
+ $(INSTALL) -m 0644 $(PC_NAME) $(INST_PKGCONFIG)
249
+
250
+ .PHONY: uninstall
251
+ uninstall:
252
+ cd $(INST_INCLUDE) && rm -f $(notdir $(HEADERS))
253
+ cd $(INST_LIBRARY) && rm -f $(notdir $(LIBRARIES) $(LINKED_LIB_SH))
254
+ cd $(INST_BINARY) && rm -f $(notdir $(RUN))
255
+ cd $(INST_PKG_CONFIG) && rm -f $(notdir $(PC_NAME))
@@ -0,0 +1,46 @@
1
+ // swift-tools-version:5.3
2
+
3
+ import PackageDescription
4
+
5
+ let package = Package(
6
+ name: "argon2",
7
+ products: [
8
+ .library(
9
+ name: "argon2",
10
+ targets: ["argon2"]),
11
+ ],
12
+ targets: [
13
+ .target(
14
+ name: "argon2",
15
+ path: ".",
16
+ exclude: [
17
+ "kats",
18
+ "vs2015",
19
+ "latex",
20
+ "libargon2.pc.in",
21
+ "export.sh",
22
+ "appveyor.yml",
23
+ "Argon2.sln",
24
+ "argon2-specs.pdf",
25
+ "CHANGELOG.md",
26
+ "LICENSE",
27
+ "Makefile",
28
+ "man",
29
+ "README.md",
30
+ "src/bench.c",
31
+ "src/genkat.c",
32
+ "src/opt.c",
33
+ "src/run.c",
34
+ "src/test.c",
35
+ ],
36
+ sources: [
37
+ "src/blake2/blake2b.c",
38
+ "src/argon2.c",
39
+ "src/core.c",
40
+ "src/encoding.c",
41
+ "src/ref.c",
42
+ "src/thread.c"
43
+ ]
44
+ )
45
+ ]
46
+ )
@@ -0,0 +1,303 @@
1
+ # Argon2
2
+
3
+ [![Build Status](https://travis-ci.org/P-H-C/phc-winner-argon2.svg?branch=master)](https://travis-ci.org/P-H-C/phc-winner-argon2)
4
+ [![Build status](https://ci.appveyor.com/api/projects/status/8nfwuwq55sgfkele?svg=true)](https://ci.appveyor.com/project/P-H-C/phc-winner-argon2)
5
+ [![codecov.io](https://codecov.io/github/P-H-C/phc-winner-argon2/coverage.svg?branch=master)](https://codecov.io/github/P-H-C/phc-winner-argon2?branch=master)
6
+
7
+ This is the reference C implementation of Argon2, the password-hashing
8
+ function that won the [Password Hashing Competition
9
+ (PHC)](https://password-hashing.net).
10
+
11
+ Argon2 is a password-hashing function that summarizes the state of the
12
+ art in the design of memory-hard functions and can be used to hash
13
+ passwords for credential storage, key derivation, or other applications.
14
+
15
+ It has a simple design aimed at the highest memory filling rate and
16
+ effective use of multiple computing units, while still providing defense
17
+ against tradeoff attacks (by exploiting the cache and memory organization
18
+ of the recent processors).
19
+
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
+ against GPU cracking attacks and suitable for applications with no threats
23
+ from side-channel timing attacks (eg. cryptocurrencies). Argon2i instead
24
+ uses data-independent memory access, which is preferred for password
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. 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.
31
+
32
+ Argon2i, Argon2d, and Argon2id are parametrized by:
33
+
34
+ * A **time** cost, which defines the amount of computation realized and
35
+ therefore the execution time, given in number of iterations
36
+ * A **memory** cost, which defines the memory usage, given in kibibytes
37
+ * A **parallelism** degree, which defines the number of parallel threads
38
+
39
+ The [Argon2 document](argon2-specs.pdf) gives detailed specs and design
40
+ rationale.
41
+
42
+ Please report bugs as issues on this repository.
43
+
44
+ ## Usage
45
+
46
+ `make` builds the executable `argon2`, the static library `libargon2.a`,
47
+ and the shared library `libargon2.so` (or on macOS, the dynamic library
48
+ `libargon2.dylib` -- make sure to specify the installation prefix when
49
+ you compile: `make PREFIX=/usr`). Make sure to run `make test` to verify
50
+ that your build produces valid results. `sudo make install PREFIX=/usr`
51
+ installs it to your system.
52
+
53
+ ### Command-line utility
54
+
55
+ `argon2` is a command-line utility to test specific Argon2 instances
56
+ on your system. To show usage instructions, run
57
+ `./argon2 -h` as
58
+ ```
59
+ Usage: ./argon2 [-h] salt [-i|-d|-id] [-t iterations] [-m memory] [-p parallelism] [-l hash length] [-e|-r] [-v (10|13)]
60
+ Password is read from stdin
61
+ Parameters:
62
+ salt The salt to use, at least 8 characters
63
+ -i Use Argon2i (this is the default)
64
+ -d Use Argon2d instead of Argon2i
65
+ -id Use Argon2id instead of Argon2i
66
+ -t N Sets the number of iterations to N (default = 3)
67
+ -m N Sets the memory usage of 2^N KiB (default 12)
68
+ -p N Sets parallelism to N threads (default 1)
69
+ -l N Sets hash output length to N bytes (default 32)
70
+ -e Output only encoded hash
71
+ -r Output only the raw bytes of the hash
72
+ -v (10|13) Argon2 version (defaults to the most recent version, currently 13)
73
+ -h Print argon2 usage
74
+ ```
75
+ For example, to hash "password" using "somesalt" as a salt and doing 2
76
+ iterations, consuming 64 MiB, using four parallel threads and an output hash
77
+ of 24 bytes
78
+ ```
79
+ $ echo -n "password" | ./argon2 somesalt -t 2 -m 16 -p 4 -l 24
80
+ Type: Argon2i
81
+ Iterations: 2
82
+ Memory: 65536 KiB
83
+ Parallelism: 4
84
+ Hash: 45d7ac72e76f242b20b77b9bf9bf9d5915894e669a24e6c6
85
+ Encoded: $argon2i$v=19$m=65536,t=2,p=4$c29tZXNhbHQ$RdescudvJCsgt3ub+b+dWRWJTmaaJObG
86
+ 0.188 seconds
87
+ Verification ok
88
+ ```
89
+
90
+ ### Library
91
+
92
+ `libargon2` provides an API to both low-level and high-level functions
93
+ for using Argon2.
94
+
95
+ The example program below hashes the string "password" with Argon2i
96
+ using the high-level API and then using the low-level API. While the
97
+ high-level API takes the three cost parameters (time, memory, and
98
+ parallelism), the password input buffer, the salt input buffer, and the
99
+ output buffers, the low-level API takes in these and additional parameters
100
+ , as defined in [`include/argon2.h`](include/argon2.h).
101
+
102
+ There are many additional parameters, but we will highlight three of them here.
103
+
104
+ 1. The `secret` parameter, which is used for [keyed hashing](
105
+ https://en.wikipedia.org/wiki/Hash-based_message_authentication_code).
106
+ This allows a secret key to be input at hashing time (from some external
107
+ location) and be folded into the value of the hash. This means that even if
108
+ your salts and hashes are compromized, an attacker cannot brute-force to find
109
+ the password without the key.
110
+
111
+ 2. The `ad` parameter, which is used to fold any additional data into the hash
112
+ value. Functionally, this behaves almost exactly like the `secret` or `salt`
113
+ parameters; the `ad` parameter is folding into the value of the hash.
114
+ However, this parameter is used for different data. The `salt` should be a
115
+ random string stored alongside your password. The `secret` should be a random
116
+ key only usable at hashing time. The `ad` is for any other data.
117
+
118
+ 3. The `flags` parameter, which determines which memory should be securely
119
+ erased. This is useful if you want to securly delete the `pwd` or `secret`
120
+ fields right after they are used. To do this set `flags` to either
121
+ `ARGON2_FLAG_CLEAR_PASSWORD` or `ARGON2_FLAG_CLEAR_SECRET`. To change how
122
+ internal memory is cleared, change the global flag
123
+ `FLAG_clear_internal_memory` (defaults to clearing internal memory).
124
+
125
+ Here the time cost `t_cost` is set to 2 iterations, the
126
+ memory cost `m_cost` is set to 2<sup>16</sup> kibibytes (64 mebibytes),
127
+ and parallelism is set to 1 (single-thread).
128
+
129
+ Compile for example as `gcc test.c libargon2.a -Isrc -o test`, if the program
130
+ below is named `test.c` and placed in the project's root directory.
131
+
132
+ ```c
133
+ #include "argon2.h"
134
+ #include <stdio.h>
135
+ #include <string.h>
136
+ #include <stdlib.h>
137
+
138
+ #define HASHLEN 32
139
+ #define SALTLEN 16
140
+ #define PWD "password"
141
+
142
+ int main(void)
143
+ {
144
+ uint8_t hash1[HASHLEN];
145
+ uint8_t hash2[HASHLEN];
146
+
147
+ uint8_t salt[SALTLEN];
148
+ memset( salt, 0x00, SALTLEN );
149
+
150
+ uint8_t *pwd = (uint8_t *)strdup(PWD);
151
+ uint32_t pwdlen = strlen((char *)pwd);
152
+
153
+ uint32_t t_cost = 2; // 2-pass computation
154
+ uint32_t m_cost = (1<<16); // 64 mebibytes memory usage
155
+ uint32_t parallelism = 1; // number of threads and lanes
156
+
157
+ // high-level API
158
+ argon2i_hash_raw(t_cost, m_cost, parallelism, pwd, pwdlen, salt, SALTLEN, hash1, HASHLEN);
159
+
160
+ // low-level API
161
+ argon2_context context = {
162
+ hash2, /* output array, at least HASHLEN in size */
163
+ HASHLEN, /* digest length */
164
+ pwd, /* password array */
165
+ pwdlen, /* password length */
166
+ salt, /* salt array */
167
+ SALTLEN, /* salt length */
168
+ NULL, 0, /* optional secret data */
169
+ NULL, 0, /* optional associated data */
170
+ t_cost, m_cost, parallelism, parallelism,
171
+ ARGON2_VERSION_13, /* algorithm version */
172
+ NULL, NULL, /* custom memory allocation / deallocation functions */
173
+ /* by default only internal memory is cleared (pwd is not wiped) */
174
+ ARGON2_DEFAULT_FLAGS
175
+ };
176
+
177
+ int rc = argon2i_ctx( &context );
178
+ if(ARGON2_OK != rc) {
179
+ printf("Error: %s\n", argon2_error_message(rc));
180
+ exit(1);
181
+ }
182
+ free(pwd);
183
+
184
+ for( int i=0; i<HASHLEN; ++i ) printf( "%02x", hash1[i] ); printf( "\n" );
185
+ if (memcmp(hash1, hash2, HASHLEN)) {
186
+ for( int i=0; i<HASHLEN; ++i ) {
187
+ printf( "%02x", hash2[i] );
188
+ }
189
+ printf("\nfail\n");
190
+ }
191
+ else printf("ok\n");
192
+ return 0;
193
+ }
194
+ ```
195
+
196
+ To use Argon2d instead of Argon2i call `argon2d_hash_raw` instead of
197
+ `argon2i_hash_raw` using the high-level API, and `argon2d` instead of
198
+ `argon2i` using the low-level API. Similarly for Argon2id, call `argon2id_hash_raw`
199
+ and `argon2id`.
200
+
201
+ To produce the crypt-like encoding rather than the raw hash, call
202
+ `argon2i_hash_encoded` for Argon2i, `argon2d_hash_encoded` for Argon2d, and
203
+ `argon2id_hash_encoded` for Argon2id
204
+
205
+ See [`include/argon2.h`](include/argon2.h) for API details.
206
+
207
+ *Note: in this example the salt is set to the all-`0x00` string for the
208
+ sake of simplicity, but in your application you should use a random salt.*
209
+
210
+
211
+ ### Benchmarks
212
+
213
+ `make bench` creates the executable `bench`, which measures the execution
214
+ time of various Argon2 instances:
215
+
216
+ ```
217
+ $ ./bench
218
+ Argon2d 1 iterations 1 MiB 1 threads: 5.91 cpb 5.91 Mcycles
219
+ Argon2i 1 iterations 1 MiB 1 threads: 4.64 cpb 4.64 Mcycles
220
+ 0.0041 seconds
221
+
222
+ Argon2d 1 iterations 1 MiB 2 threads: 2.76 cpb 2.76 Mcycles
223
+ Argon2i 1 iterations 1 MiB 2 threads: 2.87 cpb 2.87 Mcycles
224
+ 0.0038 seconds
225
+
226
+ Argon2d 1 iterations 1 MiB 4 threads: 3.25 cpb 3.25 Mcycles
227
+ Argon2i 1 iterations 1 MiB 4 threads: 3.57 cpb 3.57 Mcycles
228
+ 0.0048 seconds
229
+
230
+ (...)
231
+
232
+ Argon2d 1 iterations 4096 MiB 2 threads: 2.15 cpb 8788.08 Mcycles
233
+ Argon2i 1 iterations 4096 MiB 2 threads: 2.15 cpb 8821.59 Mcycles
234
+ 13.0112 seconds
235
+
236
+ Argon2d 1 iterations 4096 MiB 4 threads: 1.79 cpb 7343.72 Mcycles
237
+ Argon2i 1 iterations 4096 MiB 4 threads: 2.72 cpb 11124.86 Mcycles
238
+ 19.3974 seconds
239
+
240
+ (...)
241
+ ```
242
+
243
+ ## Bindings
244
+
245
+ Bindings are available for the following languages (make sure to read
246
+ their documentation):
247
+
248
+ * [Android (Java/Kotlin)](https://github.com/lambdapioneer/argon2kt) by [@lambdapioneer](https://github.com/lambdapioneer)
249
+ * [Dart](https://github.com/tmthecoder/dargon2) by [@tmthecoder](https://github.com/tmthecoder)
250
+ * [Elixir](https://github.com/riverrun/argon2_elixir) by [@riverrun](https://github.com/riverrun)
251
+ * [Erlang](https://github.com/ergenius/eargon2) by [@ergenius](https://github.com/ergenius)
252
+ * [Go](https://github.com/tvdburgt/go-argon2) by [@tvdburgt](https://github.com/tvdburgt)
253
+ * [Haskell](https://hackage.haskell.org/package/argon2) by [@hvr](https://github.com/hvr)
254
+ * [JavaScript (native)](https://github.com/ranisalt/node-argon2), by [@ranisalt](https://github.com/ranisalt)
255
+ * [JavaScript (native)](https://github.com/jdconley/argon2themax), by [@jdconley](https://github.com/jdconley)
256
+ * [JavaScript (ffi)](https://github.com/cjlarose/argon2-ffi), by [@cjlarose](https://github.com/cjlarose)
257
+ * [JavaScript (browser)](https://github.com/antelle/argon2-browser), by [@antelle](https://github.com/antelle)
258
+ * [JVM](https://github.com/phxql/argon2-jvm) by [@phXql](https://github.com/phxql)
259
+ * [JVM (with keyed hashing)](https://github.com/kosprov/jargon2-api) by [@kosprov](https://github.com/kosprov)
260
+ * [Lua (native)](https://github.com/thibaultCha/lua-argon2) by [@thibaultCha](https://github.com/thibaultCha)
261
+ * [Lua (ffi)](https://github.com/thibaultCha/lua-argon2-ffi) by [@thibaultCha](https://github.com/thibaultCha)
262
+ * [OCaml](https://github.com/Khady/ocaml-argon2) by [@Khady](https://github.com/Khady)
263
+ * [Python (native)](https://pypi.python.org/pypi/argon2), by [@flamewow](https://github.com/flamewow)
264
+ * [Python (ffi)](https://pypi.python.org/pypi/argon2_cffi), by [@hynek](https://github.com/hynek)
265
+ * [Python (ffi, with keyed hashing)](https://github.com/thusoy/porridge), by [@thusoy](https://github.com/thusoy)
266
+ * [Python (ffi, with keyed hashing)](https://github.com/ultrahorizon/pyargon2), by [@ultrahorizon](https://github.com/ultrahorizon)
267
+ * [R](https://cran.r-project.org/package=argon2) by [@wrathematics](https://github.com/wrathematics)
268
+ * [Ruby](https://github.com/technion/ruby-argon2) by [@technion](https://github.com/technion)
269
+ * [Rust](https://github.com/quininer/argon2-rs) by [@quininer](https://github.com/quininer)
270
+ * [Rust](https://docs.rs/argonautica/) by [@bcmyers](https://github.com/bcmyers/)
271
+ * [C#/.NET CoreCLR](https://github.com/kmaragon/Konscious.Security.Cryptography) by [@kmaragon](https://github.com/kmaragon)
272
+ * [Perl](https://github.com/Leont/crypt-argon2) by [@leont](https://github.com/Leont)
273
+ * [mruby](https://github.com/Asmod4n/mruby-argon2) by [@Asmod4n](https://github.com/Asmod4n)
274
+ * [Swift](https://github.com/ImKcat/CatCrypto) by [@ImKcat](https://github.com/ImKcat)
275
+ * [Swift](https://github.com/tmthecoder/Argon2Swift) by [@tmthecoder](https://github.com/tmthecoder)
276
+
277
+
278
+ ## Test suite
279
+
280
+ There are two sets of test suites. One is a low level test for the hash
281
+ function, the other tests the higher level API. Both of these are built and
282
+ executed by running:
283
+
284
+ `make test`
285
+
286
+ ## Intellectual property
287
+
288
+ Except for the components listed below, the Argon2 code in this
289
+ repository is copyright (c) 2015 Daniel Dinu, Dmitry Khovratovich (main
290
+ authors), Jean-Philippe Aumasson and Samuel Neves, and dual licensed under the
291
+ [CC0 License](https://creativecommons.org/about/cc0) and the
292
+ [Apache 2.0 License](https://www.apache.org/licenses/LICENSE-2.0). For more info
293
+ see the LICENSE file.
294
+
295
+ The string encoding routines in [`src/encoding.c`](src/encoding.c) are
296
+ copyright (c) 2015 Thomas Pornin, and under
297
+ [CC0 License](https://creativecommons.org/about/cc0).
298
+
299
+ The BLAKE2 code in [`src/blake2/`](src/blake2) is copyright (c) Samuel
300
+ Neves, 2013-2015, and under
301
+ [CC0 License](https://creativecommons.org/about/cc0).
302
+
303
+ All licenses are therefore GPL-compatible.