LCOV - code coverage report
Current view: top level - src/test/fuzz - crypto_aes256cbc.cpp (source / functions) Coverage Total Hit
Test: fuzz_coverage.info Lines: 100.0 % 18 18
Test Date: 2024-12-04 04:00:22 Functions: 100.0 % 2 2
Branches: 60.0 % 30 18

             Branch data     Line data    Source code
       1                 :             : // Copyright (c) 2020-2021 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/aes.h>
       6                 :             : #include <test/fuzz/FuzzedDataProvider.h>
       7                 :             : #include <test/fuzz/fuzz.h>
       8                 :             : #include <test/fuzz/util.h>
       9                 :             : 
      10                 :             : #include <cassert>
      11                 :             : #include <cstdint>
      12                 :             : #include <vector>
      13                 :             : 
      14         [ +  - ]:         533 : FUZZ_TARGET(crypto_aes256cbc)
      15                 :             : {
      16                 :         121 :     FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
      17                 :         121 :     const std::vector<uint8_t> key = ConsumeFixedLengthByteVector(fuzzed_data_provider, AES256_KEYSIZE);
      18                 :         121 :     const std::vector<uint8_t> iv = ConsumeFixedLengthByteVector(fuzzed_data_provider, AES_BLOCKSIZE);
      19                 :         121 :     const bool pad = fuzzed_data_provider.ConsumeBool();
      20                 :             : 
      21         [ +  - ]:         121 :     AES256CBCEncrypt encrypt{key.data(), iv.data(), pad};
      22         [ +  - ]:         121 :     AES256CBCDecrypt decrypt{key.data(), iv.data(), pad};
      23                 :             : 
      24   [ +  +  +  + ]:       59089 :     LIMITED_WHILE(fuzzed_data_provider.ConsumeBool(), 10000) {
      25                 :       58968 :         const std::vector<uint8_t> plaintext = ConsumeRandomLengthByteVector(fuzzed_data_provider);
      26         [ +  - ]:       58968 :         std::vector<uint8_t> ciphertext(plaintext.size() + AES_BLOCKSIZE);
      27         [ +  - ]:       58968 :         const int encrypt_ret = encrypt.Encrypt(plaintext.data(), plaintext.size(), ciphertext.data());
      28         [ +  - ]:       58968 :         ciphertext.resize(encrypt_ret);
      29         [ +  - ]:       58968 :         std::vector<uint8_t> decrypted_plaintext(ciphertext.size());
      30         [ +  - ]:       58968 :         const int decrypt_ret = decrypt.Decrypt(ciphertext.data(), ciphertext.size(), decrypted_plaintext.data());
      31         [ +  - ]:       58968 :         decrypted_plaintext.resize(decrypt_ret);
      32   [ +  +  +  -  :       58968 :         assert(decrypted_plaintext == plaintext || (!pad && plaintext.size() % AES_BLOCKSIZE != 0 && encrypt_ret == 0 && decrypt_ret == 0));
             +  -  -  + ]
      33                 :       58968 :     }
      34                 :         121 : }
        

Generated by: LCOV version 2.0-1