9#include <botan/assert.h>
11#include <botan/pwdhash.h>
12#include <botan/internal/ffi_rng.h>
13#include <botan/internal/ffi_util.h>
15#if defined(BOTAN_HAS_BCRYPT)
16 #include <botan/bcrypt.h>
30 return botan_pwdhash(algo, iterations, 0, 0, out, out_len, pass, 0, salt, salt_len);
40 size_t* iterations_used) {
42 static_cast<uint32_t
>(ms_to_run),
64 if(algo ==
nullptr || password ==
nullptr) {
68 if(password_len == 0) {
69 password_len = std::strlen(password);
79 auto pwdhash = pwdhash_fam->from_params(param1, param2, param3);
81 pwdhash->derive_key(out, out_len, password, password_len, salt, salt_len);
98 if(algo ==
nullptr || password ==
nullptr) {
102 if(password_len == 0) {
103 password_len = std::strlen(password);
113 auto pwdhash = pwdhash_fam->tune_params(out_len, msec);
115 if(param1 !=
nullptr) {
116 *param1 = pwdhash->iterations();
118 if(param2 !=
nullptr) {
119 *param2 = pwdhash->parallelism();
121 if(param3 !=
nullptr) {
122 *param3 = pwdhash->memory_param();
125 pwdhash->derive_key(out, out_len, password, password_len, salt, salt_len);
134 const uint8_t secret[],
136 const uint8_t salt[],
138 const uint8_t label[],
142 kdf->kdf(out, out_len, secret, secret_len, salt, salt_len, label, label_len);
149 const char* password,
150 const uint8_t salt[],
155 return botan_pwdhash(
"Scrypt", N, r, p, out, out_len, password, 0, salt, salt_len);
159 uint8_t* out,
size_t* out_len,
const char* pass,
botan_rng_t rng_obj,
size_t wf, uint32_t flags) {
160#if defined(BOTAN_HAS_BCRYPT)
162 if(out ==
nullptr || out_len ==
nullptr || pass ==
nullptr) {
170 if(wf < 4 || wf > 18) {
191#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)
T & safe_get(botan_struct< T, M > *p)
int ffi_guard_thunk(const char *func_name, T thunk)
int write_str_output(char out[], size_t *out_len, const std::string &str)
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)