?? md5.c
字號:
HH( b, c, d, a, in[ 6], S34, 76029189UL); /* 44 */ HH( a, b, c, d, in[ 9], S31, 3654602809UL); /* 45 */ HH( d, a, b, c, in[12], S32, 3873151461UL); /* 46 */ HH( c, d, a, b, in[15], S33, 530742520UL); /* 47 */ HH( b, c, d, a, in[ 2], S34, 3299628645UL); /* 48 */ /* Round 4 */ II( a, b, c, d, in[ 0], S41, 4096336452UL); /* 49 */ II( d, a, b, c, in[ 7], S42, 1126891415UL); /* 50 */ II( c, d, a, b, in[14], S43, 2878612391UL); /* 51 */ II( b, c, d, a, in[ 5], S44, 4237533241UL); /* 52 */ II( a, b, c, d, in[12], S41, 1700485571UL); /* 53 */ II( d, a, b, c, in[ 3], S42, 2399980690UL); /* 54 */ II( c, d, a, b, in[10], S43, 4293915773UL); /* 55 */ II( b, c, d, a, in[ 1], S44, 2240044497UL); /* 56 */ II( a, b, c, d, in[ 8], S41, 1873313359UL); /* 57 */ II( d, a, b, c, in[15], S42, 4264355552UL); /* 58 */ II( c, d, a, b, in[ 6], S43, 2734768916UL); /* 59 */ II( b, c, d, a, in[13], S44, 1309151649UL); /* 60 */ II( a, b, c, d, in[ 4], S41, 4149444226UL); /* 61 */ II( d, a, b, c, in[11], S42, 3174756917UL); /* 62 */ II( c, d, a, b, in[ 2], S43, 718787259UL); /* 63 */ II( b, c, d, a, in[ 9], S44, 3951481745UL); /* 64 */ digest[0] += a; digest[1] += b; digest[2] += c; digest[3] += d;}/* * MD5_chkpt - checkpoint a MD5 state * * given: * state the state to checkpoint * * This function will ensure that the the hash chunk buffer is empty. * Any partially hashed data will be padded out with 0's and hashed. */static voidMD5_chkpt(HASH *state){ MD5_CTX *dig = &state->h_union.h_md5; /* digest state */#if CALC_BYTE_ORDER == BIG_ENDIAN int cnt;#endif /* * checkpoint if partial buffer exists */ if (dig->datalen > 0) { /* pad to the end of the chunk */ memset((USB8 *)dig->data + dig->datalen, 0, MD5_CHUNKSIZE-dig->datalen);#if CALC_BYTE_ORDER == BIG_ENDIAN if (state->bytes) { /* byte swap data into little endian order */ for (cnt=0; cnt < (int)MD5_CHUNKWORDS; ++cnt) { SWAP_B8_IN_B32(dig->data + cnt, dig->data + cnt); } }#endif /* transform padded chunk */ MD5Transform((USB32*)dig->digest, dig->data); MD5COUNT(dig, MD5_CHUNKSIZE-dig->datalen); /* empty buffer */ dig->datalen = 0; }}/* * MD5_note - note a special value * * given: * state the state to hash * special a special value (MD5_HASH_XYZ) to note * * This function will note that a special value is about to be hashed. * Types include negative values, complex values, division, zero numeric * and array of HALFs. */static voidMD5_note(int special, HASH *state){ MD5_CTX *dig = &state->h_union.h_md5; /* digest state */ unsigned int i; /* * change state to reflect a special value */ dig->digest[0] ^= special; for (i=1; i < MD5_DIGESTWORDS; ++i) { dig->digest[i] ^= (special + dig->digest[i-1] + i); } return;}/* * MD5_type - note a VALUE type * * given: * state the state to hash * type the VALUE type to note * * This function will note that a type of value is about to be hashed. * The type of a VALUE will be noted. For purposes of hash comparison, * we will do nothing with V_NUM and V_COM so that the other functions * can hash to the same value regardless of if MD5_value() is called * or not. We also do nothing with V_STR so that a hash of a string * will produce the same value as the standard hash function. */static voidMD5_type(int type, HASH *state){ MD5_CTX *dig = &state->h_union.h_md5; /* digest state */ unsigned int i; /* * ignore NUMBER and COMPLEX */ if (type == V_NUM || type == V_COM || type == V_STR) { return; } /* * change state to reflect a VALUE type */ dig->digest[0] += type; for (i=1; i < MD5_DIGESTWORDS; ++i) { dig->digest[i] += ((type+i) ^ dig->digest[i-1]); } return;}/* * MD5_init_state - initialize a hash state structure for this hash * * given: * state - pointer to the hfunction element to initialize */voidMD5_init_state(HASH *state){ /* * initalize state */ state->hashtype = MD5_HASH_TYPE; state->bytes = TRUE; state->update = MD5Update; state->chkpt = MD5_chkpt; state->note = MD5_note; state->type = MD5_type; state->final = MD5_final_state; state->cmp = MD5_cmp; state->print = MD5_print; state->base = MD5_BASE; state->chunksize = MD5_CHUNKSIZE; state->unionsize = sizeof(MD5_CTX); /* * perform the internal init function */ memset((void *)&(state->h_union.h_md5), 0, sizeof(MD5_CTX)); MD5Init(state); return;}/* * MD5_final_state - complete hash state and return a ZVALUE * * given: * state the state to complete and convert * * returns: * a ZVALUE representing the state */static ZVALUEMD5_final_state(HASH *state){ MD5_CTX *dig = &state->h_union.h_md5; /* digest state */ ZVALUE ret; /* return ZVALUE of completed hash state */ unsigned int i; /* * malloc and initialize if state is NULL */ if (state == NULL) { state = (HASH *)malloc(sizeof(HASH)); if (state == NULL) { math_error("cannot malloc HASH"); /*NOTREACHED*/ } MD5_init_state(state); } /* * complete the hash state */ MD5Final(state); /* * allocate storage for ZVALUE */ ret.len = MD5_DIGESTSIZE/sizeof(HALF); ret.sign = 0; ret.v = alloc(ret.len); /* * load ZVALUE */#if CALC_BYTE_ORDER == LITTLE_ENDIAN && BASEB == 16 for (i = 0; i < MD5_DIGESTSIZE; i += 2) { SWAP_B8_IN_B16(((USB8 *)dig->digest) + i, ((USB8 *) dig->digest) + i); }#else for (i = 0; i < MD5_DIGESTWORDS; ++i) { SWAP_B8_IN_B32(dig->digest + i, dig->digest + i); }#endif for (i=0; i < (unsigned int)ret.len; ++i) { ret.v[ret.len-i-1] = ((HALF*)dig->digest)[i]; } ztrim(&ret); /* * return ZVALUE */ return ret;}/* * MD5_cmp - compare two hash states * * given: * a first hash state * b second hash state * * returns: * TRUE => hash states are different * FALSE => hash states are the same */static intMD5_cmp(HASH *a, HASH *b){ /* * firewall and quick check */ if (a == b) { /* pointers to the same object */ return FALSE; } if (a == NULL || b == NULL) { /* one is NULL, so they differ */ return TRUE; } /* * compare concat states */ if (a->bytes != b->bytes) return TRUE; /* * compare bit counts */ if (a->h_union.h_md5.countLo != b->h_union.h_md5.countLo || a->h_union.h_md5.countHi != b->h_union.h_md5.countHi) { /* counts differ */ return TRUE; } /* * compare pending buffers */ if (a->h_union.h_md5.datalen != b->h_union.h_md5.datalen) { /* buffer lengths differ */ return TRUE; } if (memcmp((char*)a->h_union.h_md5.data, (char*)b->h_union.h_md5.data, a->h_union.h_md5.datalen) != 0) { /* buffer contents differ */ return TRUE; } /* * compare digest */ return (memcmp((char*)(a->h_union.h_md5.digest), (char*)(b->h_union.h_md5.digest), MD5_DIGESTSIZE) != 0);}/* * MD5_print - print a hash state * * given: * state the hash state to print */static voidMD5_print(HASH *state){ /* * form the hash value */ if (conf->calc_debug & CALCDBG_HASH_STATE) { char buf[DEBUG_SIZE+1]; /* hash value buffer */ /* * print numeric debug value * * NOTE: This value represents only the hash value as of * the last full update or finalization. Thus it * may NOT be the actual hash value. */ sprintf(buf, "md5: 0x%08x%08x%08x%08x data: %d octets", (int)state->h_union.h_md5.digest[0], (int)state->h_union.h_md5.digest[1], (int)state->h_union.h_md5.digest[2], (int)state->h_union.h_md5.digest[3], (int)state->h_union.h_md5.datalen); math_str(buf); } else { math_str("md5 hash state"); } return;}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -