RSA BSAFE Micro Edition Suite

Streamlined security for mobile and embedded devices

Search  Print

r_endian.h

Go to the documentation of this file.
00001 /* $Id: r_endian.h,v 1.15 2003/05/23 05:20:29 sparki Exp $ */
00002 /*
00003  * Copyright (C) 1998-2003 RSA Security Inc. All rights reserved. 
00004  *
00005  * This work contains proprietary information of RSA Security. 
00006  * Distribution is limited to authorized licensees of RSA 
00007  * Security. Any unauthorized reproduction, distribution or 
00008  * modification of this work is strictly prohibited.
00009  */
00016 #ifndef HEADER_COMMON_R_ENDIAN_H
00017 #define HEADER_COMMON_R_ENDIAN_H
00018 
00019 #ifdef  __cplusplus
00020 extern "C" {
00021 #endif
00022 
00023 /* Basic operations defines */
00024 #define R_BYTE_SIZE                             8
00025 #define R_UINT8_SIZE                            1
00026 #define R_UINT16_SIZE                           2
00027 #define R_UINT32_SIZE                           4
00028 
00029 /* Some masks */
00030 #if defined(OPT_64_BIT)
00031 #define R_UINT8_MASK                            0x00000000000000ff
00032 #define R_UINT16_MASK                           0x000000000000ffff
00033 #define R_UINT32_MASK                           0x00000000ffffffff
00034 #elif defined(OPT_32_BIT)
00035 #define R_UINT8_MASK                            0x000000ff
00036 #define R_UINT16_MASK                           0x0000ffff
00037 #define R_UINT32_MASK                           0xffffffff
00038 #else /* !OPT_64_BIT && !OPT_32_BIT */
00039 #define R_UINT8_MASK                            0x00ff
00040 #define R_UINT16_MASK                           0xffff
00041 #define R_UINT32_MASK                           0xffffffffL
00042 #endif /* !OPT_64_BIT && !OPT_32_BIT */
00043 
00044 /* Read from and write to network defines */
00045 #define R_WRITE_UINT32(data,buf)                                        \
00046         *(buf++) = (char)((data>>24) & R_UINT8_MASK);                   \
00047         *(buf++) = (char)((data>>16) & R_UINT8_MASK);                   \
00048         *(buf++) = (char)((data>> 8) & R_UINT8_MASK);                   \
00049         *(buf++) = (char)((data    ) & R_UINT8_MASK);
00050 
00051 #define R_WRITE_UINT16(data,buf)                                        \
00052         *(buf++) = (char)((data>>8) & R_UINT8_MASK);                    \
00053         *(buf++) = (char)((data   ) & R_UINT8_MASK);
00054 
00055 #define R_WRITE_UINT8(data,buf)                                         \
00056         *(buf++) = (char)(data & R_UINT8_MASK);
00057 
00058 #define R_READ_UINT32(data,out)                                         \
00059         out = (int)(((unsigned char)data[0]));                          \
00060         out = (int)((out << R_BYTE_SIZE) | ((unsigned char)data[1]));   \
00061         out = (int)((out << R_BYTE_SIZE) | ((unsigned char)data[2]));   \
00062         out = (int)((out << R_BYTE_SIZE) | ((unsigned char)data[3]));
00063 
00064 #define R_READ_UINT16(data,out)                                         \
00065         out = (int)(((unsigned char)data[0]));                          \
00066         out = (int)((out << R_BYTE_SIZE) | ((unsigned char)data[1]));
00067 
00068 #define R_READ_UINT8(data,out)                                          \
00069         out = (int)(((unsigned char)data[0]) & R_UINT8_MASK);
00070 
00071 
00072 
00073 #ifdef  __cplusplus
00074 }
00075 #endif
00076 
00077 #endif  /* HEADER_COMMON_R_ENDIAN_H */
00078 

Copyright (c) 1999-2005 RSA Security Inc. All rights reserved. 072-001001-2100-001-000 - 2.1