Coverage Report

Created: 2025-10-31 09:06

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/node/src/crypto/crypto_chacha20_poly1305.h
Line
Count
Source
1
#ifndef SRC_CRYPTO_CRYPTO_CHACHA20_POLY1305_H_
2
#define SRC_CRYPTO_CRYPTO_CHACHA20_POLY1305_H_
3
4
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
6
#include "crypto/crypto_cipher.h"
7
#include "crypto/crypto_keys.h"
8
#include "crypto/crypto_util.h"
9
#include "env.h"
10
#include "v8.h"
11
12
namespace node::crypto {
13
constexpr unsigned kChaCha20Poly1305AuthTagLength = 16;
14
15
struct ChaCha20Poly1305CipherConfig final : public MemoryRetainer {
16
  CryptoJobMode mode;
17
  ncrypto::Cipher cipher;
18
  ByteSource iv;
19
  ByteSource additional_data;
20
  ByteSource tag;
21
22
0
  ChaCha20Poly1305CipherConfig() = default;
23
24
  ChaCha20Poly1305CipherConfig(ChaCha20Poly1305CipherConfig&& other) noexcept;
25
26
  ChaCha20Poly1305CipherConfig& operator=(
27
      ChaCha20Poly1305CipherConfig&& other) noexcept;
28
29
  void MemoryInfo(MemoryTracker* tracker) const override;
30
  SET_MEMORY_INFO_NAME(ChaCha20Poly1305CipherConfig)
31
  SET_SELF_SIZE(ChaCha20Poly1305CipherConfig)
32
};
33
34
struct ChaCha20Poly1305CipherTraits final {
35
  static constexpr const char* JobName = "ChaCha20Poly1305CipherJob";
36
37
  using AdditionalParameters = ChaCha20Poly1305CipherConfig;
38
39
  static v8::Maybe<void> AdditionalConfig(
40
      CryptoJobMode mode,
41
      const v8::FunctionCallbackInfo<v8::Value>& args,
42
      unsigned int offset,
43
      WebCryptoCipherMode cipher_mode,
44
      ChaCha20Poly1305CipherConfig* config);
45
46
  static WebCryptoCipherStatus DoCipher(
47
      Environment* env,
48
      const KeyObjectData& key_data,
49
      WebCryptoCipherMode cipher_mode,
50
      const ChaCha20Poly1305CipherConfig& params,
51
      const ByteSource& in,
52
      ByteSource* out);
53
};
54
55
using ChaCha20Poly1305CryptoJob = CipherJob<ChaCha20Poly1305CipherTraits>;
56
57
namespace ChaCha20Poly1305 {
58
void Initialize(Environment* env, v8::Local<v8::Object> target);
59
void RegisterExternalReferences(ExternalReferenceRegistry* registry);
60
}  // namespace ChaCha20Poly1305
61
}  // namespace node::crypto
62
63
#endif  // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
64
#endif  // SRC_CRYPTO_CRYPTO_CHACHA20_POLY1305_H_