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_rsa.h Lines: 4 12 33.3 %
Date: 2021-04-23 04:11:39 Branches: 0 0 - %

Line Branch Exec Source
1
#ifndef SRC_CRYPTO_CRYPTO_RSA_H_
2
#define SRC_CRYPTO_CRYPTO_RSA_H_
3
4
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
6
#include "crypto/crypto_cipher.h"
7
#include "crypto/crypto_keygen.h"
8
#include "crypto/crypto_keys.h"
9
#include "crypto/crypto_util.h"
10
#include "allocated_buffer.h"
11
#include "env.h"
12
#include "memory_tracker.h"
13
#include "v8.h"
14
15
namespace node {
16
namespace crypto {
17
enum RSAKeyVariant {
18
  kKeyVariantRSA_SSA_PKCS1_v1_5,
19
  kKeyVariantRSA_PSS,
20
  kKeyVariantRSA_OAEP
21
};
22
23
207
struct RsaKeyPairParams final : public MemoryRetainer {
24
  RSAKeyVariant variant;
25
  unsigned int modulus_bits;
26
  unsigned int exponent;
27
28
  // The following used for RSA-PSS
29
  const EVP_MD* md = nullptr;
30
  const EVP_MD* mgf1_md = nullptr;
31
  int saltlen = 0;
32
33
  SET_NO_MEMORY_INFO()
34
  SET_MEMORY_INFO_NAME(RsaKeyPairParams);
35
  SET_SELF_SIZE(RsaKeyPairParams);
36
};
37
38
using RsaKeyPairGenConfig = KeyPairGenConfig<RsaKeyPairParams>;
39
40
struct RsaKeyGenTraits final {
41
  using AdditionalParameters = RsaKeyPairGenConfig;
42
  static constexpr const char* JobName = "RsaKeyPairGenJob";
43
44
  static EVPKeyCtxPointer Setup(RsaKeyPairGenConfig* params);
45
46
  static v8::Maybe<bool> AdditionalConfig(
47
      CryptoJobMode mode,
48
      const v8::FunctionCallbackInfo<v8::Value>& args,
49
      unsigned int* offset,
50
      RsaKeyPairGenConfig* params);
51
};
52
53
using RSAKeyPairGenJob = KeyGenJob<KeyPairGenTraits<RsaKeyGenTraits>>;
54
55
438
struct RSAKeyExportConfig final : public MemoryRetainer {
56
  RSAKeyVariant variant = kKeyVariantRSA_SSA_PKCS1_v1_5;
57
  SET_NO_MEMORY_INFO()
58
  SET_MEMORY_INFO_NAME(RSAKeyExportConfig)
59
  SET_SELF_SIZE(RSAKeyExportConfig)
60
};
61
62
struct RSAKeyExportTraits final {
63
  static constexpr const char* JobName = "RSAKeyExportJob";
64
  using AdditionalParameters = RSAKeyExportConfig;
65
66
  static v8::Maybe<bool> AdditionalConfig(
67
      const v8::FunctionCallbackInfo<v8::Value>& args,
68
      unsigned int offset,
69
      RSAKeyExportConfig* config);
70
71
  static WebCryptoKeyExportStatus DoExport(
72
      std::shared_ptr<KeyObjectData> key_data,
73
      WebCryptoKeyFormat format,
74
      const RSAKeyExportConfig& params,
75
      ByteSource* out);
76
};
77
78
using RSAKeyExportJob = KeyExportJob<RSAKeyExportTraits>;
79
80
268
struct RSACipherConfig final : public MemoryRetainer {
81
  CryptoJobMode mode;
82
  ByteSource label;
83
  int padding = 0;
84
  const EVP_MD* digest = nullptr;
85
86
134
  RSACipherConfig() = default;
87
88
  RSACipherConfig(RSACipherConfig&& other) noexcept;
89
90
  void MemoryInfo(MemoryTracker* tracker) const override;
91
  SET_MEMORY_INFO_NAME(RSACipherConfig);
92
  SET_SELF_SIZE(RSACipherConfig);
93
};
94
95
struct RSACipherTraits final {
96
  static constexpr const char* JobName = "RSACipherJob";
97
  using AdditionalParameters = RSACipherConfig;
98
99
  static v8::Maybe<bool> AdditionalConfig(
100
      CryptoJobMode mode,
101
      const v8::FunctionCallbackInfo<v8::Value>& args,
102
      unsigned int offset,
103
      WebCryptoCipherMode cipher_mode,
104
      RSACipherConfig* config);
105
106
  static WebCryptoCipherStatus DoCipher(
107
      Environment* env,
108
      std::shared_ptr<KeyObjectData> key_data,
109
      WebCryptoCipherMode cipher_mode,
110
      const RSACipherConfig& params,
111
      const ByteSource& in,
112
      ByteSource* out);
113
};
114
115
using RSACipherJob = CipherJob<RSACipherTraits>;
116
117
v8::Maybe<bool> ExportJWKRsaKey(
118
    Environment* env,
119
    std::shared_ptr<KeyObjectData> key,
120
    v8::Local<v8::Object> target);
121
122
std::shared_ptr<KeyObjectData> ImportJWKRsaKey(
123
    Environment* env,
124
    v8::Local<v8::Object> jwk,
125
    const v8::FunctionCallbackInfo<v8::Value>& args,
126
    unsigned int offset);
127
128
v8::Maybe<bool> GetRsaKeyDetail(
129
    Environment* env,
130
    std::shared_ptr<KeyObjectData> key,
131
    v8::Local<v8::Object> target);
132
133
namespace RSAAlg {
134
void Initialize(Environment* env, v8::Local<v8::Object> target);
135
}  // namespace RSAAlg
136
}  // namespace crypto
137
}  // namespace node
138
139
#endif  // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
140
#endif  // SRC_CRYPTO_CRYPTO_RSA_H_