LCOV - code coverage report
Current view: top level - src/crypto - common.h (source / functions) Hit Total Coverage
Test: test_dash_coverage.info Lines: 38 38 100.0 %
Date: 2026-06-25 07:23:51 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        2627 : uint16_t static inline ReadLE16(const unsigned char* ptr)
      14             : {
      15             :     uint16_t x;
      16        2627 :     memcpy(&x, ptr, 2);
      17        2627 :     return le16toh_internal(x);
      18             : }
      19             : 
      20   320726178 : uint32_t static inline ReadLE32(const unsigned char* ptr)
      21             : {
      22             :     uint32_t x;
      23   320726178 :     memcpy(&x, ptr, 4);
      24   320726178 :     return le32toh_internal(x);
      25             : }
      26             : 
      27   275457270 : uint64_t static inline ReadLE64(const unsigned char* ptr)
      28             : {
      29             :     uint64_t x;
      30   275457270 :     memcpy(&x, ptr, 8);
      31   275457270 :     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   183822237 : void static inline WriteLE32(unsigned char* ptr, uint32_t x)
      41             : {
      42   183822237 :     uint32_t v = htole32_internal(x);
      43   183822237 :     memcpy(ptr, &v, 4);
      44   183822237 : }
      45             : 
      46     9769665 : void static inline WriteLE64(unsigned char* ptr, uint64_t x)
      47             : {
      48     9769665 :     uint64_t v = htole64_internal(x);
      49     9769665 :     memcpy(ptr, &v, 8);
      50     9769665 : }
      51             : 
      52        1368 : uint16_t static inline ReadBE16(const unsigned char* ptr)
      53             : {
      54             :     uint16_t x;
      55        1368 :     memcpy(&x, ptr, 2);
      56        1368 :     return be16toh_internal(x);
      57             : }
      58             : 
      59   175266445 : uint32_t static inline ReadBE32(const unsigned char* ptr)
      60             : {
      61             :     uint32_t x;
      62   175266445 :     memcpy(&x, ptr, 4);
      63   175266445 :     return be32toh_internal(x);
      64             : }
      65             : 
      66   232287616 : uint64_t static inline ReadBE64(const unsigned char* ptr)
      67             : {
      68             :     uint64_t x;
      69   232287616 :     memcpy(&x, ptr, 8);
      70   232287616 :     return be64toh_internal(x);
      71             : }
      72             : 
      73    41893369 : void static inline WriteBE32(unsigned char* ptr, uint32_t x)
      74             : {
      75    41893369 :     uint32_t v = htobe32_internal(x);
      76    41893369 :     memcpy(ptr, &v, 4);
      77    41893369 : }
      78             : 
      79   123950900 : void static inline WriteBE64(unsigned char* ptr, uint64_t x)
      80             : {
      81   123950900 :     uint64_t v = htobe64_internal(x);
      82   123950900 :     memcpy(ptr, &v, 8);
      83   123950900 : }
      84             : 
      85             : #endif // BITCOIN_CRYPTO_COMMON_H

Generated by: LCOV version 1.16