argon2 0.1.4 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +5 -9
  3. data/.travis.yml +0 -1
  4. data/CONTRIBUTING.md +12 -0
  5. data/Changelog.md +10 -11
  6. data/README.md +23 -14
  7. data/ext/argon2_wrap/Makefile +8 -6
  8. data/ext/argon2_wrap/argon_wrap.c +23 -12
  9. data/ext/argon2_wrap/test.c +14 -42
  10. data/ext/phc-winner-argon2/.gitignore +5 -1
  11. data/ext/phc-winner-argon2/.travis.yml +14 -0
  12. data/ext/phc-winner-argon2/Makefile +33 -12
  13. data/ext/phc-winner-argon2/README.md +48 -19
  14. data/ext/phc-winner-argon2/argon2-specs.pdf +0 -0
  15. data/ext/phc-winner-argon2/{src → include}/argon2.h +137 -137
  16. data/ext/phc-winner-argon2/kats/argon2d +12290 -12290
  17. data/ext/phc-winner-argon2/kats/argon2d.shasum +1 -1
  18. data/ext/phc-winner-argon2/kats/argon2i +12290 -12290
  19. data/ext/phc-winner-argon2/kats/argon2i.shasum +1 -1
  20. data/ext/phc-winner-argon2/opt.o +0 -0
  21. data/ext/phc-winner-argon2/src/argon2.c +125 -145
  22. data/ext/phc-winner-argon2/src/bench.c +5 -5
  23. data/ext/phc-winner-argon2/src/core.c +15 -20
  24. data/ext/phc-winner-argon2/src/core.h +5 -2
  25. data/ext/phc-winner-argon2/src/encoding.c +45 -72
  26. data/ext/phc-winner-argon2/src/encoding.h +24 -0
  27. data/ext/phc-winner-argon2/src/genkat.c +2 -2
  28. data/ext/phc-winner-argon2/src/opt.c +19 -10
  29. data/ext/phc-winner-argon2/src/opt.h +5 -17
  30. data/ext/phc-winner-argon2/src/ref.c +12 -9
  31. data/ext/phc-winner-argon2/src/ref.h +4 -12
  32. data/ext/phc-winner-argon2/src/run.c +67 -42
  33. data/ext/phc-winner-argon2/src/test.c +131 -0
  34. data/lib/argon2.rb +6 -5
  35. data/lib/argon2/constants.rb +3 -2
  36. data/lib/argon2/engine.rb +1 -0
  37. data/lib/argon2/errors.rb +37 -36
  38. data/lib/argon2/ffi_engine.rb +10 -10
  39. data/lib/argon2/version.rb +2 -1
  40. metadata +7 -12
@@ -1,21 +1,34 @@
1
1
  # Argon2
