8#include <botan/internal/ffi_util.h>
9#include <botan/internal/ffi_rng.h>
10#include <botan/pbkdf.h>
11#include <botan/pwdhash.h>
14#if defined(BOTAN_HAS_BCRYPT)
15 #include <botan/bcrypt.h>
22int botan_pbkdf(
const char* algo, uint8_t out[],
size_t out_len,
23 const char* pass,
const uint8_t salt[],
size_t salt_len,
36 uint8_t out[],
size_t out_len,
38 const uint8_t salt[],
size_t salt_len,
40 size_t* iterations_used)
43 static_cast<uint32_t
>(ms_to_run),
64 if(algo ==
nullptr || password ==
nullptr)
68 password_len = std::strlen(password);
76 auto pwdhash = pwdhash_fam->from_params(param1, param2, param3);
78 pwdhash->derive_key(out, out_len,
79 password, password_len,
99 if(algo ==
nullptr || password ==
nullptr)
102 if(password_len == 0)
103 password_len = std::strlen(password);
112 auto pwdhash = pwdhash_fam->tune(out_len, std::chrono::milliseconds(msec));
115 *param1 = pwdhash->iterations();
117 *param2 = pwdhash->parallelism();
119 *param3 = pwdhash->memory_param();
121 pwdhash->derive_key(out, out_len,
122 password, password_len,
130 uint8_t out[],
size_t out_len,
131 const uint8_t secret[],
size_t secret_len,
132 const uint8_t salt[],
size_t salt_len,
133 const uint8_t label[],
size_t label_len)
137 kdf->kdf(out, out_len, secret, secret_len, salt,
salt_len, label, label_len);
143 const char* password,
144 const uint8_t salt[],
size_t salt_len,
145 size_t N,
size_t r,
size_t p)
158#if defined(BOTAN_HAS_BCRYPT)
160 if(out ==
nullptr || out_len ==
nullptr || pass ==
nullptr)
166 if(wf < 4 || wf > 18)
180#if defined(BOTAN_HAS_BCRYPT)
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)
int ffi_guard_thunk(const char *func_name, std::function< int()> thunk)
T & safe_get(botan_struct< T, M > *p)
int write_str_output(uint8_t out[], size_t *out_len, const std::string &str)
KDF * get_kdf(const std::string &algo_spec)
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)