/src/boringssl/fuzz/pkcs8.cc
Line | Count | Source |
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/crypto.h> |
16 | | #include <openssl/bio.h> |
17 | | #include <openssl/bytestring.h> |
18 | | #include <openssl/err.h> |
19 | | #include <openssl/evp.h> |
20 | | #include <openssl/mem.h> |
21 | | |
22 | 5.14k | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t len) { |
23 | 5.14k | #if defined(FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION) |
24 | 5.14k | CRYPTO_set_fuzzer_mode(1); |
25 | 5.14k | #endif |
26 | | |
27 | 5.14k | CBS cbs; |
28 | 5.14k | CBS_init(&cbs, buf, len); |
29 | 5.14k | bssl::UniquePtr<EVP_PKEY> pkey(EVP_parse_private_key(&cbs)); |
30 | 5.14k | if (pkey == nullptr) { |
31 | 3.57k | ERR_clear_error(); |
32 | 3.57k | return 0; |
33 | 3.57k | } |
34 | | |
35 | | // Every parsed private key should be serializable. |
36 | 1.56k | bssl::ScopedCBB cbb; |
37 | 1.56k | BSSL_CHECK(CBB_init(cbb.get(), 0)); |
38 | 1.56k | BSSL_CHECK(EVP_marshal_public_key(cbb.get(), pkey.get())); |
39 | 1.56k | BSSL_CHECK(EVP_marshal_private_key(cbb.get(), pkey.get())); |
40 | | |
41 | 1.56k | bssl::UniquePtr<BIO> bio(BIO_new(BIO_s_mem())); |
42 | 1.56k | EVP_PKEY_print_params(bio.get(), pkey.get(), 0, nullptr); |
43 | 1.56k | EVP_PKEY_print_public(bio.get(), pkey.get(), 0, nullptr); |
44 | 1.56k | EVP_PKEY_print_private(bio.get(), pkey.get(), 0, nullptr); |
45 | | |
46 | 1.56k | ERR_clear_error(); |
47 | 1.56k | return 0; |
48 | 1.56k | } |