2
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
+ [![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)
5
+
3
6
  This is the reference C implementation of Argon2, the password-hashing
4
7
  function that won the [Password Hashing Competition
5
- (PHC)](https://password-hashing.net).
8
+ (PHC)](https://password-hashing.net).
9
+
10
+ Argon2 is a password-hashing function that summarizes the state of the
11
+ art in the design of memory-hard functions and can be used to hash
12
+ passwords for credential storage, key derivation, or other applications.
6
13
 
7
- You should use Argon2 whenever you need to hash passwords for credential
8
- storage, key derivation, or other applications.
14
+ It has a simple design aimed at the highest memory filling rate and
15
+ effective use of multiple computing units, while still providing defense
16
+ against tradeoff attacks (by exploiting the cache and memory organization
17
+ of the recent processors).
9
18
 
10
- There are two main versions of Argon2, **Argon2i** and **Argon2d**. Argon2i
11
- is the safest against side-channel attacks, while Argon2d provides the
12
- highest resistance against GPU cracking attacks.
19
+ Argon2 has two variants: Argon2d and Argon2i. Argon2d is faster and
20
+ uses data-depending memory access, which makes it highly resistant
21
+ against GPU cracking attacks and suitable for applications with no threats
22
+ from side-channel timing attacks (eg. cryptocurrencies). Argon2i instead
23
+ uses data-independent memory access, which is preferred for password
24
+ hashing and password-based key derivation, but it is slower as it makes
25
+ more passes over the memory to protect from tradeoff attacks.
13
26
 
14
- Argon2i and Argon2d are parametrized by
27
+ Argon2i and Argon2d are parametrized by:
15
28
 
16
29
  * A **time** cost, which defines the amount of computation realized and
17
30
  therefore the execution time, given in number of iterations
18
- * A **memory** cost, which defines the memory usage, given in kibibytes
31
+ * A **memory** cost, which defines the memory usage, given in kibibytes
19
32
  * A **parallelism** degree, which defines the number of parallel threads
20
33
 
21
34
  The [Argon2 document](argon2-specs.pdf) gives detailed specs and design
@@ -39,23 +52,25 @@ on your system. To show usage instructions, run
39
52
  Usage: ./argon2 salt [-d] [-t iterations] [-m memory] [-p parallelism]
40
53
  Password is read from stdin
41
54
  Parameters:
42
- salt The salt to use, at most 16 characters
55
+ salt The salt to use, at least 8 characters
43
56
  -d Use Argon2d instead of Argon2i (which is the default)
44
57
  -t N Sets the number of iterations to N (default = 3)
45
58
  -m N Sets the memory usage of 2^N KiB (default 12)
46
59
  -p N Sets parallelism to N threads (default 1)
60
+ -h N Sets hash output length to N bytes (default 32)
47
61
  ```
48
62
  For example, to hash "password" using "somesalt" as a salt and doing 2
49
- iterations, consuming 64 MiB, and using four parallel threads:
63
+ iterations, consuming 64 MiB, using four parallel threads and an output hash
64
+ of 24 bytes
50
65
  ```
51
- $ echo -n "password" | ./argon2 somesalt -t 2 -m 16 -p 4
66
+ $ echo -n "password" | ./argon2 somesalt -t 2 -m 16 -p 4 -h 24
52
67
  Type: Argon2i
53
68
  Iterations: 2
54
69
  Memory: 65536 KiB
55
70
  Parallelism: 4
56
- Hash: 4162f32384d8f4790bd994cb73c83a4a29f076165ec18af3cfdcf10a8d1b9066
57
- Encoded: $argon2i$m=65536,t=2,p=4$c29tZXNhbHQAAAAAAAAAAA$QWLzI4TY9HkL2ZTLc8g6SinwdhZewYrzz9zxCo0bkGY
58
- 0.271 seconds
71
+ Hash: 5a028f1a99c9eae671ee448ab80057b78510430865abe57f
72
+ Encoded: $argon2i$m=65536,t=2,p=4$c29tZXNhbHQ$WgKPGpnJ6uZx7kSKuABXt4UQQwhlq+V/
73
+ 0.188 seconds
59
74
  Verification ok
60
75
  ```
61
76
 
@@ -68,7 +83,7 @@ The example program below hashes the string "password" with Argon2i
68
83
  using the high-level API and then using the low-level API. While the
69
84
  high-level API only takes input/output buffers and the two cost
70
85
  parameters, the low-level API additionally takes parallelism parameters
71
- and several others, as defined in [`src/argon2.h`](src/argon2.h).
86
+ and several others, as defined in [`include/argon2.h`](include/argon2.h).
72
87
 
73
88
 
74
89
  Here the time cost `t_cost` is set to 2 iterations, the
@@ -110,12 +125,12 @@ int main(void)
110
125
  uint32_t lanes = parallelism;
111
126
  uint32_t threads = parallelism;
112
127
  argon2_context context = {
113
- hash2, HASHLEN,
114
- pwd, pwdlen,
128
+ hash2, HASHLEN,
129
+ pwd, pwdlen,
115
130
  salt, SALTLEN,
116
131
  NULL, 0, /* secret data */
117
132
  NULL, 0, /* associated data */
118
- t_cost, m_cost, parallelism, parallelism,
133
+ t_cost, m_cost, parallelism, parallelism,
119
134
  NULL, NULL, /* custom memory allocation / deallocation functions */
120
135
  ARGON2_DEFAULT_FLAGS /* by default the password is zeroed on exit */
121
136
  };
@@ -140,7 +155,7 @@ To use Argon2d instead of Argon2i call `argon2d_hash` instead of
140
155
  To produce the crypt-like encoding rather than the raw hash, call
141
156
  `argon2i_hash_encoded` for Argon2i and `argon2d_hash_encoded` for Argon2d.
142
157
 
143
- See [`src/argon2.h`](src/argon2.h) for API detais.
158
+ See [`include/argon2.h`](include/argon2.h) for API details.
144
159
 
145
160
  *Note: in this example the salt is set to the all-`0x00` string for the
146
161
  sake of simplicity, but in your application you should use a random salt.*
@@ -183,10 +198,24 @@ Argon2i 1 iterations 4096 MiB 4 threads: 2.72 cpb 11124.86 Mcycles
183
198
  Bindings are available for the following languages (make sure to read
184
199
  their documentation):
185
200
 
201
+ * [Go](https://github.com/tvdburgt/go-argon2) by [@tvdburgt](https://github.com/tvdburgt)
202
+ * [Haskell](https://hackage.haskell.org/package/argon2-1.0.0/docs/Crypto-Argon2.html) by [@ocharles](https://github.com/ocharles)
186
203
  * [Javascript](https://github.com/ranisalt/node-argon2), by [@ranisalt](https://github.com/ranisalt)
204
+ * [JVM](https://github.com/phxql/argon2-jvm) by [@phXql](https://github.com/phxql)
205
+ * [Lua](https://github.com/thibaultCha/lua-argon2) by [@thibaultCha](https://github.com/thibaultCha)
206
+ * [OCaml](https://github.com/Khady/ocaml-argon2) by [@Khady](https://github.com/Khady)
187
207
  * [Python](https://pypi.python.org/pypi/argon2), by [@flamewow](https://github.com/flamewow)
208
+ * [Python](https://pypi.python.org/pypi/argon2_cffi), by [@hynek](https://github.com/hynek)
188
209
  * [Ruby](https://github.com/technion/ruby-argon2) by [@technion](https://github.com/technion)
210
+ * [Rust](https://github.com/quininer/argon2-rs) by [@quininer](https://github.com/quininer)
211
+
212
+ ## Test Suite
213
+
214
+ There are two sets of test suites. One is a low level test for the hash
215
+ function, the other tests the higher level API. Both of these are built and
216
+ executed by running:
189
217
 
218
+ `make test`
190
219
 
191
220
  ## Intellectual property
192
221
 
@@ -5,11 +5,11 @@
5
5
  *
6
6
  * This work is licensed under a Creative Commons CC0 1.0 License/Waiver.
7
7
  *
8
- * You should have received a copy of the CC0 Public Domain Dedication along
9
- * with
10
- * this software. If not, see
8
+ * You should have received a copy of the CC0 Public Domain Dedication
9
+ * along with this software. If not, see
11
10
  * <http://creativecommons.org/publicdomain/zero/1.0/>.
12
11
  */
12
+
13
13
  #ifndef ARGON2_H
14
14
  #define ARGON2_H
15
15
 
@@ -21,8 +21,16 @@
21
21
  extern "C" {
22
22
  #endif
23
23
 
24
- /*************************Argon2 input parameter
25
- * restrictions**************************************************/
24
+ /* Symbols visibility control */
25
+ #ifdef A2_VISCTL
26
+ #define ARGON2_PUBLIC __attribute__((visibility("default")))
27
+ #else
28
+ #define ARGON2_PUBLIC
29
+ #endif
30
+
31
+ /*
32
+ * Argon2 input parameter restrictions
33
+ */
26
34
 
27
35
  /* Minimum and maximum number of lanes (degree of parallelism) */
28
36
  #define ARGON2_MIN_LANES UINT32_C(1)
@@ -43,8 +51,7 @@ extern "C" {
43
51
  #define ARGON2_MIN_MEMORY (2 * ARGON2_SYNC_POINTS) /* 2 blocks per slice */
44
52
 
45
53
  #define ARGON2_MIN(a, b) ((a) < (b) ? (a) : (b))
46
- /* Max memory size is half the addressing space, topping at 2^32 blocks (4 TB)
47
- */
54
+ /* Max memory size is addressing-space/2, topping at 2^32 blocks (4 TB) */
48
55
  #define ARGON2_MAX_MEMORY_BITS \
49
56
  ARGON2_MIN(UINT32_C(32), (sizeof(void *) * CHAR_BIT - 10 - 1))
50
57
  #define ARGON2_MAX_MEMORY \
@@ -79,59 +86,61 @@ extern "C" {
79
86
  typedef enum Argon2_ErrorCodes {
80
87
  ARGON2_OK = 0,
81
88
 
82
- ARGON2_OUTPUT_PTR_NULL = 1,
89
+ ARGON2_OUTPUT_PTR_NULL = -1,
90
+
91
+ ARGON2_OUTPUT_TOO_SHORT = -2,
92
+ ARGON2_OUTPUT_TOO_LONG = -3,
83
93
 
84
- ARGON2_OUTPUT_TOO_SHORT = 2,
85
- ARGON2_OUTPUT_TOO_LONG = 3,
94
+ ARGON2_PWD_TOO_SHORT = -4,
95
+ ARGON2_PWD_TOO_LONG = -5,
86
96
 
87
- ARGON2_PWD_TOO_SHORT = 4,
88
- ARGON2_PWD_TOO_LONG = 5,
97
+ ARGON2_SALT_TOO_SHORT = -6,
98
+ ARGON2_SALT_TOO_LONG = -7,
89
99
 
90
- ARGON2_SALT_TOO_SHORT = 6,
91
- ARGON2_SALT_TOO_LONG = 7,
100
+ ARGON2_AD_TOO_SHORT = -8,
101
+ ARGON2_AD_TOO_LONG = -9,
92
102
 
93
- ARGON2_AD_TOO_SHORT = 8,
94
- ARGON2_AD_TOO_LONG = 9,
103
+ ARGON2_SECRET_TOO_SHORT = -10,
104
+ ARGON2_SECRET_TOO_LONG = -11,
95
105
 
96
- ARGON2_SECRET_TOO_SHORT = 10,
97
- ARGON2_SECRET_TOO_LONG = 11,
106
+ ARGON2_TIME_TOO_SMALL = -12,
107
+ ARGON2_TIME_TOO_LARGE = -13,
98
108
 
99
- ARGON2_TIME_TOO_SMALL = 12,
100
- ARGON2_TIME_TOO_LARGE = 13,
109
+ ARGON2_MEMORY_TOO_LITTLE = -14,
110
+ ARGON2_MEMORY_TOO_MUCH = -15,
101
111
 
102
- ARGON2_MEMORY_TOO_LITTLE = 14,
103
- ARGON2_MEMORY_TOO_MUCH = 15,
112
+ ARGON2_LANES_TOO_FEW = -16,
113
+ ARGON2_LANES_TOO_MANY = -17,
104
114
 
105
- ARGON2_LANES_TOO_FEW = 16,
106
- ARGON2_LANES_TOO_MANY = 17,
115
+ ARGON2_PWD_PTR_MISMATCH = -18, /* NULL ptr with non-zero length */
116
+ ARGON2_SALT_PTR_MISMATCH = -19, /* NULL ptr with non-zero length */
117
+ ARGON2_SECRET_PTR_MISMATCH = -20, /* NULL ptr with non-zero length */
118
+ ARGON2_AD_PTR_MISMATCH = -21, /* NULL ptr with non-zero length */
107
119
 
108
- ARGON2_PWD_PTR_MISMATCH = 18, /* NULL ptr with non-zero length */
109
- ARGON2_SALT_PTR_MISMATCH = 19, /* NULL ptr with non-zero length */
110
- ARGON2_SECRET_PTR_MISMATCH = 20, /* NULL ptr with non-zero length */
111
- ARGON2_AD_PTR_MISMATCH = 21, /* NULL ptr with non-zero length */
120
+ ARGON2_MEMORY_ALLOCATION_ERROR = -22,
112
121
 
113
- ARGON2_MEMORY_ALLOCATION_ERROR = 22,
122
+ ARGON2_FREE_MEMORY_CBK_NULL = -23,
123
+ ARGON2_ALLOCATE_MEMORY_CBK_NULL = -24,
114
124
 
115
- ARGON2_FREE_MEMORY_CBK_NULL = 23,
116
- ARGON2_ALLOCATE_MEMORY_CBK_NULL = 24,
125
+ ARGON2_INCORRECT_PARAMETER = -25,
126
+ ARGON2_INCORRECT_TYPE = -26,
117
127
 
118
- ARGON2_INCORRECT_PARAMETER = 25,
119
- ARGON2_INCORRECT_TYPE = 26,
128
+ ARGON2_OUT_PTR_MISMATCH = -27,
120
129
 
121
- ARGON2_OUT_PTR_MISMATCH = 27,
130
+ ARGON2_THREADS_TOO_FEW = -28,
131
+ ARGON2_THREADS_TOO_MANY = -29,
122
132
 
123
- ARGON2_THREADS_TOO_FEW = 28,
124
- ARGON2_THREADS_TOO_MANY = 29,
133
+ ARGON2_MISSING_ARGS = -30,
125
134
 
126
- ARGON2_MISSING_ARGS = 30,
135
+ ARGON2_ENCODING_FAIL = -31,
127
136
 
128
- ARGON2_ENCODING_FAIL = 31,
137
+ ARGON2_DECODING_FAIL = -32,
129
138
 
130
- ARGON2_DECODING_FAIL = 32,
139
+ ARGON2_THREAD_FAIL = -33,
131
140
 
132
- ARGON2_ERROR_CODES_LENGTH /* Do NOT remove; Do NOT add error codes after
133
- this
134
- error code */
141
+ ARGON2_DECODING_LENGTH_FAIL = -34,
142
+
143
+ ARGON2_VERIFY_MISMATCH = -35
135
144
  } argon2_error_codes;
136
145
 
137
146
  /* Memory allocator types --- for external allocation */
@@ -141,28 +150,29 @@ typedef void (*deallocate_fptr)(uint8_t *memory, size_t bytes_to_allocate);
141
150
  /* Argon2 external data structures */
142
151
 
143
152
  /*
144
- *****Context: structure to hold Argon2 inputs:
145
- * output array and its length,
146
- * password and its length,
147
- * salt and its length,
148
- * secret and its length,
149
- * associated data and its length,
150
- * number of passes, amount of used memory (in KBytes, can be rounded up a bit)
151
- * number of parallel threads that will be run.
153
+ *****
154
+ * Context: structure to hold Argon2 inputs:
155
+ * output array and its length,
156
+ * password and its length,
157
+ * salt and its length,
158
+ * secret and its length,
159
+ * associated data and its length,
160
+ * number of passes, amount of used memory (in KBytes, can be rounded up a bit)
161
+ * number of parallel threads that will be run.
152
162
  * All the parameters above affect the output hash value.
153
163
  * Additionally, two function pointers can be provided to allocate and
154
- deallocate the memory (if NULL, memory will be allocated internally).
164
+ * deallocate the memory (if NULL, memory will be allocated internally).
155
165
  * Also, three flags indicate whether to erase password, secret as soon as they
156
- are pre-hashed (and thus not needed anymore), and the entire memory
157
- ****************************
158
- Simplest situation: you have output array out[8], password is stored in
159
- pwd[32], salt is stored in salt[16], you do not have keys nor associated data.
160
- You need to spend 1 GB of RAM and you run 5 passes of Argon2d with 4 parallel
161
- lanes.
162
- You want to erase the password, but you're OK with last pass not being erased.
163
- You want to use the default memory allocator.
164
- Then you initialize
165
- Argon2_Context(out,8,pwd,32,salt,16,NULL,0,NULL,0,5,1<<20,4,4,NULL,NULL,true,false,false,false).
166
+ * are pre-hashed (and thus not needed anymore), and the entire memory
167
+ *****
168
+ * Simplest situation: you have output array out[8], password is stored in
169
+ * pwd[32], salt is stored in salt[16], you do not have keys nor associated
170
+ * data. You need to spend 1 GB of RAM and you run 5 passes of Argon2d with
171
+ * 4 parallel lanes.
172
+ * You want to erase the password, but you're OK with last pass not being
173
+ * erased. You want to use the default memory allocator.
174
+ * Then you initialize:
175
+ Argon2_Context(out,8,pwd,32,salt,16,NULL,0,NULL,0,5,1<<20,4,4,NULL,NULL,true,false,false,false)
166
176
  */
167
177
  typedef struct Argon2_Context {
168
178
  uint8_t *out; /* output array */
@@ -194,18 +204,17 @@ typedef struct Argon2_Context {
194
204
  /* Argon2 primitive type */
195
205
  typedef enum Argon2_type { Argon2_d = 0, Argon2_i = 1 } argon2_type;
196
206
 
197
-
198
207
  /*
199
208
  * Function that performs memory-hard hashing with certain degree of parallelism
200
209
  * @param context Pointer to the Argon2 internal structure
201
210
  * @return Error code if smth is wrong, ARGON2_OK otherwise
202
211
  */
203
- int argon2_core(argon2_context *context, argon2_type type);
212
+ ARGON2_PUBLIC int argon2_ctx(argon2_context *context, argon2_type type);
204
213
 
205
214
  /**
206
215
  * Hashes a password with Argon2i, producing an encoded hash
207
216
  * @param t_cost Number of iterations
208
- * @param m_cost Sets memory usage to 2^m_cost kibibytes
217
+ * @param m_cost Sets memory usage to m_cost kibibytes
209
218
  * @param parallelism Number of threads and compute lanes
210
219
  * @param pwd Pointer to password
211
220
  * @param pwdlen Password size in bytes
@@ -217,130 +226,121 @@ int argon2_core(argon2_context *context, argon2_type type);
217
226
  * @pre Different parallelism levels will give different results
218
227
  * @pre Returns ARGON2_OK if successful
219
228
  */
220
- int argon2i_hash_encoded(const uint32_t t_cost, const uint32_t m_cost,
221
- const uint32_t parallelism, const void *pwd,
222
- const size_t pwdlen, const void *salt,
223
- const size_t saltlen, const size_t hashlen,
224
- char *encoded, const size_t encodedlen);
229
+ ARGON2_PUBLIC int argon2i_hash_encoded(const uint32_t t_cost,
230
+ const uint32_t m_cost,
231
+ const uint32_t parallelism,
232
+ const void *pwd, const size_t pwdlen,
233
+ const void *salt, const size_t saltlen,
234
+ const size_t hashlen, char *encoded,
235
+ const size_t encodedlen);
225
236
 
226
237
  /**
227
- * Hashes a password with Argon2i, producing a raw hash
238
+ * Hashes a password with Argon2i, producing a raw hash by allocating memory at
239
+ * @hash
228
240
  * @param t_cost Number of iterations
229
- * @param m_cost Sets memory usage to 2^m_cost kibibytes
241
+ * @param m_cost Sets memory usage to m_cost kibibytes
230
242
  * @param parallelism Number of threads and compute lanes
231
243
  * @param pwd Pointer to password
232
244
  * @param pwdlen Password size in bytes
233
245
  * @param salt Pointer to salt
234
246
  * @param saltlen Salt size in bytes
235
- * @param hash Buffer where to write the raw hash
247
+ * @param hash Buffer where to write the raw hash - updated by the function
236
248
  * @param hashlen Desired length of the hash in bytes
237
249
  * @pre Different parallelism levels will give different results
238
250
  * @pre Returns ARGON2_OK if successful
239
251
  */
240
- int argon2i_hash_raw(const uint32_t t_cost, const uint32_t m_cost,
241
- const uint32_t parallelism, const void *pwd,
242
- const size_t pwdlen, const void *salt,
243
- const size_t saltlen, void *hash, const size_t hashlen);
244
-
245
- int argon2d_hash_encoded(const uint32_t t_cost, const uint32_t m_cost,
246
- const uint32_t parallelism, const void *pwd,
247
- const size_t pwdlen, const void *salt,
248
- const size_t saltlen, const size_t hashlen,
249
- char *encoded, const size_t encodedlen);
250
-
251
- int argon2d_hash_raw(const uint32_t t_cost, const uint32_t m_cost,
252
- const uint32_t parallelism, const void *pwd,
253
- const size_t pwdlen, const void *salt,
254
- const size_t saltlen, void *hash, const size_t hashlen);
252
+ ARGON2_PUBLIC int argon2i_hash_raw(const uint32_t t_cost, const uint32_t m_cost,
253
+ const uint32_t parallelism, const void *pwd,
254
+ const size_t pwdlen, const void *salt,
255
+ const size_t saltlen, void *hash,
256
+ const size_t hashlen);
257
+
258
+ ARGON2_PUBLIC int argon2d_hash_encoded(const uint32_t t_cost,
259
+ const uint32_t m_cost,
260
+ const uint32_t parallelism,
261
+ const void *pwd, const size_t pwdlen,
262
+ const void *salt, const size_t saltlen,
263
+ const size_t hashlen, char *encoded,
264
+ const size_t encodedlen);
265
+
266
+ ARGON2_PUBLIC int argon2d_hash_raw(const uint32_t t_cost, const uint32_t m_cost,
267
+ const uint32_t parallelism, const void *pwd,
268
+ const size_t pwdlen, const void *salt,
269
+ const size_t saltlen, void *hash,
270
+ const size_t hashlen);
255
271
 
256
272
  /* generic function underlying the above ones */
257
- int argon2_hash(const uint32_t t_cost, const uint32_t m_cost,
258
- const uint32_t parallelism, const void *pwd,
259
- const size_t pwdlen, const void *salt, const size_t saltlen,
260
- void *hash, const size_t hashlen, char *encoded,
261
- const size_t encodedlen, argon2_type type);
273
+ ARGON2_PUBLIC int argon2_hash(const uint32_t t_cost, const uint32_t m_cost,
274
+ const uint32_t parallelism, const void *pwd,
275
+ const size_t pwdlen, const void *salt,
276
+ const size_t saltlen, void *hash,
277
+ const size_t hashlen, char *encoded,
278
+ const size_t encodedlen, argon2_type type);
262
279
 
263
280
  /**
264
281
  * Verifies a password against an encoded string
282
+ * Encoded string is restricted as in validate_inputs()
265
283
  * @param encoded String encoding parameters, salt, hash
266
284
  * @param pwd Pointer to password
267
285
  * @pre Returns ARGON2_OK if successful
268
286
  */
269
- int argon2i_verify(const char *encoded, const void *pwd, const size_t pwdlen);
287
+ ARGON2_PUBLIC int argon2i_verify(const char *encoded, const void *pwd,
288
+ const size_t pwdlen);
270
289
 
271
- int argon2d_verify(const char *encoded, const void *pwd, const size_t pwdlen);
290
+ ARGON2_PUBLIC int argon2d_verify(const char *encoded, const void *pwd,
291
+ const size_t pwdlen);
272
292
 
273
293
  /* generic function underlying the above ones */
274
- int argon2_verify(const char *encoded, const void *pwd, const size_t pwdlen,
275
- argon2_type type);
294
+ ARGON2_PUBLIC int argon2_verify(const char *encoded, const void *pwd,
295
+ const size_t pwdlen, argon2_type type);
276
296
 
277
- /*
278
- * **************Argon2d: Version of Argon2 that picks memory blocks depending
297
+ /**
298
+ * Argon2d: Version of Argon2 that picks memory blocks depending
279
299
  * on the password and salt. Only for side-channel-free
280
- * environment!!***************
281
- * @param context Pointer to current Argon2 context
282
- * @return Zero if successful, a non zero error code otherwise
283
- */
284
- int argon2d(argon2_context *context);
285
-
286
- /*
287
- * * **************Argon2i: Version of Argon2 that picks memory blocks
288
- *independent on the password and salt. Good for side-channels,
289
- ******************* but worse w.r.t. tradeoff attacks if
290
- *******************only one pass is used***************
291
- * @param context Pointer to current Argon2 context
292
- * @return Zero if successful, a non zero error code otherwise
293
- */
294
- int argon2i(argon2_context *context);
295
-
296
- /*
297
- * * **************Argon2di: Reserved name***************
300
+ * environment!!
301
+ *****
298
302
  * @param context Pointer to current Argon2 context
299
303
  * @return Zero if successful, a non zero error code otherwise
300
304
  */
301
- int argon2di(argon2_context *context);
305
+ ARGON2_PUBLIC int argon2d_ctx(argon2_context *context);
302
306
 
303
- /*
304
- * * **************Argon2ds: Argon2d hardened against GPU attacks, 20%
305
- * slower***************
306
- * @param context Pointer to current Argon2 context
307
- * @return Zero if successful, a non zero error code otherwise
308
- */
309
- int argon2ds(argon2_context *context);
310
-
311
- /*
312
- * * **************Argon2id: First half-pass over memory is
313
- *password-independent, the rest are password-dependent
314
- ********************OK against side channels: they reduce to 1/2-pass
315
- *Argon2i***************
307
+ /**
308
+ * Argon2i: Version of Argon2 that picks memory blocks
309
+ * independent on the password and salt. Good for side-channels,
310
+ * but worse w.r.t. tradeoff attacks if only one pass is used.
311
+ *****
316
312
  * @param context Pointer to current Argon2 context
317
313
  * @return Zero if successful, a non zero error code otherwise
318
314
  */
319
- int argon2id(argon2_context *context);
315
+ ARGON2_PUBLIC int argon2i_ctx(argon2_context *context);
320
316
 
321
- /*
317
+ /**
322
318
  * Verify if a given password is correct for Argon2d hashing
323
319
  * @param context Pointer to current Argon2 context
324
320
  * @param hash The password hash to verify. The length of the hash is
325
321
  * specified by the context outlen member
326
322
  * @return Zero if successful, a non zero error code otherwise
327
323
  */
328
- int verify_d(argon2_context *context, const char *hash);
324
+ ARGON2_PUBLIC int argon2d_verify_ctx(argon2_context *context, const char *hash);
329
325
 
330
- /*
326
+ /**
331
327
  * Verify if a given password is correct for Argon2i hashing
332
328
  * @param context Pointer to current Argon2 context
333
329
  * @param hash The password hash to verify. The length of the hash is
334
330
  * specified by the context outlen member
335
331
  * @return Zero if successful, a non zero error code otherwise
336
332
  */
337
- int verify_i(argon2_context *context, const char *hash);
333
+ ARGON2_PUBLIC int argon2i_verify_ctx(argon2_context *context, const char *hash);
338
334
 
339
- /*
335
+ /* generic function underlying the above ones */
336
+ ARGON2_PUBLIC int argon2_verify_ctx(argon2_context *context, const char *hash,
337
+ argon2_type type);
338
+
339
+ /**
340
340
  * Get the associated error message for given error code
341
341
  * @return The error message associated with the given error code
342
342
  */
343
- const char *error_message(int error_code);
343
+ ARGON2_PUBLIC const char *argon2_error_message(int error_code);
344
344
 
345
345
  #if defined(__cplusplus)
346
346
  }