MCPcopy Create free account
hub / github.com/ElementsProject/elements / FUZZ_TARGET

Function FUZZ_TARGET

src/test/fuzz/crypto_chacha20.cpp:13–45  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11#include <vector>
12
13FUZZ_TARGET(crypto_chacha20)
14{
15 FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
16
17 ChaCha20 chacha20;
18 if (fuzzed_data_provider.ConsumeBool()) {
19 const std::vector<unsigned char> key = ConsumeFixedLengthByteVector(fuzzed_data_provider, fuzzed_data_provider.ConsumeIntegralInRange<size_t>(16, 32));
20 chacha20 = ChaCha20{key.data(), key.size()};
21 }
22 LIMITED_WHILE(fuzzed_data_provider.ConsumeBool(), 10000) {
23 CallOneOf(
24 fuzzed_data_provider,
25 [&] {
26 const std::vector<unsigned char> key = ConsumeFixedLengthByteVector(fuzzed_data_provider, fuzzed_data_provider.ConsumeIntegralInRange<size_t>(16, 32));
27 chacha20.SetKey(key.data(), key.size());
28 },
29 [&] {
30 chacha20.SetIV(fuzzed_data_provider.ConsumeIntegral<uint64_t>());
31 },
32 [&] {
33 chacha20.Seek(fuzzed_data_provider.ConsumeIntegral<uint64_t>());
34 },
35 [&] {
36 std::vector<uint8_t> output(fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, 4096));
37 chacha20.Keystream(output.data(), output.size());
38 },
39 [&] {
40 std::vector<uint8_t> output(fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, 4096));
41 const std::vector<uint8_t> input = ConsumeFixedLengthByteVector(fuzzed_data_provider, output.size());
42 chacha20.Crypt(input.data(), output.data(), input.size());
43 });
44 }
45}

Callers

nothing calls this directly

Calls 10

CallOneOfFunction · 0.85
ConsumeBoolMethod · 0.80
SetIVMethod · 0.80
KeystreamMethod · 0.80
dataMethod · 0.45
sizeMethod · 0.45
SetKeyMethod · 0.45
SeekMethod · 0.45
CryptMethod · 0.45

Tested by

no test coverage detected