1 // Copyright 2016 The BoringSSL Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include <openssl/bio.h>
16 #include <openssl/bytestring.h>
17 #include <openssl/err.h>
18 #include <openssl/evp.h>
19 #include <openssl/mem.h>
20
LLVMFuzzerTestOneInput(const uint8_t * buf,size_t len)21 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t len) {
22 CBS cbs;
23 CBS_init(&cbs, buf, len);
24 bssl::UniquePtr<EVP_PKEY> pkey(EVP_parse_public_key(&cbs));
25 if (pkey == nullptr) {
26 ERR_clear_error();
27 return 0;
28 }
29
30 // Every parsed public key should be serializable.
31 bssl::ScopedCBB cbb;
32 BSSL_CHECK(CBB_init(cbb.get(), 0));
33 BSSL_CHECK(EVP_marshal_public_key(cbb.get(), pkey.get()));
34
35 bssl::UniquePtr<BIO> bio(BIO_new(BIO_s_mem()));
36 EVP_PKEY_print_params(bio.get(), pkey.get(), 0, nullptr);
37 EVP_PKEY_print_public(bio.get(), pkey.get(), 0, nullptr);
38
39 ERR_clear_error();
40 return 0;
41 }
42