LCOV - code coverage report
Current view: top level - src/crypto - common.h (source / functions) Hit Total Coverage
Test: coverage.lcov Lines: 55 68 80.9 %
Date: 2022-04-21 14:51:19 Functions: 57 2712 2.1 %
Legend: Modified by patch:
Lines: hit not hit | Branches: + taken - not taken # not executed

Not modified by patch:
Lines: hit not hit | Branches: + taken - not taken # not executed
Branches: 8 180 4.4 %

           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                 :            : #if defined(HAVE_CONFIG_H)
#       9                 :            : #include <config/bitcoin-config.h>
#      10                 :            : #endif
#      11                 :            : 
#      12                 :            : #include <stdint.h>
#      13                 :            : #include <string.h>
#      14                 :            : 
#      15                 :            : #include <compat/endian.h>
#      16                 :            : 
#      17                 :            : uint16_t static inline ReadLE16(const unsigned char* ptr)
#      18                 :     313798 : {
#      19                 :     313798 :     uint16_t x;
#      20                 :     313798 :     memcpy((char*)&x, ptr, 2);
#      21                 :     313798 :     return le16toh(x);
#      22                 :     313798 : }
#      23                 :            : 
#      24                 :            : uint32_t static inline ReadLE32(const unsigned char* ptr)
#      25                 :  353891859 : {
#      26                 :  353891859 :     uint32_t x;
#      27                 :  353891859 :     memcpy((char*)&x, ptr, 4);
#      28                 :  353891859 :     return le32toh(x);
#      29                 :  353891859 : }
#      30                 :            : 
#      31                 :            : uint64_t static inline ReadLE64(const unsigned char* ptr)
#      32                 :   29320528 : {
#      33                 :   29320528 :     uint64_t x;
#      34                 :   29320528 :     memcpy((char*)&x, ptr, 8);
#      35                 :   29320528 :     return le64toh(x);
#      36                 :   29320528 : }
#      37                 :            : 
#      38                 :            : void static inline WriteLE16(unsigned char* ptr, uint16_t x)
#      39                 :        706 : {
#      40                 :        706 :     uint16_t v = htole16(x);
#      41                 :        706 :     memcpy(ptr, (char*)&v, 2);
#      42                 :        706 : }
#      43                 :            : 
#      44                 :            : void static inline WriteLE32(unsigned char* ptr, uint32_t x)
#      45                 :  142396963 : {
#      46                 :  142396963 :     uint32_t v = htole32(x);
#      47                 :  142396963 :     memcpy(ptr, (char*)&v, 4);
#      48                 :  142396963 : }
#      49                 :            : 
#      50                 :            : void static inline WriteLE64(unsigned char* ptr, uint64_t x)
#      51                 :   21931943 : {
#      52                 :   21931943 :     uint64_t v = htole64(x);
#      53                 :   21931943 :     memcpy(ptr, (char*)&v, 8);
#      54                 :   21931943 : }
#      55                 :            : 
#      56                 :            : uint16_t static inline ReadBE16(const unsigned char* ptr)
#      57                 :      14072 : {
#      58                 :      14072 :     uint16_t x;
#      59                 :      14072 :     memcpy((char*)&x, ptr, 2);
#      60                 :      14072 :     return be16toh(x);
#      61                 :      14072 : }
#      62                 :            : 
#      63                 :            : uint32_t static inline ReadBE32(const unsigned char* ptr)
#      64                 :  428108042 : {
#      65                 :  428108042 :     uint32_t x;
#      66                 :  428108042 :     memcpy((char*)&x, ptr, 4);
#      67                 :  428108042 :     return be32toh(x);
#      68                 :  428108042 : }
#      69                 :            : 
#      70                 :            : uint64_t static inline ReadBE64(const unsigned char* ptr)
#      71                 :  769263614 : {
#      72                 :  769263614 :     uint64_t x;
#      73                 :  769263614 :     memcpy((char*)&x, ptr, 8);
#      74                 :  769263614 :     return be64toh(x);
#      75                 :  769263614 : }
#      76                 :            : 
#      77                 :            : void static inline WriteBE32(unsigned char* ptr, uint32_t x)
#      78                 :  362406938 : {
#      79                 :  362406938 :     uint32_t v = htobe32(x);
#      80                 :  362406938 :     memcpy(ptr, (char*)&v, 4);
#      81                 :  362406938 : }
#      82                 :            : 
#      83                 :            : void static inline WriteBE64(unsigned char* ptr, uint64_t x)
#      84                 :  451053299 : {
#      85                 :  451053299 :     uint64_t v = htobe64(x);
#      86                 :  451053299 :     memcpy(ptr, (char*)&v, 8);
#      87                 :  451053299 : }
#      88                 :            : 
#      89                 :            : /** Return the smallest number n such that (x >> n) == 0 (or 64 if the highest bit in x is set. */
#      90                 :            : uint64_t static inline CountBits(uint64_t x)
#      91                 :   17278718 : {
#      92                 :   17278718 : #if HAVE_BUILTIN_CLZL
#      93                 :   17278718 :     if (sizeof(unsigned long) >= sizeof(uint64_t)) {
#      94 [ #  # ][ #  # ]:   17278718 :         return x ? 8 * sizeof(unsigned long) - __builtin_clzl(x) : 0;
#         [ #  # ][ #  # ]
#         [ +  + ][ #  # ]
#         [ #  # ][ #  # ]
#         [ #  # ][ #  # ]
#         [ #  # ][ #  # ]
#         [ #  # ][ #  # ]
#         [ +  + ][ #  # ]
#         [ #  # ][ #  # ]
#         [ #  # ][ +  - ]
#         [ #  # ][ #  # ]
#         [ #  # ][ #  # ]
#         [ +  - ][ +  + ]
#         [ #  # ][ #  # ]
#         [ #  # ][ #  # ]
#      95                 :   17278718 :     }
#      96                 :          0 : #endif
#      97                 :          0 : #if HAVE_BUILTIN_CLZLL
#      98                 :          0 :     if (sizeof(unsigned long long) >= sizeof(uint64_t)) {
#      99 [ #  # ][ #  # ]:          0 :         return x ? 8 * sizeof(unsigned long long) - __builtin_clzll(x) : 0;
#         [ #  # ][ #  # ]
#         [ #  # ][ #  # ]
#         [ #  # ][ #  # ]
#         [ #  # ][ #  # ]
#         [ #  # ][ #  # ]
#         [ #  # ][ #  # ]
#         [ #  # ][ #  # ]
#         [ #  # ][ #  # ]
#         [ #  # ][ #  # ]
#         [ #  # ][ #  # ]
#         [ #  # ][ #  # ]
#         [ #  # ][ #  # ]
#         [ #  # ][ #  # ]
#         [ #  # ][ #  # ]
#     100                 :          0 :     }
#     101                 :          0 : #endif
#     102                 :          0 :     int ret = 0;
#     103 [ #  # ][ #  # ]:          0 :     while (x) {
#         [ #  # ][ #  # ]
#         [ #  # ][ #  # ]
#         [ #  # ][ #  # ]
#         [ #  # ][ #  # ]
#         [ #  # ][ #  # ]
#         [ #  # ][ #  # ]
#         [ #  # ][ #  # ]
#         [ #  # ][ #  # ]
#         [ #  # ][ #  # ]
#         [ #  # ][ #  # ]
#         [ #  # ][ #  # ]
#         [ #  # ][ #  # ]
#         [ #  # ][ #  # ]
#         [ #  # ][ #  # ]
#     104                 :          0 :         x >>= 1;
#     105                 :          0 :         ++ret;
#     106                 :          0 :     }
#     107                 :          0 :     return ret;
#     108                 :          0 : }
#     109                 :            : 
#     110                 :            : #endif // BITCOIN_CRYPTO_COMMON_H

Generated by: LCOV version 0-eol-96201-ge66f56f4af6a