enzoic 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +19 -0
  3. data/.gitmodules +3 -0
  4. data/.travis.yml +3 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE +5 -0
  7. data/README.md +90 -0
  8. data/Rakefile +28 -0
  9. data/enzoic.gemspec +36 -0
  10. data/ext/.DS_Store +0 -0
  11. data/ext/argon2-wrapper/Makefile +74 -0
  12. data/ext/argon2-wrapper/argon2-wrapper.c +165 -0
  13. data/ext/argon2-wrapper/extconf.rb +1 -0
  14. data/ext/argon2_import/.DS_Store +0 -0
  15. data/ext/digest/whirlpool/extconf.rb +10 -0
  16. data/ext/digest/whirlpool/whirlpool-algorithm.c +476 -0
  17. data/ext/digest/whirlpool/whirlpool-algorithm.h +86 -0
  18. data/ext/digest/whirlpool/whirlpool-constants.h +1116 -0
  19. data/ext/digest/whirlpool/whirlpool-portability.h +142 -0
  20. data/ext/digest/whirlpool/whirlpool.c +51 -0
  21. data/ext/phc-winner-argon2/.gitattributes +10 -0
  22. data/ext/phc-winner-argon2/.gitignore +21 -0
  23. data/ext/phc-winner-argon2/.travis.yml +14 -0
  24. data/ext/phc-winner-argon2/Argon2.sln +160 -0
  25. data/ext/phc-winner-argon2/CHANGELOG.md +25 -0
  26. data/ext/phc-winner-argon2/LICENSE +314 -0
  27. data/ext/phc-winner-argon2/Makefile +187 -0
  28. data/ext/phc-winner-argon2/README.md +290 -0
  29. data/ext/phc-winner-argon2/appveyor.yml +25 -0
  30. data/ext/phc-winner-argon2/argon2-specs.pdf +0 -0
  31. data/ext/phc-winner-argon2/export.sh +7 -0
  32. data/ext/phc-winner-argon2/include/argon2.h +435 -0
  33. data/ext/phc-winner-argon2/kats/argon2d +12304 -0
  34. data/ext/phc-winner-argon2/kats/argon2d.shasum +1 -0
  35. data/ext/phc-winner-argon2/kats/argon2d_v16 +12304 -0
  36. data/ext/phc-winner-argon2/kats/argon2d_v16.shasum +1 -0
  37. data/ext/phc-winner-argon2/kats/argon2i +12304 -0
  38. data/ext/phc-winner-argon2/kats/argon2i.shasum +1 -0
  39. data/ext/phc-winner-argon2/kats/argon2i_v16 +12304 -0
  40. data/ext/phc-winner-argon2/kats/argon2i_v16.shasum +1 -0
  41. data/ext/phc-winner-argon2/kats/argon2id +12304 -0
  42. data/ext/phc-winner-argon2/kats/argon2id.shasum +1 -0
  43. data/ext/phc-winner-argon2/kats/argon2id_v16 +12304 -0
  44. data/ext/phc-winner-argon2/kats/argon2id_v16.shasum +1 -0
  45. data/ext/phc-winner-argon2/kats/check-sums.ps1 +42 -0
  46. data/ext/phc-winner-argon2/kats/check-sums.sh +13 -0
  47. data/ext/phc-winner-argon2/kats/test.ps1 +50 -0
  48. data/ext/phc-winner-argon2/kats/test.sh +49 -0
  49. data/ext/phc-winner-argon2/latex/IEEEtran.cls +6347 -0
  50. data/ext/phc-winner-argon2/latex/Makefile +18 -0
  51. data/ext/phc-winner-argon2/latex/argon2-specs.tex +920 -0
  52. data/ext/phc-winner-argon2/latex/pics/argon2-par.pdf +0 -0
  53. data/ext/phc-winner-argon2/latex/pics/compression.pdf +0 -0
  54. data/ext/phc-winner-argon2/latex/pics/generic.pdf +0 -0
  55. data/ext/phc-winner-argon2/latex/pics/power-distribution.jpg +0 -0
  56. data/ext/phc-winner-argon2/latex/tradeoff.bib +822 -0
  57. data/ext/phc-winner-argon2/libargon2.pc +16 -0
  58. data/ext/phc-winner-argon2/man/argon2.1 +57 -0
  59. data/ext/phc-winner-argon2/src/argon2.c +452 -0
  60. data/ext/phc-winner-argon2/src/bench.c +111 -0
  61. data/ext/phc-winner-argon2/src/blake2/blake2-impl.h +156 -0
  62. data/ext/phc-winner-argon2/src/blake2/blake2.h +91 -0
  63. data/ext/phc-winner-argon2/src/blake2/blake2b.c +390 -0
  64. data/ext/phc-winner-argon2/src/blake2/blamka-round-opt.h +328 -0
  65. data/ext/phc-winner-argon2/src/blake2/blamka-round-ref.h +56 -0
  66. data/ext/phc-winner-argon2/src/core.c +635 -0
  67. data/ext/phc-winner-argon2/src/core.h +227 -0
  68. data/ext/phc-winner-argon2/src/encoding.c +463 -0
  69. data/ext/phc-winner-argon2/src/encoding.h +57 -0
  70. data/ext/phc-winner-argon2/src/genkat.c +208 -0
  71. data/ext/phc-winner-argon2/src/genkat.h +49 -0
  72. data/ext/phc-winner-argon2/src/opt.c +241 -0
  73. data/ext/phc-winner-argon2/src/ref.c +194 -0
  74. data/ext/phc-winner-argon2/src/run.c +317 -0
  75. data/ext/phc-winner-argon2/src/test.c +254 -0
  76. data/ext/phc-winner-argon2/src/thread.c +57 -0
  77. data/ext/phc-winner-argon2/src/thread.h +67 -0
  78. data/ext/phc-winner-argon2/vs2015/Argon2Opt/Argon2Opt.vcxproj +226 -0
  79. data/ext/phc-winner-argon2/vs2015/Argon2Opt/Argon2Opt.vcxproj.filters +69 -0
  80. data/ext/phc-winner-argon2/vs2015/Argon2OptBench/Argon2OptBench.vcxproj +226 -0
  81. data/ext/phc-winner-argon2/vs2015/Argon2OptBench/Argon2OptBench.vcxproj.filters +69 -0
  82. data/ext/phc-winner-argon2/vs2015/Argon2OptDll/Argon2OptDll.vcxproj +225 -0
  83. data/ext/phc-winner-argon2/vs2015/Argon2OptDll/Argon2OptDll.vcxproj.filters +66 -0
  84. data/ext/phc-winner-argon2/vs2015/Argon2OptGenKAT/Argon2OptGenKAT.vcxproj +239 -0
  85. data/ext/phc-winner-argon2/vs2015/Argon2OptGenKAT/Argon2OptGenKAT.vcxproj.filters +72 -0
  86. data/ext/phc-winner-argon2/vs2015/Argon2OptTestCI/Argon2OptTestCI.vcxproj +227 -0
  87. data/ext/phc-winner-argon2/vs2015/Argon2OptTestCI/Argon2OptTestCI.vcxproj.filters +69 -0
  88. data/ext/phc-winner-argon2/vs2015/Argon2Ref/Argon2Ref.vcxproj +226 -0
  89. data/ext/phc-winner-argon2/vs2015/Argon2Ref/Argon2Ref.vcxproj.filters +69 -0
  90. data/ext/phc-winner-argon2/vs2015/Argon2RefBench/Argon2RefBench.vcxproj +226 -0
  91. data/ext/phc-winner-argon2/vs2015/Argon2RefBench/Argon2RefBench.vcxproj.filters +69 -0
  92. data/ext/phc-winner-argon2/vs2015/Argon2RefDll/Argon2RefDll.vcxproj +225 -0
  93. data/ext/phc-winner-argon2/vs2015/Argon2RefDll/Argon2RefDll.vcxproj.filters +66 -0
  94. data/ext/phc-winner-argon2/vs2015/Argon2RefGenKAT/Argon2RefGenKAT.vcxproj +227 -0
  95. data/ext/phc-winner-argon2/vs2015/Argon2RefGenKAT/Argon2RefGenKAT.vcxproj.filters +72 -0
  96. data/ext/phc-winner-argon2/vs2015/Argon2RefTestCI/Argon2RefTestCI.vcxproj +226 -0
  97. data/ext/phc-winner-argon2/vs2015/Argon2RefTestCI/Argon2RefTestCI.vcxproj.filters +69 -0
  98. data/lib/enzoic.rb +189 -0
  99. data/lib/enzoic/argon2_errors.rb +39 -0
  100. data/lib/enzoic/argon2_wrapper_ffi.rb +89 -0
  101. data/lib/enzoic/constants.rb +10 -0
  102. data/lib/enzoic/errors.rb +3 -0
  103. data/lib/enzoic/hashing.rb +258 -0
  104. data/lib/enzoic/password_type.rb +25 -0
  105. data/lib/enzoic/version.rb +5 -0
  106. metadata +354 -0
@@ -0,0 +1,187 @@
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 : 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.
16
+ #
17
+
18
+ RUN = argon2
19
+ BENCH = bench
20
+ GENKAT = genkat
21
+
22
+ # Increment on an ABI breaking change
23
+ ABI_VERSION = 0
24
+
25
+ DIST = phc-winner-argon2
26
+
27
+ SRC = src/argon2.c src/core.c src/blake2/blake2b.c src/thread.c src/encoding.c
28
+ SRC_RUN = src/run.c
29
+ SRC_BENCH = src/bench.c
30
+ SRC_GENKAT = src/genkat.c
31
+ OBJ = $(SRC:.c=.o)
32
+
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
+
41
+ CI_CFLAGS := $(CFLAGS) -Werror=declaration-after-statement -D_FORTIFY_SOURCE=2 \
42
+ -Wextra -Wno-type-limits -Werror -coverage -DTEST_LARGE_RAM
43
+
44
+ OPTTARGET ?= native
45
+ OPTTEST := $(shell $(CC) -Iinclude -Isrc -march=$(OPTTARGET) src/opt.c -c \
46
+ -o /dev/null 2>/dev/null; echo $$?)
47
+ # Detect compatible platform
48
+ ifneq ($(OPTTEST), 0)
49
+ $(info Building without optimizations)
50
+ SRC += src/ref.c
51
+ else
52
+ $(info Building with optimizations for $(OPTTARGET))
53
+ CFLAGS += -march=$(OPTTARGET)
54
+ SRC += src/opt.c
55
+ endif
56
+
57
+ BUILD_PATH := $(shell pwd)
58
+ KERNEL_NAME := $(shell uname -s)
59
+
60
+ LIB_NAME=argon2
61
+ ifeq ($(KERNEL_NAME), Linux)
62
+ LIB_EXT := so.$(ABI_VERSION)
63
+ LIB_CFLAGS := -shared -fPIC -fvisibility=hidden -DA2_VISCTL=1
64
+ SO_LDFLAGS := -Wl,-soname,lib$(LIB_NAME).$(LIB_EXT)
65
+ LINKED_LIB_EXT := so
66
+ endif
67
+ ifeq ($(KERNEL_NAME), $(filter $(KERNEL_NAME),FreeBSD NetBSD OpenBSD))
68
+ LIB_EXT := so
69
+ LIB_CFLAGS := -shared -fPIC
70
+ endif
71
+ ifeq ($(KERNEL_NAME), Darwin)
72
+ LIB_EXT := $(ABI_VERSION).dylib
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
79
+ endif
80
+ ifeq ($(findstring MINGW, $(KERNEL_NAME)), MINGW)
81
+ LIB_EXT := dll
82
+ LIB_CFLAGS := -shared -Wl,--out-implib,lib$(LIB_NAME).$(LIB_EXT).a
83
+ endif
84
+ ifeq ($(findstring MSYS, $(KERNEL_NAME)), MSYS)
85
+ LIB_EXT := dll
86
+ LIB_CFLAGS := -shared -Wl,--out-implib,lib$(LIB_NAME).$(LIB_EXT).a
87
+ endif
88
+ ifeq ($(KERNEL_NAME), SunOS)
89
+ CC := gcc
90
+ CFLAGS += -D_REENTRANT
91
+ LIB_EXT := so
92
+ LIB_CFLAGS := -shared -fPIC
93
+ endif
94
+
95
+ ifeq ($(KERNEL_NAME), Linux)
96
+ ifeq ($(CC), clang)
97
+ CI_CFLAGS += -fsanitize=address -fsanitize=undefined
98
+ endif
99
+ endif
100
+
101
+ LIB_SH := lib$(LIB_NAME).$(LIB_EXT)
102
+ LIB_ST := lib$(LIB_NAME).a
103
+
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
119
+
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)
128
+
129
+ $(RUN): $(SRC) $(SRC_RUN)
130
+ $(CC) $(CFLAGS) $(LDFLAGS) $^ -o $@
131
+
132
+ $(BENCH): $(SRC) $(SRC_BENCH)
133
+ $(CC) $(CFLAGS) $^ -o $@
134
+
135
+ $(GENKAT): $(SRC) $(SRC_GENKAT)
136
+ $(CC) $(CFLAGS) $^ -o $@ -DGENKAT
137
+
138
+ $(LIB_SH): $(SRC)
139
+ $(CC) $(CFLAGS) $(LIB_CFLAGS) $(LDFLAGS) $(SO_LDFLAGS) $^ -o $@
140
+
141
+ $(LIB_ST): $(OBJ)
142
+ ar rcs $@ $^
143
+
144
+ clean:
145
+ rm -f $(RUN) $(BENCH) $(GENKAT)
146
+ rm -f $(LIB_SH) $(LIB_ST) kat-argon2*
147
+ rm -f testcase
148
+ rm -rf *.dSYM
149
+ cd src/ && rm -f *.o
150
+ cd src/blake2/ && rm -f *.o
151
+ cd kats/ && rm -f kat-* diff* run_* make_*
152
+
153
+ dist:
154
+ cd ..; \
155
+ tar -c --exclude='.??*' -z -f $(DIST)-`date "+%Y%m%d"`.tgz $(DIST)/*
156
+
157
+ test: $(SRC) src/test.c
158
+ $(CC) $(CFLAGS) -Wextra -Wno-type-limits $^ -o testcase
159
+ @sh kats/test.sh
160
+ ./testcase
161
+
162
+ testci: $(SRC) src/test.c
163
+ $(CC) $(CI_CFLAGS) $^ -o testcase
164
+ @sh kats/test.sh
165
+ ./testcase
166
+
167
+ .PHONY: test
168
+
169
+ format:
170
+ clang-format -style="{BasedOnStyle: llvm, IndentWidth: 4}" \
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))
@@ -0,0 +1,290 @@
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 `libargon2.dylib` on OSX).
48
+ Make sure to run `make test` to verify that your build produces valid
49
+ results. `make install PREFIX=/usr` installs it to your system.
50
+
51
+ ### Command-line utility
52
+
53
+ `argon2` is a command-line utility to test specific Argon2 instances
54
+ on your system. To show usage instructions, run
55
+ `./argon2 -h` as
56
+ ```
57
+ Usage: ./argon2 [-h] salt [-i|-d|-id] [-t iterations] [-m memory] [-p parallelism] [-l hash length] [-e|-r] [-v (10|13)]
58
+ Password is read from stdin
59
+ Parameters:
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
64
+ -t N Sets the number of iterations to N (default = 3)
65
+ -m N Sets the memory usage of 2^N KiB (default 12)
66
+ -p N Sets parallelism to N threads (default 1)
67
+ -l N Sets hash output length to N bytes (default 32)
68
+ -e Output only encoded hash
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
72
+ ```
73
+ For example, to hash "password" using "somesalt" as a salt and doing 2
74
+ iterations, consuming 64 MiB, using four parallel threads and an output hash
75
+ of 24 bytes
76
+ ```
77
+ $ echo -n "password" | ./argon2 somesalt -t 2 -m 16 -p 4 -l 24
78
+ Type: Argon2i
79
+ Iterations: 2
80
+ Memory: 65536 KiB
81
+ Parallelism: 4
82
+ Hash: 45d7ac72e76f242b20b77b9bf9bf9d5915894e669a24e6c6
83
+ Encoded: $argon2i$v=19$m=65536,t=2,p=4$c29tZXNhbHQ$RdescudvJCsgt3ub+b+dWRWJTmaaJObG
84
+ 0.188 seconds
85
+ Verification ok
86
+ ```
87
+
88
+ ### Library
89
+
90
+ `libargon2` provides an API to both low-level and high-level functions
91
+ for using Argon2.
92
+
93
+ The example program below hashes the string "password" with Argon2i
94
+ using the high-level API and then using the low-level API. While the
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).
122
+
123
+ Here the time cost `t_cost` is set to 2 iterations, the
124
+ memory cost `m_cost` is set to 2<sup>16</sup> kibibytes (64 mebibytes),
125
+ and parallelism is set to 1 (single-thread).
126
+
127
+ Compile for example as `gcc test.c libargon2.a -Isrc -o test`, if the program
128
+ below is named `test.c` and placed in the project's root directory.
129
+
130
+ ```c
131
+ #include "argon2.h"
132
+ #include <stdio.h>
133
+ #include <string.h>
134
+ #include <stdlib.h>
135
+
136
+ #define HASHLEN 32
137
+ #define SALTLEN 16
138
+ #define PWD "password"
139
+
140
+ int main(void)
141
+ {
142
+ uint8_t hash1[HASHLEN];
143
+ uint8_t hash2[HASHLEN];
144
+
145
+ uint8_t salt[SALTLEN];
146
+ memset( salt, 0x00, SALTLEN );
147
+
148
+ uint8_t *pwd = (uint8_t *)strdup(PWD);
149
+ uint32_t pwdlen = strlen((char *)pwd);
150
+
151
+ uint32_t t_cost = 2; // 1-pass computation
152
+ uint32_t m_cost = (1<<16); // 64 mebibytes memory usage
153
+ uint32_t parallelism = 1; // number of threads and lanes
154
+
155
+ // high-level API
156
+ argon2i_hash_raw(t_cost, m_cost, parallelism, pwd, pwdlen, salt, SALTLEN, hash1, HASHLEN);
157
+
158
+ // low-level API
159
+ argon2_context context = {
160
+ hash2, /* output array, at least HASHLEN in size */
161
+ HASHLEN, /* digest length */
162
+ pwd, /* password array */
163
+ pwdlen, /* password length */
164
+ salt, /* salt array */
165
+ SALTLEN, /* salt length */
166
+ NULL, 0, /* optional secret data */
167
+ NULL, 0, /* optional associated data */
168
+ t_cost, m_cost, parallelism, parallelism,
169
+ ARGON2_VERSION_13, /* algorithm version */
170
+ NULL, NULL, /* custom memory allocation / deallocation functions */
171
+ /* by default only internal memory is cleared (pwd is not wiped) */
172
+ ARGON2_DEFAULT_FLAGS
173
+ };
174
+
175
+ int rc = argon2i_ctx( &context );
176
+ if(ARGON2_OK != rc) {
177
+ printf("Error: %s\n", argon2_error_message(rc));
178
+ exit(1);
179
+ }
180
+ free(pwd);
181
+
182
+ for( int i=0; i<HASHLEN; ++i ) printf( "%02x", hash1[i] ); printf( "\n" );
183
+ if (memcmp(hash1, hash2, HASHLEN)) {
184
+ for( int i=0; i<HASHLEN; ++i ) {
185
+ printf( "%02x", hash2[i] );
186
+ }
187
+ printf("\nfail\n");
188
+ }
189
+ else printf("ok\n");
190
+ return 0;
191
+ }
192
+ ```
193
+
194
+ To use Argon2d instead of Argon2i call `argon2d_hash` instead of
195
+ `argon2i_hash` using the high-level API, and `argon2d` instead of
196
+ `argon2i` using the low-level API. Similarly for Argon2id, call `argond2id_hash`
197
+ and `argon2id`.
198
+
199
+ To produce the crypt-like encoding rather than the raw hash, call
200
+ `argon2i_hash_encoded` for Argon2i, `argon2d_hash_encoded` for Argon2d, and
201
+ `argon2id_hash_encoded` for Argon2id
202
+
203
+ See [`include/argon2.h`](include/argon2.h) for API details.
204
+
205
+ *Note: in this example the salt is set to the all-`0x00` string for the
206
+ sake of simplicity, but in your application you should use a random salt.*
207
+
208
+
209
+ ### Benchmarks
210
+
211
+ `make bench` creates the executable `bench`, which measures the execution
212
+ time of various Argon2 instances:
213
+
214
+ ```
215
+ $ ./bench
216
+ Argon2d 1 iterations 1 MiB 1 threads: 5.91 cpb 5.91 Mcycles
217
+ Argon2i 1 iterations 1 MiB 1 threads: 4.64 cpb 4.64 Mcycles
218
+ 0.0041 seconds
219
+
220
+ Argon2d 1 iterations 1 MiB 2 threads: 2.76 cpb 2.76 Mcycles
221
+ Argon2i 1 iterations 1 MiB 2 threads: 2.87 cpb 2.87 Mcycles
222
+ 0.0038 seconds
223
+
224
+ Argon2d 1 iterations 1 MiB 4 threads: 3.25 cpb 3.25 Mcycles
225
+ Argon2i 1 iterations 1 MiB 4 threads: 3.57 cpb 3.57 Mcycles
226
+ 0.0048 seconds
227
+
228
+ (...)
229
+
230
+ Argon2d 1 iterations 4096 MiB 2 threads: 2.15 cpb 8788.08 Mcycles
231
+ Argon2i 1 iterations 4096 MiB 2 threads: 2.15 cpb 8821.59 Mcycles
232
+ 13.0112 seconds
233
+
234
+ Argon2d 1 iterations 4096 MiB 4 threads: 1.79 cpb 7343.72 Mcycles
235
+ Argon2i 1 iterations 4096 MiB 4 threads: 2.72 cpb 11124.86 Mcycles
236
+ 19.3974 seconds
237
+
238
+ (...)
239
+ ```
240
+
241
+ ## Bindings
242
+
243
+ Bindings are available for the following languages (make sure to read
244
+ their documentation):
245
+
246
+ * [Elixir](https://github.com/riverrun/argon2_elixir) by [@riverrun](https://github.com/riverrun)
247
+ * [Go](https://github.com/tvdburgt/go-argon2) by [@tvdburgt](https://github.com/tvdburgt)
248
+ * [Haskell](https://hackage.haskell.org/package/argon2-1.0.0/docs/Crypto-Argon2.html) by [@ocharles](https://github.com/ocharles)
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)
253
+ * [JVM](https://github.com/phxql/argon2-jvm) by [@phXql](https://github.com/phxql)
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)
256
+ * [OCaml](https://github.com/Khady/ocaml-argon2) by [@Khady](https://github.com/Khady)
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)
259
+ * [Ruby](https://github.com/technion/ruby-argon2) by [@technion](https://github.com/technion)
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
+
264
+
265
+ ## Test suite
266
+
267
+ There are two sets of test suites. One is a low level test for the hash
268
+ function, the other tests the higher level API. Both of these are built and
269
+ executed by running:
270
+
271
+ `make test`
272
+
273
+ ## Intellectual property
274
+
275
+ Except for the components listed below, the Argon2 code in this
276
+ repository is copyright (c) 2015 Daniel Dinu, Dmitry Khovratovich (main
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.
281
+
282
+ The string encoding routines in [`src/encoding.c`](src/encoding.c) are
283
+ copyright (c) 2015 Thomas Pornin, and under
284
+ [CC0 License](https://creativecommons.org/about/cc0).
285
+
286
+ The BLAKE2 code in [`src/blake2/`](src/blake2) is copyright (c) Samuel
287
+ Neves, 2013-2015, and under
288
+ [CC0 License](https://creativecommons.org/about/cc0).
289
+
290
+ All licenses are therefore GPL-compatible.