forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcrypto_kmac.h
More file actions
79 lines (60 loc) · 2.29 KB
/
crypto_kmac.h
File metadata and controls
79 lines (60 loc) · 2.29 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
#ifndef SRC_CRYPTO_CRYPTO_KMAC_H_
#define SRC_CRYPTO_CRYPTO_KMAC_H_
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
#include <string>
#include "crypto/crypto_keys.h"
#include "crypto/crypto_sig.h"
#include "crypto/crypto_util.h"
namespace node::crypto {
// KMAC (Keccak Message Authentication Code) is available since OpenSSL 3.0.
#if OPENSSL_VERSION_MAJOR >= 3
enum class KmacVariant { KMAC128, KMAC256 };
struct KmacConfig final : public MemoryRetainer {
CryptoJobMode job_mode;
SignConfiguration::Mode mode;
KeyObjectData key;
ByteSource data;
ByteSource signature;
ByteSource customization;
KmacVariant variant;
uint32_t length; // Output length in bytes
KmacConfig() = default;
explicit KmacConfig(KmacConfig&& other) noexcept;
KmacConfig& operator=(KmacConfig&& other) noexcept;
void MemoryInfo(MemoryTracker* tracker) const override;
SET_MEMORY_INFO_NAME(KmacConfig)
SET_SELF_SIZE(KmacConfig)
};
struct KmacTraits final {
using AdditionalParameters = KmacConfig;
static constexpr const char* JobName = "KmacJob";
static constexpr AsyncWrap::ProviderType Provider =
AsyncWrap::PROVIDER_SIGNREQUEST;
static v8::Maybe<void> AdditionalConfig(
CryptoJobMode mode,
const v8::FunctionCallbackInfo<v8::Value>& args,
unsigned int offset,
KmacConfig* params);
static bool DeriveBits(Environment* env,
const KmacConfig& params,
ByteSource* out,
CryptoJobMode mode);
static v8::MaybeLocal<v8::Value> EncodeOutput(Environment* env,
const KmacConfig& params,
ByteSource* out);
};
using KmacJob = DeriveBitsJob<KmacTraits>;
namespace Kmac {
void Initialize(Environment* env, v8::Local<v8::Object> target);
void RegisterExternalReferences(ExternalReferenceRegistry* registry);
} // namespace Kmac
#else
// If there is no KMAC support, provide empty namespace functions.
namespace Kmac {
void Initialize(Environment* env, v8::Local<v8::Object> target) {}
void RegisterExternalReferences(ExternalReferenceRegistry* registry) {}
} // namespace Kmac
#endif
} // namespace node::crypto
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
#endif // SRC_CRYPTO_CRYPTO_KMAC_H_