libcurl: updated to 7.49.0
[tomato.git] / release / src / router / libsodium / src / libsodium / crypto_pwhash / scryptsalsa208sha256 / sysendian.h
blob080aae8b8bbd8b9045a6a270aae8b3729863161b
1 #ifndef sysendian_H
2 #define sysendian_H
4 #include <stdint.h>
6 /* Avoid namespace collisions with BSD <sys/endian.h>. */
7 #define be16dec scrypt_be16dec
8 #define be16enc scrypt_be16enc
9 #define be32dec scrypt_be32dec
10 #define be32enc scrypt_be32enc
11 #define be64dec scrypt_be64dec
12 #define be64enc scrypt_be64enc
13 #define le16dec scrypt_le16dec
14 #define le16enc scrypt_le16enc
15 #define le32dec scrypt_le32dec
16 #define le32enc scrypt_le32enc
17 #define le64dec scrypt_le64dec
18 #define le64enc scrypt_le64enc
20 static inline uint16_t
21 be16dec(const void *pp)
23 const uint8_t *p = (uint8_t const *)pp;
25 return ((uint16_t)(p[1]) + ((uint16_t)(p[0]) << 8));
28 static inline void
29 be16enc(void *pp, uint16_t x)
31 uint8_t * p = (uint8_t *)pp;
33 p[1] = x & 0xff;
34 p[0] = (x >> 8) & 0xff;
37 static inline uint32_t
38 be32dec(const void *pp)
40 const uint8_t *p = (uint8_t const *)pp;
42 return ((uint32_t)(p[3]) + ((uint32_t)(p[2]) << 8) +
43 ((uint32_t)(p[1]) << 16) + ((uint32_t)(p[0]) << 24));
46 static inline void
47 be32enc(void *pp, uint32_t x)
49 uint8_t * p = (uint8_t *)pp;
51 p[3] = x & 0xff;
52 p[2] = (x >> 8) & 0xff;
53 p[1] = (x >> 16) & 0xff;
54 p[0] = (x >> 24) & 0xff;
57 static inline uint64_t
58 be64dec(const void *pp)
60 const uint8_t *p = (uint8_t const *)pp;
62 return ((uint64_t)(p[7]) + ((uint64_t)(p[6]) << 8) +
63 ((uint64_t)(p[5]) << 16) + ((uint64_t)(p[4]) << 24) +
64 ((uint64_t)(p[3]) << 32) + ((uint64_t)(p[2]) << 40) +
65 ((uint64_t)(p[1]) << 48) + ((uint64_t)(p[0]) << 56));
68 static inline void
69 be64enc(void *pp, uint64_t x)
71 uint8_t * p = (uint8_t *)pp;
73 p[7] = x & 0xff;
74 p[6] = (x >> 8) & 0xff;
75 p[5] = (x >> 16) & 0xff;
76 p[4] = (x >> 24) & 0xff;
77 p[3] = (x >> 32) & 0xff;
78 p[2] = (x >> 40) & 0xff;
79 p[1] = (x >> 48) & 0xff;
80 p[0] = (x >> 56) & 0xff;
83 static inline uint16_t
84 le16dec(const void *pp)
86 const uint8_t *p = (uint8_t const *)pp;
88 return ((uint16_t)(p[0]) + ((uint16_t)(p[1]) << 8));
91 static inline void
92 le16enc(void *pp, uint16_t x)
94 uint8_t * p = (uint8_t *)pp;
96 p[0] = x & 0xff;
97 p[1] = (x >> 8) & 0xff;
100 static inline uint32_t
101 le32dec(const void *pp)
103 const uint8_t *p = (uint8_t const *)pp;
105 return ((uint32_t)(p[0]) + ((uint32_t)(p[1]) << 8) +
106 ((uint32_t)(p[2]) << 16) + ((uint32_t)(p[3]) << 24));
109 static inline void
110 le32enc(void *pp, uint32_t x)
112 uint8_t * p = (uint8_t *)pp;
114 p[0] = x & 0xff;
115 p[1] = (x >> 8) & 0xff;
116 p[2] = (x >> 16) & 0xff;
117 p[3] = (x >> 24) & 0xff;
120 static inline uint64_t
121 le64dec(const void *pp)
123 const uint8_t *p = (uint8_t const *)pp;
125 return ((uint64_t)(p[0]) + ((uint64_t)(p[1]) << 8) +
126 ((uint64_t)(p[2]) << 16) + ((uint64_t)(p[3]) << 24) +
127 ((uint64_t)(p[4]) << 32) + ((uint64_t)(p[5]) << 40) +
128 ((uint64_t)(p[6]) << 48) + ((uint64_t)(p[7]) << 56));
131 static inline void
132 le64enc(void *pp, uint64_t x)
134 uint8_t * p = (uint8_t *)pp;
136 p[0] = x & 0xff;
137 p[1] = (x >> 8) & 0xff;
138 p[2] = (x >> 16) & 0xff;
139 p[3] = (x >> 24) & 0xff;
140 p[4] = (x >> 32) & 0xff;
141 p[5] = (x >> 40) & 0xff;
142 p[6] = (x >> 48) & 0xff;
143 p[7] = (x >> 56) & 0xff;
146 #endif /* !_SYSENDIAN_H_ */