LCOV - code coverage report
Current view: top level - src/test/fuzz - message.cpp (source / functions) Hit Total Coverage
Test: fuzz_coverage.info Lines: 1 21 4.8 %
Date: 2023-11-10 23:46:46 Functions: 1 4 25.0 %
Branches: 1 34 2.9 %

           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 <chainparams.h>
       6                 :            : #include <key_io.h>
       7                 :            : #include <test/fuzz/FuzzedDataProvider.h>
       8                 :            : #include <test/fuzz/fuzz.h>
       9                 :            : #include <test/fuzz/util.h>
      10                 :            : #include <util/chaintype.h>
      11                 :            : #include <util/message.h>
      12                 :            : #include <util/strencodings.h>
      13                 :            : 
      14                 :            : #include <cassert>
      15                 :            : #include <cstdint>
      16                 :            : #include <iostream>
      17                 :            : #include <string>
      18                 :            : #include <vector>
      19                 :            : 
      20                 :          0 : void initialize_message()
      21                 :            : {
      22                 :          0 :     ECC_Start();
      23                 :          0 :     SelectParams(ChainType::REGTEST);
      24                 :          0 : }
      25                 :            : 
      26         [ +  - ]:          4 : FUZZ_TARGET(message, .init = initialize_message)
      27                 :            : {
      28                 :          0 :     FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
      29                 :          0 :     const std::string random_message = fuzzed_data_provider.ConsumeRandomLengthString(1024);
      30                 :            :     {
      31                 :          0 :         CKey private_key = ConsumePrivateKey(fuzzed_data_provider);
      32                 :          0 :         std::string signature;
      33         [ #  # ]:          0 :         const bool message_signed = MessageSign(private_key, random_message, signature);
      34 [ #  # ][ #  # ]:          0 :         if (private_key.IsValid()) {
      35         [ #  # ]:          0 :             assert(message_signed);
      36 [ #  # ][ #  # ]:          0 :             const MessageVerificationResult verification_result = MessageVerify(EncodeDestination(PKHash(private_key.GetPubKey().GetID())), signature, random_message);
         [ #  # ][ #  # ]
                 [ #  # ]
      37         [ #  # ]:          0 :             assert(verification_result == MessageVerificationResult::OK);
      38                 :          0 :         }
      39                 :          0 :     }
      40                 :            :     {
      41         [ #  # ]:          0 :         (void)MessageHash(random_message);
      42 [ #  # ][ #  # ]:          0 :         (void)MessageVerify(fuzzed_data_provider.ConsumeRandomLengthString(1024), fuzzed_data_provider.ConsumeRandomLengthString(1024), random_message);
                 [ #  # ]
      43 [ #  # ][ #  # ]:          0 :         (void)SigningResultString(fuzzed_data_provider.PickValueInArray({SigningResult::OK, SigningResult::PRIVATE_KEY_NOT_AVAILABLE, SigningResult::SIGNING_FAILED}));
      44                 :            :     }
      45                 :          0 : }

Generated by: LCOV version 1.14