GCC Code Coverage Report
Directory: ../ Exec Total Coverage
File: /home/iojs/build/workspace/node-test-commit-linux-coverage-daily/nodes/benchmark/out/../src/crypto/crypto_ecdh.h Lines: 3 14 21.4 %
Date: 2020-11-21 04:10:54 Branches: 0 0 - %

Line Branch Exec Source
1
#ifndef SRC_CRYPTO_CRYPTO_ECDH_H_
2
#define SRC_CRYPTO_CRYPTO_ECDH_H_
3
4
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
6
#include "crypto/crypto_keys.h"
7
#include "crypto/crypto_keygen.h"
8
#include "crypto/crypto_util.h"
9
#include "allocated_buffer.h"
10
#include "async_wrap.h"
11
#include "base_object.h"
12
#include "env.h"
13
#include "memory_tracker.h"
14
#include "node_internals.h"
15
#include "v8.h"
16
17
namespace node {
18
namespace crypto {
19
class ECDH final : public BaseObject {
20
 public:
21
  ~ECDH() override;
22
23
  static void Initialize(Environment* env, v8::Local<v8::Object> target);
24
  static ECPointPointer BufferToPoint(Environment* env,
25
                                      const EC_GROUP* group,
26
                                      v8::Local<v8::Value> buf);
27
28
  void MemoryInfo(MemoryTracker* tracker) const override;
29
  SET_MEMORY_INFO_NAME(ECDH)
30
  SET_SELF_SIZE(ECDH)
31
32
  static void ConvertKey(const v8::FunctionCallbackInfo<v8::Value>& args);
33
34
  static void GetCurves(const v8::FunctionCallbackInfo<v8::Value>& args);
35
36
 protected:
37
  ECDH(Environment* env, v8::Local<v8::Object> wrap, ECKeyPointer&& key);
38
39
  static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
40
  static void GenerateKeys(const v8::FunctionCallbackInfo<v8::Value>& args);
41
  static void ComputeSecret(const v8::FunctionCallbackInfo<v8::Value>& args);
42
  static void GetPrivateKey(const v8::FunctionCallbackInfo<v8::Value>& args);
43
  static void SetPrivateKey(const v8::FunctionCallbackInfo<v8::Value>& args);
44
  static void GetPublicKey(const v8::FunctionCallbackInfo<v8::Value>& args);
45
  static void SetPublicKey(const v8::FunctionCallbackInfo<v8::Value>& args);
46
47
  bool IsKeyPairValid();
48
  bool IsKeyValidForCurve(const BignumPointer& private_key);
49
50
  ECKeyPointer key_;
51
  const EC_GROUP* group_;
52
};
53
54
60
struct ECDHBitsConfig final : public MemoryRetainer {
55
  ECKeyPointer private_key;
56
  ECKeyPointer public_key;
57
  const EC_GROUP* group = nullptr;
58
59
  SET_NO_MEMORY_INFO();
60
  SET_MEMORY_INFO_NAME(ECDHBitsConfig);
61
  SET_SELF_SIZE(ECDHBitsConfig);
62
};
63
64
struct ECDHBitsTraits final {
65
  using AdditionalParameters = ECDHBitsConfig;
66
  static constexpr const char* JobName = "ECDHBitsJob";
67
  static constexpr AsyncWrap::ProviderType Provider =
68
      AsyncWrap::PROVIDER_DERIVEBITSREQUEST;
69
70
  static v8::Maybe<bool> AdditionalConfig(
71
      CryptoJobMode mode,
72
      const v8::FunctionCallbackInfo<v8::Value>& args,
73
      unsigned int offset,
74
      ECDHBitsConfig* params);
75
76
  static bool DeriveBits(
77
      Environment* env,
78
      const ECDHBitsConfig& params,
79
      ByteSource* out_);
80
81
  static v8::Maybe<bool> EncodeOutput(
82
      Environment* env,
83
      const ECDHBitsConfig& params,
84
      ByteSource* out,
85
      v8::Local<v8::Value>* result);
86
};
87
88
using ECDHBitsJob = DeriveBitsJob<ECDHBitsTraits>;
89
90
252
struct EcKeyPairParams final : public MemoryRetainer {
91
  int curve_nid;
92
  int param_encoding;
93
  SET_NO_MEMORY_INFO()
94
  SET_MEMORY_INFO_NAME(EcKeyPairParams)
95
  SET_SELF_SIZE(EcKeyPairParams)
96
};
97
98
using EcKeyPairGenConfig = KeyPairGenConfig<EcKeyPairParams>;
99
100
struct EcKeyGenTraits final {
101
  using AdditionalParameters = EcKeyPairGenConfig;
102
  static constexpr const char* JobName = "EcKeyPairGenJob";
103
104
  static EVPKeyCtxPointer Setup(EcKeyPairGenConfig* params);
105
106
  static v8::Maybe<bool> AdditionalConfig(
107
      CryptoJobMode mode,
108
      const v8::FunctionCallbackInfo<v8::Value>& args,
109
      unsigned int* offset,
110
      EcKeyPairGenConfig* params);
111
};
112
113
using ECKeyPairGenJob = KeyGenJob<KeyPairGenTraits<EcKeyGenTraits>>;
114
115
// There is currently no additional information that the
116
// ECKeyExport needs to collect, but we need to provide
117
// the base struct anyway.
118
210
struct ECKeyExportConfig final : public MemoryRetainer {
119
  SET_NO_MEMORY_INFO()
120
  SET_MEMORY_INFO_NAME(ECKeyExportConfig)
121
  SET_SELF_SIZE(ECKeyExportConfig)
122
};
123
124
struct ECKeyExportTraits final {
125
  static constexpr const char* JobName = "ECKeyExportJob";
126
  using AdditionalParameters = ECKeyExportConfig;
127
128
  static v8::Maybe<bool> AdditionalConfig(
129
      const v8::FunctionCallbackInfo<v8::Value>& args,
130
      unsigned int offset,
131
      ECKeyExportConfig* config);
132
133
  static WebCryptoKeyExportStatus DoExport(
134
      std::shared_ptr<KeyObjectData> key_data,
135
      WebCryptoKeyFormat format,
136
      const ECKeyExportConfig& params,
137
      ByteSource* out);
138
};
139
140
using ECKeyExportJob = KeyExportJob<ECKeyExportTraits>;
141
142
v8::Maybe<bool> ExportJWKEcKey(
143
    Environment* env,
144
    std::shared_ptr<KeyObjectData> key,
145
    v8::Local<v8::Object> target);
146
147
std::shared_ptr<KeyObjectData> ImportJWKEcKey(
148
    Environment* env,
149
    v8::Local<v8::Object> jwk,
150
    const v8::FunctionCallbackInfo<v8::Value>& args,
151
    unsigned int offset);
152
153
v8::Maybe<bool> GetEcKeyDetail(
154
    Environment* env,
155
    std::shared_ptr<KeyObjectData> key,
156
    v8::Local<v8::Object> target);
157
158
ByteSource ConvertToWebCryptoSignature(
159
  ManagedEVPPKey key,
160
  const ByteSource& signature);
161
162
ByteSource ConvertFromWebCryptoSignature(
163
    ManagedEVPPKey key,
164
    const ByteSource& signature);
165
166
}  // namespace crypto
167
}  // namespace node
168
169
#endif  // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
170
#endif  // SRC_CRYPTO_CRYPTO_ECDH_H_