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