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