8#include <botan/internal/ffi_util.h>
9#include <botan/internal/ffi_rng.h>
10#include <botan/pwdhash.h>
13#if defined(BOTAN_HAS_BCRYPT)
14 #include <botan/bcrypt.h>
21int botan_pbkdf(
const char* algo, uint8_t out[],
size_t out_len,
22 const char* pass,
const uint8_t salt[],
size_t salt_len,
35 uint8_t out[],
size_t out_len,
37 const uint8_t salt[],
size_t salt_len,
39 size_t* iterations_used)
42 static_cast<uint32_t
>(ms_to_run),
63 if(algo ==
nullptr || password ==
nullptr)
67 password_len = std::strlen(password);
75 auto pwdhash = pwdhash_fam->from_params(param1, param2, param3);
77 pwdhash->derive_key(out, out_len,
78 password, password_len,
98 if(algo ==
nullptr || password ==
nullptr)
101 if(password_len == 0)
102 password_len = std::strlen(password);
111 auto pwdhash = pwdhash_fam->tune(out_len, std::chrono::milliseconds(msec));
114 *param1 = pwdhash->iterations();
116 *param2 = pwdhash->parallelism();
118 *param3 = pwdhash->memory_param();
120 pwdhash->derive_key(out, out_len,
121 password, password_len,
129 uint8_t out[],
size_t out_len,
130 const uint8_t secret[],
size_t secret_len,
131 const uint8_t salt[],
size_t salt_len,
132 const uint8_t label[],
size_t label_len)
136 kdf->kdf(out, out_len, secret, secret_len, salt,
salt_len, label, label_len);
142 const char* password,
143 const uint8_t salt[],
size_t salt_len,
144 size_t N,
size_t r,
size_t p)
157#if defined(BOTAN_HAS_BCRYPT)
159 if(out ==
nullptr || out_len ==
nullptr || pass ==
nullptr)
165 if(wf < 4 || wf > 18)
179#if defined(BOTAN_HAS_BCRYPT)
static std::unique_ptr< KDF > create_or_throw(const std::string &algo_spec, const std::string &provider="")
static std::unique_ptr< PasswordHashFamily > create(const std::string &algo_spec, const std::string &provider="")
struct botan_rng_struct * botan_rng_t
@ BOTAN_FFI_ERROR_NOT_IMPLEMENTED
@ BOTAN_FFI_INVALID_VERIFIER
@ BOTAN_FFI_ERROR_BAD_FLAG
@ BOTAN_FFI_ERROR_NULL_POINTER
@ BOTAN_FFI_ERROR_BAD_PARAMETER
int botan_pbkdf(const char *algo, uint8_t out[], size_t out_len, const char *pass, const uint8_t salt[], size_t salt_len, size_t iterations)
int botan_pwdhash_timed(const char *algo, uint32_t msec, size_t *param1, size_t *param2, size_t *param3, uint8_t out[], size_t out_len, const char *password, size_t password_len, const uint8_t salt[], size_t salt_len)
int botan_pbkdf_timed(const char *algo, uint8_t out[], size_t out_len, const char *password, const uint8_t salt[], size_t salt_len, size_t ms_to_run, size_t *iterations_used)
int botan_scrypt(uint8_t out[], size_t out_len, const char *password, const uint8_t salt[], size_t salt_len, size_t N, size_t r, size_t p)
int botan_bcrypt_generate(uint8_t *out, size_t *out_len, const char *pass, botan_rng_t rng_obj, size_t wf, uint32_t flags)
int botan_kdf(const char *kdf_algo, uint8_t out[], size_t out_len, const uint8_t secret[], size_t secret_len, const uint8_t salt[], size_t salt_len, const uint8_t label[], size_t label_len)
int botan_pwdhash(const char *algo, size_t param1, size_t param2, size_t param3, uint8_t out[], size_t out_len, const char *password, size_t password_len, const uint8_t salt[], size_t salt_len)
int botan_bcrypt_is_valid(const char *pass, const char *hash)
T & safe_get(botan_struct< T, M > *p)
int write_str_output(uint8_t out[], size_t *out_len, const std::string &str)
int ffi_guard_thunk(const char *func_name, const std::function< int()> &thunk)
std::string generate_bcrypt(const std::string &pass, RandomNumberGenerator &rng, uint16_t work_factor, char version)
bool check_bcrypt(const std::string &pass, const std::string &hash)