88#include < vector>
99
1010#include " HybridHkdf.hpp"
11+ #include " Utils.hpp"
1112
1213namespace margelo ::nitro::crypto {
1314
14- std::shared_ptr<ArrayBuffer> HybridHkdf::deriveKey (const std::string& algorithm, const std::shared_ptr<ArrayBuffer>& key,
15+ std::shared_ptr<Promise<std::shared_ptr<ArrayBuffer>>> HybridHkdf::hkdf (const std::string& algorithm,
16+ const std::shared_ptr<ArrayBuffer>& key,
17+ const std::shared_ptr<ArrayBuffer>& salt,
18+ const std::shared_ptr<ArrayBuffer>& info, double length) {
19+ // get owned NativeArrayBuffers before passing to sync function
20+ auto nativeKey = ToNativeArrayBuffer (key);
21+ auto nativeSalt = ToNativeArrayBuffer (salt);
22+ auto nativeInfo = ToNativeArrayBuffer (info);
23+
24+ return Promise<std::shared_ptr<ArrayBuffer>>::async ([this , algorithm, nativeKey, nativeSalt, nativeInfo, length]() {
25+ return this ->deriveKey (algorithm, nativeKey, nativeSalt, nativeInfo, length);
26+ });
27+ }
28+
29+ std::shared_ptr<ArrayBuffer> HybridHkdf::deriveKey (const std::string& algorithm, const std::shared_ptr<ArrayBuffer>& baseKey,
1530 const std::shared_ptr<ArrayBuffer>& salt, const std::shared_ptr<ArrayBuffer>& info,
1631 double length) {
1732 EVP_KDF* kdf = EVP_KDF_fetch (nullptr , " HKDF" , nullptr );
@@ -32,8 +47,8 @@ std::shared_ptr<ArrayBuffer> HybridHkdf::deriveKey(const std::string& algorithm,
3247 params[paramIndex++] = OSSL_PARAM_construct_utf8_string (OSSL_KDF_PARAM_DIGEST, const_cast <char *>(algorithm.c_str ()), 0 );
3348
3449 // Key (Input Keying Material)
35- if (key && key ->size () > 0 ) {
36- params[paramIndex++] = OSSL_PARAM_construct_octet_string (OSSL_KDF_PARAM_KEY, key ->data (), key ->size ());
50+ if (baseKey && baseKey ->size () > 0 ) {
51+ params[paramIndex++] = OSSL_PARAM_construct_octet_string (OSSL_KDF_PARAM_KEY, baseKey ->data (), baseKey ->size ());
3752 } else {
3853 // Empty key is allowed in HKDF (defaults to zero string of hashLen) but explicit param usually expected if not null
3954 // If we want empty, we can pass generic empty buffer or handle it.
0 commit comments