?? tiger.c
字號(hào):
/* The key mixing schedule */static void key_schedule(ulong64 *x) { x[0] -= x[7] ^ CONST64(0xA5A5A5A5A5A5A5A5); x[1] ^= x[0]; x[2] += x[1]; x[3] -= x[2] ^ ((~x[1])<<19); x[4] ^= x[3]; x[5] += x[4]; x[6] -= x[5] ^ ((~x[4])>>23); x[7] ^= x[6]; x[0] += x[7]; x[1] -= x[0] ^ ((~x[7])<<19); x[2] ^= x[1]; x[3] += x[2]; x[4] -= x[3] ^ ((~x[2])>>23); x[5] ^= x[4]; x[6] += x[5]; x[7] -= x[6] ^ CONST64(0x0123456789ABCDEF);} #ifdef CLEAN_STACKstatic void _tiger_compress(hash_state *md, unsigned char *buf)#elsestatic void tiger_compress(hash_state *md, unsigned char *buf)#endif{ ulong64 a, b, c, x[8]; unsigned long i; /* load words */ for (i = 0; i < 8; i++) { LOAD64L(x[i],&buf[8*i]); } a = md->tiger.state[0]; b = md->tiger.state[1]; c = md->tiger.state[2]; pass(&a,&b,&c,x,5); key_schedule(x); pass(&c,&a,&b,x,7); key_schedule(x); pass(&b,&c,&a,x,9); /* store state */ md->tiger.state[0] = a ^ md->tiger.state[0]; md->tiger.state[1] = b - md->tiger.state[1]; md->tiger.state[2] = c + md->tiger.state[2];}#ifdef CLEAN_STACKstatic void tiger_compress(hash_state *md, unsigned char *buf){ _tiger_compress(md, buf); burn_stack(sizeof(ulong64) * 11 + sizeof(unsigned long));}#endifvoid tiger_init(hash_state *md){ _ARGCHK(md != NULL); md->tiger.state[0] = CONST64(0x0123456789ABCDEF); md->tiger.state[1] = CONST64(0xFEDCBA9876543210); md->tiger.state[2] = CONST64(0xF096A5B4C3B2E187); md->tiger.curlen = 0; md->tiger.length = 0;}HASH_PROCESS(tiger_process, tiger_compress, tiger, 64)int tiger_done(hash_state * md, unsigned char *hash){ _ARGCHK(md != NULL); _ARGCHK(hash != NULL); if (md->tiger.curlen >= sizeof(md->tiger.buf)) { return CRYPT_INVALID_ARG; } /* increase the length of the message */ md->tiger.length += md->tiger.curlen * 8; /* append the '1' bit */ md->tiger.buf[md->tiger.curlen++] = (unsigned char)0x01; /* if the length is currently above 56 bytes we append zeros * then compress. Then we can fall back to padding zeros and length * encoding like normal. */ if (md->tiger.curlen > 56) { while (md->tiger.curlen < 64) { md->tiger.buf[md->tiger.curlen++] = (unsigned char)0; } tiger_compress(md, md->tiger.buf); md->tiger.curlen = 0; } /* pad upto 56 bytes of zeroes */ while (md->tiger.curlen < 56) { md->tiger.buf[md->tiger.curlen++] = (unsigned char)0; } /* store length */ STORE64L(md->tiger.length, md->tiger.buf+56); tiger_compress(md, md->tiger.buf); /* copy output */ STORE64L(md->tiger.state[0], &hash[0]); STORE64L(md->tiger.state[1], &hash[8]); STORE64L(md->tiger.state[2], &hash[16]);#ifdef CLEAN_STACK zeromem(md, sizeof(hash_state));#endif return CRYPT_OK;}int tiger_test(void){ #ifndef LTC_TEST return CRYPT_NOP; #else static const struct { char *msg; unsigned char hash[24]; } tests[] = { { "", { 0x32, 0x93, 0xac, 0x63, 0x0c, 0x13, 0xf0, 0x24, 0x5f, 0x92, 0xbb, 0xb1, 0x76, 0x6e, 0x16, 0x16, 0x7a, 0x4e, 0x58, 0x49, 0x2d, 0xde, 0x73, 0xf3 } }, { "abc", { 0x2a, 0xab, 0x14, 0x84, 0xe8, 0xc1, 0x58, 0xf2, 0xbf, 0xb8, 0xc5, 0xff, 0x41, 0xb5, 0x7a, 0x52, 0x51, 0x29, 0x13, 0x1c, 0x95, 0x7b, 0x5f, 0x93 } }, { "Tiger", { 0xdd, 0x00, 0x23, 0x07, 0x99, 0xf5, 0x00, 0x9f, 0xec, 0x6d, 0xeb, 0xc8, 0x38, 0xbb, 0x6a, 0x27, 0xdf, 0x2b, 0x9d, 0x6f, 0x11, 0x0c, 0x79, 0x37 } }, { "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-", { 0xf7, 0x1c, 0x85, 0x83, 0x90, 0x2a, 0xfb, 0x87, 0x9e, 0xdf, 0xe6, 0x10, 0xf8, 0x2c, 0x0d, 0x47, 0x86, 0xa3, 0xa5, 0x34, 0x50, 0x44, 0x86, 0xb5 } }, { "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-", { 0xc5, 0x40, 0x34, 0xe5, 0xb4, 0x3e, 0xb8, 0x00, 0x58, 0x48, 0xa7, 0xe0, 0xae, 0x6a, 0xac, 0x76, 0xe4, 0xff, 0x59, 0x0a, 0xe7, 0x15, 0xfd, 0x25 } }, }; int i; unsigned char tmp[24]; hash_state md; for (i = 0; i < (int)(sizeof(tests) / sizeof(tests[0])); i++) { tiger_init(&md); tiger_process(&md, (unsigned char *)tests[i].msg, (unsigned long)strlen(tests[i].msg)); tiger_done(&md, tmp); if (memcmp(tmp, tests[i].hash, 24) != 0) { return CRYPT_FAIL_TESTVECTOR; } } return CRYPT_OK; #endif}#endif/*Hash of "": 24F0130C63AC9332 16166E76B1BB925F F373DE2D49584E7AHash of "abc": F258C1E88414AB2A 527AB541FFC5B8BF 935F7B951C132951Hash of "Tiger": 9F00F599072300DD 276ABB38C8EB6DEC 37790C116F9D2BDFHash of "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-": 87FB2A9083851CF7 470D2CF810E6DF9E B586445034A5A386Hash of "ABCDEFGHIJKLMNOPQRSTUVWXYZ=abcdefghijklmnopqrstuvwxyz+0123456789": 467DB80863EBCE48 8DF1CD1261655DE9 57896565975F9197Hash of "Tiger - A Fast New Hash Function, by Ross Anderson and Eli Biham": 0C410A042968868A 1671DA5A3FD29A72 5EC1E457D3CDB303Hash of "Tiger - A Fast New Hash Function, by Ross Anderson and Eli Biham, proceedings of Fast Software Encryption 3, Cambridge.": EBF591D5AFA655CE 7F22894FF87F54AC 89C811B6B0DA3193Hash of "Tiger - A Fast New Hash Function, by Ross Anderson and Eli Biham, proceedings of Fast Software Encryption 3, Cambridge, 1996.": 3D9AEB03D1BD1A63 57B2774DFD6D5B24 DD68151D503974FCHash of "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-": 00B83EB4E53440C5 76AC6AAEE0A74858 25FD15E70A59FFE4*/
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -