Annotation of truecrypt/common/endian.h, revision 1.1.1.12

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
        !             7:  this file are Copyright (c) 2003-2008 TrueCrypt Foundation and are governed
        !             8:  by the TrueCrypt License 2.4 the full text of which is contained in the
        !             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.12! root       15: #if defined(__cplusplus)
        !            16: extern "C"
        !            17: {
        !            18: #endif
        !            19: 
1.1.1.6   root       20: #ifdef _WIN32
                     21: 
                     22: #      ifndef LITTLE_ENDIAN
                     23: #              define LITTLE_ENDIAN 1234
                     24: #      endif
                     25: #      ifndef BYTE_ORDER
                     26: #              define BYTE_ORDER LITTLE_ENDIAN
                     27: #      endif
                     28: 
                     29: #elif !defined(BYTE_ORDER)
                     30: 
                     31: #      ifdef LINUX_DRIVER
                     32: #              include <asm/byteorder.h>
                     33: 
1.1.1.10  root       34: #              define LITTLE_ENDIAN 1234
                     35: #              define BIG_ENDIAN 4321
                     36: 
1.1.1.6   root       37: #              ifdef __LITTLE_ENDIAN
                     38: #                      define BYTE_ORDER LITTLE_ENDIAN
                     39: #              endif
                     40: 
                     41: #              ifdef __BIG_ENDIAN
                     42: #                      define BYTE_ORDER BIG_ENDIAN
                     43: #              endif
                     44: 
1.1.1.10  root       45: #              ifndef BYTE_ORDER
                     46: #                      error Byte order cannot be determined - kernel source not prepared for building of modules
                     47: #              endif
                     48: #      else
1.1.1.12! root       49: #              ifdef TC_MACOSX
        !            50: #                      include <machine/endian.h>
        !            51: #              elif defined (TC_BSD)
        !            52: #                      include <sys/endian.h>
        !            53: #              else
        !            54: #                      include <endian.h>
        !            55: #              endif
1.1.1.6   root       56: 
1.1.1.10  root       57: #              ifndef BYTE_ORDER
                     58: #                      ifndef __BYTE_ORDER
                     59: #                              error Byte order cannot be determined (BYTE_ORDER undefined)
                     60: #                      endif
1.1.1.6   root       61: 
1.1.1.10  root       62: #                      define BYTE_ORDER __BYTE_ORDER
                     63: #              endif
1.1.1.6   root       64: 
                     65: #              ifndef LITTLE_ENDIAN
                     66: #                      define LITTLE_ENDIAN __LITTLE_ENDIAN
                     67: #              endif
                     68: 
                     69: #              ifndef BIG_ENDIAN
                     70: #                      define BIG_ENDIAN __BIG_ENDIAN
                     71: #              endif
1.1.1.10  root       72: #      endif
1.1.1.4   root       73: 
1.1.1.6   root       74: #endif // !BYTE_ORDER
1.1.1.4   root       75: 
                     76: /* Macros to read and write 16, 32, and 64-bit quantities in a portable manner.
                     77:    These functions are implemented as macros rather than true functions as
                     78:    the need to adjust the memory pointers makes them somewhat painful to call
                     79:    in user code */
                     80: 
                     81: #define mputInt64(memPtr,data) \
                     82:        *memPtr++ = ( unsigned char ) ( ( ( data ) >> 56 ) & 0xFF ), \
                     83:        *memPtr++ = ( unsigned char ) ( ( ( data ) >> 48 ) & 0xFF ), \
                     84:        *memPtr++ = ( unsigned char ) ( ( ( data ) >> 40 ) & 0xFF ), \
                     85:        *memPtr++ = ( unsigned char ) ( ( ( data ) >> 32 ) & 0xFF ), \
                     86:        *memPtr++ = ( unsigned char ) ( ( ( data ) >> 24 ) & 0xFF ), \
                     87:        *memPtr++ = ( unsigned char ) ( ( ( data ) >> 16 ) & 0xFF ), \
                     88:        *memPtr++ = ( unsigned char ) ( ( ( data ) >> 8 ) & 0xFF ), \
                     89:        *memPtr++ = ( unsigned char ) ( ( data ) & 0xFF )
                     90: 
1.1       root       91: #define mputLong(memPtr,data) \
                     92:        *memPtr++ = ( unsigned char ) ( ( ( data ) >> 24 ) & 0xFF ), \
                     93:        *memPtr++ = ( unsigned char ) ( ( ( data ) >> 16 ) & 0xFF ), \
                     94:        *memPtr++ = ( unsigned char ) ( ( ( data ) >> 8 ) & 0xFF ), \
                     95:        *memPtr++ = ( unsigned char ) ( ( data ) & 0xFF )
                     96: 
                     97: #define mputWord(memPtr,data) \
                     98:        *memPtr++ = ( unsigned char ) ( ( ( data ) >> 8 ) & 0xFF ), \
                     99:        *memPtr++ = ( unsigned char ) ( ( data ) & 0xFF )
                    100: 
                    101: #define mputByte(memPtr,data)  \
                    102:        *memPtr++ = ( unsigned char ) data
                    103: 
                    104: #define mputBytes(memPtr,data,len)  \
                    105:        memcpy (memPtr,data,len); \
                    106:        memPtr += len;
                    107: 
1.1.1.4   root      108: #define mgetInt64(memPtr)              \
                    109:        ( memPtr += 8, ( ( unsigned __int64 ) memPtr[ -8 ] << 56 ) | ( ( unsigned __int64 ) memPtr[ -7 ] << 48 ) | \
                    110:        ( ( unsigned __int64 ) memPtr[ -6 ] << 40 ) | ( ( unsigned __int64 ) memPtr[ -5 ] << 32 ) | \
                    111:        ( ( unsigned __int64 ) memPtr[ -4 ] << 24 ) | ( ( unsigned __int64 ) memPtr[ -3 ] << 16 ) | \
                    112:          ( ( unsigned __int64 ) memPtr[ -2 ] << 8 ) | ( unsigned __int64 ) memPtr[ -1 ] )
                    113: 
1.1       root      114: #define mgetLong(memPtr)               \
1.1.1.6   root      115:        ( memPtr += 4, ( ( unsigned __int32 ) memPtr[ -4 ] << 24 ) | ( ( unsigned __int32 ) memPtr[ -3 ] << 16 ) | \
                    116:          ( ( unsigned __int32 ) memPtr[ -2 ] << 8 ) | ( unsigned __int32 ) memPtr[ -1 ] )
1.1       root      117: 
                    118: #define mgetWord(memPtr)               \
                    119:        ( memPtr += 2, ( unsigned short ) memPtr[ -2 ] << 8 ) | ( ( unsigned short ) memPtr[ -1 ] ) 
                    120: 
                    121: #define mgetByte(memPtr)               \
                    122:        ( ( unsigned char ) *memPtr++ )
                    123: 
1.1.1.6   root      124: #if BYTE_ORDER == BIG_ENDIAN
1.1.1.10  root      125: #      define LE16(x) MirrorBytes16(x)
1.1.1.6   root      126: #      define LE32(x) MirrorBytes32(x)
                    127: #      define LE64(x) MirrorBytes64(x)
                    128: #else
1.1.1.10  root      129: #      define LE16(x) (x)
1.1.1.6   root      130: #      define LE32(x) (x)
                    131: #      define LE64(x) (x)
                    132: #endif
                    133: 
1.1.1.7   root      134: #if BYTE_ORDER == LITTLE_ENDIAN
1.1.1.10  root      135: #      define BE16(x) MirrorBytes16(x)
1.1.1.7   root      136: #      define BE32(x) MirrorBytes32(x)
                    137: #      define BE64(x) MirrorBytes64(x)
                    138: #else
1.1.1.10  root      139: #      define BE16(x) (x)
1.1.1.7   root      140: #      define BE32(x) (x)
                    141: #      define BE64(x) (x)
                    142: #endif
                    143: 
1.1.1.10  root      144: unsigned __int16 MirrorBytes16 (unsigned __int16 x);
1.1.1.6   root      145: unsigned __int32 MirrorBytes32 (unsigned __int32 x);
1.1.1.12! root      146: #ifndef TC_NO_COMPILER_INT64
1.1.1.6   root      147: unsigned __int64 MirrorBytes64 (unsigned __int64 x);
1.1.1.12! root      148: #endif 
1.1.1.6   root      149: void LongReverse ( unsigned __int32 *buffer , unsigned byteCount );
1.1.1.8   root      150: 
1.1.1.12! root      151: #if defined(__cplusplus)
        !           152: }
        !           153: #endif
        !           154: 
1.1.1.8   root      155: #endif /* TC_ENDIAN_H */

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.