GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: crypto/crypto_rsa.h Lines: 1 9 11.1 %
Date: 2021-10-01 04:12:33 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
struct RsaKeyPairParams final : public MemoryRetainer {
24
  RSAKeyVariant variant;
25
  unsigned int modulus_bits;
26
  unsigned int exponent;
27
28
  // The following options are used for RSA-PSS. If any of them are set, a
29
  // RSASSA-PSS-params sequence will be added to the key.
30
  const EVP_MD* md = nullptr;
31
  const EVP_MD* mgf1_md = nullptr;
32
  int saltlen = -1;
33
34
  SET_NO_MEMORY_INFO()
35
  SET_MEMORY_INFO_NAME(RsaKeyPairParams)
36
  SET_SELF_SIZE(RsaKeyPairParams)
37
};
38
39
using RsaKeyPairGenConfig = KeyPairGenConfig<RsaKeyPairParams>;
40
41
struct RsaKeyGenTraits final {
42
  using AdditionalParameters = RsaKeyPairGenConfig;
43
  static constexpr const char* JobName = "RsaKeyPairGenJob";
44
45
  static EVPKeyCtxPointer Setup(RsaKeyPairGenConfig* params);
46
47
  static v8::Maybe<bool> AdditionalConfig(
48
      CryptoJobMode mode,
49
      const v8::FunctionCallbackInfo<v8::Value>& args,
50
      unsigned int* offset,
51
      RsaKeyPairGenConfig* params);
52
};
53
54
using RSAKeyPairGenJob = KeyGenJob<KeyPairGenTraits<RsaKeyGenTraits>>;
55
56
struct RSAKeyExportConfig final : public MemoryRetainer {
57
  RSAKeyVariant variant = kKeyVariantRSA_SSA_PKCS1_v1_5;
58
  SET_NO_MEMORY_INFO()
59
  SET_MEMORY_INFO_NAME(RSAKeyExportConfig)
60
  SET_SELF_SIZE(RSAKeyExportConfig)
61
};
62
63
struct RSAKeyExportTraits final {
64
  static constexpr const char* JobName = "RSAKeyExportJob";
65
  using AdditionalParameters = RSAKeyExportConfig;
66
67
  static v8::Maybe<bool> AdditionalConfig(
68
      const v8::FunctionCallbackInfo<v8::Value>& args,
69
      unsigned int offset,
70
      RSAKeyExportConfig* config);
71
72
  static WebCryptoKeyExportStatus DoExport(
73
      std::shared_ptr<KeyObjectData> key_data,
74
      WebCryptoKeyFormat format,
75
      const RSAKeyExportConfig& params,
76
      ByteSource* out);
77
};
78
79
using RSAKeyExportJob = KeyExportJob<RSAKeyExportTraits>;
80
81
struct RSACipherConfig final : public MemoryRetainer {
82
  CryptoJobMode mode;
83
  ByteSource label;
84
  int padding = 0;
85
  const EVP_MD* digest = nullptr;
86
87
357
  RSACipherConfig() = default;
88
89
  RSACipherConfig(RSACipherConfig&& other) noexcept;
90
91
  void MemoryInfo(MemoryTracker* tracker) const override;
92
  SET_MEMORY_INFO_NAME(RSACipherConfig)
93
  SET_SELF_SIZE(RSACipherConfig)
94
};
95
96
struct RSACipherTraits final {
97
  static constexpr const char* JobName = "RSACipherJob";
98
  using AdditionalParameters = RSACipherConfig;
99
100
  static v8::Maybe<bool> AdditionalConfig(
101
      CryptoJobMode mode,
102
      const v8::FunctionCallbackInfo<v8::Value>& args,
103
      unsigned int offset,
104
      WebCryptoCipherMode cipher_mode,
105
      RSACipherConfig* config);
106
107
  static WebCryptoCipherStatus DoCipher(
108
      Environment* env,
109
      std::shared_ptr<KeyObjectData> key_data,
110
      WebCryptoCipherMode cipher_mode,
111
      const RSACipherConfig& params,
112
      const ByteSource& in,
113
      ByteSource* out);
114
};
115
116
using RSACipherJob = CipherJob<RSACipherTraits>;
117
118
v8::Maybe<bool> ExportJWKRsaKey(
119
    Environment* env,
120
    std::shared_ptr<KeyObjectData> key,
121
    v8::Local<v8::Object> target);
122
123
std::shared_ptr<KeyObjectData> ImportJWKRsaKey(
124
    Environment* env,
125
    v8::Local<v8::Object> jwk,
126
    const v8::FunctionCallbackInfo<v8::Value>& args,
127
    unsigned int offset);
128
129
v8::Maybe<bool> GetRsaKeyDetail(
130
    Environment* env,
131
    std::shared_ptr<KeyObjectData> key,
132
    v8::Local<v8::Object> target);
133
134
namespace RSAAlg {
135
void Initialize(Environment* env, v8::Local<v8::Object> target);
136
}  // namespace RSAAlg
137
}  // namespace crypto
138
}  // namespace node
139
140
#endif  // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
141
#endif  // SRC_CRYPTO_CRYPTO_RSA_H_