LCOV - code coverage report
Current view: top level - src/crypto - common.h (source / functions) Coverage Total Hit
Test: total_coverage.info Lines: 100.0 % 44 44
Test Date: 2024-07-07 05:05:19 Functions: 100.0 % 5 5
Branches: 63.6 % 44 28

             Branch data     Line data    Source code
       1                 :             : // Copyright (c) 2014-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                 :             : #ifndef BITCOIN_CRYPTO_COMMON_H
       6                 :             : #define BITCOIN_CRYPTO_COMMON_H
       7                 :             : 
       8                 :             : #include <compat/endian.h>
       9                 :             : 
      10                 :             : #include <cstdint>
      11                 :             : #include <cstring>
      12                 :             : 
      13                 :       10508 : uint16_t static inline ReadLE16(const unsigned char* ptr)
      14                 :             : {
      15                 :       10508 :     uint16_t x;
      16         [ #  # ]:       10508 :     memcpy(&x, ptr, 2);
      17         [ #  # ]:       10508 :     return le16toh_internal(x);
      18                 :             : }
      19                 :             : 
      20                 :   234263973 : uint32_t static inline ReadLE32(const unsigned char* ptr)
      21                 :             : {
      22                 :   234263973 :     uint32_t x;
      23         [ +  + ]:   227368157 :     memcpy(&x, ptr, 4);
      24         [ +  + ]:   227368157 :     return le32toh_internal(x);
      25                 :             : }
      26                 :             : 
      27                 :   336232605 : uint64_t static inline ReadLE64(const unsigned char* ptr)
      28                 :             : {
      29                 :   336232605 :     uint64_t x;
      30         [ +  + ]:   336232605 :     memcpy(&x, ptr, 8);
           [ +  +  +  + ]
      31         [ +  + ]:   336232605 :     return le64toh_internal(x);
           [ +  +  +  + ]
      32                 :             : }
      33                 :             : 
      34                 :         357 : void static inline WriteLE16(unsigned char* ptr, uint16_t x)
      35                 :             : {
      36                 :         357 :     uint16_t v = htole16_internal(x);
      37                 :         357 :     memcpy(ptr, &v, 2);
      38                 :         357 : }
      39                 :             : 
      40                 :   320906607 : void static inline WriteLE32(unsigned char* ptr, uint32_t x)
      41                 :             : {
      42                 :   320906607 :     uint32_t v = htole32_internal(x);
      43                 :   320906607 :     memcpy(ptr, &v, 4);
      44                 :   320906607 : }
      45                 :             : 
      46                 :    18072900 : void static inline WriteLE64(unsigned char* ptr, uint64_t x)
      47                 :             : {
      48                 :    18072900 :     uint64_t v = htole64_internal(x);
      49                 :    18072900 :     memcpy(ptr, &v, 8);
      50                 :    18072900 : }
      51                 :             : 
      52                 :        2479 : uint16_t static inline ReadBE16(const unsigned char* ptr)
      53                 :             : {
      54                 :        2479 :     uint16_t x;
      55                 :        2479 :     memcpy(&x, ptr, 2);
      56                 :        2479 :     return be16toh_internal(x);
      57                 :             : }
      58                 :             : 
      59                 :   369734942 : uint32_t static inline ReadBE32(const unsigned char* ptr)
      60                 :             : {
      61                 :   369734942 :     uint32_t x;
      62 [ +  + ][ +  -  :    25520582 :     memcpy(&x, ptr, 4);
          +  -  +  -  +  
                      - ]
      63 [ +  + ][ +  -  :    25520582 :     return be32toh_internal(x);
          +  -  +  -  +  
                      - ]
      64                 :             : }
      65                 :             : 
      66                 :  2099279055 : uint64_t static inline ReadBE64(const unsigned char* ptr)
      67                 :             : {
      68                 :  2239230992 :     uint64_t x;
      69         [ #  # ]:   139951937 :     memcpy(&x, ptr, 8);
      70         [ #  # ]:   139951937 :     return be64toh_internal(x);
      71                 :             : }
      72                 :             : 
      73                 :   351487883 : void static inline WriteBE32(unsigned char* ptr, uint32_t x)
      74                 :             : {
      75                 :   351487883 :     uint32_t v = htobe32_internal(x);
      76                 :   351487883 :     memcpy(ptr, &v, 4);
      77                 :   351487883 : }
      78                 :             : 
      79                 :  1277520417 : void static inline WriteBE64(unsigned char* ptr, uint64_t x)
      80                 :             : {
      81                 :  1277520417 :     uint64_t v = htobe64_internal(x);
      82                 :  1277520417 :     memcpy(ptr, &v, 8);
      83                 :  1277520417 : }
      84                 :             : 
      85                 :             : #endif // BITCOIN_CRYPTO_COMMON_H
        

Generated by: LCOV version 2.0-1