10#include <botan/pwdhash.h>
11#include <botan/internal/ffi_rng.h>
12#include <botan/internal/ffi_util.h>
14#if defined(BOTAN_HAS_BCRYPT)
15 #include <botan/bcrypt.h>
29 return botan_pwdhash(algo, iterations, 0, 0, out, out_len, pass, 0, salt, salt_len);
39 size_t* iterations_used) {
41 static_cast<uint32_t
>(ms_to_run),
63 if(algo ==
nullptr || password ==
nullptr) {
67 if(password_len == 0) {
68 password_len = std::strlen(password);
78 auto pwdhash = pwdhash_fam->from_params(param1, param2, param3);
80 pwdhash->derive_key(out, out_len, password, password_len, salt, salt_len);
97 if(algo ==
nullptr || password ==
nullptr) {
101 if(password_len == 0) {
102 password_len = std::strlen(password);
112 auto pwdhash = pwdhash_fam->tune(out_len, std::chrono::milliseconds(msec));
115 *param1 = pwdhash->iterations();
118 *param2 = pwdhash->parallelism();
121 *param3 = pwdhash->memory_param();
124 pwdhash->derive_key(out, out_len, password, password_len, salt, salt_len);
133 const uint8_t secret[],
135 const uint8_t salt[],
137 const uint8_t label[],
141 kdf->kdf(out, out_len, secret, secret_len, salt, salt_len, label, label_len);
148 const char* password,
149 const uint8_t salt[],
154 return botan_pwdhash(
"Scrypt", N, r, p, out, out_len, password, 0, salt, salt_len);
158 uint8_t* out,
size_t* out_len,
const char* pass,
botan_rng_t rng_obj,
size_t wf, uint32_t flags) {
159#if defined(BOTAN_HAS_BCRYPT)
161 if(out ==
nullptr || out_len ==
nullptr || pass ==
nullptr) {
169 if(wf < 4 || wf > 18) {
189#if defined(BOTAN_HAS_BCRYPT)
static std::unique_ptr< KDF > create_or_throw(std::string_view algo_spec, std::string_view provider="")
static std::unique_ptr< PasswordHashFamily > create(std::string_view algo_spec, std::string_view 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_INSUFFICIENT_BUFFER_SPACE
@ 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 write_str_output(uint8_t out[], size_t *out_len, std::string_view str)
T & safe_get(botan_struct< T, M > *p)
int ffi_guard_thunk(const char *func_name, const std::function< int()> &thunk)
std::string generate_bcrypt(std::string_view pass, RandomNumberGenerator &rng, uint16_t work_factor, char version)
bool check_bcrypt(std::string_view pass, std::string_view hash)