passwordping 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +16 -0
  3. data/.gitmodules +3 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE +5 -0
  6. data/README.md +89 -0
  7. data/Rakefile +11 -0
  8. data/ext/argon2-wrapper/Makefile +74 -0
  9. data/ext/argon2-wrapper/extconf.rb +1 -0
  10. data/ext/phc-winner-argon2/.gitattributes +10 -0
  11. data/ext/phc-winner-argon2/.gitignore +21 -0
  12. data/ext/phc-winner-argon2/.travis.yml +14 -0
  13. data/ext/phc-winner-argon2/Argon2.sln +160 -0
  14. data/ext/phc-winner-argon2/CHANGELOG.md +25 -0
  15. data/ext/phc-winner-argon2/LICENSE +314 -0
  16. data/ext/phc-winner-argon2/Makefile +187 -0
  17. data/ext/phc-winner-argon2/README.md +290 -0
  18. data/ext/phc-winner-argon2/appveyor.yml +25 -0
  19. data/ext/phc-winner-argon2/argon2-specs.pdf +0 -0
  20. data/ext/phc-winner-argon2/export.sh +7 -0
  21. data/ext/phc-winner-argon2/include/argon2.h +435 -0
  22. data/ext/phc-winner-argon2/kats/argon2d +12304 -0
  23. data/ext/phc-winner-argon2/kats/argon2d.shasum +1 -0
  24. data/ext/phc-winner-argon2/kats/argon2d_v16 +12304 -0
  25. data/ext/phc-winner-argon2/kats/argon2d_v16.shasum +1 -0
  26. data/ext/phc-winner-argon2/kats/argon2i +12304 -0
  27. data/ext/phc-winner-argon2/kats/argon2i.shasum +1 -0
  28. data/ext/phc-winner-argon2/kats/argon2i_v16 +12304 -0
  29. data/ext/phc-winner-argon2/kats/argon2i_v16.shasum +1 -0
  30. data/ext/phc-winner-argon2/kats/argon2id +12304 -0
  31. data/ext/phc-winner-argon2/kats/argon2id.shasum +1 -0
  32. data/ext/phc-winner-argon2/kats/argon2id_v16 +12304 -0
  33. data/ext/phc-winner-argon2/kats/argon2id_v16.shasum +1 -0
  34. data/ext/phc-winner-argon2/kats/check-sums.ps1 +42 -0
  35. data/ext/phc-winner-argon2/kats/check-sums.sh +13 -0
  36. data/ext/phc-winner-argon2/kats/test.ps1 +50 -0
  37. data/ext/phc-winner-argon2/kats/test.sh +49 -0
  38. data/ext/phc-winner-argon2/latex/IEEEtran.cls +6347 -0
  39. data/ext/phc-winner-argon2/latex/Makefile +18 -0
  40. data/ext/phc-winner-argon2/latex/argon2-specs.tex +920 -0
  41. data/ext/phc-winner-argon2/latex/pics/argon2-par.pdf +0 -0
  42. data/ext/phc-winner-argon2/latex/pics/compression.pdf +0 -0
  43. data/ext/phc-winner-argon2/latex/pics/generic.pdf +0 -0
  44. data/ext/phc-winner-argon2/latex/pics/power-distribution.jpg +0 -0
  45. data/ext/phc-winner-argon2/latex/tradeoff.bib +822 -0
  46. data/ext/phc-winner-argon2/libargon2.pc +16 -0
  47. data/ext/phc-winner-argon2/man/argon2.1 +57 -0
  48. data/ext/phc-winner-argon2/src/argon2.c +452 -0
  49. data/ext/phc-winner-argon2/src/bench.c +111 -0
  50. data/ext/phc-winner-argon2/src/blake2/blake2-impl.h +156 -0
  51. data/ext/phc-winner-argon2/src/blake2/blake2.h +91 -0
  52. data/ext/phc-winner-argon2/src/blake2/blake2b.c +390 -0
  53. data/ext/phc-winner-argon2/src/blake2/blamka-round-opt.h +328 -0
  54. data/ext/phc-winner-argon2/src/blake2/blamka-round-ref.h +56 -0
  55. data/ext/phc-winner-argon2/src/core.c +635 -0
  56. data/ext/phc-winner-argon2/src/core.h +227 -0
  57. data/ext/phc-winner-argon2/src/encoding.c +463 -0
  58. data/ext/phc-winner-argon2/src/encoding.h +57 -0
  59. data/ext/phc-winner-argon2/src/genkat.c +208 -0
  60. data/ext/phc-winner-argon2/src/genkat.h +49 -0
  61. data/ext/phc-winner-argon2/src/opt.c +241 -0
  62. data/ext/phc-winner-argon2/src/ref.c +194 -0
  63. data/ext/phc-winner-argon2/src/run.c +317 -0
  64. data/ext/phc-winner-argon2/src/test.c +254 -0
  65. data/ext/phc-winner-argon2/src/thread.c +57 -0
  66. data/ext/phc-winner-argon2/src/thread.h +67 -0
  67. data/ext/phc-winner-argon2/vs2015/Argon2Opt/Argon2Opt.vcxproj +226 -0
  68. data/ext/phc-winner-argon2/vs2015/Argon2Opt/Argon2Opt.vcxproj.filters +69 -0
  69. data/ext/phc-winner-argon2/vs2015/Argon2OptBench/Argon2OptBench.vcxproj +226 -0
  70. data/ext/phc-winner-argon2/vs2015/Argon2OptBench/Argon2OptBench.vcxproj.filters +69 -0
  71. data/ext/phc-winner-argon2/vs2015/Argon2OptDll/Argon2OptDll.vcxproj +225 -0
  72. data/ext/phc-winner-argon2/vs2015/Argon2OptDll/Argon2OptDll.vcxproj.filters +66 -0
  73. data/ext/phc-winner-argon2/vs2015/Argon2OptGenKAT/Argon2OptGenKAT.vcxproj +239 -0
  74. data/ext/phc-winner-argon2/vs2015/Argon2OptGenKAT/Argon2OptGenKAT.vcxproj.filters +72 -0
  75. data/ext/phc-winner-argon2/vs2015/Argon2OptTestCI/Argon2OptTestCI.vcxproj +227 -0
  76. data/ext/phc-winner-argon2/vs2015/Argon2OptTestCI/Argon2OptTestCI.vcxproj.filters +69 -0
  77. data/ext/phc-winner-argon2/vs2015/Argon2Ref/Argon2Ref.vcxproj +226 -0
  78. data/ext/phc-winner-argon2/vs2015/Argon2Ref/Argon2Ref.vcxproj.filters +69 -0
  79. data/ext/phc-winner-argon2/vs2015/Argon2RefBench/Argon2RefBench.vcxproj +226 -0
  80. data/ext/phc-winner-argon2/vs2015/Argon2RefBench/Argon2RefBench.vcxproj.filters +69 -0
  81. data/ext/phc-winner-argon2/vs2015/Argon2RefDll/Argon2RefDll.vcxproj +225 -0
  82. data/ext/phc-winner-argon2/vs2015/Argon2RefDll/Argon2RefDll.vcxproj.filters +66 -0
  83. data/ext/phc-winner-argon2/vs2015/Argon2RefGenKAT/Argon2RefGenKAT.vcxproj +227 -0
  84. data/ext/phc-winner-argon2/vs2015/Argon2RefGenKAT/Argon2RefGenKAT.vcxproj.filters +72 -0
  85. data/ext/phc-winner-argon2/vs2015/Argon2RefTestCI/Argon2RefTestCI.vcxproj +226 -0
  86. data/ext/phc-winner-argon2/vs2015/Argon2RefTestCI/Argon2RefTestCI.vcxproj.filters +69 -0
  87. data/lib/passwordping.rb +186 -0
  88. data/lib/passwordping/argon2_wrapper_ffi.rb +89 -0
  89. data/lib/passwordping/constants.rb +10 -0
  90. data/lib/passwordping/errors.rb +3 -0
  91. data/lib/passwordping/hashing.rb +160 -0
  92. data/lib/passwordping/password_type.rb +24 -0
  93. data/lib/passwordping/version.rb +5 -0
  94. data/passwordping.gemspec +34 -0
  95. metadata +304 -0
