-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathkey_blob_fuzzer.cc
39 lines (30 loc) · 1.05 KB
/
key_blob_fuzzer.cc
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
// Copyright 2018 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Fuzzer that tests parsing and serialization of key blobs.
#include <stddef.h>
#include <stdint.h>
#include <string>
#include "base/logging.h"
#include "trunks/blob_parser.h"
struct Environment {
Environment() {
logging::SetMinLogLevel(logging::LOG_FATAL); // Disable logging.
}
};
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
if (size < 1)
return 0;
static Environment env;
static trunks::BlobParser blob_parser;
// Parse.
std::string key_blob(reinterpret_cast<const char*>(data), size);
trunks::TPM2B_PUBLIC public_info;
trunks::TPM2B_PRIVATE private_info;
if (!blob_parser.ParseKeyBlob(key_blob, &public_info, &private_info))
return 0; // Quit early on failure to avoid serializing unitialized data.
// Serialize.
std::string serialized;
blob_parser.SerializeKeyBlob(public_info, private_info, &serialized);
return 0;
}