|
|
1.1.1.10 root 1: /*
1.1.1.12 root 2: Legal Notice: Some portions of the source code contained in this file were
3: derived from the source code of Encryption for the Masses 2.02a, which is
4: Copyright (c) 1998-2000 Paul Le Roux and which is governed by the 'License
5: Agreement for Encryption for the Masses'. Modifications and additions to
6: the original source code (contained in this file) and all other portions of
1.1.1.16 root 7: this file are Copyright (c) 2003-2009 TrueCrypt Foundation and are governed
1.1.1.17! root 8: by the TrueCrypt License 2.7 the full text of which is contained in the
1.1.1.12 root 9: file License.txt included in TrueCrypt binary and source code distribution
1.1.1.10 root 10: packages. */
1.1.1.6 root 11:
1.1.1.8 root 12: #ifndef TC_ENDIAN_H
13: #define TC_ENDIAN_H
14:
1.1.1.16 root 15: #include "Common/Tcdefs.h"
16:
1.1.1.12 root 17: #if defined(__cplusplus)
18: extern "C"
19: {
20: #endif
21:
1.1.1.6 root 22: #ifdef _WIN32
23:
24: # ifndef LITTLE_ENDIAN
25: # define LITTLE_ENDIAN 1234
26: # endif
27: # ifndef BYTE_ORDER
28: # define BYTE_ORDER LITTLE_ENDIAN
29: # endif
30:
31: #elif !defined(BYTE_ORDER)
32:
1.1.1.13 root 33: # ifdef TC_MACOSX
34: # include <machine/endian.h>
35: # elif defined (TC_BSD)
36: # include <sys/endian.h>
1.1.1.16 root 37: # elif defined (TC_SOLARIS)
38: # include <sys/types.h>
39: # define LITTLE_ENDIAN 1234
40: # define BIG_ENDIAN 4321
41: # ifdef _BIG_ENDIAN
42: # define BYTE_ORDER BIG_ENDIAN
43: # else
44: # define BYTE_ORDER LITTLE_ENDIAN
45: # endif
1.1.1.10 root 46: # else
1.1.1.13 root 47: # include <endian.h>
48: # endif
1.1.1.6 root 49:
1.1.1.13 root 50: # ifndef BYTE_ORDER
51: # ifndef __BYTE_ORDER
52: # error Byte order cannot be determined (BYTE_ORDER undefined)
1.1.1.10 root 53: # endif
1.1.1.6 root 54:
1.1.1.13 root 55: # define BYTE_ORDER __BYTE_ORDER
56: # endif
1.1.1.6 root 57:
1.1.1.13 root 58: # ifndef LITTLE_ENDIAN
59: # define LITTLE_ENDIAN __LITTLE_ENDIAN
60: # endif
61:
62: # ifndef BIG_ENDIAN
63: # define BIG_ENDIAN __BIG_ENDIAN
1.1.1.10 root 64: # endif
1.1.1.4 root 65:
1.1.1.6 root 66: #endif // !BYTE_ORDER
1.1.1.4 root 67:
68: /* Macros to read and write 16, 32, and 64-bit quantities in a portable manner.
69: These functions are implemented as macros rather than true functions as
70: the need to adjust the memory pointers makes them somewhat painful to call
71: in user code */
72:
73: #define mputInt64(memPtr,data) \
74: *memPtr++ = ( unsigned char ) ( ( ( data ) >> 56 ) & 0xFF ), \
75: *memPtr++ = ( unsigned char ) ( ( ( data ) >> 48 ) & 0xFF ), \
76: *memPtr++ = ( unsigned char ) ( ( ( data ) >> 40 ) & 0xFF ), \
77: *memPtr++ = ( unsigned char ) ( ( ( data ) >> 32 ) & 0xFF ), \
78: *memPtr++ = ( unsigned char ) ( ( ( data ) >> 24 ) & 0xFF ), \
79: *memPtr++ = ( unsigned char ) ( ( ( data ) >> 16 ) & 0xFF ), \
80: *memPtr++ = ( unsigned char ) ( ( ( data ) >> 8 ) & 0xFF ), \
81: *memPtr++ = ( unsigned char ) ( ( data ) & 0xFF )
82:
1.1 root 83: #define mputLong(memPtr,data) \
84: *memPtr++ = ( unsigned char ) ( ( ( data ) >> 24 ) & 0xFF ), \
85: *memPtr++ = ( unsigned char ) ( ( ( data ) >> 16 ) & 0xFF ), \
86: *memPtr++ = ( unsigned char ) ( ( ( data ) >> 8 ) & 0xFF ), \
87: *memPtr++ = ( unsigned char ) ( ( data ) & 0xFF )
88:
89: #define mputWord(memPtr,data) \
90: *memPtr++ = ( unsigned char ) ( ( ( data ) >> 8 ) & 0xFF ), \
91: *memPtr++ = ( unsigned char ) ( ( data ) & 0xFF )
92:
93: #define mputByte(memPtr,data) \
94: *memPtr++ = ( unsigned char ) data
95:
96: #define mputBytes(memPtr,data,len) \
97: memcpy (memPtr,data,len); \
98: memPtr += len;
99:
1.1.1.4 root 100: #define mgetInt64(memPtr) \
101: ( memPtr += 8, ( ( unsigned __int64 ) memPtr[ -8 ] << 56 ) | ( ( unsigned __int64 ) memPtr[ -7 ] << 48 ) | \
102: ( ( unsigned __int64 ) memPtr[ -6 ] << 40 ) | ( ( unsigned __int64 ) memPtr[ -5 ] << 32 ) | \
103: ( ( unsigned __int64 ) memPtr[ -4 ] << 24 ) | ( ( unsigned __int64 ) memPtr[ -3 ] << 16 ) | \
104: ( ( unsigned __int64 ) memPtr[ -2 ] << 8 ) | ( unsigned __int64 ) memPtr[ -1 ] )
105:
1.1 root 106: #define mgetLong(memPtr) \
1.1.1.6 root 107: ( memPtr += 4, ( ( unsigned __int32 ) memPtr[ -4 ] << 24 ) | ( ( unsigned __int32 ) memPtr[ -3 ] << 16 ) | \
108: ( ( unsigned __int32 ) memPtr[ -2 ] << 8 ) | ( unsigned __int32 ) memPtr[ -1 ] )
1.1 root 109:
110: #define mgetWord(memPtr) \
111: ( memPtr += 2, ( unsigned short ) memPtr[ -2 ] << 8 ) | ( ( unsigned short ) memPtr[ -1 ] )
112:
113: #define mgetByte(memPtr) \
114: ( ( unsigned char ) *memPtr++ )
115:
1.1.1.6 root 116: #if BYTE_ORDER == BIG_ENDIAN
1.1.1.10 root 117: # define LE16(x) MirrorBytes16(x)
1.1.1.6 root 118: # define LE32(x) MirrorBytes32(x)
119: # define LE64(x) MirrorBytes64(x)
120: #else
1.1.1.10 root 121: # define LE16(x) (x)
1.1.1.6 root 122: # define LE32(x) (x)
123: # define LE64(x) (x)
124: #endif
125:
1.1.1.7 root 126: #if BYTE_ORDER == LITTLE_ENDIAN
1.1.1.10 root 127: # define BE16(x) MirrorBytes16(x)
1.1.1.7 root 128: # define BE32(x) MirrorBytes32(x)
129: # define BE64(x) MirrorBytes64(x)
130: #else
1.1.1.10 root 131: # define BE16(x) (x)
1.1.1.7 root 132: # define BE32(x) (x)
133: # define BE64(x) (x)
134: #endif
135:
1.1.1.10 root 136: unsigned __int16 MirrorBytes16 (unsigned __int16 x);
1.1.1.6 root 137: unsigned __int32 MirrorBytes32 (unsigned __int32 x);
1.1.1.12 root 138: #ifndef TC_NO_COMPILER_INT64
1.1.1.16 root 139: uint64 MirrorBytes64 (uint64 x);
1.1.1.12 root 140: #endif
1.1.1.6 root 141: void LongReverse ( unsigned __int32 *buffer , unsigned byteCount );
1.1.1.8 root 142:
1.1.1.12 root 143: #if defined(__cplusplus)
144: }
145: #endif
146:
1.1.1.8 root 147: #endif /* TC_ENDIAN_H */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.