forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcrypto_turboshake.h
More file actions
107 lines (79 loc) · 3.48 KB
/
Copy pathcrypto_turboshake.h
File metadata and controls
107 lines (79 loc) · 3.48 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
#ifndef SRC_CRYPTO_CRYPTO_TURBOSHAKE_H_
#define SRC_CRYPTO_CRYPTO_TURBOSHAKE_H_
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
#include "crypto/crypto_util.h"
namespace node::crypto {
enum class TurboShakeVariant { TurboSHAKE128, TurboSHAKE256 };
struct TurboShakeConfig final : public MemoryRetainer {
CryptoJobMode job_mode;
TurboShakeVariant variant;
uint32_t output_length; // Output length in bytes
uint8_t domain_separation; // Domain separation byte (0x01–0x7F)
ByteSource data;
TurboShakeConfig() = default;
explicit TurboShakeConfig(TurboShakeConfig&& other) noexcept;
TurboShakeConfig& operator=(TurboShakeConfig&& other) noexcept;
void MemoryInfo(MemoryTracker* tracker) const override;
SET_MEMORY_INFO_NAME(TurboShakeConfig)
SET_SELF_SIZE(TurboShakeConfig)
};
struct TurboShakeTraits final {
using AdditionalParameters = TurboShakeConfig;
static constexpr const char* JobName = "TurboShakeJob";
static constexpr AsyncWrap::ProviderType Provider =
AsyncWrap::PROVIDER_DERIVEBITSREQUEST;
static v8::Maybe<void> AdditionalConfig(
CryptoJobMode mode,
const v8::FunctionCallbackInfo<v8::Value>& args,
unsigned int offset,
TurboShakeConfig* params);
static bool DeriveBits(Environment* env,
const TurboShakeConfig& params,
ByteSource* out,
CryptoJobMode mode,
CryptoErrorStore* errors);
static v8::MaybeLocal<v8::Value> EncodeOutput(Environment* env,
const TurboShakeConfig& params,
ByteSource* out);
};
using TurboShakeJob = DeriveBitsJob<TurboShakeTraits>;
enum class KangarooTwelveVariant { KT128, KT256 };
struct KangarooTwelveConfig final : public MemoryRetainer {
CryptoJobMode job_mode;
KangarooTwelveVariant variant;
uint32_t output_length; // Output length in bytes
ByteSource data;
ByteSource customization;
KangarooTwelveConfig() = default;
explicit KangarooTwelveConfig(KangarooTwelveConfig&& other) noexcept;
KangarooTwelveConfig& operator=(KangarooTwelveConfig&& other) noexcept;
void MemoryInfo(MemoryTracker* tracker) const override;
SET_MEMORY_INFO_NAME(KangarooTwelveConfig)
SET_SELF_SIZE(KangarooTwelveConfig)
};
struct KangarooTwelveTraits final {
using AdditionalParameters = KangarooTwelveConfig;
static constexpr const char* JobName = "KangarooTwelveJob";
static constexpr AsyncWrap::ProviderType Provider =
AsyncWrap::PROVIDER_DERIVEBITSREQUEST;
static v8::Maybe<void> AdditionalConfig(
CryptoJobMode mode,
const v8::FunctionCallbackInfo<v8::Value>& args,
unsigned int offset,
KangarooTwelveConfig* params);
static bool DeriveBits(Environment* env,
const KangarooTwelveConfig& params,
ByteSource* out,
CryptoJobMode mode,
CryptoErrorStore* errors);
static v8::MaybeLocal<v8::Value> EncodeOutput(
Environment* env, const KangarooTwelveConfig& params, ByteSource* out);
};
using KangarooTwelveJob = DeriveBitsJob<KangarooTwelveTraits>;
namespace TurboShake {
void Initialize(Environment* env, v8::Local<v8::Object> target);
void RegisterExternalReferences(ExternalReferenceRegistry* registry);
} // namespace TurboShake
} // namespace node::crypto
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
#endif // SRC_CRYPTO_CRYPTO_TURBOSHAKE_H_