📄 tiger.c
字号:
0xB8E319A27AB3F215LL /* 938 */, 0x31AD9C1151341A4DLL /* 939 */, 0x773C22A57BEF5805LL /* 940 */, 0x45C7561A07968633LL /* 941 */, 0xF913DA9E249DBE36LL /* 942 */, 0xDA652D9B78A64C68LL /* 943 */, 0x4C27A97F3BC334EFLL /* 944 */, 0x76621220E66B17F4LL /* 945 */, 0x967743899ACD7D0BLL /* 946 */, 0xF3EE5BCAE0ED6782LL /* 947 */, 0x409F753600C879FCLL /* 948 */, 0x06D09A39B5926DB6LL /* 949 */, 0x6F83AEB0317AC588LL /* 950 */, 0x01E6CA4A86381F21LL /* 951 */, 0x66FF3462D19F3025LL /* 952 */, 0x72207C24DDFD3BFBLL /* 953 */, 0x4AF6B6D3E2ECE2EBLL /* 954 */, 0x9C994DBEC7EA08DELL /* 955 */, 0x49ACE597B09A8BC4LL /* 956 */, 0xB38C4766CF0797BALL /* 957 */, 0x131B9373C57C2A75LL /* 958 */, 0xB1822CCE61931E58LL /* 959 */, 0x9D7555B909BA1C0CLL /* 960 */, 0x127FAFDD937D11D2LL /* 961 */, 0x29DA3BADC66D92E4LL /* 962 */, 0xA2C1D57154C2ECBCLL /* 963 */, 0x58C5134D82F6FE24LL /* 964 */, 0x1C3AE3515B62274FLL /* 965 */, 0xE907C82E01CB8126LL /* 966 */, 0xF8ED091913E37FCBLL /* 967 */, 0x3249D8F9C80046C9LL /* 968 */, 0x80CF9BEDE388FB63LL /* 969 */, 0x1881539A116CF19ELL /* 970 */, 0x5103F3F76BD52457LL /* 971 */, 0x15B7E6F5AE47F7A8LL /* 972 */, 0xDBD7C6DED47E9CCFLL /* 973 */, 0x44E55C410228BB1ALL /* 974 */, 0xB647D4255EDB4E99LL /* 975 */, 0x5D11882BB8AAFC30LL /* 976 */, 0xF5098BBB29D3212ALL /* 977 */, 0x8FB5EA14E90296B3LL /* 978 */, 0x677B942157DD025ALL /* 979 */, 0xFB58E7C0A390ACB5LL /* 980 */, 0x89D3674C83BD4A01LL /* 981 */, 0x9E2DA4DF4BF3B93BLL /* 982 */, 0xFCC41E328CAB4829LL /* 983 */, 0x03F38C96BA582C52LL /* 984 */, 0xCAD1BDBD7FD85DB2LL /* 985 */, 0xBBB442C16082AE83LL /* 986 */, 0xB95FE86BA5DA9AB0LL /* 987 */, 0xB22E04673771A93FLL /* 988 */, 0x845358C9493152D8LL /* 989 */, 0xBE2A488697B4541ELL /* 990 */, 0x95A2DC2DD38E6966LL /* 991 */, 0xC02C11AC923C852BLL /* 992 */, 0x2388B1990DF2A87BLL /* 993 */, 0x7C8008FA1B4F37BELL /* 994 */, 0x1F70D0C84D54E503LL /* 995 */, 0x5490ADEC7ECE57D4LL /* 996 */, 0x002B3C27D9063A3ALL /* 997 */, 0x7EAEA3848030A2BFLL /* 998 */, 0xC602326DED2003C0LL /* 999 */, 0x83A7287D69A94086LL /* 1000 */, 0xC57A5FCB30F57A8ALL /* 1001 */, 0xB56844E479EBE779LL /* 1002 */, 0xA373B40F05DCBCE9LL /* 1003 */, 0xD71A786E88570EE2LL /* 1004 */, 0x879CBACDBDE8F6A0LL /* 1005 */, 0x976AD1BCC164A32FLL /* 1006 */, 0xAB21E25E9666D78BLL /* 1007 */, 0x901063AAE5E5C33CLL /* 1008 */, 0x9818B34448698D90LL /* 1009 */, 0xE36487AE3E1E8ABBLL /* 1010 */, 0xAFBDF931893BDCB4LL /* 1011 */, 0x6345A0DC5FBBD519LL /* 1012 */, 0x8628FE269B9465CALL /* 1013 */, 0x1E5D01603F9C51ECLL /* 1014 */, 0x4DE44006A15049B7LL /* 1015 */, 0xBF6C70E5F776CBB1LL /* 1016 */, 0x411218F2EF552BEDLL /* 1017 */, 0xCB0C0708705A36A3LL /* 1018 */, 0xE74D14754F986044LL /* 1019 */, 0xCD56D9430EA8280ELL /* 1020 */, 0xC12591D7535F5065LL /* 1021 */, 0xC83223F1720AEF96LL /* 1022 */, 0xC3A0396F7363A51FLL /* 1023 */};/* Big endian: */#if !(defined(__alpha)||defined(__i386__)||defined(__vax__))#define BIG_ENDIAN#endif/* The following macro denotes that an optimization *//* for Alpha is required. It is used only for *//* optimization of time. Otherwise it does nothing. */#ifdef __alpha#define OPTIMIZE_FOR_ALPHA#endif/* NOTE that this code is NOT FULLY OPTIMIZED for any *//* machine. Assembly code might be much faster on some *//* machines, especially if the code is compiled with *//* gcc. *//* The number of passes of the hash function. *//* Three passes are recommended. *//* Use four passes when you need extra security. *//* Must be at least three. */#define PASSES 3extern word64 table[4*256];#define t1 (table)#define t2 (table+256)#define t3 (table+256*2)#define t4 (table+256*3)#define save_abc \ aa = a; \ bb = b; \ cc = c;#ifdef OPTIMIZE_FOR_ALPHA/* This is the official definition of round */#define round(a,b,c,x,mul) \ c ^= x; \ a -= t1[((c)>>(0*8))&0xFF] ^ t2[((c)>>(2*8))&0xFF] ^ \ t3[((c)>>(4*8))&0xFF] ^ t4[((c)>>(6*8))&0xFF] ; \ b += t4[((c)>>(1*8))&0xFF] ^ t3[((c)>>(3*8))&0xFF] ^ \ t2[((c)>>(5*8))&0xFF] ^ t1[((c)>>(7*8))&0xFF] ; \ b *= mul;#else/* This code works faster when compiled on 32-bit machines *//* (but works slower on Alpha) */#define round(a,b,c,x,mul) \ c ^= x; \ a -= t1[(byte)(c)] ^ \ t2[(byte)(((word32)(c))>>(2*8))] ^ \ t3[(byte)((c)>>(4*8))] ^ \ t4[(byte)(((word32)((c)>>(4*8)))>>(2*8))] ; \ b += t4[(byte)(((word32)(c))>>(1*8))] ^ \ t3[(byte)(((word32)(c))>>(3*8))] ^ \ t2[(byte)(((word32)((c)>>(4*8)))>>(1*8))] ^ \ t1[(byte)(((word32)((c)>>(4*8)))>>(3*8))]; \ b *= mul;#endif#define pass(a,b,c,mul) \ round(a,b,c,x0,mul) \ round(b,c,a,x1,mul) \ round(c,a,b,x2,mul) \ round(a,b,c,x3,mul) \ round(b,c,a,x4,mul) \ round(c,a,b,x5,mul) \ round(a,b,c,x6,mul) \ round(b,c,a,x7,mul)#define key_schedule \ x0 -= x7 ^ 0xA5A5A5A5A5A5A5A5LL; \ x1 ^= x0; \ x2 += x1; \ x3 -= x2 ^ ((~x1)<<19); \ x4 ^= x3; \ x5 += x4; \ x6 -= x5 ^ ((~x4)>>23); \ x7 ^= x6; \ x0 += x7; \ x1 -= x0 ^ ((~x7)<<19); \ x2 ^= x1; \ x3 += x2; \ x4 -= x3 ^ ((~x2)>>23); \ x5 ^= x4; \ x6 += x5; \ x7 -= x6 ^ 0x0123456789ABCDEFLL;#define feedforward \ a ^= aa; \ b -= bb; \ c += cc;#ifdef OPTIMIZE_FOR_ALPHA/* The loop is unrolled: works better on Alpha */#define compress \ save_abc \ pass(a,b,c,5) \ key_schedule \ pass(c,a,b,7) \ key_schedule \ pass(b,c,a,9) \ for(pass_no=3; pass_no<PASSES; pass_no++) { \ key_schedule \ pass(a,b,c,9) \ tmpa=a; a=c; c=b; b=tmpa;} \ feedforward#else/* loop: works better on PC and Sun (smaller cache?) */#define compress \ save_abc \ for(pass_no=0; pass_no<PASSES; pass_no++) { \ if(pass_no != 0) {key_schedule} \ pass(a,b,c,(pass_no==0?5:pass_no==1?7:9)); \ tmpa=a; a=c; c=b; b=tmpa;} \ feedforward#endif#define tiger_compress_macro(str, state) \{ \ register word64 a, b, c, tmpa; \ word64 aa, bb, cc; \ register word64 x0, x1, x2, x3, x4, x5, x6, x7; \ int pass_no; \\ a = state[0]; \ b = state[1]; \ c = state[2]; \\ x0=str[0]; x1=str[1]; x2=str[2]; x3=str[3]; \ x4=str[4]; x5=str[5]; x6=str[6]; x7=str[7]; \\ compress; \\ state[0] = a; \ state[1] = b; \ state[2] = c; \}/* The compress function is a function. Requires smaller cache? */voidtiger_compress(word64 *str, word64 state[3]){ tiger_compress_macro(((word64*)str), ((word64*)state));}#ifdef OPTIMIZE_FOR_ALPHA/* The compress function is inlined: works better on Alpha. *//* Still leaves the function above in the code, in case some other *//* module calls it directly. */#define tiger_compress(str, state) \ tiger_compress_macro(((word64*)str), ((word64*)state))#endifvoidtiger(word64 *str, word64 length, word64 res[3]){ register word64 i, j; unsigned char temp[64]; res[0]=0x0123456789ABCDEFLL; res[1]=0xFEDCBA9876543210LL; res[2]=0xF096A5B4C3B2E187LL; for(i=length; i>=64; i-=64) {#ifdef BIG_ENDIAN for(j=0; j<64; j++) temp[j^7] = ((byte*)str)[j]; tiger_compress(((word64*)temp), res);#else tiger_compress(str, res);#endif str += 8; }#ifdef BIG_ENDIAN for(j=0; j<i; j++) temp[j^7] = ((byte*)str)[j]; temp[j^7] = 0x01; j++; for(; j&7; j++) temp[j^7] = 0;#else for(j=0; j<i; j++) temp[j] = ((byte*)str)[j]; temp[j++] = 0x01; for(; j&7; j++) temp[j] = 0;#endif if(j>56) { for(; j<64; j++) temp[j] = 0; tiger_compress(((word64*)temp), res); j=0; } for(; j<56; j++) temp[j] = 0; ((word64*)(&(temp[56])))[0] = ((word64)length)<<3; tiger_compress(((word64*)temp), res);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -