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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
#ifndef SRC_CRYPTO_CRYPTO_RANDOM_H_
#define SRC_CRYPTO_CRYPTO_RANDOM_H_
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
#include "base_object.h"
#include "crypto/crypto_util.h"
#include "env.h"
#include "memory_tracker.h"
#include "node_internals.h"
#include "v8.h"
namespace node {
namespace crypto {
struct RandomBytesConfig final : public MemoryRetainer {
unsigned char* buffer;
size_t size;
SET_NO_MEMORY_INFO()
SET_MEMORY_INFO_NAME(RandomBytesConfig)
SET_SELF_SIZE(RandomBytesConfig)
};
struct RandomBytesTraits final {
using AdditionalParameters = RandomBytesConfig;
static constexpr const char* JobName = "RandomBytesJob";
static constexpr AsyncWrap::ProviderType Provider =
AsyncWrap::PROVIDER_RANDOMBYTESREQUEST;
static v8::Maybe<bool> AdditionalConfig(
CryptoJobMode mode,
const v8::FunctionCallbackInfo<v8::Value>& args,
unsigned int offset,
RandomBytesConfig* params);
static bool DeriveBits(
Environment* env,
const RandomBytesConfig& params,
ByteSource* out_);
static v8::Maybe<bool> EncodeOutput(
Environment* env,
const RandomBytesConfig& params,
ByteSource* unused,
v8::Local<v8::Value>* result);
};
using RandomBytesJob = DeriveBitsJob<RandomBytesTraits>;
struct RandomPrimeConfig final : public MemoryRetainer {
BignumPointer prime;
BignumPointer rem;
BignumPointer add;
int bits;
bool safe;
void MemoryInfo(MemoryTracker* tracker) const override;
SET_MEMORY_INFO_NAME(RandomPrimeConfig)
SET_SELF_SIZE(RandomPrimeConfig)
};
struct RandomPrimeTraits final {
using AdditionalParameters = RandomPrimeConfig;
static constexpr const char* JobName = "RandomPrimeJob";
static constexpr AsyncWrap::ProviderType Provider =
AsyncWrap::PROVIDER_RANDOMPRIMEREQUEST;
static v8::Maybe<bool> AdditionalConfig(
CryptoJobMode mode,
const v8::FunctionCallbackInfo<v8::Value>& args,
unsigned int offset,
RandomPrimeConfig* params);
static bool DeriveBits(
Environment* env,
const RandomPrimeConfig& params,
ByteSource* out_);
static v8::Maybe<bool> EncodeOutput(
Environment* env,
const RandomPrimeConfig& params,
ByteSource* unused,
v8::Local<v8::Value>* result);
};
using RandomPrimeJob = DeriveBitsJob<RandomPrimeTraits>;
struct CheckPrimeConfig final : public MemoryRetainer {
BignumPointer candidate;
int checks = 1;
void MemoryInfo(MemoryTracker* tracker) const override;
SET_MEMORY_INFO_NAME(CheckPrimeConfig)
SET_SELF_SIZE(CheckPrimeConfig)
};
struct CheckPrimeTraits final {
using AdditionalParameters = CheckPrimeConfig;
static constexpr const char* JobName = "CheckPrimeJob";
static constexpr AsyncWrap::ProviderType Provider =
AsyncWrap::PROVIDER_CHECKPRIMEREQUEST;
static v8::Maybe<bool> AdditionalConfig(
CryptoJobMode mode,
const v8::FunctionCallbackInfo<v8::Value>& args,
unsigned int offset,
CheckPrimeConfig* params);
static bool DeriveBits(
Environment* env,
const CheckPrimeConfig& params,
ByteSource* out);
static v8::Maybe<bool> EncodeOutput(
Environment* env,
const CheckPrimeConfig& params,
ByteSource* out,
v8::Local<v8::Value>* result);
};
using CheckPrimeJob = DeriveBitsJob<CheckPrimeTraits>;
namespace Random {
void Initialize(Environment* env, v8::Local<v8::Object> target);
void RegisterExternalReferences(ExternalReferenceRegistry* registry);
} // namespace Random
} // namespace crypto
} // namespace node
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
#endif // SRC_CRYPTO_CRYPTO_RANDOM_H_
|