LCOV - code coverage report
Current view: top level - src/test/fuzz - crypto_poly1305.cpp (source / functions) Coverage Total Hit
Test: fuzz_coverage.info Lines: 100.0 % 24 24
Test Date: 2024-09-01 05:20:30 Functions: 100.0 % 4 4
Branches: 54.8 % 42 23

             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 <crypto/poly1305.h>
       6                 :             : #include <test/fuzz/FuzzedDataProvider.h>
       7                 :             : #include <test/fuzz/fuzz.h>
       8                 :             : #include <test/fuzz/util.h>
       9                 :             : 
      10                 :             : #include <cstdint>
      11                 :             : #include <vector>
      12                 :             : 
      13   [ +  -  +  - ]:          81 : FUZZ_TARGET(crypto_poly1305)
      14                 :             : {
      15                 :          78 :     FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
      16                 :             : 
      17                 :          78 :     const auto key = ConsumeFixedLengthByteVector<std::byte>(fuzzed_data_provider, Poly1305::KEYLEN);
      18                 :          78 :     const auto in = ConsumeRandomLengthByteVector<std::byte>(fuzzed_data_provider);
      19                 :             : 
      20         [ +  - ]:          78 :     std::vector<std::byte> tag_out(Poly1305::TAGLEN);
      21   [ +  -  +  -  :          78 :     Poly1305{key}.Update(in).Finalize(tag_out);
                   +  - ]
      22                 :          78 : }
      23                 :             : 
      24   [ +  -  +  - ]:         112 : FUZZ_TARGET(crypto_poly1305_split)
      25                 :             : {
      26                 :         109 :     FuzzedDataProvider provider{buffer.data(), buffer.size()};
      27                 :             : 
      28                 :             :     // Read key and instantiate two Poly1305 objects with it.
      29                 :         109 :     auto key = provider.ConsumeBytes<std::byte>(Poly1305::KEYLEN);
      30         [ +  - ]:         109 :     key.resize(Poly1305::KEYLEN);
      31   [ +  -  +  - ]:         109 :     Poly1305 poly_full{key}, poly_split{key};
      32                 :             : 
      33                 :             :     // Vector that holds all bytes processed so far.
      34                 :         109 :     std::vector<std::byte> total_input;
      35                 :             : 
      36                 :             :     // Process input in pieces.
      37   [ +  -  +  +  :        3714 :     LIMITED_WHILE(provider.remaining_bytes(), 100) {
                   +  + ]
      38                 :        3605 :         auto in = ConsumeRandomLengthByteVector<std::byte>(provider);
      39         [ -  + ]:        3605 :         poly_split.Update(in);
      40                 :             :         // Update total_input to match what was processed.
      41         [ -  + ]:        3605 :         total_input.insert(total_input.end(), in.begin(), in.end());
      42                 :        3605 :     }
      43                 :             : 
      44                 :             :     // Process entire input at once.
      45         [ +  - ]:         109 :     poly_full.Update(total_input);
      46                 :             : 
      47                 :             :     // Verify both agree.
      48                 :         109 :     std::array<std::byte, Poly1305::TAGLEN> tag_split, tag_full;
      49         [ +  - ]:         109 :     poly_split.Finalize(tag_split);
      50         [ +  - ]:         109 :     poly_full.Finalize(tag_full);
      51   [ +  -  +  - ]:         109 :     assert(tag_full == tag_split);
      52                 :         109 : }
        

Generated by: LCOV version 2.0-1