diff options
author | Mike Buland <eichlan@xagasoft.com> | 2012-05-22 15:45:16 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2012-05-22 15:45:16 +0000 |
commit | 690ad7280e655654a3bcca2ca5ced9caacf75c8b (patch) | |
tree | 970fe179ae503e0a86d1935218729da675fa62c5 | |
parent | e898d4911f05b143546ca2f49ce6931efafa17bc (diff) | |
download | libbu++-690ad7280e655654a3bcca2ca5ced9caacf75c8b.tar.gz libbu++-690ad7280e655654a3bcca2ca5ced9caacf75c8b.tar.bz2 libbu++-690ad7280e655654a3bcca2ca5ced9caacf75c8b.tar.xz libbu++-690ad7280e655654a3bcca2ca5ced9caacf75c8b.zip |
Added libbu++ endianness support. It's probably not as fast as system
endianness, but on gnu it'll use the libc versions, if you don't have those, at
least libbu++ will compile.
Diffstat (limited to '')
-rw-r--r-- | src/config.h | 111 | ||||
-rw-r--r-- | src/experimental/blowfish.h | 1 |
2 files changed, 107 insertions, 5 deletions
diff --git a/src/config.h b/src/config.h index 8a79166..fa304bb 100644 --- a/src/config.h +++ b/src/config.h | |||
@@ -18,13 +18,114 @@ | |||
18 | #include "bu/extratypes.h" | 18 | #include "bu/extratypes.h" |
19 | 19 | ||
20 | #ifndef WIN32 | 20 | #ifndef WIN32 |
21 | #include "bu/autoconfig.h" | 21 | # include "bu/autoconfig.h" |
22 | #else | 22 | #else |
23 | #define __LITTLE_ENDIAN 1234 | 23 | # define __LITTLE_ENDIAN 1234 |
24 | #define __BIG_ENDIAN 4321 | 24 | # define __BIG_ENDIAN 4321 |
25 | #define __PDP_ENDIAN 3412 | 25 | # define __PDP_ENDIAN 3412 |
26 | #define __BYTE_ORDER __LITTLE_ENDIAN | 26 | # define __BYTE_ORDER __LITTLE_ENDIAN |
27 | |||
28 | # ifndef LITTLE_ENDIAN | ||
29 | # define LITTLE_ENDIAN __LITTLE_ENDIAN | ||
30 | # endif | ||
31 | # ifndef BIG_ENDIAN | ||
32 | # define BIG_ENDIAN __BIG_ENDIAN | ||
33 | # endif | ||
34 | # ifndef PDP_ENDIAN | ||
35 | # define PDP_ENDIAN __PDP_ENDIAN | ||
36 | # endif | ||
37 | # ifndef BYTE_ORDER | ||
38 | # define BYTE_ORDER __BYTE_ORDER | ||
39 | # endif | ||
27 | #endif | 40 | #endif |
28 | 41 | ||
42 | // At this point the system endian.h should be included, but if it's missing | ||
43 | // an endian conversion macro, lets fix that now... | ||
44 | |||
45 | #define bu_byte_swap16(x) (((x&0xffu)<<8)|((x&0xff00u)>>8)) | ||
46 | #define bu_byte_swap32(x) (((x&0xfful)<<24)|((x&0xff00ul)<<8)|((x&0xff0000ul)>>8)|((x&0xff000000ul)>>24)) | ||
47 | #define bu_byte_swap64(x) (((x&0xffull)<<56)|((x&0xff00ull)<<40)|((x&0xff0000ull)<<24)|((x&0xff000000ull)<<8)|((x&0xff00000000000000ull)>>56)|((x&0xff000000000000ull)>>40)|((x&0xff0000000000ull)>>24)|((x&0xff00000000ull)>>8)) | ||
48 | |||
49 | #if BYTE_ORDER == LITTLE_ENDIAN | ||
50 | # ifndef htobe16 | ||
51 | # define htobe16(x) bu_byte_swap16(x) | ||
52 | # endif | ||
53 | # ifndef htole16 | ||
54 | # define htole16(x) (x) | ||
55 | # endif | ||
56 | # ifndef be16toh | ||
57 | # define be16toh(x) bu_byte_swap16(x) | ||
58 | # endif | ||
59 | # ifndef le16toh | ||
60 | # define le16toh(x) (x) | ||
61 | # endif | ||
62 | |||
63 | # ifndef htobe32 | ||
64 | # define htobe32(x) bu_byte_swap32(x) | ||
65 | # endif | ||
66 | # ifndef htole32 | ||
67 | # define htole32(x) (x) | ||
68 | # endif | ||
69 | # ifndef be32toh | ||
70 | # define be32toh(x) bu_byte_swap32(x) | ||
71 | # endif | ||
72 | # ifndef le32toh | ||
73 | # define le32toh(x) (x) | ||
74 | # endif | ||
75 | |||
76 | # ifndef htobe64 | ||
77 | # define htobe64(x) bu_byte_swap64(x) | ||
78 | # endif | ||
79 | # ifndef htole64 | ||
80 | # define htole64(x) (x) | ||
81 | # endif | ||
82 | # ifndef be64toh | ||
83 | # define be64toh(x) bu_byte_swap64(x) | ||
84 | # endif | ||
85 | # ifndef le64toh | ||
86 | # define le64toh(x) (x) | ||
87 | # endif | ||
88 | #elif BYTE_ORDER == BIG_ENDIAN | ||
89 | # ifndef htole16 | ||
90 | # define htole16(x) bu_byte_swap16(x) | ||
91 | # endif | ||
92 | # ifndef htobe16 | ||
93 | # define htobe16(x) (x) | ||
94 | # endif | ||
95 | # ifndef le16toh | ||
96 | # define le16toh(x) bu_byte_swap16(x) | ||
97 | # endif | ||
98 | # ifndef be16toh | ||
99 | # define be16toh(x) (x) | ||
100 | # endif | ||
101 | |||
102 | # ifndef htole32 | ||
103 | # define htole32(x) bu_byte_swap32(x) | ||
104 | # endif | ||
105 | # ifndef htobe32 | ||
106 | # define htobe32(x) (x) | ||
107 | # endif | ||
108 | # ifndef le32toh | ||
109 | # define le32toh(x) bu_byte_swap32(x) | ||
110 | # endif | ||
111 | # ifndef be32toh | ||
112 | # define be32toh(x) (x) | ||
113 | # endif | ||
114 | |||
115 | # ifndef htole64 | ||
116 | # define htole64(x) bu_byte_swap64(x) | ||
117 | # endif | ||
118 | # ifndef htobe64 | ||
119 | # define htobe64(x) (x) | ||
120 | # endif | ||
121 | # ifndef le64toh | ||
122 | # define le64toh(x) bu_byte_swap64(x) | ||
123 | # endif | ||
124 | # ifndef be64toh | ||
125 | # define be64toh(x) (x) | ||
126 | # endif | ||
127 | #else | ||
128 | #error Unhandled endianness detected | ||
129 | #endif | ||
29 | 130 | ||
30 | #endif | 131 | #endif |
diff --git a/src/experimental/blowfish.h b/src/experimental/blowfish.h index 7e816ca..c2a8be5 100644 --- a/src/experimental/blowfish.h +++ b/src/experimental/blowfish.h | |||
@@ -8,6 +8,7 @@ | |||
8 | #ifndef BU_BLOWFISH_H | 8 | #ifndef BU_BLOWFISH_H |
9 | #define BU_BLOWFISH_H | 9 | #define BU_BLOWFISH_H |
10 | 10 | ||
11 | #include "bu/config.h" | ||
11 | #include "bu/cipher.h" | 12 | #include "bu/cipher.h" |
12 | 13 | ||
13 | #include "bu/ciphermodeecb.h" | 14 | #include "bu/ciphermodeecb.h" |