/src/node/src/node_crypto.cc
Line  | Count  | Source  | 
1  |  | // Copyright Joyent, Inc. and other Node contributors.  | 
2  |  | //  | 
3  |  | // Permission is hereby granted, free of charge, to any person obtaining a  | 
4  |  | // copy of this software and associated documentation files (the  | 
5  |  | // "Software"), to deal in the Software without restriction, including  | 
6  |  | // without limitation the rights to use, copy, modify, merge, publish,  | 
7  |  | // distribute, sublicense, and/or sell copies of the Software, and to permit  | 
8  |  | // persons to whom the Software is furnished to do so, subject to the  | 
9  |  | // following conditions:  | 
10  |  | //  | 
11  |  | // The above copyright notice and this permission notice shall be included  | 
12  |  | // in all copies or substantial portions of the Software.  | 
13  |  | //  | 
14  |  | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  | 
15  |  | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF  | 
16  |  | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN  | 
17  |  | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,  | 
18  |  | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR  | 
19  |  | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE  | 
20  |  | // USE OR OTHER DEALINGS IN THE SOFTWARE.  | 
21  |  |  | 
22  |  | #include "node_crypto.h"  | 
23  |  | #include "async_wrap-inl.h"  | 
24  |  | #include "debug_utils-inl.h"  | 
25  |  | #include "memory_tracker-inl.h"  | 
26  |  | #include "node_external_reference.h"  | 
27  |  | #include "threadpoolwork-inl.h"  | 
28  |  | #include "v8.h"  | 
29  |  |  | 
30  |  | namespace node { | 
31  |  |  | 
32  |  | using v8::Context;  | 
33  |  | using v8::Local;  | 
34  |  | using v8::Object;  | 
35  |  | using v8::Value;  | 
36  |  |  | 
37  |  | namespace crypto { | 
38  |  |  | 
39  |  | #define CRYPTO_NAMESPACE_LIST_BASE(V)                                          \  | 
40  | 0  |   V(AES)                                                                       \  | 
41  | 0  |   V(ChaCha20Poly1305)                                                          \  | 
42  | 0  |   V(CipherBase)                                                                \  | 
43  | 0  |   V(DiffieHellman)                                                             \  | 
44  | 0  |   V(DSAAlg)                                                                    \  | 
45  | 0  |   V(ECDH)                                                                      \  | 
46  | 0  |   V(Hash)                                                                      \  | 
47  | 0  |   V(HKDFJob)                                                                   \  | 
48  | 0  |   V(Hmac)                                                                      \  | 
49  | 0  |   V(Keygen)                                                                    \  | 
50  | 0  |   V(Keys)                                                                      \  | 
51  | 0  |   V(NativeKeyObject)                                                           \  | 
52  | 0  |   V(PBKDF2Job)                                                                 \  | 
53  | 0  |   V(Random)                                                                    \  | 
54  | 0  |   V(RSAAlg)                                                                    \  | 
55  | 0  |   V(SecureContext)                                                             \  | 
56  | 0  |   V(Sign)                                                                      \  | 
57  | 0  |   V(SPKAC)                                                                     \  | 
58  | 0  |   V(Timing)                                                                    \  | 
59  | 0  |   V(Util)                                                                      \  | 
60  | 0  |   V(Verify)                                                                    \  | 
61  | 0  |   V(X509Certificate)  | 
62  |  |  | 
63  |  | #if !defined(OPENSSL_NO_ARGON2) && OPENSSL_VERSION_NUMBER >= 0x30200000L  | 
64  | 0  | #define ARGON2_NAMESPACE_LIST(V) V(Argon2)  | 
65  |  | #else  | 
66  |  | #define ARGON2_NAMESPACE_LIST(V)  | 
67  |  | #endif  // !OPENSSL_NO_ARGON2 && OpenSSL >= 3.2  | 
68  |  |  | 
69  |  | // KEM and KMAC functionality requires OpenSSL 3.0.0 or later  | 
70  |  | #if OPENSSL_VERSION_MAJOR >= 3  | 
71  | 0  | #define KEM_NAMESPACE_LIST(V) V(KEM)  | 
72  | 0  | #define KMAC_NAMESPACE_LIST(V) V(Kmac)  | 
73  |  | #else  | 
74  |  | #define KEM_NAMESPACE_LIST(V)  | 
75  |  | #define KMAC_NAMESPACE_LIST(V)  | 
76  |  | #endif  | 
77  |  |  | 
78  |  | #ifdef OPENSSL_NO_SCRYPT  | 
79  |  | #define SCRYPT_NAMESPACE_LIST(V)  | 
80  |  | #else  | 
81  | 0  | #define SCRYPT_NAMESPACE_LIST(V) V(ScryptJob)  | 
82  |  | #endif  // OPENSSL_NO_SCRYPT  | 
83  |  |  | 
84  |  | #define CRYPTO_NAMESPACE_LIST(V)                                               \  | 
85  | 0  |   CRYPTO_NAMESPACE_LIST_BASE(V)                                                \  | 
86  | 0  |   ARGON2_NAMESPACE_LIST(V)                                                     \  | 
87  | 0  |   KEM_NAMESPACE_LIST(V)                                                        \  | 
88  | 0  |   KMAC_NAMESPACE_LIST(V)                                                       \  | 
89  | 0  |   SCRYPT_NAMESPACE_LIST(V)  | 
90  |  |  | 
91  |  | void Initialize(Local<Object> target,  | 
92  |  |                 Local<Value> unused,  | 
93  |  |                 Local<Context> context,  | 
94  | 0  |                 void* priv) { | 
95  | 0  |   Environment* env = Environment::GetCurrent(context);  | 
96  |  | 
  | 
97  | 0  |   if (!InitCryptoOnce(env->isolate())) { | 
98  | 0  |     return;  | 
99  | 0  |   }  | 
100  |  |  | 
101  | 0  | #define V(Namespace) Namespace::Initialize(env, target);  | 
102  | 0  |   CRYPTO_NAMESPACE_LIST(V)  | 
103  | 0  | #undef V  | 
104  | 0  | }  | 
105  |  |  | 
106  | 0  | void RegisterExternalReferences(ExternalReferenceRegistry* registry) { | 
107  | 0  | #define V(Namespace) Namespace::RegisterExternalReferences(registry);  | 
108  | 0  |   CRYPTO_NAMESPACE_LIST(V)  | 
109  | 0  | #undef V  | 
110  | 0  | }  | 
111  |  | }  // namespace crypto  | 
112  |  | }  // namespace node  | 
113  |  |  | 
114  |  | NODE_BINDING_CONTEXT_AWARE_INTERNAL(crypto, node::crypto::Initialize)  | 
115  |  | NODE_BINDING_EXTERNAL_REFERENCE(crypto,  | 
116  |  |                                 node::crypto::RegisterExternalReferences)  |