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_sig.h Lines: 8 12 66.7 %
Date: 2020-11-21 04:10:54 Branches: 0 0 - %

Line Branch Exec Source
1
#ifndef SRC_CRYPTO_CRYPTO_SIG_H_
2
#define SRC_CRYPTO_CRYPTO_SIG_H_
3
4
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
6
#include "crypto/crypto_keys.h"
7
#include "crypto/crypto_util.h"
8
#include "allocated_buffer.h"
9
#include "base_object.h"
10
#include "env.h"
11
#include "memory_tracker.h"
12
13
namespace node {
14
namespace crypto {
15
static const unsigned int kNoDsaSignature = static_cast<unsigned int>(-1);
16
17
enum DSASigEnc {
18
  kSigEncDER, kSigEncP1363
19
};
20
21
728
class SignBase : public BaseObject {
22
 public:
23
  typedef enum {
24
    kSignOk,
25
    kSignUnknownDigest,
26
    kSignInit,
27
    kSignNotInitialised,
28
    kSignUpdate,
29
    kSignPrivateKey,
30
    kSignPublicKey,
31
    kSignMalformedSignature
32
  } Error;
33
34
  SignBase(Environment* env, v8::Local<v8::Object> wrap);
35
36
  Error Init(const char* sign_type);
37
  Error Update(const char* data, size_t len);
38
39
  // TODO(joyeecheung): track the memory used by OpenSSL types
40
  void MemoryInfo(MemoryTracker* tracker) const override;
41
  SET_MEMORY_INFO_NAME(SignBase)
42
  SET_SELF_SIZE(SignBase)
43
44
 protected:
45
  EVPMDPointer mdctx_;
46
};
47
48
278
class Sign : public SignBase {
49
 public:
50
  static void Initialize(Environment* env, v8::Local<v8::Object> target);
51
52
112
  struct SignResult {
53
    Error error;
54
    AllocatedBuffer signature;
55
56
112
    explicit SignResult(
57
        Error err,
58
        AllocatedBuffer&& sig = AllocatedBuffer())
59
112
      : error(err), signature(std::move(sig)) {}
60
  };
61
62
  SignResult SignFinal(
63
      const ManagedEVPPKey& pkey,
64
      int padding,
65
      const v8::Maybe<int>& saltlen,
66
      DSASigEnc dsa_sig_enc);
67
68
  static void SignSync(const v8::FunctionCallbackInfo<v8::Value>& args);
69
70
 protected:
71
  static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
72
  static void SignInit(const v8::FunctionCallbackInfo<v8::Value>& args);
73
  static void SignUpdate(const v8::FunctionCallbackInfo<v8::Value>& args);
74
  static void SignFinal(const v8::FunctionCallbackInfo<v8::Value>& args);
75
76
  Sign(Environment* env, v8::Local<v8::Object> wrap);
77
};
78
79
1178
class Verify : public SignBase {
80
 public:
81
  static void Initialize(Environment* env, v8::Local<v8::Object> target);
82
83
  Error VerifyFinal(const ManagedEVPPKey& key,
84
                    const ByteSource& sig,
85
                    int padding,
86
                    const v8::Maybe<int>& saltlen,
87
                    bool* verify_result);
88
89
  static void VerifySync(const v8::FunctionCallbackInfo<v8::Value>& args);
90
91
 protected:
92
  static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
93
  static void VerifyInit(const v8::FunctionCallbackInfo<v8::Value>& args);
94
  static void VerifyUpdate(const v8::FunctionCallbackInfo<v8::Value>& args);
95
  static void VerifyFinal(const v8::FunctionCallbackInfo<v8::Value>& args);
96
97
  Verify(Environment* env, v8::Local<v8::Object> wrap);
98
};
99
100
492
struct SignConfiguration final : public MemoryRetainer {
101
  enum Mode {
102
    kSign,
103
    kVerify
104
  };
105
  enum Flags {
106
    kHasNone = 0,
107
    kHasSaltLength = 1,
108
    kHasPadding = 2
109
  };
110
111
  CryptoJobMode job_mode;
112
  Mode mode;
113
  std::shared_ptr<KeyObjectData> key;
114
  ByteSource data;
115
  ByteSource signature;
116
  const EVP_MD* digest = nullptr;
117
  int flags = SignConfiguration::kHasNone;
118
  int padding = 0;
119
  int salt_length = 0;
120
121
246
  SignConfiguration() = default;
122
123
  explicit SignConfiguration(SignConfiguration&& other) noexcept;
124
125
  SignConfiguration& operator=(SignConfiguration&& other) noexcept;
126
127
  void MemoryInfo(MemoryTracker* tracker) const override;
128
  SET_MEMORY_INFO_NAME(SignConfiguration);
129
  SET_SELF_SIZE(SignConfiguration);
130
};
131
132
struct SignTraits final {
133
  using AdditionalParameters = SignConfiguration;
134
  static constexpr const char* JobName = "SignJob";
135
136
// TODO(@jasnell): Sign request vs. Verify request
137
138
  static constexpr AsyncWrap::ProviderType Provider =
139
      AsyncWrap::PROVIDER_SIGNREQUEST;
140
141
  static v8::Maybe<bool> AdditionalConfig(
142
      CryptoJobMode mode,
143
      const v8::FunctionCallbackInfo<v8::Value>& args,
144
      unsigned int offset,
145
      SignConfiguration* params);
146
147
  static bool DeriveBits(
148
      Environment* env,
149
      const SignConfiguration& params,
150
      ByteSource* out);
151
152
  static v8::Maybe<bool> EncodeOutput(
153
      Environment* env,
154
      const SignConfiguration& params,
155
      ByteSource* out,
156
      v8::Local<v8::Value>* result);
157
};
158
159
using SignJob = DeriveBitsJob<SignTraits>;
160
161
}  // namespace crypto
162
}  // namespace node
163
164
#endif  // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
165
#endif  // SRC_CRYPTO_CRYPTO_SIG_H_