29                                                                 {
   30  bool res = false;
   31 
   32#ifdef _WIN32_BCRYPT
   33  NTSTATUS status = 0;
   34  LPCWSTR alg = NULL;
   35  BCRYPT_ALG_HANDLE hAlg = 0;
   36 
   37  
   38
   39
   40
   41
   42
   43 
   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;
   51 
   52  if (!(hBCrypt = LoadLibrary("bcrypt.dll"))) {
   53    goto cleanup;
   54  }
   55 
   56  if (!(fnBCryptDeriveKeyPBKDF2 = (PFN_BCryptDeriveKeyPBKDF2)(
   57          (void (*)(void)) GetProcAddress(hBCrypt, "BCryptDeriveKeyPBKDF2")))) {
   58    goto cleanup;
   59  }
   60 
   62    goto cleanup;
   63  }
   64 
   65  if (!BCRYPT_SUCCESS(
   66        status = BCryptOpenAlgorithmProvider(&hAlg, alg, NULL,
   67                                             BCRYPT_ALG_HANDLE_HMAC_FLAG))) {
   68    goto cleanup;
   69  }
   70 
   71  if (!BCRYPT_SUCCESS(
   72        status =
   73          fnBCryptDeriveKeyPBKDF2(hAlg, (PUCHAR) password, (ULONG) cb_password,
   74                                  (PUCHAR) salt, (ULONG) cb_salt, iterations,
   75                                  key, (ULONG) cb_key, 0))) {
   76    goto cleanup;
   77  }
   78 
   79  res = true;
   80 
   81cleanup:
   82 
   83  if (hAlg) {
   84    BCryptCloseAlgorithmProvider(hAlg, 0);
   85  }
   86  if (hBCrypt) {
   87    FreeLibrary(hBCrypt);
   88  }
   89 
   90#else
   91  const EVP_MD *md = NULL;
   92 
   94    return false;
   95  }
   96 
   97  
   98  if (1 != PKCS5_PBKDF2_HMAC((const char *) password, cb_password, salt,
   99                             cb_salt, iterations, md, cb_key, key)) {
  100    return false;
  101  }
  102 
  103  res = true;
  104 
  105#endif
  106  return res;
  107}
const YH_INTERNAL EVP_MD * get_hash(hash_t hash)