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_dh.h Lines: 3 15 20.0 %
Date: 2021-06-02 04:11:51 Branches: 0 0 - %

Line Branch Exec Source
1
#ifndef SRC_CRYPTO_CRYPTO_DH_H_
2
#define SRC_CRYPTO_CRYPTO_DH_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 "env.h"
10
#include "memory_tracker.h"
11
#include "v8.h"
12
13
#include <vector>
14
15
namespace node {
16
namespace crypto {
17
116
class DiffieHellman : public BaseObject {
18
 public:
19
  static void Initialize(Environment* env, v8::Local<v8::Object> target);
20
21
  bool Init(int primeLength, int g);
22
  bool Init(const char* p, int p_len, int g);
23
  bool Init(const char* p, int p_len, const char* g, int g_len);
24
25
  static void Stateless(const v8::FunctionCallbackInfo<v8::Value>& args);
26
27
 protected:
28
  static void DiffieHellmanGroup(
29
      const v8::FunctionCallbackInfo<v8::Value>& args);
30
  static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
31
  static void GenerateKeys(const v8::FunctionCallbackInfo<v8::Value>& args);
32
  static void GetPrime(const v8::FunctionCallbackInfo<v8::Value>& args);
33
  static void GetGenerator(const v8::FunctionCallbackInfo<v8::Value>& args);
34
  static void GetPublicKey(const v8::FunctionCallbackInfo<v8::Value>& args);
35
  static void GetPrivateKey(const v8::FunctionCallbackInfo<v8::Value>& args);
36
  static void ComputeSecret(const v8::FunctionCallbackInfo<v8::Value>& args);
37
  static void SetPublicKey(const v8::FunctionCallbackInfo<v8::Value>& args);
38
  static void SetPrivateKey(const v8::FunctionCallbackInfo<v8::Value>& args);
39
  static void VerifyErrorGetter(
40
      const v8::FunctionCallbackInfo<v8::Value>& args);
41
42
  DiffieHellman(Environment* env, v8::Local<v8::Object> wrap);
43
44
  void MemoryInfo(MemoryTracker* tracker) const override;
45
  SET_MEMORY_INFO_NAME(DiffieHellman)
46
  SET_SELF_SIZE(DiffieHellman)
47
48
 private:
49
  static void GetField(const v8::FunctionCallbackInfo<v8::Value>& args,
50
                       const BIGNUM* (*get_field)(const DH*),
51
                       const char* err_if_null);
52
  static void SetKey(const v8::FunctionCallbackInfo<v8::Value>& args,
53
                     int (*set_field)(DH*, BIGNUM*), const char* what);
54
  bool VerifyContext();
55
56
  int verifyError_;
57
  DHPointer dh_;
58
};
59
60
52
struct DhKeyPairParams final : public MemoryRetainer {
61
  // TODO(tniessen): Use std::variant instead.
62
  // Diffie-Hellman can either generate keys using a fixed prime, or by first
63
  // generating a random prime of a given size (in bits). Only one of both
64
  // options may be specified.
65
  BignumPointer prime_fixed_value;
66
  unsigned int prime_size;
67
  unsigned int generator;
68
  SET_NO_MEMORY_INFO()
69
  SET_MEMORY_INFO_NAME(DhKeyPairParams)
70
  SET_SELF_SIZE(DhKeyPairParams)
71
};
72
73
using DhKeyPairGenConfig = KeyPairGenConfig<DhKeyPairParams>;
74
75
struct DhKeyGenTraits final {
76
  using AdditionalParameters = DhKeyPairGenConfig;
77
  static constexpr const char* JobName = "DhKeyPairGenJob";
78
79
  static EVPKeyCtxPointer Setup(DhKeyPairGenConfig* params);
80
81
  static v8::Maybe<bool> AdditionalConfig(
82
      CryptoJobMode mode,
83
      const v8::FunctionCallbackInfo<v8::Value>& args,
84
      unsigned int* offset,
85
      DhKeyPairGenConfig* params);
86
};
87
88
using DHKeyPairGenJob = KeyGenJob<KeyPairGenTraits<DhKeyGenTraits>>;
89
90
struct DHKeyExportConfig final : public MemoryRetainer {
91
  SET_NO_MEMORY_INFO()
92
  SET_MEMORY_INFO_NAME(DHKeyExportConfig)
93
  SET_SELF_SIZE(DHKeyExportConfig)
94
};
95
96
struct DHKeyExportTraits final {
97
  static constexpr const char* JobName = "DHKeyExportJob";
98
  using AdditionalParameters = DHKeyExportConfig;
99
100
  static v8::Maybe<bool> AdditionalConfig(
101
      const v8::FunctionCallbackInfo<v8::Value>& args,
102
      unsigned int offset,
103
      DHKeyExportConfig* config);
104
105
  static WebCryptoKeyExportStatus DoExport(
106
      std::shared_ptr<KeyObjectData> key_data,
107
      WebCryptoKeyFormat format,
108
      const DHKeyExportConfig& params,
109
      ByteSource* out);
110
};
111
112
using DHKeyExportJob = KeyExportJob<DHKeyExportTraits>;
113
114
15
struct DHBitsConfig final : public MemoryRetainer {
115
  std::shared_ptr<KeyObjectData> private_key;
116
  std::shared_ptr<KeyObjectData> public_key;
117
  SET_NO_MEMORY_INFO()
118
  SET_MEMORY_INFO_NAME(DHBitsConfig)
119
  SET_SELF_SIZE(DHBitsConfig)
120
};
121
122
struct DHBitsTraits final {
123
  using AdditionalParameters = DHBitsConfig;
124
  static constexpr const char* JobName = "DHBitsJob";
125
  static constexpr AsyncWrap::ProviderType Provider =
126
      AsyncWrap::PROVIDER_DERIVEBITSREQUEST;
127
128
  static v8::Maybe<bool> AdditionalConfig(
129
      CryptoJobMode mode,
130
      const v8::FunctionCallbackInfo<v8::Value>& args,
131
      unsigned int offset,
132
      DHBitsConfig* params);
133
134
  static bool DeriveBits(
135
      Environment* env,
136
      const DHBitsConfig& params,
137
      ByteSource* out_);
138
139
  static v8::Maybe<bool> EncodeOutput(
140
      Environment* env,
141
      const DHBitsConfig& params,
142
      ByteSource* out,
143
      v8::Local<v8::Value>* result);
144
};
145
146
using DHBitsJob = DeriveBitsJob<DHBitsTraits>;
147
148
v8::Maybe<bool> GetDhKeyDetail(
149
    Environment* env,
150
    std::shared_ptr<KeyObjectData> key,
151
    v8::Local<v8::Object> target);
152
153
}  // namespace crypto
154
}  // namespace node
155
156
#endif  // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
157
#endif  // SRC_CRYPTO_CRYPTO_DH_H_