LCOV - code coverage report
Current view: top level - src/test/fuzz - secp256k1_ec_seckey_import_export_der.cpp (source / functions) Coverage Total Hit
Test: fuzz_coverage.info Lines: 100.0 % 19 19
Test Date: 2024-09-01 05:20:30 Functions: 100.0 % 2 2
Branches: 53.8 % 26 14

             Branch data     Line data    Source code
       1                 :             : // Copyright (c) 2020 The Bitcoin Core developers
       2                 :             : // Distributed under the MIT software license, see the accompanying
       3                 :             : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
       4                 :             : 
       5                 :             : #include <key.h>
       6                 :             : #include <secp256k1.h>
       7                 :             : #include <test/fuzz/FuzzedDataProvider.h>
       8                 :             : #include <test/fuzz/fuzz.h>
       9                 :             : #include <test/fuzz/util.h>
      10                 :             : 
      11                 :             : #include <cstdint>
      12                 :             : #include <vector>
      13                 :             : 
      14                 :             : int ec_seckey_import_der(const secp256k1_context* ctx, unsigned char* out32, const unsigned char* seckey, size_t seckeylen);
      15                 :             : int ec_seckey_export_der(const secp256k1_context* ctx, unsigned char* seckey, size_t* seckeylen, const unsigned char* key32, bool compressed);
      16                 :             : 
      17   [ +  -  +  - ]:          35 : FUZZ_TARGET(secp256k1_ec_seckey_import_export_der)
      18                 :             : {
      19                 :          32 :     FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
      20                 :          32 :     secp256k1_context* secp256k1_context_sign = secp256k1_context_create(SECP256K1_CONTEXT_NONE);
      21                 :             :     {
      22         [ +  - ]:          32 :         std::vector<uint8_t> out32(32);
      23         [ +  - ]:          32 :         (void)ec_seckey_import_der(secp256k1_context_sign, out32.data(), ConsumeFixedLengthByteVector(fuzzed_data_provider, CKey::SIZE).data(), CKey::SIZE);
      24                 :          32 :     }
      25                 :             :     {
      26         [ +  - ]:          32 :         std::vector<uint8_t> seckey(CKey::SIZE);
      27                 :          32 :         const std::vector<uint8_t> key32 = ConsumeFixedLengthByteVector(fuzzed_data_provider, 32);
      28                 :          32 :         size_t seckeylen = CKey::SIZE;
      29         [ +  - ]:          32 :         const bool compressed = fuzzed_data_provider.ConsumeBool();
      30         [ +  - ]:          32 :         const bool exported = ec_seckey_export_der(secp256k1_context_sign, seckey.data(), &seckeylen, key32.data(), compressed);
      31         [ +  + ]:          32 :         if (exported) {
      32         [ +  - ]:          14 :             std::vector<uint8_t> out32(32);
      33         [ +  - ]:          14 :             const bool imported = ec_seckey_import_der(secp256k1_context_sign, out32.data(), seckey.data(), seckey.size()) == 1;
      34   [ +  -  +  -  :          28 :             assert(imported && key32 == out32);
                   +  - ]
      35                 :          14 :         }
      36                 :          32 :     }
      37                 :          32 :     secp256k1_context_destroy(secp256k1_context_sign);
      38                 :          32 : }
        

Generated by: LCOV version 2.0-1