131 #if defined( _MSC_VER )
132 #pragma warning( disable: 4311 )
135 #if !defined(DATA_ORDER_IS_BIG_ENDIAN) && !defined(DATA_ORDER_IS_LITTLE_ENDIAN)
136 #error "DATA_ORDER must be defined!"
140 #error "HASH_CBLOCK must be defined!"
143 #error "HASH_LONG must be defined!"
146 #error "HASH_CTX must be defined!"
150 #error "HASH_UPDATE must be defined!"
152 #ifndef HASH_TRANSFORM
153 #error "HASH_TRANSFORM must be defined!"
156 #error "HASH_FINAL must be defined!"
159 #ifndef HASH_BLOCK_HOST_ORDER
160 #error "HASH_BLOCK_HOST_ORDER must be defined!"
168 #ifndef HASH_BLOCK_DATA_ORDER
169 #error "HASH_BLOCK_DATA_ORDER must be defined!"
174 #define HASH_LBLOCK (HASH_CBLOCK/4)
177 #ifndef HASH_LONG_LOG2
178 #define HASH_LONG_LOG2 2
186 # if defined(_MSC_VER) || defined( __BORLANDC__ )
187 # define ROTATE(a,n) _lrotl(a,n)
188 # elif defined(__MWERKS__)
189 # if defined(__POWERPC__)
190 # define ROTATE(a,n) __rlwinm(a,n,0,31)
191 # elif defined(__MC68K__)
193 # define ROTATE(a,n) ( n<24 ? __rol(a,n) : __ror(a,32-n) )
195 # define ROTATE(a,n) __rol(a,n)
197 # elif defined(__GNUC__) && __GNUC__>=2 && !defined(NO_ASM) && !defined(NO_INLINE_ASM)
205 # if defined(__i386) || defined(__i386__)
206 # define ROTATE(a,n) ({ register unsigned int ret; \
214 # elif defined(__powerpc) || defined(__ppc)
215 # define ROTATE(a,n) ({ register unsigned int ret; \
217 "rlwinm %0,%1,%2,0,31" \
229 # if defined(__GNUC__) && __GNUC__>=2 && !defined(NO_ASM) && !defined(NO_INLINE_ASM)
231 # if (defined(__i386) || defined(__i386__)) && !defined(I386_ONLY)
232 # define BE_FETCH32(a) ({ register unsigned int l=(a);\
235 : "=r"(l) : "0"(l)); \
238 # elif defined(__powerpc)
239 # define LE_FETCH32(a) ({ register unsigned int l; \
247 # elif defined(__sparc) && defined(ULTRASPARC)
248 # define LE_FETCH32(a) ({ register unsigned int l; \
250 "lda [%1]#ASI_PRIMARY_LITTLE,%0"\
259 #if HASH_LONG_LOG2==2
263 #define REVERSE_FETCH32(a,l) ( \
264 l=*(const HASH_LONG *)(a), \
265 ((ROTATE(l,8)&0x00FF00FF)|(ROTATE((l&0x00FF00FF),24))) \
269 #define REVERSE_FETCH32(a,l) ( \
270 l=*(const HASH_LONG *)(a), \
271 l=(((l>>8)&0x00FF00FF)|((l&0x00FF00FF)<<8)), \
292 #define ROTATE(a,n) (((a)<<(n))|(((a)&0xffffffff)>>(32-(n))))
303 #if defined(B_ENDIAN)
304 # if defined(DATA_ORDER_IS_BIG_ENDIAN)
305 # if !defined(HASH_BLOCK_DATA_ORDER_ALIGNED) && HASH_LONG_LOG2==2
306 # define HASH_BLOCK_DATA_ORDER_ALIGNED HASH_BLOCK_HOST_ORDER
308 # elif defined(DATA_ORDER_IS_LITTLE_ENDIAN)
309 # ifndef HOST_FETCH32
311 # define HOST_FETCH32(p,l) LE_FETCH32(p)
312 # elif defined(REVERSE_FETCH32)
313 # define HOST_FETCH32(p,l) REVERSE_FETCH32(p,l)
317 #elif defined(L_ENDIAN)
318 # if defined(DATA_ORDER_IS_LITTLE_ENDIAN)
319 # if !defined(HASH_BLOCK_DATA_ORDER_ALIGNED) && HASH_LONG_LOG2==2
320 # define HASH_BLOCK_DATA_ORDER_ALIGNED HASH_BLOCK_HOST_ORDER
322 # elif defined(DATA_ORDER_IS_BIG_ENDIAN)
323 # ifndef HOST_FETCH32
325 # define HOST_FETCH32(p,l) BE_FETCH32(p)
326 # elif defined(REVERSE_FETCH32)
327 # define HOST_FETCH32(p,l) REVERSE_FETCH32(p,l)
333 #if !defined(HASH_BLOCK_DATA_ORDER_ALIGNED)
334 #ifndef HASH_BLOCK_DATA_ORDER
335 #error "HASH_BLOCK_DATA_ORDER must be defined!"
339 #if defined(DATA_ORDER_IS_BIG_ENDIAN)
341 #define HOST_c2l(c,l) (l =(((unsigned long)(*((c)++)))<<24), \
342 l|=(((unsigned long)(*((c)++)))<<16), \
343 l|=(((unsigned long)(*((c)++)))<< 8), \
344 l|=(((unsigned long)(*((c)++))) ), \
346 #define HOST_p_c2l(c,l,n) { \
348 case 0: l =((unsigned long)(*((c)++)))<<24; \
349 case 1: l|=((unsigned long)(*((c)++)))<<16; \
350 case 2: l|=((unsigned long)(*((c)++)))<< 8; \
351 case 3: l|=((unsigned long)(*((c)++))); \
353 #define HOST_p_c2l_p(c,l,sc,len) { \
355 case 0: l =((unsigned long)(*((c)++)))<<24; \
356 if (--len == 0) break; \
357 case 1: l|=((unsigned long)(*((c)++)))<<16; \
358 if (--len == 0) break; \
359 case 2: l|=((unsigned long)(*((c)++)))<< 8; \
362 #define HOST_c2l_p(c,l,n) { \
365 case 3: l =((unsigned long)(*(--(c))))<< 8; \
366 case 2: l|=((unsigned long)(*(--(c))))<<16; \
367 case 1: l|=((unsigned long)(*(--(c))))<<24; \
369 #define HOST_l2c(l,c) (*((c)++)=(unsigned char)(((l)>>24)&0xff), \
370 *((c)++)=(unsigned char)(((l)>>16)&0xff), \
371 *((c)++)=(unsigned char)(((l)>> 8)&0xff), \
372 *((c)++)=(unsigned char)(((l) )&0xff), \
375 #elif defined(DATA_ORDER_IS_LITTLE_ENDIAN)
377 #define HOST_c2l(c,l) (l =(((unsigned long)(*((c)++))) ), \
378 l|=(((unsigned long)(*((c)++)))<< 8), \
379 l|=(((unsigned long)(*((c)++)))<<16), \
380 l|=(((unsigned long)(*((c)++)))<<24), \
382 #define HOST_p_c2l(c,l,n) { \
384 case 0: l =((unsigned long)(*((c)++))); \
385 case 1: l|=((unsigned long)(*((c)++)))<< 8; \
386 case 2: l|=((unsigned long)(*((c)++)))<<16; \
387 case 3: l|=((unsigned long)(*((c)++)))<<24; \
389 #define HOST_p_c2l_p(c,l,sc,len) { \
391 case 0: l =((unsigned long)(*((c)++))); \
392 if (--len == 0) break; \
393 case 1: l|=((unsigned long)(*((c)++)))<< 8; \
394 if (--len == 0) break; \
395 case 2: l|=((unsigned long)(*((c)++)))<<16; \
398 #define HOST_c2l_p(c,l,n) { \
401 case 3: l =((unsigned long)(*(--(c))))<<16; \
402 case 2: l|=((unsigned long)(*(--(c))))<< 8; \
403 case 1: l|=((unsigned long)(*(--(c)))); \
405 #define HOST_l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \
406 *((c)++)=(unsigned char)(((l)>> 8)&0xff), \
407 *((c)++)=(unsigned char)(((l)>>16)&0xff), \
408 *((c)++)=(unsigned char)(((l)>>24)&0xff), \
419 const unsigned char *
data=data_;
421 register unsigned long l;
426 l=(c->Nl+(len<<3))&0xffffffffL;
442 l=p[sw]; HOST_p_c2l(data,l,sc); p[sw++]=l;
445 HOST_c2l(data,l); p[sw]=l;
457 l=p[sw]; HOST_p_c2l_p(data,l,sc,len); p[sw]=l;
463 l=p[sw]; HOST_p_c2l(data,l,sc); p[sw++]=l;
464 for (; sw < ew; sw++)
466 HOST_c2l(data,l); p[sw]=l;
470 HOST_c2l_p(data,l,ec); p[sw]=l;
480 #if defined(HASH_BLOCK_DATA_ORDER_ALIGNED)
488 #if defined( _WIN32 ) && defined( _M_X64 )
489 if ((((__int64)data)%4) == 0)
491 if ((((
unsigned long)data)%4) == 0)
495 HASH_BLOCK_DATA_ORDER_ALIGNED (c,(
HASH_LONG *)data,sw);
501 #if !defined(HASH_BLOCK_DATA_ORDER)
505 HASH_BLOCK_DATA_ORDER_ALIGNED(c,p,1);
511 #if defined(HASH_BLOCK_DATA_ORDER)
529 HOST_c2l(data,l); *p=l;
531 HOST_c2l_p(data,l,ec);
539 #if defined(HASH_BLOCK_DATA_ORDER_ALIGNED)
540 if ((((
unsigned long)data)%4) == 0)
542 HASH_BLOCK_DATA_ORDER_ALIGNED (c,(
HASH_LONG *)data,1);
544 #if !defined(HASH_BLOCK_DATA_ORDER)
547 HASH_BLOCK_DATA_ORDER_ALIGNED (c,c->data,1);
551 #if defined(HASH_BLOCK_DATA_ORDER)
560 register unsigned long l;
562 static const unsigned char end[4]={0x80,0x00,0x00,0x00};
563 const unsigned char *cp=end;
585 l = (j==0) ? 0 : p[i];
587 HOST_p_c2l(cp,l,j); p[i++]=l;
598 #if defined(DATA_ORDER_IS_BIG_ENDIAN)
601 #elif defined(DATA_ORDER_IS_LITTLE_ENDIAN)
607 #ifndef HASH_MAKE_STRING
608 #error "HASH_MAKE_STRING must be defined!"