35 BCRYPT_ALG_HANDLE hAlg = 0;
44 typedef NTSTATUS WINAPI (
45 *PFN_BCryptDeriveKeyPBKDF2)(BCRYPT_ALG_HANDLE hPrf, PUCHAR pbPassword,
46 ULONG cbPassword, PUCHAR pbSalt, ULONG cbSalt,
47 ULONGLONG cIterations, PUCHAR pbDerivedKey,
48 ULONG cbDerivedKey, ULONG dwFlags);
49 HMODULE hBCrypt = NULL;
50 PFN_BCryptDeriveKeyPBKDF2 fnBCryptDeriveKeyPBKDF2 = NULL;
52 if (!(hBCrypt = LoadLibrary(
"bcrypt.dll"))) {
56 if (!(fnBCryptDeriveKeyPBKDF2 = (PFN_BCryptDeriveKeyPBKDF2)(
57 (
void (*)(
void)) GetProcAddress(hBCrypt,
"BCryptDeriveKeyPBKDF2")))) {
66 status = BCryptOpenAlgorithmProvider(&hAlg, alg, NULL,
67 BCRYPT_ALG_HANDLE_HMAC_FLAG))) {
73 fnBCryptDeriveKeyPBKDF2(hAlg, (PUCHAR) password, (ULONG) cb_password,
74 (PUCHAR) salt, (ULONG) cb_salt, iterations,
75 key, (ULONG) cb_key, 0))) {
84 BCryptCloseAlgorithmProvider(hAlg, 0);
91 const EVP_MD *md = NULL;
98 if (1 != PKCS5_PBKDF2_HMAC((
const char *) password, cb_password, salt,
99 cb_salt, iterations, md, cb_key, key)) {
bool pkcs5_pbkdf2_hmac(const uint8_t *password, size_t cb_password, const uint8_t *salt, size_t cb_salt, uint64_t iterations, hash_t hash, uint8_t *key, size_t cb_key)