Botan 2.19.5 Crypto and TLS for C&

argon2.h
Go to the documentation of this file.
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 size_t M() const { return m_M; }
39 size_t t() const { return m_t; }
40 size_t p() const { return m_p; }
41
42 size_t iterations() const override { return t(); }
43
44 size_t parallelism() const override { return p(); }
45
46 size_t memory_param() const override { return M(); }
47
48 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
Botan::Argon2_Family
Definition: argon2.h:56
Botan::Argon2
Definition: argon2.h:22
Botan::Argon2::p
size_t p() const
Definition: argon2.h:40
Botan::Argon2::iterations
size_t iterations() const override
Definition: argon2.h:42
Botan::Argon2::total_memory_usage
size_t total_memory_usage() const override
Definition: argon2.h:48
Botan::Argon2::operator=
Argon2 & operator=(const Argon2 &)=default
Botan::Argon2::t
size_t t() const
Definition: argon2.h:39
Botan::Argon2::parallelism
size_t parallelism() const override
Definition: argon2.h:44
Botan::Argon2::Argon2
Argon2(const Argon2 &other)=default
Botan::Argon2::M
size_t M() const
Definition: argon2.h:38
Botan::Argon2::memory_param
size_t memory_param() const override
Definition: argon2.h:46
Botan::PasswordHashFamily
Definition: pwdhash.h:80
Botan::PasswordHash
Definition: pwdhash.h:25
Botan::RandomNumberGenerator
Definition: rng.h:26
name
std::string name
Definition: commoncrypto_hash.cpp:24
final
int(* final)(unsigned char *, CTX *)
Definition: commoncrypto_hash.cpp:29
BOTAN_PUBLIC_API
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:31
Botan
Definition: alg_id.cpp:13
Botan::argon2
void argon2(uint8_t output[], size_t output_len, const char *password, size_t password_len, const uint8_t salt[], size_t salt_len, const uint8_t key[], size_t key_len, const uint8_t ad[], size_t ad_len, uint8_t mode, size_t threads, size_t M, size_t t)
Definition: argon2.cpp:370
Botan::argon2_check_pwhash
bool argon2_check_pwhash(const char *password, size_t password_len, const std::string &hash)
Definition: argon2fmt.cpp:57
Botan::to_string
std::string to_string(ErrorType type)
Convert an ErrorType to string.
Definition: exceptn.cpp:11
Botan::argon2_generate_pwhash
std::string argon2_generate_pwhash(const char *password, size_t password_len, RandomNumberGenerator &rng, size_t p, size_t M, size_t t, uint8_t y=2, size_t salt_len=16, size_t output_len=32)
Definition: argon2fmt.cpp:26
std
Definition: bigint.h:1155
hash
MechanismType hash
Definition: p11_mechanism.cpp:64
salt_len
size_t salt_len
Definition: x509_obj.cpp:25