7#include <botan/pwdhash.h>
9#include <botan/assert.h>
10#include <botan/exceptn.h>
11#include <botan/internal/algorithm_spec.h>
12#include <botan/internal/fmt.h>
13#include <botan/internal/probe_providers.h>
15#if defined(BOTAN_HAS_PBKDF2)
16 #include <botan/pbkdf2.h>
19#if defined(BOTAN_HAS_PGP_S2K)
20 #include <botan/pgp_s2k.h>
23#if defined(BOTAN_HAS_SCRYPT)
24 #include <botan/scrypt.h>
27#if defined(BOTAN_HAS_ARGON2)
28 #include <botan/argon2.h>
31#if defined(BOTAN_HAS_PBKDF_BCRYPT)
32 #include <botan/bcrypt_pbkdf.h>
35#if defined(BOTAN_HAS_PKCS12_KDF)
36 #include <botan/internal/pkcs12_kdf.h>
50 size_t key_len)
const {
53 if(ad_len == 0 && key_len == 0) {
54 return this->
derive_key(out, out_len, password, password_len, salt, salt_len);
63#if defined(BOTAN_HAS_PBKDF2)
64 if(
auto m = req.
match(
"PBKDF2({prf})")) {
65 if(provider.empty() || provider ==
"base") {
66 const auto prf = m->str(
"prf");
68 return std::make_unique<PBKDF2_Family>(std::move(mac));
72 return std::make_unique<PBKDF2_Family>(std::move(mac));
80#if defined(BOTAN_HAS_SCRYPT)
82 return std::make_unique<Scrypt_Family>();
86#if defined(BOTAN_HAS_ARGON2)
88 return std::make_unique<Argon2_Family>(
static_cast<uint8_t
>(0));
89 }
else if(req.
matches(
"Argon2i")) {
90 return std::make_unique<Argon2_Family>(
static_cast<uint8_t
>(1));
91 }
else if(req.
matches(
"Argon2id")) {
92 return std::make_unique<Argon2_Family>(
static_cast<uint8_t
>(2));
96#if defined(BOTAN_HAS_PBKDF_BCRYPT)
97 if(req.
matches(
"Bcrypt-PBKDF")) {
98 return std::make_unique<Bcrypt_PBKDF_Family>();
102#if defined(BOTAN_HAS_PGP_S2K)
103 if(
auto m = req.
match(
"OpenPGP-S2K({hash})")) {
105 return std::make_unique<RFC4880_S2K_Family>(std::move(hash));
110#if defined(BOTAN_HAS_PKCS12_KDF)
111 if(
auto m = req.
match(
"PKCS12-KDF({hash},{id:int})")) {
113 return std::make_unique<PKCS12_KDF_Family>(std::move(hash), m->integer(
"id"));
126 std::string_view provider) {
130 throw Lookup_Error(
"PasswordHashFamily", algo, provider);
bool matches(const AlgorithmPattern &pattern) const
std::optional< AlgorithmMatch > match(const AlgorithmPattern &pattern) const &
static std::unique_ptr< HashFunction > create(std::string_view algo_spec, std::string_view provider="")
static std::unique_ptr< MessageAuthenticationCode > create(std::string_view algo_spec, std::string_view provider="")
static std::unique_ptr< PasswordHashFamily > create_or_throw(std::string_view algo_spec, std::string_view provider="")
static std::vector< std::string > providers(std::string_view algo_spec)
static std::unique_ptr< PasswordHashFamily > create(std::string_view algo_spec, std::string_view provider="")
virtual void derive_key(uint8_t out[], size_t out_len, const char *password, size_t password_len, const uint8_t salt[], size_t salt_len) const =0
virtual std::string to_string() const =0
std::string fmt(std::string_view format, const T &... args)
std::vector< std::string > probe_providers_of(std::string_view algo_spec, const std::vector< std::string > &possible={"base"})