Kagome
Polkadot Runtime Engine in C++17
pbkdf2_provider_impl.cpp
Go to the documentation of this file.
1 
7 
8 #include <openssl/evp.h>
9 
10 namespace kagome::crypto {
11 
12  outcome::result<common::Buffer> Pbkdf2ProviderImpl::deriveKey(
13  gsl::span<const uint8_t> data,
14  gsl::span<const uint8_t> salt,
15  size_t iterations,
16  size_t key_length) const {
17  common::Buffer out(key_length, 0);
18  const auto *digest = EVP_sha512();
19 
20  std::string pass(data.begin(), data.end());
21 
22  int res = PKCS5_PBKDF2_HMAC(pass.data(),
23  pass.size(),
24  salt.data(),
25  salt.size(),
26  iterations,
27  digest,
28  key_length,
29  out.data());
30  if (res != 1) {
32  }
33 
34  return out;
35  }
36 } // namespace kagome::crypto
37 
40  switch (error) {
42  return "failed to derive key";
43  }
44  return "unknown Pbkdf2ProviderError";
45 }
Class represents arbitrary (including empty) byte buffer.
Definition: buffer.hpp:29
OUTCOME_CPP_DEFINE_CATEGORY(kagome::crypto, Pbkdf2ProviderError, error)
outcome::result< common::Buffer > deriveKey(gsl::span< const uint8_t > data, gsl::span< const uint8_t > salt, size_t iterations, size_t key_length) const override
derives key from password and salt