GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: crypto/crypto_scrypt.h Lines: 3 3 100.0 %
Date: 2021-09-27 04:13:02 Branches: 0 0 - %

Line Branch Exec Source
1
#ifndef SRC_CRYPTO_CRYPTO_SCRYPT_H_
2
#define SRC_CRYPTO_CRYPTO_SCRYPT_H_
3
4
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
6
#include "crypto/crypto_util.h"
7
#include "env.h"
8
#include "memory_tracker.h"
9
#include "v8.h"
10
11
namespace node {
12
namespace crypto {
13
#ifndef OPENSSL_NO_SCRYPT
14
15
// Scrypt is a password-based key derivation algorithm
16
// defined in https://tools.ietf.org/html/rfc7914
17
18
// It takes as input a password, a salt value, and a
19
// handful of additional parameters that control the
20
// cost of the operation. In this case, the higher
21
// the cost, the better the result. The length parameter
22
// defines the number of bytes that are generated.
23
24
// The salt must be as random as possible and should be
25
// at least 16 bytes in length.
26
27
struct ScryptConfig final : public MemoryRetainer {
28
  CryptoJobMode mode;
29
  ByteSource pass;
30
  ByteSource salt;
31
  uint32_t N;
32
  uint32_t r;
33
  uint32_t p;
34
  uint64_t maxmem;
35
  int32_t length;
36
37
43
  ScryptConfig() = default;
38
39
  explicit ScryptConfig(ScryptConfig&& other) noexcept;
40
41
  ScryptConfig& operator=(ScryptConfig&& other) noexcept;
42
43
  void MemoryInfo(MemoryTracker* tracker) const override;
44
1
  SET_MEMORY_INFO_NAME(ScryptConfig)
45
1
  SET_SELF_SIZE(ScryptConfig)
46
};
47
48
struct ScryptTraits final {
49
  using AdditionalParameters = ScryptConfig;
50
  static constexpr const char* JobName = "ScryptJob";
51
  static constexpr AsyncWrap::ProviderType Provider =
52
      AsyncWrap::PROVIDER_SCRYPTREQUEST;
53
54
  static v8::Maybe<bool> AdditionalConfig(
55
      CryptoJobMode mode,
56
      const v8::FunctionCallbackInfo<v8::Value>& args,
57
      unsigned int offset,
58
      ScryptConfig* params);
59
60
  static bool DeriveBits(
61
      Environment* env,
62
      const ScryptConfig& params,
63
      ByteSource* out);
64
65
  static v8::Maybe<bool> EncodeOutput(
66
      Environment* env,
67
      const ScryptConfig& params,
68
      ByteSource* out,
69
      v8::Local<v8::Value>* result);
70
};
71
72
using ScryptJob = DeriveBitsJob<ScryptTraits>;
73
74
#else
75
// If there is no Scrypt support, ScryptJob becomes a non-op
76
struct ScryptJob {
77
  static void Initialize(
78
      Environment* env,
79
      v8::Local<v8::Object> target) {}
80
}
81
#endif  // !OPENSSL_NO_SCRIPT
82
83
}  // namespace crypto
84
}  // namespace node
85
86
#endif  // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
87
#endif  // SRC_CRYPTO_CRYPTO_SCRYPT_H_