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