forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcrypto_ec.h
More file actions
102 lines (77 loc) · 3.25 KB
/
Copy pathcrypto_ec.h
File metadata and controls
102 lines (77 loc) · 3.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#ifndef SRC_CRYPTO_CRYPTO_EC_H_
#define SRC_CRYPTO_CRYPTO_EC_H_
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
#include "async_wrap.h"
#include "base_object.h"
#include "crypto/crypto_keygen.h"
#include "crypto/crypto_keys.h"
#include "crypto/crypto_util.h"
#include "env.h"
#include "memory_tracker.h"
#include "node_internals.h"
#include "v8.h"
namespace node {
namespace crypto {
class ECDH final : public BaseObject {
public:
~ECDH() override = default;
static void Initialize(Environment* env, v8::Local<v8::Object> target);
static void RegisterExternalReferences(ExternalReferenceRegistry* registry);
static ncrypto::ECPointPointer BufferToPoint(Environment* env,
const EC_GROUP* group,
v8::Local<v8::Value> buf);
void MemoryInfo(MemoryTracker* tracker) const override;
SET_MEMORY_INFO_NAME(ECDH)
SET_SELF_SIZE(ECDH)
static void ConvertKey(const v8::FunctionCallbackInfo<v8::Value>& args);
static void GetCurves(const v8::FunctionCallbackInfo<v8::Value>& args);
protected:
ECDH(Environment* env,
v8::Local<v8::Object> wrap,
ncrypto::ECKeyPointer&& key);
static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
static void GenerateKeys(const v8::FunctionCallbackInfo<v8::Value>& args);
static void ComputeSecret(const v8::FunctionCallbackInfo<v8::Value>& args);
static void GetPrivateKey(const v8::FunctionCallbackInfo<v8::Value>& args);
static void SetPrivateKey(const v8::FunctionCallbackInfo<v8::Value>& args);
static void GetPublicKey(const v8::FunctionCallbackInfo<v8::Value>& args);
static void SetPublicKey(const v8::FunctionCallbackInfo<v8::Value>& args);
bool IsKeyPairValid();
bool IsKeyValidForCurve(const ncrypto::BignumPointer& private_key);
ncrypto::ECKeyPointer key_;
const EC_GROUP* group_;
};
struct EcKeyPairParams final : public MemoryRetainer {
int curve_nid;
int param_encoding;
SET_NO_MEMORY_INFO()
SET_MEMORY_INFO_NAME(EcKeyPairParams)
SET_SELF_SIZE(EcKeyPairParams)
};
using EcKeyPairGenConfig = KeyPairGenConfig<EcKeyPairParams>;
struct EcKeyGenTraits final {
using AdditionalParameters = EcKeyPairGenConfig;
static constexpr const char* JobName = "EcKeyPairGenJob";
static ncrypto::EVPKeyCtxPointer Setup(EcKeyPairGenConfig* params);
static v8::Maybe<void> AdditionalConfig(
CryptoJobMode mode,
const v8::FunctionCallbackInfo<v8::Value>& args,
unsigned int* offset,
EcKeyPairGenConfig* params);
};
using ECKeyPairGenJob = KeyGenJob<KeyPairGenTraits<EcKeyGenTraits>>;
bool ExportJWKEcKey(Environment* env,
const KeyObjectData& key,
v8::Local<v8::Object> target);
bool ExportJWKEdKey(Environment* env,
const KeyObjectData& key,
v8::Local<v8::Object> target);
KeyObjectData ImportJWKEdKey(Environment* env, v8::Local<v8::Object> jwk);
KeyObjectData ImportJWKEcKey(Environment* env, v8::Local<v8::Object> jwk);
bool GetEcKeyDetail(Environment* env,
const KeyObjectData& key,
v8::Local<v8::Object> target);
} // namespace crypto
} // namespace node
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
#endif // SRC_CRYPTO_CRYPTO_EC_H_