diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2021-07-15 02:04:54 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2021-07-15 02:04:54 +0000 |
commit | f1c8f58947e416e96732b7d2d690c9c6234f802a (patch) | |
tree | 328e6c9629b196cec1de3a94ee804d9fee3a0524 /projects/pycryptodome/pcd_hash_fuzzer.cc | |
parent | fc25fcf0519e5da3d5acfea27eadaa9ccffaef55 (diff) | |
parent | 8dd31c7112ba7b07fcafe02c83dc9ef3808cdab7 (diff) | |
download | oss-fuzz-f1c8f58947e416e96732b7d2d690c9c6234f802a.tar.gz |
Snap for 7550930 from 8dd31c7112ba7b07fcafe02c83dc9ef3808cdab7 to mainline-resolv-releaseandroid-mainline-12.0.0_r94android-mainline-12.0.0_r80android-mainline-12.0.0_r65android-mainline-12.0.0_r52android-mainline-12.0.0_r35android-mainline-12.0.0_r16android-mainline-12.0.0_r124android-mainline-12.0.0_r108android12-mainline-resolv-release
Change-Id: Ida417a0680eda28a5ae3f036b56b8cf8ec2fcfa6
Diffstat (limited to 'projects/pycryptodome/pcd_hash_fuzzer.cc')
-rw-r--r-- | projects/pycryptodome/pcd_hash_fuzzer.cc | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/projects/pycryptodome/pcd_hash_fuzzer.cc b/projects/pycryptodome/pcd_hash_fuzzer.cc new file mode 100644 index 000000000..681f83445 --- /dev/null +++ b/projects/pycryptodome/pcd_hash_fuzzer.cc @@ -0,0 +1,71 @@ +// Copyright 2020 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "common.h" +#include <fuzzer/FuzzedDataProvider.h> + +#ifndef HASHTYPE +#error Macro HASHTYPE must be defined. +#endif + +#ifndef FNAME +#error Macro FNAME must be defined. +#endif + +#define CONCAT_TYPE(x) _PASTE2(HASHTYPE, x) + +#define init CONCAT_TYPE(_init) +#define update CONCAT_TYPE(_update) +#define digest CONCAT_TYPE(_digest) +#define destroy CONCAT_TYPE(_destroy) + +#define STR(x) #x +#define INCLUDE(x) STR(x) + +#include INCLUDE(FNAME) + +#ifndef DIGEST_SIZE +#error Macro DIGEST_SIZE must be defined. +#endif + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { + + if (!size) + return 0; + + FuzzedDataProvider stream(data, size); + hash_state *hs; + if (init(&hs)) + return 0; + + while (stream.remaining_bytes()) { + size_t num_bytes = stream.ConsumeIntegral<size_t>(); + std::vector<uint8_t> buffer = stream.ConsumeBytes<uint8_t>(num_bytes); + + if (update(hs, buffer.data(), buffer.size())) + goto error; + } + + uint8_t result[DIGEST_SIZE]; + +#ifndef DIGEST_THIRD_PARAM + digest(hs, result); +#else + digest(hs, result, DIGEST_SIZE); +#endif + +error: + destroy(hs); + return 0; +} |