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) {
67 if(out_len > 0 && out ==
nullptr) {
70 if(salt_len > 0 && salt ==
nullptr) {
74 if(password_len == 0) {
75 password_len = std::strlen(password);
85 auto pwdhash = pwdhash_fam->from_params(param1, param2, param3);
87 pwdhash->derive_key(out, out_len, password, password_len, salt, salt_len);
100 const char* password,
102 const uint8_t salt[],
104 if(algo ==
nullptr || password ==
nullptr) {
107 if(out_len > 0 && out ==
nullptr) {
110 if(salt_len > 0 && salt ==
nullptr) {
114 if(password_len == 0) {
115 password_len = std::strlen(password);
125 auto pwdhash = pwdhash_fam->tune_params(out_len, msec);
127 if(param1 !=
nullptr) {
128 *param1 = pwdhash->iterations();
130 if(param2 !=
nullptr) {
131 *param2 = pwdhash->parallelism();
133 if(param3 !=
nullptr) {
134 *param3 = pwdhash->memory_param();
137 pwdhash->derive_key(out, out_len, password, password_len, salt, salt_len);
146 const uint8_t secret[],
148 const uint8_t salt[],
150 const uint8_t label[],
152 if(kdf_algo ==
nullptr) {
155 if((out_len > 0 && out ==
nullptr) || (secret_len > 0 && secret ==
nullptr) || (salt_len > 0 && salt ==
nullptr) ||
156 (label_len > 0 && label ==
nullptr)) {
161 kdf->kdf(out, out_len, secret, secret_len, salt, salt_len, label, label_len);
168 const char* password,
169 const uint8_t salt[],
174 return botan_pwdhash(
"Scrypt", N, r, p, out, out_len, password, 0, salt, salt_len);
178 uint8_t* out,
size_t* out_len,
const char* pass,
botan_rng_t rng_obj,
size_t wf, uint32_t flags) {
179#if defined(BOTAN_HAS_BCRYPT)
181 if(out ==
nullptr || out_len ==
nullptr || pass ==
nullptr) {
189 if(wf < 4 || wf > 18) {
213#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)
bool any_null_pointers(Ptrs... ptr)
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)