@@ -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.
@@ -0,0 +1,25 @@
1
+ os: Visual Studio 2015
2
+
3
+ environment:
4
+ matrix:
5
+ - platform: x86
6
+ configuration: Debug
7
+ - platform: x86
8
+ configuration: Release
9
+ - platform: x64
10
+ configuration: Debug
11
+ - platform: x64
12
+ configuration: Release
13
+
14
+ matrix:
15
+ fast_finish: false
16
+
17
+ build:
18
+ parallel: true
19
+ project: Argon2.sln
20
+ verbosity: minimal
21
+
22
+ test_script:
23
+ - ps: kats\test.ps1
24
+ - ps: if ("Release" -eq $env:configuration) { vs2015\build\Argon2OptTestCI.exe }
25
+ - ps: if ("Release" -eq $env:configuration) { vs2015\build\Argon2RefTestCI.exe }
@@ -0,0 +1,7 @@
1
+ #!/bin/sh
2
+
3
+ FILE=`date "+%Y%m%d"`
4
+ BRANCH=master
5
+
6
+ git archive --format zip --output $FILE.zip $BRANCH
7
+ git archive --format tar.gz --output $FILE.tar.gz $BRANCH
@@ -0,0 +1,435 @@
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
+ #ifndef ARGON2_H
19
+ #define ARGON2_H
20
+
21
+ #include <stdint.h>
22
+ #include <stddef.h>
23
+ #include <limits.h>
24
+
25
+ #if defined(__cplusplus)
26
+ extern "C" {
27
+ #endif
28
+
29
+ /* Symbols visibility control */
30
+ #ifdef A2_VISCTL
31
+ #define ARGON2_PUBLIC __attribute__((visibility("default")))
32
+ #elif _MSC_VER
33
+ #define ARGON2_PUBLIC __declspec(dllexport)
34
+ #else
35
+ #define ARGON2_PUBLIC
36
+ #endif
37
+
38
+ /*
39
+ * Argon2 input parameter restrictions
40
+ */
41
+
42
+ /* Minimum and maximum number of lanes (degree of parallelism) */
43
+ #define ARGON2_MIN_LANES UINT32_C(1)
44
+ #define ARGON2_MAX_LANES UINT32_C(0xFFFFFF)
45
+
46
+ /* Minimum and maximum number of threads */
47
+ #define ARGON2_MIN_THREADS UINT32_C(1)
48
+ #define ARGON2_MAX_THREADS UINT32_C(0xFFFFFF)
49
+
50
+ /* Number of synchronization points between lanes per pass */
51
+ #define ARGON2_SYNC_POINTS UINT32_C(4)
52
+
53
+ /* Minimum and maximum digest size in bytes */
54
+ #define ARGON2_MIN_OUTLEN UINT32_C(4)
55
+ #define ARGON2_MAX_OUTLEN UINT32_C(0xFFFFFFFF)
56
+
57
+ /* Minimum and maximum number of memory blocks (each of BLOCK_SIZE bytes) */
58
+ #define ARGON2_MIN_MEMORY (2 * ARGON2_SYNC_POINTS) /* 2 blocks per slice */
59
+
60
+ #define ARGON2_MIN(a, b) ((a) < (b) ? (a) : (b))
61
+ /* Max memory size is addressing-space/2, topping at 2^32 blocks (4 TB) */
62
+ #define ARGON2_MAX_MEMORY_BITS \
63
+ ARGON2_MIN(UINT32_C(32), (sizeof(void *) * CHAR_BIT - 10 - 1))
64
+ #define ARGON2_MAX_MEMORY \
65
+ ARGON2_MIN(UINT32_C(0xFFFFFFFF), UINT64_C(1) << ARGON2_MAX_MEMORY_BITS)
66
+
67
+ /* Minimum and maximum number of passes */
68
+ #define ARGON2_MIN_TIME UINT32_C(1)
69
+ #define ARGON2_MAX_TIME UINT32_C(0xFFFFFFFF)
70
+
71
+ /* Minimum and maximum password length in bytes */
72
+ #define ARGON2_MIN_PWD_LENGTH UINT32_C(0)
73
+ #define ARGON2_MAX_PWD_LENGTH UINT32_C(0xFFFFFFFF)
74
+
75
+ /* Minimum and maximum associated data length in bytes */
76
+ #define ARGON2_MIN_AD_LENGTH UINT32_C(0)
77
+ #define ARGON2_MAX_AD_LENGTH UINT32_C(0xFFFFFFFF)
78
+
79
+ /* Minimum and maximum salt length in bytes */
80
+ #define ARGON2_MIN_SALT_LENGTH UINT32_C(8)
81
+ #define ARGON2_MAX_SALT_LENGTH UINT32_C(0xFFFFFFFF)
82
+
83
+ /* Minimum and maximum key length in bytes */
84
+ #define ARGON2_MIN_SECRET UINT32_C(0)
85
+ #define ARGON2_MAX_SECRET UINT32_C(0xFFFFFFFF)
86
+
87
+ /* Flags to determine which fields are securely wiped (default = no wipe). */
88
+ #define ARGON2_DEFAULT_FLAGS UINT32_C(0)
89
+ #define ARGON2_FLAG_CLEAR_PASSWORD (UINT32_C(1) << 0)
90
+ #define ARGON2_FLAG_CLEAR_SECRET (UINT32_C(1) << 1)
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;
95
+
96
+ /* Error codes */
97
+ typedef enum Argon2_ErrorCodes {
98
+ ARGON2_OK = 0,
99
+
100
+ ARGON2_OUTPUT_PTR_NULL = -1,
101
+
102
+ ARGON2_OUTPUT_TOO_SHORT = -2,
103
+ ARGON2_OUTPUT_TOO_LONG = -3,
104
+
105
+ ARGON2_PWD_TOO_SHORT = -4,
106
+ ARGON2_PWD_TOO_LONG = -5,
107
+
108
+ ARGON2_SALT_TOO_SHORT = -6,
109
+ ARGON2_SALT_TOO_LONG = -7,
110
+
111
+ ARGON2_AD_TOO_SHORT = -8,
112
+ ARGON2_AD_TOO_LONG = -9,
113
+
114
+ ARGON2_SECRET_TOO_SHORT = -10,
115
+ ARGON2_SECRET_TOO_LONG = -11,
116
+
117
+ ARGON2_TIME_TOO_SMALL = -12,
118
+ ARGON2_TIME_TOO_LARGE = -13,
119
+
120
+ ARGON2_MEMORY_TOO_LITTLE = -14,
121
+ ARGON2_MEMORY_TOO_MUCH = -15,
122
+
123
+ ARGON2_LANES_TOO_FEW = -16,
124
+ ARGON2_LANES_TOO_MANY = -17,
125
+
126
+ ARGON2_PWD_PTR_MISMATCH = -18, /* NULL ptr with non-zero length */
127
+ ARGON2_SALT_PTR_MISMATCH = -19, /* NULL ptr with non-zero length */
128
+ ARGON2_SECRET_PTR_MISMATCH = -20, /* NULL ptr with non-zero length */
129
+ ARGON2_AD_PTR_MISMATCH = -21, /* NULL ptr with non-zero length */
130
+
131
+ ARGON2_MEMORY_ALLOCATION_ERROR = -22,
132
+
133
+ ARGON2_FREE_MEMORY_CBK_NULL = -23,
134
+ ARGON2_ALLOCATE_MEMORY_CBK_NULL = -24,
135
+
136
+ ARGON2_INCORRECT_PARAMETER = -25,
137
+ ARGON2_INCORRECT_TYPE = -26,
138
+
139
+ ARGON2_OUT_PTR_MISMATCH = -27,
140
+
141
+ ARGON2_THREADS_TOO_FEW = -28,
142
+ ARGON2_THREADS_TOO_MANY = -29,
143
+
144
+ ARGON2_MISSING_ARGS = -30,
145
+
146
+ ARGON2_ENCODING_FAIL = -31,
147
+
148
+ ARGON2_DECODING_FAIL = -32,
149
+
150
+ ARGON2_THREAD_FAIL = -33,
151
+
152
+ ARGON2_DECODING_LENGTH_FAIL = -34,
153
+
154
+ ARGON2_VERIFY_MISMATCH = -35
155
+ } argon2_error_codes;
156
+
157
+ /* Memory allocator types --- for external allocation */
158
+ typedef int (*allocate_fptr)(uint8_t **memory, size_t bytes_to_allocate);
159
+ typedef void (*deallocate_fptr)(uint8_t *memory, size_t bytes_to_allocate);
160
+
161
+ /* Argon2 external data structures */
162
+
163
+ /*
164
+ *****
165
+ * Context: structure to hold Argon2 inputs:
166
+ * output array and its length,
167
+ * password and its length,
168
+ * salt and its length,
169
+ * secret and its length,
170
+ * associated data and its length,
171
+ * number of passes, amount of used memory (in KBytes, can be rounded up a bit)
172
+ * number of parallel threads that will be run.
173
+ * All the parameters above affect the output hash value.
174
+ * Additionally, two function pointers can be provided to allocate and
175
+ * deallocate the memory (if NULL, memory will be allocated internally).
176
+ * Also, three flags indicate whether to erase password, secret as soon as they
177
+ * are pre-hashed (and thus not needed anymore), and the entire memory
178
+ *****
179
+ * Simplest situation: you have output array out[8], password is stored in
180
+ * pwd[32], salt is stored in salt[16], you do not have keys nor associated
181
+ * data. You need to spend 1 GB of RAM and you run 5 passes of Argon2d with
182
+ * 4 parallel lanes.
183
+ * You want to erase the password, but you're OK with last pass not being
184
+ * erased. You want to use the default memory allocator.
185
+ * Then you initialize:
186
+ Argon2_Context(out,8,pwd,32,salt,16,NULL,0,NULL,0,5,1<<20,4,4,NULL,NULL,true,false,false,false)
187
+ */
188
+ typedef struct Argon2_Context {
189
+ uint8_t *out; /* output array */
190
+ uint32_t outlen; /* digest length */
191
+
192
+ uint8_t *pwd; /* password array */
193
+ uint32_t pwdlen; /* password length */
194
+
195
+ uint8_t *salt; /* salt array */
196
+ uint32_t saltlen; /* salt length */
197
+
198
+ uint8_t *secret; /* key array */
199
+ uint32_t secretlen; /* key length */
200
+
201
+ uint8_t *ad; /* associated data array */
202
+ uint32_t adlen; /* associated data length */
203
+
204
+ uint32_t t_cost; /* number of passes */
205
+ uint32_t m_cost; /* amount of memory requested (KB) */
206
+ uint32_t lanes; /* number of lanes */
207
+ uint32_t threads; /* maximum number of threads */
208
+
209
+ uint32_t version; /* version number */
210
+
211
+ allocate_fptr allocate_cbk; /* pointer to memory allocator */
212
+ deallocate_fptr free_cbk; /* pointer to memory deallocator */
213
+
214
+ uint32_t flags; /* array of bool options */
215
+ } argon2_context;
216
+
217
+ /* Argon2 primitive type */
218
+ typedef enum Argon2_type {
219
+ Argon2_d = 0,
220
+ Argon2_i = 1,
221
+ Argon2_id = 2
222
+ } argon2_type;
223
+
224
+ /* Version of the algorithm */
225
+ typedef enum Argon2_version {
226
+ ARGON2_VERSION_10 = 0x10,
227
+ ARGON2_VERSION_13 = 0x13,
228
+ ARGON2_VERSION_NUMBER = ARGON2_VERSION_13
229
+ } argon2_version;
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
+
239
+ /*
240
+ * Function that performs memory-hard hashing with certain degree of parallelism
241
+ * @param context Pointer to the Argon2 internal structure
242
+ * @return Error code if smth is wrong, ARGON2_OK otherwise
243
+ */
244
+ ARGON2_PUBLIC int argon2_ctx(argon2_context *context, argon2_type type);
245
+
246
+ /**
247
+ * Hashes a password with Argon2i, producing an encoded hash
248
+ * @param t_cost Number of iterations
249
+ * @param m_cost Sets memory usage to m_cost kibibytes
250
+ * @param parallelism Number of threads and compute lanes
251
+ * @param pwd Pointer to password
252
+ * @param pwdlen Password size in bytes
253
+ * @param salt Pointer to salt
254
+ * @param saltlen Salt size in bytes
255
+ * @param hashlen Desired length of the hash in bytes
256
+ * @param encoded Buffer where to write the encoded hash
257
+ * @param encodedlen Size of the buffer (thus max size of the encoded hash)
258
+ * @pre Different parallelism levels will give different results
259
+ * @pre Returns ARGON2_OK if successful
260
+ */
261
+ ARGON2_PUBLIC int argon2i_hash_encoded(const uint32_t t_cost,
262
+ const uint32_t m_cost,
263
+ const uint32_t parallelism,
264
+ const void *pwd, const size_t pwdlen,
265
+ const void *salt, const size_t saltlen,
266
+ const size_t hashlen, char *encoded,
267
+ const size_t encodedlen);
268
+
269
+ /**
270
+ * Hashes a password with Argon2i, producing a raw hash by allocating memory at
271
+ * @hash
272
+ * @param t_cost Number of iterations
273
+ * @param m_cost Sets memory usage to m_cost kibibytes
274
+ * @param parallelism Number of threads and compute lanes
275
+ * @param pwd Pointer to password
276
+ * @param pwdlen Password size in bytes
277
+ * @param salt Pointer to salt
278
+ * @param saltlen Salt size in bytes
279
+ * @param hash Buffer where to write the raw hash - updated by the function
280
+ * @param hashlen Desired length of the hash in bytes
281
+ * @pre Different parallelism levels will give different results
282
+ * @pre Returns ARGON2_OK if successful
283
+ */
284
+ ARGON2_PUBLIC int argon2i_hash_raw(const uint32_t t_cost, const uint32_t m_cost,
285
+ const uint32_t parallelism, const void *pwd,
286
+ const size_t pwdlen, const void *salt,
287
+ const size_t saltlen, void *hash,
288
+ const size_t hashlen);
289
+
290
+ ARGON2_PUBLIC int argon2d_hash_encoded(const uint32_t t_cost,
291
+ const uint32_t m_cost,
292
+ const uint32_t parallelism,
293
+ const void *pwd, const size_t pwdlen,
294
+ const void *salt, const size_t saltlen,
295
+ const size_t hashlen, char *encoded,
296
+ const size_t encodedlen);
297
+
298
+ ARGON2_PUBLIC int argon2d_hash_raw(const uint32_t t_cost, const uint32_t m_cost,
299
+ const uint32_t parallelism, const void *pwd,
300
+ const size_t pwdlen, const void *salt,
301
+ const size_t saltlen, void *hash,
302
+ const size_t hashlen);
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
+
319
+ /* generic function underlying the above ones */
320
+ ARGON2_PUBLIC int argon2_hash(const uint32_t t_cost, const uint32_t m_cost,
321
+ const uint32_t parallelism, const void *pwd,
322
+ const size_t pwdlen, const void *salt,
323
+ const size_t saltlen, void *hash,
324
+ const size_t hashlen, char *encoded,
325
+ const size_t encodedlen, argon2_type type,
326
+ const uint32_t version);
327
+
328
+ /**
329
+ * Verifies a password against an encoded string
330
+ * Encoded string is restricted as in validate_inputs()
331
+ * @param encoded String encoding parameters, salt, hash
332
+ * @param pwd Pointer to password
333
+ * @pre Returns ARGON2_OK if successful
334
+ */
335
+ ARGON2_PUBLIC int argon2i_verify(const char *encoded, const void *pwd,
336
+ const size_t pwdlen);
337
+
338
+ ARGON2_PUBLIC int argon2d_verify(const char *encoded, const void *pwd,
339
+ const size_t pwdlen);
340
+
341
+ ARGON2_PUBLIC int argon2id_verify(const char *encoded, const void *pwd,
342
+ const size_t pwdlen);
343
+
344
+ /* generic function underlying the above ones */
345
+ ARGON2_PUBLIC int argon2_verify(const char *encoded, const void *pwd,
346
+ const size_t pwdlen, argon2_type type);
347
+
348
+ /**
349
+ * Argon2d: Version of Argon2 that picks memory blocks depending
350
+ * on the password and salt. Only for side-channel-free
351
+ * environment!!
352
+ *****
353
+ * @param context Pointer to current Argon2 context
354
+ * @return Zero if successful, a non zero error code otherwise
355
+ */
356
+ ARGON2_PUBLIC int argon2d_ctx(argon2_context *context);
357
+
358
+ /**
359
+ * Argon2i: Version of Argon2 that picks memory blocks
360
+ * independent on the password and salt. Good for side-channels,
361
+ * but worse w.r.t. tradeoff attacks if only one pass is used.
362
+ *****
363
+ * @param context Pointer to current Argon2 context
364
+ * @return Zero if successful, a non zero error code otherwise
365
+ */
366
+ ARGON2_PUBLIC int argon2i_ctx(argon2_context *context);
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
+
379
+ /**
380
+ * Verify if a given password is correct for Argon2d hashing
381
+ * @param context Pointer to current Argon2 context
382
+ * @param hash The password hash to verify. The length of the hash is
383
+ * specified by the context outlen member
384
+ * @return Zero if successful, a non zero error code otherwise
385
+ */
386
+ ARGON2_PUBLIC int argon2d_verify_ctx(argon2_context *context, const char *hash);
387
+
388
+ /**
389
+ * Verify if a given password is correct for Argon2i hashing
390
+ * @param context Pointer to current Argon2 context
391
+ * @param hash The password hash to verify. The length of the hash is
392
+ * specified by the context outlen member
393
+ * @return Zero if successful, a non zero error code otherwise
394
+ */
395
+ ARGON2_PUBLIC int argon2i_verify_ctx(argon2_context *context, const char *hash);
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
+
407
+ /* generic function underlying the above ones */
408
+ ARGON2_PUBLIC int argon2_verify_ctx(argon2_context *context, const char *hash,
409
+ argon2_type type);
410
+
411
+ /**
412
+ * Get the associated error message for given error code
413
+ * @return The error message associated with the given error code
414
+ */
415
+ ARGON2_PUBLIC const char *argon2_error_message(int error_code);
416
+
417
+ /**
418
+ * Returns the encoded hash length for the given input parameters
419
+ * @param t_cost Number of iterations
420
+ * @param m_cost Memory usage in kibibytes
421
+ * @param parallelism Number of threads; used to compute lanes
422
+ * @param saltlen Salt size in bytes
423
+ * @param hashlen Hash size in bytes
424
+ * @param type The argon2_type that we want the encoded length for
425
+ * @return The encoded hash length in bytes
426
+ */
427
+ ARGON2_PUBLIC size_t argon2_encodedlen(uint32_t t_cost, uint32_t m_cost,
428
+ uint32_t parallelism, uint32_t saltlen,
429
+ uint32_t hashlen, argon2_type type);
430
+
431
+ #if defined(__cplusplus)
432
+ }
433
+ #endif
434
+
435
+ #endif