comparison mycrypt_macros.h @ 89:cecb105ff479 libtomcrypt

Fix for big-endian load/store macros
author Matt Johnston <matt@ucc.asn.au>
date Fri, 03 Sep 2004 08:31:12 +0000
parents 901233045998
children 7ed585a2c53b
comparison
equal deleted inserted replaced
88:901233045998 89:cecb105ff479
123 123
124 #endif /* ENDIAN_LITTLE */ 124 #endif /* ENDIAN_LITTLE */
125 125
126 #ifdef ENDIAN_BIG 126 #ifdef ENDIAN_BIG
127 #define STORE32L(x, y) \ 127 #define STORE32L(x, y) \
128 { (y)[0] = (unsigned char)(((x)>>24)&255); (y)[1] = (unsigned char)(((x)>>16)&255); \ 128 { (y)[3] = (unsigned char)(((x)>>24)&255); (y)[2] = (unsigned char)(((x)>>16)&255); \
129 (y)[2] = (unsigned char)(((x)>>8)&255); (y)[3] = (unsigned char)((x)&255); } 129 (y)[1] = (unsigned char)(((x)>>8)&255); (y)[0] = (unsigned char)((x)&255); }
130 130
131 #define LOAD32L(x, y) \ 131 #define LOAD32L(x, y) \
132 { x = ((unsigned long)((y)[0] & 255)<<24) | \ 132 { x = ((unsigned long)((y)[3] & 255)<<24) | \
133 ((unsigned long)((y)[1] & 255)<<16) | \ 133 ((unsigned long)((y)[2] & 255)<<16) | \
134 ((unsigned long)((y)[2] & 255)<<8) | \ 134 ((unsigned long)((y)[1] & 255)<<8) | \
135 ((unsigned long)((y)[3] & 255)); } 135 ((unsigned long)((y)[0] & 255)); }
136 136
137 #define STORE64L(x, y) \ 137 #define STORE64L(x, y) \
138 { (y)[7] = (unsigned char)(((x)>>56)&255); (y)[6] = (unsigned char)(((x)>>48)&255); \
139 (y)[5] = (unsigned char)(((x)>>40)&255); (y)[4] = (unsigned char)(((x)>>32)&255); \
140 (y)[3] = (unsigned char)(((x)>>24)&255); (y)[2] = (unsigned char)(((x)>>16)&255); \
141 (y)[1] = (unsigned char)(((x)>>8)&255); (y)[0] = (unsigned char)((x)&255); }
142
143 #define LOAD64L(x, y) \
144 { x = (((ulong64)((y)[7] & 255))<<56)|(((ulong64)((y)[6] & 255))<<48)| \
145 (((ulong64)((y)[5] & 255))<<40)|(((ulong64)((y)[4] & 255))<<32)| \
146 (((ulong64)((y)[3] & 255))<<24)|(((ulong64)((y)[2] & 255))<<16)| \
147 (((ulong64)((y)[1] & 255))<<8)|(((ulong64)((y)[0] & 255))); }
148
149 #ifdef ENDIAN_32BITWORD
150
151 #define STORE32H(x, y) \
152 { unsigned long __t = (x); memcpy(y, &__t, 4); }
153
154 #define LOAD32H(x, y) \
155 memcpy(&(x), y, 4);
156
157 #define STORE64H(x, y) \
138 { (y)[0] = (unsigned char)(((x)>>56)&255); (y)[1] = (unsigned char)(((x)>>48)&255); \ 158 { (y)[0] = (unsigned char)(((x)>>56)&255); (y)[1] = (unsigned char)(((x)>>48)&255); \
139 (y)[2] = (unsigned char)(((x)>>40)&255); (y)[3] = (unsigned char)(((x)>>32)&255); \ 159 (y)[2] = (unsigned char)(((x)>>40)&255); (y)[3] = (unsigned char)(((x)>>32)&255); \
140 (y)[4] = (unsigned char)(((x)>>24)&255); (y)[5] = (unsigned char)(((x)>>16)&255); \ 160 (y)[4] = (unsigned char)(((x)>>24)&255); (y)[5] = (unsigned char)(((x)>>16)&255); \
141 (y)[6] = (unsigned char)(((x)>>8)&255); (y)[7] = (unsigned char)((x)&255); } 161 (y)[6] = (unsigned char)(((x)>>8)&255); (y)[7] = (unsigned char)((x)&255); }
142 162
143 #define LOAD64L(x, y) \ 163 #define LOAD64H(x, y) \
144 { x = (((ulong64)((y)[0] & 255))<<56)|(((ulong64)((y)[1] & 255))<<48) | \ 164 { x = (((ulong64)((y)[0] & 255))<<56)|(((ulong64)((y)[1] & 255))<<48) | \
145 (((ulong64)((y)[2] & 255))<<40)|(((ulong64)((y)[3] & 255))<<32) | \ 165 (((ulong64)((y)[2] & 255))<<40)|(((ulong64)((y)[3] & 255))<<32) | \
146 (((ulong64)((y)[4] & 255))<<24)|(((ulong64)((y)[5] & 255))<<16) | \ 166 (((ulong64)((y)[4] & 255))<<24)|(((ulong64)((y)[5] & 255))<<16) | \
147 (((ulong64)((y)[6] & 255))<<8)|(((ulong64)((y)[7] & 255))); } 167 (((ulong64)((y)[6] & 255))<<8)|(((ulong64)((y)[7] & 255))); }
148
149 #ifdef ENDIAN_32BITWORD
150
151 #define STORE32H(x, y) \
152 { unsigned long __t = (x); memcpy(y, &__t, 4); }
153
154 #define LOAD32H(x, y) \
155 memcpy(&(x), y, 4);
156
157 #define STORE64H(x, y) \
158 { (y)[7] = (unsigned char)(((x)>>56)&255); (y)[6] = (unsigned char)(((x)>>48)&255); \
159 (y)[5] = (unsigned char)(((x)>>40)&255); (y)[4] = (unsigned char)(((x)>>32)&255); \
160 (y)[3] = (unsigned char)(((x)>>24)&255); (y)[2] = (unsigned char)(((x)>>16)&255); \
161 (y)[1] = (unsigned char)(((x)>>8)&255); (y)[0] = (unsigned char)((x)&255); }
162
163 #define LOAD64H(x, y) \
164 { x = (((ulong64)((y)[7] & 255))<<56)|(((ulong64)((y)[6] & 255))<<48)| \
165 (((ulong64)((y)[5] & 255))<<40)|(((ulong64)((y)[4] & 255))<<32)| \
166 (((ulong64)((y)[3] & 255))<<24)|(((ulong64)((y)[2] & 255))<<16)| \
167 (((ulong64)((y)[1] & 255))<<8)|(((ulong64)((y)[0] & 255))); }
168 168
169 #else /* 64-bit words then */ 169 #else /* 64-bit words then */
170 170
171 #define STORE32H(x, y) \ 171 #define STORE32H(x, y) \
172 { unsigned long __t = (x); memcpy(y, &__t, 4); } 172 { unsigned long __t = (x); memcpy(y, &__t, 4); }