LCOV - code coverage report
Current view: top level - src/crypto - common.h (source / functions) Hit Total Coverage
Test: total_coverage.info Lines: 38 38 100.0 %
Date: 2026-06-25 07:23:43 Functions: 11 11 100.0 %

          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        3041 : uint16_t static inline ReadLE16(const unsigned char* ptr)
      14             : {
      15             :     uint16_t x;
      16        3041 :     memcpy(&x, ptr, 2);
      17        3041 :     return le16toh_internal(x);
      18             : }
      19             : 
      20   706125224 : uint32_t static inline ReadLE32(const unsigned char* ptr)
      21             : {
      22             :     uint32_t x;
      23   706125224 :     memcpy(&x, ptr, 4);
      24   706125224 :     return le32toh_internal(x);
      25             : }
      26             : 
      27  1049959725 : uint64_t static inline ReadLE64(const unsigned char* ptr)
      28             : {
      29             :     uint64_t x;
      30  1049959725 :     memcpy(&x, ptr, 8);
      31  1049959725 :     return le64toh_internal(x);
      32             : }
      33             : 
      34         404 : void static inline WriteLE16(unsigned char* ptr, uint16_t x)
      35             : {
      36         404 :     uint16_t v = htole16_internal(x);
      37         404 :     memcpy(ptr, &v, 2);
      38         404 : }
      39             : 
      40   289251004 : void static inline WriteLE32(unsigned char* ptr, uint32_t x)
      41             : {
      42   289251004 :     uint32_t v = htole32_internal(x);
      43   289251004 :     memcpy(ptr, &v, 4);
      44   289251004 : }
      45             : 
      46    15233419 : void static inline WriteLE64(unsigned char* ptr, uint64_t x)
      47             : {
      48    15233419 :     uint64_t v = htole64_internal(x);
      49    15233419 :     memcpy(ptr, &v, 8);
      50    15233419 : }
      51             : 
      52      103344 : uint16_t static inline ReadBE16(const unsigned char* ptr)
      53             : {
      54             :     uint16_t x;
      55      103344 :     memcpy(&x, ptr, 2);
      56      103344 :     return be16toh_internal(x);
      57             : }
      58             : 
      59  4773056245 : uint32_t static inline ReadBE32(const unsigned char* ptr)
      60             : {
      61             :     uint32_t x;
      62  4773056245 :     memcpy(&x, ptr, 4);
      63  4773056245 :     return be32toh_internal(x);
      64             : }
      65             : 
      66  5217075994 : uint64_t static inline ReadBE64(const unsigned char* ptr)
      67             : {
      68             :     uint64_t x;
      69  5217075994 :     memcpy(&x, ptr, 8);
      70  5217075994 :     return be64toh_internal(x);
      71             : }
      72             : 
      73   261830855 : void static inline WriteBE32(unsigned char* ptr, uint32_t x)
      74             : {
      75   261830855 :     uint32_t v = htobe32_internal(x);
      76   261830855 :     memcpy(ptr, &v, 4);
      77   261830855 : }
      78             : 
      79  2825129766 : void static inline WriteBE64(unsigned char* ptr, uint64_t x)
      80             : {
      81  2825129766 :     uint64_t v = htobe64_internal(x);
      82  2825129766 :     memcpy(ptr, &v, 8);
      83  2825129766 : }
      84             : 
      85             : #endif // BITCOIN_CRYPTO_COMMON_H

Generated by: LCOV version 1.16