1 #ifndef SRC_CRYPTO_CRYPTO_HKDF_H_ 2 #define SRC_CRYPTO_CRYPTO_HKDF_H_ 3 4 #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS 5 6 #include "async_wrap.h" 7 #include "base_object.h" 8 #include "crypto/crypto_keys.h" 9 #include "crypto/crypto_util.h" 10 #include "v8.h" 11 12 namespace node { 13 namespace crypto { 14 struct HKDFConfig final : public MemoryRetainer { 15 CryptoJobMode mode; 16 size_t length; 17 const EVP_MD* digest; 18 std::shared_ptr<KeyObjectData> key; 19 ByteSource salt; 20 ByteSource info; 21 22 HKDFConfig() = default; 23 24 explicit HKDFConfig(HKDFConfig&& other) noexcept; 25 26 HKDFConfig& operator=(HKDFConfig&& other) noexcept; 27 28 void MemoryInfo(MemoryTracker* tracker) const override; 29 SET_MEMORY_INFO_NAME(HKDFConfig) 30 SET_SELF_SIZE(HKDFConfig) 31 }; 32 33 struct HKDFTraits final { 34 using AdditionalParameters = HKDFConfig; 35 static constexpr const char* JobName = "HKDFJob"; 36 static constexpr AsyncWrap::ProviderType Provider = 37 AsyncWrap::PROVIDER_DERIVEBITSREQUEST; 38 39 static v8::Maybe<bool> AdditionalConfig( 40 CryptoJobMode mode, 41 const v8::FunctionCallbackInfo<v8::Value>& args, 42 unsigned int offset, 43 HKDFConfig* params); 44 45 static bool DeriveBits( 46 Environment* env, 47 const HKDFConfig& params, 48 ByteSource* out); 49 50 static v8::Maybe<bool> EncodeOutput( 51 Environment* env, 52 const HKDFConfig& params, 53 ByteSource* out, 54 v8::Local<v8::Value>* result); 55 }; 56 57 using HKDFJob = DeriveBitsJob<HKDFTraits>; 58 59 } // namespace crypto 60 } // namespace node 61 62 #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS 63 #endif // SRC_CRYPTO_CRYPTO_HKDF_H_ 64