1 // Copyright (c) 2017 Martijn Rijkeboer <mrr@sru-systems.com>
2 //
3 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
5 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
6 // option. This file may not be copied, modified, or distributed
7 // except according to those terms.
8 
9 use super::context::Context;
10 use super::config::Config;
11 use super::core;
12 use super::encoding;
13 use super::memory::Memory;
14 use super::result::Result;
15 use super::thread_mode::ThreadMode;
16 use super::variant::Variant;
17 use super::version::Version;
18 
19 /// Returns the length of the encoded string.
20 ///
21 /// # Remarks
22 ///
23 /// The length is **one** less that the original C version, since no null
24 /// terminator is used.
25 ///
26 /// # Examples
27 ///
28 /// ```rust
29 /// use argon2::{self, Variant};
30 ///
31 /// let variant = Variant::Argon2i;
32 /// let mem = 4096;
33 /// let time = 10;
34 /// let parallelism = 10;
35 /// let salt_len = 8;
36 /// let hash_len = 32;
37 /// let enc_len = argon2::encoded_len(variant, mem, time, parallelism, salt_len, hash_len);
38 /// assert_eq!(enc_len, 86);
39 /// ```
40 #[cfg_attr(rustfmt, rustfmt_skip)]
encoded_len( variant: Variant, mem_cost: u32, time_cost: u32, parallelism: u32, salt_len: u32, hash_len: u32 ) -> u3241 pub fn encoded_len(
42     variant: Variant,
43     mem_cost: u32,
44     time_cost: u32,
45     parallelism: u32,
46     salt_len: u32,
47     hash_len: u32
48 ) -> u32 {
49     ("$$v=$m=,t=,p=$$".len() as u32)  +
50     (variant.as_lowercase_str().len() as u32) +
51     encoding::num_len(Version::default().as_u32()) +
52     encoding::num_len(mem_cost) +
53     encoding::num_len(time_cost) +
54     encoding::num_len(parallelism) +
55     encoding::base64_len(salt_len) +
56     encoding::base64_len(hash_len)
57 }
58 
59 /// Hashes the password and returns the encoded hash.
60 ///
61 /// # Examples
62 ///
63 /// Create an encoded hash with the default configuration:
64 ///
65 /// ```
66 /// use argon2::{self, Config};
67 ///
68 /// let pwd = b"password";
69 /// let salt = b"somesalt";
70 /// let config = Config::default();
71 /// let encoded = argon2::hash_encoded(pwd, salt, &config).unwrap();
72 /// ```
73 ///
74 ///
75 /// Create an Argon2d encoded hash with 4 lanes and parallel execution:
76 ///
77 /// ```
78 /// use argon2::{self, Config, ThreadMode, Variant};
79 ///
80 /// let pwd = b"password";
81 /// let salt = b"somesalt";
82 /// let mut config = Config::default();
83 /// config.variant = Variant::Argon2d;
84 /// config.lanes = 4;
85 /// config.thread_mode = ThreadMode::Parallel;
86 /// let encoded = argon2::hash_encoded(pwd, salt, &config).unwrap();
87 /// ```
hash_encoded(pwd: &[u8], salt: &[u8], config: &Config) -> Result<String>88 pub fn hash_encoded(pwd: &[u8], salt: &[u8], config: &Config) -> Result<String> {
89     let context = Context::new(config.clone(), pwd, salt)?;
90     let hash = run(&context);
91     let encoded = encoding::encode_string(&context, &hash);
92     Ok(encoded)
93 }
94 
95 /// Hashes the password using default settings and returns the encoded hash.
96 ///
97 /// # Examples
98 ///
99 /// ```
100 /// use argon2;
101 ///
102 /// let pwd = b"password";
103 /// let salt = b"somesalt";
104 /// let encoded = argon2::hash_encoded_defaults(pwd, salt).unwrap();
105 /// ```
106 ///
107 /// The above rewritten using `hash_encoded`:
108 ///
109 /// ```
110 /// use argon2::{self, Config};
111 ///
112 /// let pwd = b"password";
113 /// let salt = b"somesalt";
114 /// let config = Config::default();
115 /// let encoded = argon2::hash_encoded(pwd, salt, &config).unwrap();
116 /// ```
117 #[deprecated(since = "0.2.0", note = "please use `hash_encoded` instead")]
hash_encoded_defaults(pwd: &[u8], salt: &[u8]) -> Result<String>118 pub fn hash_encoded_defaults(pwd: &[u8], salt: &[u8]) -> Result<String> {
119     hash_encoded(pwd, salt, &Config::default())
120 }
121 
122 /// Hashes the password and returns the encoded hash (pre 0.2.0 `hash_encoded`).
123 ///
124 /// # Examples
125 ///
126 ///
127 /// ```
128 /// use argon2::{self, Variant, Version};
129 ///
130 /// let pwd = b"password";
131 /// let salt = b"somesalt";
132 /// let mem_cost = 4096;
133 /// let time_cost = 10;
134 /// let lanes = 1;
135 /// let threads = 1;
136 /// let secret = b"secret value";
137 /// let ad = b"associated data";
138 /// let hash_len = 32;
139 /// let encoded = argon2::hash_encoded_old(Variant::Argon2i,
140 ///                                        Version::Version13,
141 ///                                        mem_cost,
142 ///                                        time_cost,
143 ///                                        lanes,
144 ///                                        threads,
145 ///                                        pwd,
146 ///                                        salt,
147 ///                                        secret,
148 ///                                        ad,
149 ///                                        hash_len).unwrap();
150 /// ```
151 ///
152 /// The above rewritten using the new `hash_encoded`:
153 ///
154 /// ```
155 /// use argon2::{self, Config, ThreadMode, Variant, Version};
156 ///
157 /// let pwd = b"password";
158 /// let salt = b"somesalt";
159 /// let config = Config {
160 ///     variant: Variant::Argon2i,
161 ///     version: Version::Version13,
162 ///     mem_cost: 4096,
163 ///     time_cost: 10,
164 ///     lanes: 1,
165 ///     thread_mode: ThreadMode::Sequential,
166 ///     secret: b"secret value",
167 ///     ad: b"associated data",
168 ///     hash_length: 32,
169 /// };
170 /// let encoded = argon2::hash_encoded(pwd, salt, &config).unwrap();
171 /// ```
172 #[deprecated(since = "0.2.0", note = "please use new `hash_encoded` instead")]
hash_encoded_old( variant: Variant, version: Version, mem_cost: u32, time_cost: u32, lanes: u32, threads: u32, pwd: &[u8], salt: &[u8], secret: &[u8], ad: &[u8], hash_len: u32, ) -> Result<String>173 pub fn hash_encoded_old(
174     variant: Variant,
175     version: Version,
176     mem_cost: u32,
177     time_cost: u32,
178     lanes: u32,
179     threads: u32,
180     pwd: &[u8],
181     salt: &[u8],
182     secret: &[u8],
183     ad: &[u8],
184     hash_len: u32,
185 ) -> Result<String> {
186     let config = Config {
187         variant: variant,
188         version: version,
189         mem_cost: mem_cost,
190         time_cost: time_cost,
191         lanes: lanes,
192         thread_mode: ThreadMode::from_threads(threads),
193         secret: secret,
194         ad: ad,
195         hash_length: hash_len,
196     };
197     hash_encoded(pwd, salt, &config)
198 }
199 
200 /// Hashes the password and returns the encoded hash (standard).
201 ///
202 /// # Examples
203 ///
204 ///
205 /// ```
206 /// use argon2::{self, Variant, Version};
207 ///
208 /// let pwd = b"password";
209 /// let salt = b"somesalt";
210 /// let mem_cost = 4096;
211 /// let time_cost = 10;
212 /// let parallelism = 1;
213 /// let hash_len = 32;
214 /// let encoded = argon2::hash_encoded_std(Variant::Argon2i,
215 ///                                        Version::Version13,
216 ///                                        mem_cost,
217 ///                                        time_cost,
218 ///                                        parallelism,
219 ///                                        pwd,
220 ///                                        salt,
221 ///                                        hash_len).unwrap();
222 /// ```
223 ///
224 /// The above rewritten using `hash_encoded`:
225 ///
226 /// ```
227 /// use argon2::{self, Config, ThreadMode, Variant, Version};
228 ///
229 /// let pwd = b"password";
230 /// let salt = b"somesalt";
231 /// let config = Config {
232 ///     variant: Variant::Argon2i,
233 ///     version: Version::Version13,
234 ///     mem_cost: 4096,
235 ///     time_cost: 10,
236 ///     lanes: 1,
237 ///     thread_mode: ThreadMode::Sequential,
238 ///     secret: &[],
239 ///     ad: &[],
240 ///     hash_length: 32,
241 /// };
242 /// let encoded = argon2::hash_encoded(pwd, salt, &config).unwrap();
243 /// ```
244 #[deprecated(since = "0.2.0", note = "please use `hash_encoded` instead")]
hash_encoded_std( variant: Variant, version: Version, mem_cost: u32, time_cost: u32, parallelism: u32, pwd: &[u8], salt: &[u8], hash_len: u32, ) -> Result<String>245 pub fn hash_encoded_std(
246     variant: Variant,
247     version: Version,
248     mem_cost: u32,
249     time_cost: u32,
250     parallelism: u32,
251     pwd: &[u8],
252     salt: &[u8],
253     hash_len: u32,
254 ) -> Result<String> {
255     let config = Config {
256         variant: variant,
257         version: version,
258         mem_cost: mem_cost,
259         time_cost: time_cost,
260         lanes: parallelism,
261         thread_mode: ThreadMode::from_threads(parallelism),
262         secret: &[],
263         ad: &[],
264         hash_length: hash_len,
265     };
266     hash_encoded(pwd, salt, &config)
267 }
268 
269 /// Hashes the password and returns the hash as a vector.
270 ///
271 /// # Examples
272 ///
273 /// Create a hash with the default configuration:
274 ///
275 /// ```
276 /// use argon2::{self, Config};
277 ///
278 /// let pwd = b"password";
279 /// let salt = b"somesalt";
280 /// let config = Config::default();
281 /// let vec = argon2::hash_raw(pwd, salt, &config).unwrap();
282 /// ```
283 ///
284 ///
285 /// Create an Argon2d hash with 4 lanes and parallel execution:
286 ///
287 /// ```
288 /// use argon2::{self, Config, ThreadMode, Variant};
289 ///
290 /// let pwd = b"password";
291 /// let salt = b"somesalt";
292 /// let mut config = Config::default();
293 /// config.variant = Variant::Argon2d;
294 /// config.lanes = 4;
295 /// config.thread_mode = ThreadMode::Parallel;
296 /// let vec = argon2::hash_raw(pwd, salt, &config).unwrap();
297 /// ```
hash_raw(pwd: &[u8], salt: &[u8], config: &Config) -> Result<Vec<u8>>298 pub fn hash_raw(pwd: &[u8], salt: &[u8], config: &Config) -> Result<Vec<u8>> {
299     let context = Context::new(config.clone(), pwd, salt)?;
300     let hash = run(&context);
301     Ok(hash)
302 }
303 
304 /// Hashes the password using default settings and returns the hash as a vector.
305 ///
306 /// # Examples
307 ///
308 /// ```
309 /// use argon2;
310 ///
311 /// let pwd = b"password";
312 /// let salt = b"somesalt";
313 /// let vec = argon2::hash_raw_defaults(pwd, salt).unwrap();
314 /// ```
315 ///
316 /// The above rewritten using `hash_raw`:
317 ///
318 /// ```
319 /// use argon2::{self, Config};
320 ///
321 /// let pwd = b"password";
322 /// let salt = b"somesalt";
323 /// let config = Config::default();
324 /// let vec = argon2::hash_raw(pwd, salt, &config).unwrap();
325 /// ```
326 #[deprecated(since = "0.2.0", note = "please use `hash_raw` instead")]
hash_raw_defaults(pwd: &[u8], salt: &[u8]) -> Result<Vec<u8>>327 pub fn hash_raw_defaults(pwd: &[u8], salt: &[u8]) -> Result<Vec<u8>> {
328     hash_raw(pwd, salt, &Config::default())
329 }
330 
331 /// Hashes the password and returns the hash as a vector (pre 0.2.0 `hash_raw`).
332 ///
333 /// # Examples
334 ///
335 ///
336 /// ```
337 /// use argon2::{self, Variant, Version};
338 ///
339 /// let mem_cost = 4096;
340 /// let time_cost = 10;
341 /// let lanes = 1;
342 /// let threads = 1;
343 /// let pwd = b"password";
344 /// let salt = b"somesalt";
345 /// let secret = b"secret value";
346 /// let ad = b"associated data";
347 /// let hash_len = 32;
348 /// let vec = argon2::hash_raw_old(Variant::Argon2i,
349 ///                                Version::Version13,
350 ///                                mem_cost,
351 ///                                time_cost,
352 ///                                lanes,
353 ///                                threads,
354 ///                                pwd,
355 ///                                salt,
356 ///                                secret,
357 ///                                ad,
358 ///                                hash_len).unwrap();
359 /// ```
360 ///
361 /// The above rewritten using the new `hash_raw`:
362 ///
363 /// ```
364 /// use argon2::{self, Config, ThreadMode, Variant, Version};
365 ///
366 /// let pwd = b"password";
367 /// let salt = b"somesalt";
368 /// let config = Config {
369 ///     variant: Variant::Argon2i,
370 ///     version: Version::Version13,
371 ///     mem_cost: 4096,
372 ///     time_cost: 10,
373 ///     lanes: 1,
374 ///     thread_mode: ThreadMode::Sequential,
375 ///     secret: b"secret value",
376 ///     ad: b"associated data",
377 ///     hash_length: 32,
378 /// };
379 /// let vec = argon2::hash_raw(pwd, salt, &config);
380 /// ```
381 #[deprecated(since = "0.2.0", note = "please use new `hash_raw` instead")]
hash_raw_old( variant: Variant, version: Version, mem_cost: u32, time_cost: u32, lanes: u32, threads: u32, pwd: &[u8], salt: &[u8], secret: &[u8], ad: &[u8], hash_len: u32, ) -> Result<Vec<u8>>382 pub fn hash_raw_old(
383     variant: Variant,
384     version: Version,
385     mem_cost: u32,
386     time_cost: u32,
387     lanes: u32,
388     threads: u32,
389     pwd: &[u8],
390     salt: &[u8],
391     secret: &[u8],
392     ad: &[u8],
393     hash_len: u32,
394 ) -> Result<Vec<u8>> {
395     let config = Config {
396         variant: variant,
397         version: version,
398         mem_cost: mem_cost,
399         time_cost: time_cost,
400         lanes: lanes,
401         thread_mode: ThreadMode::from_threads(threads),
402         secret: secret,
403         ad: ad,
404         hash_length: hash_len,
405     };
406     hash_raw(pwd, salt, &config)
407 }
408 
409 /// Hashes the password and returns the hash as a vector (standard).
410 ///
411 /// # Examples
412 ///
413 ///
414 /// ```
415 /// use argon2::{self, Variant, Version};
416 ///
417 /// let pwd = b"password";
418 /// let salt = b"somesalt";
419 /// let mem_cost = 4096;
420 /// let time_cost = 10;
421 /// let parallelism = 1;
422 /// let hash_len = 32;
423 /// let vec = argon2::hash_raw_std(Variant::Argon2i,
424 ///                                Version::Version13,
425 ///                                mem_cost,
426 ///                                time_cost,
427 ///                                parallelism,
428 ///                                pwd,
429 ///                                salt,
430 ///                                hash_len).unwrap();
431 /// ```
432 ///
433 /// The above rewritten using `hash_raw`:
434 ///
435 /// ```
436 /// use argon2::{self, Config, ThreadMode, Variant, Version};
437 ///
438 /// let pwd = b"password";
439 /// let salt = b"somesalt";
440 /// let config = Config {
441 ///     variant: Variant::Argon2i,
442 ///     version: Version::Version13,
443 ///     mem_cost: 4096,
444 ///     time_cost: 10,
445 ///     lanes: 1,
446 ///     thread_mode: ThreadMode::Sequential,
447 ///     secret: &[],
448 ///     ad: &[],
449 ///     hash_length: 32,
450 /// };
451 /// let vec = argon2::hash_raw(pwd, salt, &config);
452 /// ```
453 #[deprecated(since = "0.2.0", note = "please use `hash_raw` instead")]
hash_raw_std( variant: Variant, version: Version, mem_cost: u32, time_cost: u32, parallelism: u32, pwd: &[u8], salt: &[u8], hash_len: u32, ) -> Result<Vec<u8>>454 pub fn hash_raw_std(
455     variant: Variant,
456     version: Version,
457     mem_cost: u32,
458     time_cost: u32,
459     parallelism: u32,
460     pwd: &[u8],
461     salt: &[u8],
462     hash_len: u32,
463 ) -> Result<Vec<u8>> {
464     let config = Config {
465         variant: variant,
466         version: version,
467         mem_cost: mem_cost,
468         time_cost: time_cost,
469         lanes: parallelism,
470         thread_mode: ThreadMode::from_threads(parallelism),
471         secret: &[],
472         ad: &[],
473         hash_length: hash_len,
474     };
475     hash_raw(pwd, salt, &config)
476 }
477 
478 /// Verifies the password with the encoded hash.
479 ///
480 /// # Examples
481 ///
482 /// ```
483 /// use argon2;
484 ///
485 /// let enc = "$argon2i$v=19$m=4096,t=3,p=1$c29tZXNhbHQ\
486 ///            $iWh06vD8Fy27wf9npn6FXWiCX4K6pW6Ue1Bnzz07Z8A";
487 /// let pwd = b"password";
488 /// let res = argon2::verify_encoded(enc, pwd).unwrap();
489 /// assert!(res);
490 /// ```
verify_encoded(encoded: &str, pwd: &[u8]) -> Result<bool>491 pub fn verify_encoded(encoded: &str, pwd: &[u8]) -> Result<bool> {
492     verify_encoded_ext(encoded, pwd, &[], &[])
493 }
494 
495 /// Verifies the password with the encoded hash, secret and associated data.
496 ///
497 /// # Examples
498 ///
499 /// ```
500 /// use argon2;
501 ///
502 /// let enc = "$argon2i$v=19$m=4096,t=3,p=1$c29tZXNhbHQ\
503 ///            $OlcSvlN20Lz43sK3jhCJ9K04oejhiY0AmI+ck6nuETo";
504 /// let pwd = b"password";
505 /// let secret = b"secret";
506 /// let ad = b"ad";
507 /// let res = argon2::verify_encoded_ext(enc, pwd, secret, ad).unwrap();
508 /// assert!(res);
509 /// ```
verify_encoded_ext(encoded: &str, pwd: &[u8], secret: &[u8], ad: &[u8]) -> Result<bool>510 pub fn verify_encoded_ext(encoded: &str, pwd: &[u8], secret: &[u8], ad: &[u8]) -> Result<bool> {
511     let decoded = encoding::decode_string(encoded)?;
512     let config = Config {
513         variant: decoded.variant,
514         version: decoded.version,
515         mem_cost: decoded.mem_cost,
516         time_cost: decoded.time_cost,
517         lanes: decoded.parallelism,
518         thread_mode: ThreadMode::from_threads(decoded.parallelism),
519         secret: secret,
520         ad: ad,
521         hash_length: decoded.hash.len() as u32,
522     };
523     verify_raw(pwd, &decoded.salt, &decoded.hash, &config)
524 }
525 
526 /// Verifies the password with the supplied configuration.
527 ///
528 /// # Examples
529 ///
530 ///
531 /// ```
532 /// use argon2::{self, Config};
533 ///
534 /// let pwd = b"password";
535 /// let salt = b"somesalt";
536 /// let hash = &[137, 104, 116, 234, 240, 252, 23, 45, 187, 193, 255, 103, 166,
537 ///              126, 133, 93, 104, 130, 95, 130, 186, 165, 110, 148, 123, 80,
538 ///              103, 207, 61, 59, 103, 192];
539 /// let config = Config::default();
540 /// let res = argon2::verify_raw(pwd, salt, hash, &config).unwrap();
541 /// assert!(res);
542 /// ```
verify_raw(pwd: &[u8], salt: &[u8], hash: &[u8], config: &Config) -> Result<bool>543 pub fn verify_raw(pwd: &[u8], salt: &[u8], hash: &[u8], config: &Config) -> Result<bool> {
544     let config = Config {
545         hash_length: hash.len() as u32,
546         ..config.clone()
547     };
548     let context = Context::new(config, pwd, salt)?;
549     Ok(run(&context) == hash)
550 }
551 
552 /// Verifies the password with the supplied settings (pre 0.2.0 `verify_raw`).
553 ///
554 /// # Examples
555 ///
556 /// ```
557 /// use argon2::{self, Variant, Version};
558 ///
559 /// let pwd = b"password";
560 /// let salt = b"somesalt";
561 /// let hash = &[137, 104, 116, 234, 240, 252, 23, 45, 187, 193, 255, 103, 166,
562 ///              126, 133, 93, 104, 130, 95, 130, 186, 165, 110, 148, 123, 80,
563 ///              103, 207, 61, 59, 103, 192];
564 /// let mem_cost = 4096;
565 /// let time_cost = 3;
566 /// let lanes = 1;
567 /// let threads = 1;
568 /// let secret = &[];
569 /// let ad = &[];
570 /// let res = argon2::verify_raw_old(Variant::Argon2i,
571 ///                                  Version::Version13,
572 ///                                  mem_cost,
573 ///                                  time_cost,
574 ///                                  lanes,
575 ///                                  threads,
576 ///                                  pwd,
577 ///                                  salt,
578 ///                                  secret,
579 ///                                  ad,
580 ///                                  hash).unwrap();
581 /// assert!(res);
582 /// ```
583 ///
584 /// The above rewritten using the new `verify_raw`:
585 ///
586 /// ```
587 /// use argon2::{self, Config, ThreadMode, Variant, Version};
588 ///
589 /// let pwd = b"password";
590 /// let salt = b"somesalt";
591 /// let hash = &[137, 104, 116, 234, 240, 252, 23, 45, 187, 193, 255, 103, 166,
592 ///              126, 133, 93, 104, 130, 95, 130, 186, 165, 110, 148, 123, 80,
593 ///              103, 207, 61, 59, 103, 192];
594 /// let config = Config {
595 ///     variant: Variant::Argon2i,
596 ///     version: Version::Version13,
597 ///     mem_cost: 4096,
598 ///     time_cost: 3,
599 ///     lanes: 1,
600 ///     thread_mode: ThreadMode::Sequential,
601 ///     secret: &[],
602 ///     ad: &[],
603 ///     hash_length: hash.len() as u32,
604 /// };
605 /// let res = argon2::verify_raw(pwd, salt, hash, &config).unwrap();
606 /// assert!(res);
607 /// ```
608 #[deprecated(since = "0.2.0", note = "please use new `verify_raw` instead")]
verify_raw_old( variant: Variant, version: Version, mem_cost: u32, time_cost: u32, lanes: u32, threads: u32, pwd: &[u8], salt: &[u8], secret: &[u8], ad: &[u8], hash: &[u8], ) -> Result<bool>609 pub fn verify_raw_old(
610     variant: Variant,
611     version: Version,
612     mem_cost: u32,
613     time_cost: u32,
614     lanes: u32,
615     threads: u32,
616     pwd: &[u8],
617     salt: &[u8],
618     secret: &[u8],
619     ad: &[u8],
620     hash: &[u8],
621 ) -> Result<bool> {
622     let config = Config {
623         variant: variant,
624         version: version,
625         mem_cost: mem_cost,
626         time_cost: time_cost,
627         lanes: lanes,
628         thread_mode: ThreadMode::from_threads(threads),
629         secret: secret,
630         ad: ad,
631         hash_length: hash.len() as u32,
632     };
633     verify_raw(pwd, salt, hash, &config)
634 }
635 
636 /// Verifies the password with the supplied settings (standard).
637 ///
638 /// # Examples
639 ///
640 ///
641 /// ```
642 /// use argon2::{self, Variant, Version};
643 ///
644 /// let pwd = b"password";
645 /// let salt = b"somesalt";
646 /// let hash = &[137, 104, 116, 234, 240, 252, 23, 45, 187, 193, 255, 103, 166,
647 ///              126, 133, 93, 104, 130, 95, 130, 186, 165, 110, 148, 123, 80,
648 ///              103, 207, 61, 59, 103, 192];
649 /// let mem_cost = 4096;
650 /// let time_cost = 3;
651 /// let parallelism = 1;
652 /// let res = argon2::verify_raw_std(Variant::Argon2i,
653 ///                                  Version::Version13,
654 ///                                  mem_cost,
655 ///                                  time_cost,
656 ///                                  parallelism,
657 ///                                  pwd,
658 ///                                  salt,
659 ///                                  hash).unwrap();
660 /// assert!(res);
661 /// ```
662 ///
663 /// The above rewritten using `verify_raw`:
664 ///
665 /// ```
666 /// use argon2::{self, Config, ThreadMode, Variant, Version};
667 ///
668 /// let pwd = b"password";
669 /// let salt = b"somesalt";
670 /// let hash = &[137, 104, 116, 234, 240, 252, 23, 45, 187, 193, 255, 103, 166,
671 ///              126, 133, 93, 104, 130, 95, 130, 186, 165, 110, 148, 123, 80,
672 ///              103, 207, 61, 59, 103, 192];
673 /// let config = Config {
674 ///     variant: Variant::Argon2i,
675 ///     version: Version::Version13,
676 ///     mem_cost: 4096,
677 ///     time_cost: 3,
678 ///     lanes: 1,
679 ///     thread_mode: ThreadMode::Sequential,
680 ///     secret: &[],
681 ///     ad: &[],
682 ///     hash_length: hash.len() as u32,
683 /// };
684 /// let res = argon2::verify_raw(pwd, salt, hash, &config).unwrap();
685 /// assert!(res);
686 /// ```
687 #[deprecated(since = "0.2.0", note = "please use `verify_raw` instead")]
verify_raw_std( variant: Variant, version: Version, mem_cost: u32, time_cost: u32, parallelism: u32, pwd: &[u8], salt: &[u8], hash: &[u8], ) -> Result<bool>688 pub fn verify_raw_std(
689     variant: Variant,
690     version: Version,
691     mem_cost: u32,
692     time_cost: u32,
693     parallelism: u32,
694     pwd: &[u8],
695     salt: &[u8],
696     hash: &[u8],
697 ) -> Result<bool> {
698     let config = Config {
699         variant: variant,
700         version: version,
701         mem_cost: mem_cost,
702         time_cost: time_cost,
703         lanes: parallelism,
704         thread_mode: ThreadMode::from_threads(parallelism),
705         secret: &[],
706         ad: &[],
707         hash_length: hash.len() as u32,
708     };
709     verify_raw(pwd, salt, hash, &config)
710 }
711 
run(context: &Context) -> Vec<u8>712 fn run(context: &Context) -> Vec<u8> {
713     let mut memory = Memory::new(context.config.lanes, context.lane_length);
714     core::initialize(context, &mut memory);
715     core::fill_memory_blocks(context, &mut memory);
716     core::finalize(context, &memory)
717 }
718