/src/node/src/crypto/crypto_pbkdf2.h
Line  | Count  | Source  | 
1  |  | #ifndef SRC_CRYPTO_CRYPTO_PBKDF2_H_  | 
2  |  | #define SRC_CRYPTO_CRYPTO_PBKDF2_H_  | 
3  |  |  | 
4  |  | #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS  | 
5  |  |  | 
6  |  | #include "crypto/crypto_util.h"  | 
7  |  | #include "async_wrap.h"  | 
8  |  | #include "env.h"  | 
9  |  | #include "memory_tracker.h"  | 
10  |  | #include "v8.h"  | 
11  |  |  | 
12  |  | namespace node { | 
13  |  | namespace crypto { | 
14  |  | // PBKDF2 is a pseudo-random key derivation scheme defined  | 
15  |  | // in https://tools.ietf.org/html/rfc8018  | 
16  |  | //  | 
17  |  | // The algorithm takes as input a password and salt  | 
18  |  | // (both of which may, but should not be zero-length),  | 
19  |  | // a number of iterations, a hash digest algorithm, and  | 
20  |  | // an output length.  | 
21  |  | //  | 
22  |  | // The salt should be as unique as possible, and should  | 
23  |  | // be at least 16 bytes in length.  | 
24  |  | //  | 
25  |  | // The iteration count should be as high as possible.  | 
26  |  |  | 
27  |  | struct PBKDF2Config final : public MemoryRetainer { | 
28  |  |   CryptoJobMode mode;  | 
29  |  |   ByteSource pass;  | 
30  |  |   ByteSource salt;  | 
31  |  |   int32_t iterations;  | 
32  |  |   int32_t length;  | 
33  |  |   ncrypto::Digest digest;  | 
34  |  |  | 
35  | 0  |   PBKDF2Config() = default;  | 
36  |  |  | 
37  |  |   explicit PBKDF2Config(PBKDF2Config&& other) noexcept;  | 
38  |  |  | 
39  |  |   PBKDF2Config& operator=(PBKDF2Config&& other) noexcept;  | 
40  |  |  | 
41  |  |   void MemoryInfo(MemoryTracker* tracker) const override;  | 
42  |  |   SET_MEMORY_INFO_NAME(PBKDF2Config)  | 
43  |  |   SET_SELF_SIZE(PBKDF2Config)  | 
44  |  | };  | 
45  |  |  | 
46  |  | struct PBKDF2Traits final { | 
47  |  |   using AdditionalParameters = PBKDF2Config;  | 
48  |  |   static constexpr const char* JobName = "PBKDF2Job";  | 
49  |  |   static constexpr AsyncWrap::ProviderType Provider =  | 
50  |  |       AsyncWrap::PROVIDER_PBKDF2REQUEST;  | 
51  |  |  | 
52  |  |   static v8::Maybe<void> AdditionalConfig(  | 
53  |  |       CryptoJobMode mode,  | 
54  |  |       const v8::FunctionCallbackInfo<v8::Value>& args,  | 
55  |  |       unsigned int offset,  | 
56  |  |       PBKDF2Config* params);  | 
57  |  |  | 
58  |  |   static bool DeriveBits(Environment* env,  | 
59  |  |                          const PBKDF2Config& params,  | 
60  |  |                          ByteSource* out,  | 
61  |  |                          CryptoJobMode mode);  | 
62  |  |  | 
63  |  |   static v8::MaybeLocal<v8::Value> EncodeOutput(Environment* env,  | 
64  |  |                                                 const PBKDF2Config& params,  | 
65  |  |                                                 ByteSource* out);  | 
66  |  | };  | 
67  |  |  | 
68  |  | using PBKDF2Job = DeriveBitsJob<PBKDF2Traits>;  | 
69  |  |  | 
70  |  | }  // namespace crypto  | 
71  |  | }  // namespace node  | 
72  |  |  | 
73  |  | #endif  // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS  | 
74  |  | #endif  // SRC_CRYPTO_CRYPTO_PBKDF2_H_  |