/src/botan/build/include/botan/argon2.h
Line | Count | Source (jump to first uncovered line) |
1 | | /** |
2 | | * (C) 2018,2019 Jack Lloyd |
3 | | * |
4 | | * Botan is released under the Simplified BSD License (see license.txt) |
5 | | */ |
6 | | |
7 | | #ifndef BOTAN_ARGON2_H_ |
8 | | #define BOTAN_ARGON2_H_ |
9 | | |
10 | | #include <botan/pwdhash.h> |
11 | | |
12 | | //BOTAN_FUTURE_INTERNAL_HEADER(argon2.h) |
13 | | |
14 | | namespace Botan { |
15 | | |
16 | | class RandomNumberGenerator; |
17 | | |
18 | | /** |
19 | | * Argon2 key derivation function |
20 | | */ |
21 | | class BOTAN_PUBLIC_API(2,11) Argon2 final : public PasswordHash |
22 | | { |
23 | | public: |
24 | | Argon2(uint8_t family, size_t M, size_t t, size_t p); |
25 | | |
26 | | Argon2(const Argon2& other) = default; |
27 | | Argon2& operator=(const Argon2&) = default; |
28 | | |
29 | | /** |
30 | | * Derive a new key under the current Argon2 parameter set |
31 | | */ |
32 | | void derive_key(uint8_t out[], size_t out_len, |
33 | | const char* password, size_t password_len, |
34 | | const uint8_t salt[], size_t salt_len) const override; |
35 | | |
36 | | std::string to_string() const override; |
37 | | |
38 | 0 | size_t M() const { return m_M; } |
39 | 0 | size_t t() const { return m_t; } |
40 | 0 | size_t p() const { return m_p; } |
41 | | |
42 | 0 | size_t iterations() const override { return t(); } |
43 | | |
44 | 0 | size_t parallelism() const override { return p(); } |
45 | | |
46 | 0 | size_t memory_param() const override { return M(); } |
47 | | |
48 | 0 | size_t total_memory_usage() const override { return M() * 1024; } |
49 | | |
50 | | private: |
51 | | uint8_t m_family; |
52 | | size_t m_M, m_t, m_p; |
53 | | }; |
54 | | |
55 | | class BOTAN_PUBLIC_API(2,11) Argon2_Family final : public PasswordHashFamily |
56 | | { |
57 | | public: |
58 | | Argon2_Family(uint8_t family); |
59 | | |
60 | | std::string name() const override; |
61 | | |
62 | | std::unique_ptr<PasswordHash> tune(size_t output_length, |
63 | | std::chrono::milliseconds msec, |
64 | | size_t max_memory) const override; |
65 | | |
66 | | std::unique_ptr<PasswordHash> default_params() const override; |
67 | | |
68 | | std::unique_ptr<PasswordHash> from_iterations(size_t iter) const override; |
69 | | |
70 | | std::unique_ptr<PasswordHash> from_params( |
71 | | size_t M, size_t t, size_t p) const override; |
72 | | private: |
73 | | const uint8_t m_family; |
74 | | }; |
75 | | |
76 | | /** |
77 | | * Argon2 key derivation function |
78 | | * |
79 | | * @param output the output will be placed here |
80 | | * @param output_len length of output |
81 | | * @param password the user password |
82 | | * @param password_len the length of password |
83 | | * @param salt the salt |
84 | | * @param salt_len length of salt |
85 | | * @param key an optional secret key |
86 | | * @param key_len the length of key |
87 | | * @param ad an optional additional input |
88 | | * @param ad_len the length of ad |
89 | | * @param y the Argon2 variant (0 = Argon2d, 1 = Argon2i, 2 = Argon2id) |
90 | | * @param p the parallelization parameter |
91 | | * @param M the amount of memory to use in Kb |
92 | | * @param t the number of iterations to use |
93 | | */ |
94 | | void BOTAN_PUBLIC_API(2,11) argon2(uint8_t output[], size_t output_len, |
95 | | const char* password, size_t password_len, |
96 | | const uint8_t salt[], size_t salt_len, |
97 | | const uint8_t key[], size_t key_len, |
98 | | const uint8_t ad[], size_t ad_len, |
99 | | uint8_t y, size_t p, size_t M, size_t t); |
100 | | |
101 | | std::string BOTAN_PUBLIC_API(2,11) |
102 | | argon2_generate_pwhash(const char* password, size_t password_len, |
103 | | RandomNumberGenerator& rng, |
104 | | size_t p, size_t M, size_t t, |
105 | | uint8_t y = 2, size_t salt_len = 16, size_t output_len = 32); |
106 | | |
107 | | /** |
108 | | * Check a previously created password hash |
109 | | * @param password the password to check against |
110 | | * @param password_len the length of password |
111 | | * @param hash the stored hash to check against |
112 | | */ |
113 | | bool BOTAN_PUBLIC_API(2,11) argon2_check_pwhash(const char* password, size_t password_len, |
114 | | const std::string& hash); |
115 | | |
116 | | } |
117 | | |
118 | | #endif |