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