@@ -13,6 +13,46 @@ namespace hmac_cpp {
1313 // / \return true if both strings are equal
1414 bool constant_time_equals (const std::string &a, const std::string &b);
1515
16+ // / \brief Derives a key from a password using PBKDF2 (RFC 8018)
17+ // / \param password_ptr Pointer to the password buffer
18+ // / \param password_len Length of the password in bytes
19+ // / \param salt_ptr Pointer to the salt buffer
20+ // / \param salt_len Length of the salt in bytes
21+ // / \param iterations Number of iterations, must be positive
22+ // / \param dk_len Desired length of the derived key in bytes, must be positive
23+ // / \param hash_type Hash function to use (SHA1, SHA256, SHA512)
24+ // / \return Derived key as a vector of bytes
25+ std::vector<uint8_t > pbkdf2 (
26+ const void * password_ptr, size_t password_len,
27+ const void * salt_ptr, size_t salt_len,
28+ int iterations, size_t dk_len,
29+ TypeHash hash_type);
30+
31+ // / \brief Derives a key using PBKDF2 from vector-based password and salt
32+ template <typename T>
33+ inline std::vector<uint8_t > pbkdf2 (
34+ const std::vector<T>& password,
35+ const std::vector<T>& salt,
36+ int iterations, size_t dk_len,
37+ TypeHash hash_type) {
38+ static_assert (std::is_same<T, char >::value || std::is_same<T, uint8_t >::value,
39+ " pbkdf2(vector<T>) supports only char or uint8_t" );
40+ return pbkdf2 (password.data (), password.size (),
41+ salt.data (), salt.size (),
42+ iterations, dk_len, hash_type);
43+ }
44+
45+ // / \brief Derives a key using PBKDF2 from string-based password and salt
46+ inline std::vector<uint8_t > pbkdf2 (
47+ const std::string& password,
48+ const std::string& salt,
49+ int iterations, size_t dk_len,
50+ TypeHash hash_type) {
51+ return pbkdf2 (password.data (), password.size (),
52+ salt.data (), salt.size (),
53+ iterations, dk_len, hash_type);
54+ }
55+
1656 // / \brief Generates a time-based HMAC-SHA256 token
1757 // / \param key Secret key used for HMAC
1858 // / \param interval_sec Interval in seconds that defines token rotation. Must be positive. Default is 60 seconds
0 commit comments