forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcrypto_rsa.h
More file actions
109 lines (85 loc) · 3.25 KB
/
Copy pathcrypto_rsa.h
File metadata and controls
109 lines (85 loc) · 3.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#ifndef SRC_CRYPTO_CRYPTO_RSA_H_
#define SRC_CRYPTO_CRYPTO_RSA_H_
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
#include "crypto/crypto_cipher.h"
#include "crypto/crypto_keygen.h"
#include "crypto/crypto_keys.h"
#include "crypto/crypto_util.h"
#include "env.h"
#include "memory_tracker.h"
#include "v8.h"
namespace node {
namespace crypto {
enum RSAKeyVariant {
kKeyVariantRSA_SSA_PKCS1_v1_5,
kKeyVariantRSA_PSS,
kKeyVariantRSA_OAEP
};
struct RsaKeyPairParams final : public MemoryRetainer {
RSAKeyVariant variant;
unsigned int modulus_bits;
unsigned int exponent;
// The following options are used for RSA-PSS. If any of them are set, a
// RSASSA-PSS-params sequence will be added to the key.
ncrypto::Digest md = nullptr;
ncrypto::Digest mgf1_md = nullptr;
int saltlen = -1;
SET_NO_MEMORY_INFO()
SET_MEMORY_INFO_NAME(RsaKeyPairParams)
SET_SELF_SIZE(RsaKeyPairParams)
};
using RsaKeyPairGenConfig = KeyPairGenConfig<RsaKeyPairParams>;
struct RsaKeyGenTraits final {
using AdditionalParameters = RsaKeyPairGenConfig;
static constexpr const char* JobName = "RsaKeyPairGenJob";
static ncrypto::EVPKeyCtxPointer Setup(RsaKeyPairGenConfig* params);
static v8::Maybe<void> AdditionalConfig(
CryptoJobMode mode,
const v8::FunctionCallbackInfo<v8::Value>& args,
unsigned int* offset,
RsaKeyPairGenConfig* params);
};
using RSAKeyPairGenJob = KeyGenJob<KeyPairGenTraits<RsaKeyGenTraits>>;
struct RSACipherConfig final : public MemoryRetainer {
CryptoJobMode mode = kCryptoJobAsync;
ByteSource label;
int padding = 0;
ncrypto::Digest digest;
RSACipherConfig() = default;
RSACipherConfig(RSACipherConfig&& other) noexcept;
void MemoryInfo(MemoryTracker* tracker) const override;
SET_MEMORY_INFO_NAME(RSACipherConfig)
SET_SELF_SIZE(RSACipherConfig)
};
struct RSACipherTraits final {
static constexpr const char* JobName = "RSACipherJob";
using AdditionalParameters = RSACipherConfig;
static v8::Maybe<void> AdditionalConfig(
CryptoJobMode mode,
const v8::FunctionCallbackInfo<v8::Value>& args,
unsigned int offset,
WebCryptoCipherMode cipher_mode,
RSACipherConfig* config);
static WebCryptoCipherStatus DoCipher(Environment* env,
const KeyObjectData& key_data,
WebCryptoCipherMode cipher_mode,
const RSACipherConfig& params,
const ByteSource& in,
ByteSource* out);
};
using RSACipherJob = CipherJob<RSACipherTraits>;
bool ExportJWKRsaKey(Environment* env,
const KeyObjectData& key,
v8::Local<v8::Object> target);
KeyObjectData ImportJWKRsaKey(Environment* env, v8::Local<v8::Object> jwk);
bool GetRsaKeyDetail(Environment* env,
const KeyObjectData& key,
v8::Local<v8::Object> target);
namespace RSAAlg {
void Initialize(Environment* env, v8::Local<v8::Object> target);
void RegisterExternalReferences(ExternalReferenceRegistry* registry);
} // namespace RSAAlg
} // namespace crypto
} // namespace node
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
#endif // SRC_CRYPTO_CRYPTO_RSA_H_