?? md32_common.h
字號:
# ifndef HOST_FETCH32# ifdef LE_FETCH32# define HOST_FETCH32(p,l) LE_FETCH32(p)# elif defined(REVERSE_FETCH32)# define HOST_FETCH32(p,l) REVERSE_FETCH32(p,l)# endif# endif# endif#elif defined(L_ENDIAN)# if defined(DATA_ORDER_IS_LITTLE_ENDIAN)# if !defined(HASH_BLOCK_DATA_ORDER_ALIGNED) && HASH_LONG_LOG2==2# define HASH_BLOCK_DATA_ORDER_ALIGNED HASH_BLOCK_HOST_ORDER# endif# elif defined(DATA_ORDER_IS_BIG_ENDIAN)# ifndef HOST_FETCH32# ifdef BE_FETCH32# define HOST_FETCH32(p,l) BE_FETCH32(p)# elif defined(REVERSE_FETCH32)# define HOST_FETCH32(p,l) REVERSE_FETCH32(p,l)# endif# endif# endif#endif#if !defined(HASH_BLOCK_DATA_ORDER_ALIGNED)#ifndef HASH_BLOCK_DATA_ORDER#error "HASH_BLOCK_DATA_ORDER must be defined!"#endif#endif#if defined(DATA_ORDER_IS_BIG_ENDIAN)#define HOST_c2l(c,l) (l =(((unsigned long)(*((c)++)))<<24), \ l|=(((unsigned long)(*((c)++)))<<16), \ l|=(((unsigned long)(*((c)++)))<< 8), \ l|=(((unsigned long)(*((c)++))) ), \ l)#define HOST_p_c2l(c,l,n) { \ switch (n) { \ case 0: l =((unsigned long)(*((c)++)))<<24; \ case 1: l|=((unsigned long)(*((c)++)))<<16; \ case 2: l|=((unsigned long)(*((c)++)))<< 8; \ case 3: l|=((unsigned long)(*((c)++))); \ } }#define HOST_p_c2l_p(c,l,sc,len) { \ switch (sc) { \ case 0: l =((unsigned long)(*((c)++)))<<24; \ if (--len == 0) break; \ case 1: l|=((unsigned long)(*((c)++)))<<16; \ if (--len == 0) break; \ case 2: l|=((unsigned long)(*((c)++)))<< 8; \ } }/* NOTE the pointer is not incremented at the end of this */#define HOST_c2l_p(c,l,n) { \ l=0; (c)+=n; \ switch (n) { \ case 3: l =((unsigned long)(*(--(c))))<< 8; \ case 2: l|=((unsigned long)(*(--(c))))<<16; \ case 1: l|=((unsigned long)(*(--(c))))<<24; \ } }#define HOST_l2c(l,c) (*((c)++)=(unsigned char)(((l)>>24)&0xff), \ *((c)++)=(unsigned char)(((l)>>16)&0xff), \ *((c)++)=(unsigned char)(((l)>> 8)&0xff), \ *((c)++)=(unsigned char)(((l) )&0xff), \ l)#elif defined(DATA_ORDER_IS_LITTLE_ENDIAN)#define HOST_c2l(c,l) (l =(((unsigned long)(*((c)++))) ), \ l|=(((unsigned long)(*((c)++)))<< 8), \ l|=(((unsigned long)(*((c)++)))<<16), \ l|=(((unsigned long)(*((c)++)))<<24), \ l)#define HOST_p_c2l(c,l,n) { \ switch (n) { \ case 0: l =((unsigned long)(*((c)++))); \ case 1: l|=((unsigned long)(*((c)++)))<< 8; \ case 2: l|=((unsigned long)(*((c)++)))<<16; \ case 3: l|=((unsigned long)(*((c)++)))<<24; \ } }#define HOST_p_c2l_p(c,l,sc,len) { \ switch (sc) { \ case 0: l =((unsigned long)(*((c)++))); \ if (--len == 0) break; \ case 1: l|=((unsigned long)(*((c)++)))<< 8; \ if (--len == 0) break; \ case 2: l|=((unsigned long)(*((c)++)))<<16; \ } }/* NOTE the pointer is not incremented at the end of this */#define HOST_c2l_p(c,l,n) { \ l=0; (c)+=n; \ switch (n) { \ case 3: l =((unsigned long)(*(--(c))))<<16; \ case 2: l|=((unsigned long)(*(--(c))))<< 8; \ case 1: l|=((unsigned long)(*(--(c)))); \ } }#define HOST_l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \ *((c)++)=(unsigned char)(((l)>> 8)&0xff), \ *((c)++)=(unsigned char)(((l)>>16)&0xff), \ *((c)++)=(unsigned char)(((l)>>24)&0xff), \ l)#endif/* * Time for some action:-) */void HASH_UPDATE (HASH_CTX *c, const void *data_, unsigned long len) { const unsigned char *data=data_; register HASH_LONG * p; register unsigned long l; int sw,sc,ew,ec; if (len==0) return; l=(c->Nl+(len<<3))&0xffffffffL; /* 95-05-24 eay Fixed a bug with the overflow handling, thanks to * Wei Dai <weidai@eskimo.com> for pointing it out. */ if (l < c->Nl) /* overflow */ c->Nh++; c->Nh+=(len>>29); c->Nl=l; if (c->num != 0) { p=c->data; sw=c->num>>2; sc=c->num&0x03; if ((c->num+len) >= HASH_CBLOCK) { l=p[sw]; HOST_p_c2l(data,l,sc); p[sw++]=l; for (; sw<HASH_LBLOCK; sw++) { HOST_c2l(data,l); p[sw]=l; } HASH_BLOCK_HOST_ORDER (c,p,1); len-=(HASH_CBLOCK-c->num); c->num=0; /* drop through and do the rest */ } else { c->num+=len; if ((sc+len) < 4) /* ugly, add char's to a word */ { l=p[sw]; HOST_p_c2l_p(data,l,sc,len); p[sw]=l; } else { ew=(c->num>>2); ec=(c->num&0x03); l=p[sw]; HOST_p_c2l(data,l,sc); p[sw++]=l; for (; sw < ew; sw++) { HOST_c2l(data,l); p[sw]=l; } if (ec) { HOST_c2l_p(data,l,ec); p[sw]=l; } } return; } } sw=len/HASH_CBLOCK; if (sw > 0) {#if defined(HASH_BLOCK_DATA_ORDER_ALIGNED) /* * Note that HASH_BLOCK_DATA_ORDER_ALIGNED gets defined * only if sizeof(HASH_LONG)==4. */ if ((((unsigned long)data)%4) == 0) { /* data is properly aligned so that we can cast it: */ HASH_BLOCK_DATA_ORDER_ALIGNED (c,(HASH_LONG *)data,sw); sw*=HASH_CBLOCK; data+=sw; len-=sw; } else#if !defined(HASH_BLOCK_DATA_ORDER) while (sw--) { memcpy (p=c->data,data,HASH_CBLOCK); HASH_BLOCK_DATA_ORDER_ALIGNED(c,p,1); data+=HASH_CBLOCK; len-=HASH_CBLOCK; }#endif#endif#if defined(HASH_BLOCK_DATA_ORDER) { HASH_BLOCK_DATA_ORDER(c,data,sw); sw*=HASH_CBLOCK; data+=sw; len-=sw; }#endif } if (len!=0) { p = c->data; c->num = len; ew=len>>2; /* words to copy */ ec=len&0x03; for (; ew; ew--,p++) { HOST_c2l(data,l); *p=l; } HOST_c2l_p(data,l,ec); *p=l; } }void HASH_TRANSFORM (HASH_CTX *c, const unsigned char *data) {#if defined(HASH_BLOCK_DATA_ORDER_ALIGNED) if ((((unsigned long)data)%4) == 0) /* data is properly aligned so that we can cast it: */ HASH_BLOCK_DATA_ORDER_ALIGNED (c,(HASH_LONG *)data,1); else#if !defined(HASH_BLOCK_DATA_ORDER) { memcpy (c->data,data,HASH_CBLOCK); HASH_BLOCK_DATA_ORDER_ALIGNED (c,c->data,1); }#endif#endif#if defined(HASH_BLOCK_DATA_ORDER) HASH_BLOCK_DATA_ORDER (c,data,1);#endif }void HASH_FINAL (unsigned char *md, HASH_CTX *c) { register HASH_LONG *p; register unsigned long l; register int i,j; static const unsigned char end[4]={0x80,0x00,0x00,0x00}; const unsigned char *cp=end; /* c->num should definitly have room for at least one more byte. */ p=c->data; i=c->num>>2; j=c->num&0x03;#if 0 /* purify often complains about the following line as an * Uninitialized Memory Read. While this can be true, the * following p_c2l macro will reset l when that case is true. * This is because j&0x03 contains the number of 'valid' bytes * already in p[i]. If and only if j&0x03 == 0, the UMR will * occur but this is also the only time p_c2l will do * l= *(cp++) instead of l|= *(cp++) * Many thanks to Alex Tang <altitude@cic.net> for pickup this * 'potential bug' */#ifdef PURIFY if (j==0) p[i]=0; /* Yeah, but that's not the way to fix it:-) */#endif l=p[i];#else l = (j==0) ? 0 : p[i];#endif HOST_p_c2l(cp,l,j); p[i++]=l; /* i is the next 'undefined word' */ if (i>(HASH_LBLOCK-2)) /* save room for Nl and Nh */ { if (i<HASH_LBLOCK) p[i]=0; HASH_BLOCK_HOST_ORDER (c,p,1); i=0; } for (; i<(HASH_LBLOCK-2); i++) p[i]=0;#if defined(DATA_ORDER_IS_BIG_ENDIAN) p[HASH_LBLOCK-2]=c->Nh; p[HASH_LBLOCK-1]=c->Nl;#elif defined(DATA_ORDER_IS_LITTLE_ENDIAN) p[HASH_LBLOCK-2]=c->Nl; p[HASH_LBLOCK-1]=c->Nh;#endif HASH_BLOCK_HOST_ORDER (c,p,1);#ifndef HASH_MAKE_STRING#error "HASH_MAKE_STRING must be defined!"#else HASH_MAKE_STRING(c,md);#endif c->num=0; /* clear stuff, HASH_BLOCK may be leaving some stuff on the stack * but I'm not worried :-) OPENSSL_cleanse((void *)c,sizeof(HASH_CTX)); */ }
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -