Line data Source code
1 : // Copyright (c) 2014 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 "bitcoin-config.h"
10 : #endif
11 :
12 : #include <stdint.h>
13 :
14 : #include "compat/endian.h"
15 :
16 : uint16_t static inline ReadLE16(const unsigned char* ptr)
17 : {
18 9048 : return le16toh(*((uint16_t*)ptr));
19 : }
20 :
21 : uint32_t static inline ReadLE32(const unsigned char* ptr)
22 : {
23 19991673 : return le32toh(*((uint32_t*)ptr));
24 : }
25 :
26 : uint64_t static inline ReadLE64(const unsigned char* ptr)
27 : {
28 : return le64toh(*((uint64_t*)ptr));
29 : }
30 :
31 : void static inline WriteLE16(unsigned char* ptr, uint16_t x)
32 : {
33 344 : *((uint16_t*)ptr) = htole16(x);
34 : }
35 :
36 : void static inline WriteLE32(unsigned char* ptr, uint32_t x)
37 : {
38 1442055 : *((uint32_t*)ptr) = htole32(x);
39 : }
40 :
41 : void static inline WriteLE64(unsigned char* ptr, uint64_t x)
42 : {
43 39819 : *((uint64_t*)ptr) = htole64(x);
44 : }
45 :
46 : uint32_t static inline ReadBE32(const unsigned char* ptr)
47 : {
48 103664276 : return be32toh(*((uint32_t*)ptr));
49 : }
50 :
51 : uint64_t static inline ReadBE64(const unsigned char* ptr)
52 : {
53 7880295 : return be64toh(*((uint64_t*)ptr));
54 : }
55 :
56 : void static inline WriteBE32(unsigned char* ptr, uint32_t x)
57 : {
58 17800159 : *((uint32_t*)ptr) = htobe32(x);
59 : }
60 :
61 : void static inline WriteBE64(unsigned char* ptr, uint64_t x)
62 : {
63 2306124 : *((uint64_t*)ptr) = htobe64(x);
64 : }
65 :
66 : #endif // BITCOIN_CRYPTO_COMMON_H
|