From 6f2559d341b4d0c72a8f02587cf9f24052f4ce25 Mon Sep 17 00:00:00 2001 From: JamesonHuang Date: Thu, 2 Jul 2015 22:52:33 +0800 Subject: [PATCH] upgrade key md5 encry --- .../c_test/md5/first_ver/enc_upgr_key | Bin 0 -> 17528 bytes .../c_test/md5/first_ver/enc_upgr_key.c | 54 ++++ 1_3.test_code/c_test/md5/first_ver/main | Bin 0 -> 17576 bytes 1_3.test_code/c_test/md5/first_ver/md5.c | 170 ++++++++++ 1_3.test_code/c_test/md5/first_ver/md5.h | 57 ++++ 1_3.test_code/c_test/md5/first_ver/md5_main | Bin 0 -> 17584 bytes 1_3.test_code/c_test/md5/first_ver/md5_main.c | 39 +++ .../c_test/md5/first_ver/openssl_md5.c | 43 +++ .../c_test/md5/second_ver/get_encry_upg_key | Bin 0 -> 17528 bytes .../c_test/md5/second_ver/get_encry_upg_key.c | 42 +++ 1_3.test_code/c_test/md5/second_ver/main | Bin 0 -> 17512 bytes 1_3.test_code/c_test/md5/second_ver/main.c | 64 ++++ 1_3.test_code/c_test/md5/second_ver/md5.c | 295 ++++++++++++++++++ 1_3.test_code/c_test/md5/second_ver/md5.h | 38 +++ 1_3.test_code/c_test/testSprintf.c | 16 - 15 files changed, 802 insertions(+), 16 deletions(-) create mode 100755 1_3.test_code/c_test/md5/first_ver/enc_upgr_key create mode 100644 1_3.test_code/c_test/md5/first_ver/enc_upgr_key.c create mode 100755 1_3.test_code/c_test/md5/first_ver/main create mode 100644 1_3.test_code/c_test/md5/first_ver/md5.c create mode 100644 1_3.test_code/c_test/md5/first_ver/md5.h create mode 100755 1_3.test_code/c_test/md5/first_ver/md5_main create mode 100644 1_3.test_code/c_test/md5/first_ver/md5_main.c create mode 100644 1_3.test_code/c_test/md5/first_ver/openssl_md5.c create mode 100755 1_3.test_code/c_test/md5/second_ver/get_encry_upg_key create mode 100644 1_3.test_code/c_test/md5/second_ver/get_encry_upg_key.c create mode 100755 1_3.test_code/c_test/md5/second_ver/main create mode 100644 1_3.test_code/c_test/md5/second_ver/main.c create mode 100644 1_3.test_code/c_test/md5/second_ver/md5.c create mode 100644 1_3.test_code/c_test/md5/second_ver/md5.h delete mode 100644 1_3.test_code/c_test/testSprintf.c diff --git a/1_3.test_code/c_test/md5/first_ver/enc_upgr_key b/1_3.test_code/c_test/md5/first_ver/enc_upgr_key new file mode 100755 index 0000000000000000000000000000000000000000..a13f4550d3857739fffd752f76d5d196f0333148 GIT binary patch literal 17528 zcmeHPe|%KcmA^B|Kz=b9(x_3ijsn{VX2=f$6LDoG$-oN+h>)m=@EDQ_1d>TQKPW*( zbcpLX4Q02bvUc6#k58-Z?q~biRW{-e5^)o)wMJJhU9lhZBQz1%MrCcbQnKgVd(X^! zFO!<2+y8R;@QJVvMT5+ z*9w*>V|Fe;JB-!l;4IKhyh3zH#xX1@*&&N|`O+?5+7a!Sff1$g;n?u6R{E1<1BWr^!XM57Y(H&!d&6V3 zJMP&B4hjUmq(L%w(nc@@a*@MkQAAV?NZ z<`{AYxYi?#i&(HN(Buy_vbJz2$W%2L^44!x>$h%K8@)}fX}shyvBg+e|Z5!k!$mXOC#6DqiEz96O|f`oYpqBDUq{jO3d=?JUdf5xe?E9Dy?T5#$kq!G6yF9r8Hz!EVk!ggg#;@MoOA zA9)<=;33ZMLLP@WxS#U@;$On{I_19q<_>x;rho$_I;8XrELBXs%3Bvhm&CnglDF)u!H?*F&tI>D z_*r;n9T*PyA+Qa-mSrF^ea?G2YKMfZM3%C!<;-`%F7E78G#KgMFt`hBu&zY!8CGJR z;XWQGuetb)5!E!)Y|j=^&5Hi?jo*o??c#|e2Sqh^M{Tif!!hnEa<&lM4Jgs@$!Oh) zKF@jd+2hALlKplWRiv&VDoi{}If7($A$>g^@KVB_dQ<`^zuH z2cw-8+UYQOi1*J=zGCW+)xp`yIsh_oR(Db{{XCZQpbgGLq}vqbb7Bmoo=?)Gp7|^E zY*H`fEA;Xnv_(9_rikYPOs5NQZnN*N#bqW=&RF9)vx}eI+zv4Wm|8HXl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Z*yCP{(S9GuFfNP_3tdN?vP0Tm5v?Ltsw0iUpVpq9LpDi!{!UwC zV3T#C-!s_L^?69z=NJMYJ97Dm!JeLLQtd*6_D@J(!a^)N1T~DG@Tcb=n;nEuz9~rj zXtaL{TD10i?Jlmn*Um}&`+C8R#_upRXzl5FYDn6@gN>R(=Z{3)P_e?FobK`GF8U7N zsBh$d0k+v1d)i0K!v_^8MtviX>k~ty{^>c$K2G}&z!v8o+0*kL{XYr)a{M$usehUW zrw#qncjChfpaBZ$3ogNv{0uZ`VPb|t{RmFPN_C|8K#K9p?ocF(v|mBIq!LbUgQA)67w=o@AX!2ElYwkAu-p%= o9gR7=y;yKHcyWPp75o*zAB~6d8m`Y|{XbO(4Nz`2G#dN=KSL;qJOBUy literal 0 HcmV?d00001 diff --git a/1_3.test_code/c_test/md5/first_ver/enc_upgr_key.c b/1_3.test_code/c_test/md5/first_ver/enc_upgr_key.c new file mode 100644 index 0000000..b14ff6e --- /dev/null +++ b/1_3.test_code/c_test/md5/first_ver/enc_upgr_key.c @@ -0,0 +1,54 @@ +/************************************************************************* + > File Name: enc_upgr_key.c + > Description: + > Conclusion: + > Author: rh_Jameson + > Created Time: 2015年07月01日 星期三 20时41分53秒 + ************************************************************************/ +#include +#include +#include +#include "md5.h" +#include "md5.c" +void get_encry_upg_key(char *serviceCode, char *sipToken, char *version) +{ + char key[] = "2635881a7ab0593849fe89e685fc56cd"; + unsigned char res[16]; + unsigned char buffer[1024] = ""; + + //unsigned char buffer[] ="com.meizu.routerR13PWGPFQRRV03A51000329.0.150702162635881a7ab0593849fe89e685fc56cd"; + sprintf((char *)buffer, "%s%s%s%s", serviceCode, sipToken, version, key); + //strcat((char *)buffer, key); + MD5_CTX md5; + MD5Init(&md5); + MD5Update(&md5, buffer, strlen((char *)buffer)); //对欲加密的字符进行加密 + MD5Final(&md5, res); //获得最终结果 + + printf("加密前:%s\n加密后:",buffer); + for(int i = 0; i < 16; i++) + { + printf("%02x ",res[i]); + } + printf("\n\n\n加密结束!\n"); + +} +int main(int argc, char *argv[]) +{ + get_encry_upg_key("com.meizu.router", "R13PWGPFQRRV03A5100032", "9.0.15070216"); + return 0; +} + + /* + MD5_CTX md5; + MD5Init(&md5); + int i; + unsigned char encrypt[] ="com.meizu.routerR13PWGPFQRRV03A51000329.0.150702162635881a7ab0593849fe89e685fc56cd";//21232f297a57a5a743894a0e4a801fc3 + unsigned char decrypt[16]; + MD5Update(&md5,encrypt,strlen((char *)encrypt)); + MD5Final(&md5,decrypt); + printf("加密前:%s\n加密后:",encrypt); + for(i=0;i<16;i++) + { + printf("%02x",decrypt[i]); + } +*/ diff --git a/1_3.test_code/c_test/md5/first_ver/main b/1_3.test_code/c_test/md5/first_ver/main new file mode 100755 index 0000000000000000000000000000000000000000..cd94992f7b4ba43b99ffba83781290c27b6dc679 GIT binary patch literal 17576 zcmeHPe|%KcmA^B|kROC(k_H<^>&TDYh-SzSeoVybOp<{YO&~y`qQYZHCJ;y_+4+Hl zDxhOr$7xu0TPoYuU8;WCy50Tkem<*wA_^p86K!jau3FmC{h%MAiQpQQ)oe}4o^$U# zGw;1jYBIb1FPBf=x#!$-&OP`0?mh3l`{uFFU9-w;GBGMztJ` z2g_hi_BA$-%>s!9{+zr8si+Yhm9B}VOT84Jsqp783xUJz9Ve zg1$UoutXWNaRJ(4tX4Z`fo|ayq9Za6D+b1kjUQ2rc7@WeP}&h4lz|bY@!{C;uU`7C zH#>nt-id@&@nf8#E|$7;!6vLfY(oyIQ%74l#~4wvTL*R+=TwVTDz2CPO^S;g--x7= zuqCZ6TbD0g(%Mwi+TsiCF52x_UbK9vJN;GsJnVi1Mi7&v;l`P=ffXDjqT69 zx!?3j|Ej{=&rXhQGDR=k^3%SD(3bw7I_2^e(9BDqef=czf=T3AlgL+0BCiIy4gQR! z7zBypnLUY|0j`Y*<8l`0@VEGa&8#C73@}v<1U-#A)yC~R)n-piD+>hutzI8%^R_j1 zbV4)Qp^iVOws~57AlcT|?voOgt*)uAs8mbsB}-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sq4P(gUZ`ZlpPcTo`)2xX->7foe*v~R8hhGzE5HXEC`NrFkLwddr2gr- z$u>p%-+?X8J+i0gL;8Oe2Icr^ep3H556&C8A#m0~E1C5&`_yCLX%kD@F_m!f0 zTU^3x5>9S|f?W8E_02WJ;WlZXP6o2gz;Zvdb~NVfu2RAAFU+BO4gBGhAlxXg;rdL} Pe{VT7K=B$Hjs5>GZT*d8 literal 0 HcmV?d00001 diff --git a/1_3.test_code/c_test/md5/first_ver/md5.c b/1_3.test_code/c_test/md5/first_ver/md5.c new file mode 100644 index 0000000..599a76c --- /dev/null +++ b/1_3.test_code/c_test/md5/first_ver/md5.c @@ -0,0 +1,170 @@ +/************************************************************************* + > File Name: MD5.c + > Description: md5 encription + > Conclusion: + > Author: rh_Jameson + > Created Time: 2015年07月02日 星期四 17时20分04秒 + ************************************************************************/ + + +#include +#include "md5.h" + +unsigned char PADDING[]={0x80,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; + +void MD5Init(MD5_CTX *context) +{ + context->count[0] = 0; + context->count[1] = 0; + context->state[0] = 0x67452301; + context->state[1] = 0xEFCDAB89; + context->state[2] = 0x98BADCFE; + context->state[3] = 0x10325476; +} +void MD5Update(MD5_CTX *context,unsigned char *input,unsigned int inputlen) +{ + unsigned int i = 0,index = 0,partlen = 0; + index = (context->count[0] >> 3) & 0x3F; + partlen = 64 - index; + context->count[0] += inputlen << 3; + if(context->count[0] < (inputlen << 3)) + context->count[1]++; + context->count[1] += inputlen >> 29; + + if(inputlen >= partlen) + { + memcpy(&context->buffer[index],input,partlen); + MD5Transform(context->state,context->buffer); + for(i = partlen;i+64 <= inputlen;i+=64) + MD5Transform(context->state,&input[i]); + index = 0; + } + else + { + i = 0; + } + memcpy(&context->buffer[index],&input[i],inputlen-i); +} +void MD5Final(MD5_CTX *context,unsigned char digest[16]) +{ + unsigned int index = 0,padlen = 0; + unsigned char bits[8]; + index = (context->count[0] >> 3) & 0x3F; + padlen = (index < 56)?(56-index):(120-index); + MD5Encode(bits,context->count,8); + MD5Update(context,PADDING,padlen); + MD5Update(context,bits,8); + MD5Encode(digest,context->state,16); +} +void MD5Encode(unsigned char *output,unsigned int *input,unsigned int len) +{ + unsigned int i = 0,j = 0; + while(j < len) + { + output[j] = input[i] & 0xFF; + output[j+1] = (input[i] >> 8) & 0xFF; + output[j+2] = (input[i] >> 16) & 0xFF; + output[j+3] = (input[i] >> 24) & 0xFF; + i++; + j+=4; + } +} +void MD5Decode(unsigned int *output,unsigned char *input,unsigned int len) +{ + unsigned int i = 0,j = 0; + while(j < len) + { + output[i] = (input[j]) | + (input[j+1] << 8) | + (input[j+2] << 16) | + (input[j+3] << 24); + i++; + j+=4; + } +} +void MD5Transform(unsigned int state[4],unsigned char block[64]) +{ + unsigned int a = state[0]; + unsigned int b = state[1]; + unsigned int c = state[2]; + unsigned int d = state[3]; + unsigned int x[64]; + MD5Decode(x,block,64); + FF(a, b, c, d, x[ 0], 7, 0xd76aa478); /* 1 */ + FF(d, a, b, c, x[ 1], 12, 0xe8c7b756); /* 2 */ + FF(c, d, a, b, x[ 2], 17, 0x242070db); /* 3 */ + FF(b, c, d, a, x[ 3], 22, 0xc1bdceee); /* 4 */ + FF(a, b, c, d, x[ 4], 7, 0xf57c0faf); /* 5 */ + FF(d, a, b, c, x[ 5], 12, 0x4787c62a); /* 6 */ + FF(c, d, a, b, x[ 6], 17, 0xa8304613); /* 7 */ + FF(b, c, d, a, x[ 7], 22, 0xfd469501); /* 8 */ + FF(a, b, c, d, x[ 8], 7, 0x698098d8); /* 9 */ + FF(d, a, b, c, x[ 9], 12, 0x8b44f7af); /* 10 */ + FF(c, d, a, b, x[10], 17, 0xffff5bb1); /* 11 */ + FF(b, c, d, a, x[11], 22, 0x895cd7be); /* 12 */ + FF(a, b, c, d, x[12], 7, 0x6b901122); /* 13 */ + FF(d, a, b, c, x[13], 12, 0xfd987193); /* 14 */ + FF(c, d, a, b, x[14], 17, 0xa679438e); /* 15 */ + FF(b, c, d, a, x[15], 22, 0x49b40821); /* 16 */ + + /* Round 2 */ + GG(a, b, c, d, x[ 1], 5, 0xf61e2562); /* 17 */ + GG(d, a, b, c, x[ 6], 9, 0xc040b340); /* 18 */ + GG(c, d, a, b, x[11], 14, 0x265e5a51); /* 19 */ + GG(b, c, d, a, x[ 0], 20, 0xe9b6c7aa); /* 20 */ + GG(a, b, c, d, x[ 5], 5, 0xd62f105d); /* 21 */ + GG(d, a, b, c, x[10], 9, 0x2441453); /* 22 */ + GG(c, d, a, b, x[15], 14, 0xd8a1e681); /* 23 */ + GG(b, c, d, a, x[ 4], 20, 0xe7d3fbc8); /* 24 */ + GG(a, b, c, d, x[ 9], 5, 0x21e1cde6); /* 25 */ + GG(d, a, b, c, x[14], 9, 0xc33707d6); /* 26 */ + GG(c, d, a, b, x[ 3], 14, 0xf4d50d87); /* 27 */ + GG(b, c, d, a, x[ 8], 20, 0x455a14ed); /* 28 */ + GG(a, b, c, d, x[13], 5, 0xa9e3e905); /* 29 */ + GG(d, a, b, c, x[ 2], 9, 0xfcefa3f8); /* 30 */ + GG(c, d, a, b, x[ 7], 14, 0x676f02d9); /* 31 */ + GG(b, c, d, a, x[12], 20, 0x8d2a4c8a); /* 32 */ + + /* Round 3 */ + HH(a, b, c, d, x[ 5], 4, 0xfffa3942); /* 33 */ + HH(d, a, b, c, x[ 8], 11, 0x8771f681); /* 34 */ + HH(c, d, a, b, x[11], 16, 0x6d9d6122); /* 35 */ + HH(b, c, d, a, x[14], 23, 0xfde5380c); /* 36 */ + HH(a, b, c, d, x[ 1], 4, 0xa4beea44); /* 37 */ + HH(d, a, b, c, x[ 4], 11, 0x4bdecfa9); /* 38 */ + HH(c, d, a, b, x[ 7], 16, 0xf6bb4b60); /* 39 */ + HH(b, c, d, a, x[10], 23, 0xbebfbc70); /* 40 */ + HH(a, b, c, d, x[13], 4, 0x289b7ec6); /* 41 */ + HH(d, a, b, c, x[ 0], 11, 0xeaa127fa); /* 42 */ + HH(c, d, a, b, x[ 3], 16, 0xd4ef3085); /* 43 */ + HH(b, c, d, a, x[ 6], 23, 0x4881d05); /* 44 */ + HH(a, b, c, d, x[ 9], 4, 0xd9d4d039); /* 45 */ + HH(d, a, b, c, x[12], 11, 0xe6db99e5); /* 46 */ + HH(c, d, a, b, x[15], 16, 0x1fa27cf8); /* 47 */ + HH(b, c, d, a, x[ 2], 23, 0xc4ac5665); /* 48 */ + + /* Round 4 */ + II(a, b, c, d, x[ 0], 6, 0xf4292244); /* 49 */ + II(d, a, b, c, x[ 7], 10, 0x432aff97); /* 50 */ + II(c, d, a, b, x[14], 15, 0xab9423a7); /* 51 */ + II(b, c, d, a, x[ 5], 21, 0xfc93a039); /* 52 */ + II(a, b, c, d, x[12], 6, 0x655b59c3); /* 53 */ + II(d, a, b, c, x[ 3], 10, 0x8f0ccc92); /* 54 */ + II(c, d, a, b, x[10], 15, 0xffeff47d); /* 55 */ + II(b, c, d, a, x[ 1], 21, 0x85845dd1); /* 56 */ + II(a, b, c, d, x[ 8], 6, 0x6fa87e4f); /* 57 */ + II(d, a, b, c, x[15], 10, 0xfe2ce6e0); /* 58 */ + II(c, d, a, b, x[ 6], 15, 0xa3014314); /* 59 */ + II(b, c, d, a, x[13], 21, 0x4e0811a1); /* 60 */ + II(a, b, c, d, x[ 4], 6, 0xf7537e82); /* 61 */ + II(d, a, b, c, x[11], 10, 0xbd3af235); /* 62 */ + II(c, d, a, b, x[ 2], 15, 0x2ad7d2bb); /* 63 */ + II(b, c, d, a, x[ 9], 21, 0xeb86d391); /* 64 */ + state[0] += a; + state[1] += b; + state[2] += c; + state[3] += d; +} diff --git a/1_3.test_code/c_test/md5/first_ver/md5.h b/1_3.test_code/c_test/md5/first_ver/md5.h new file mode 100644 index 0000000..449ead4 --- /dev/null +++ b/1_3.test_code/c_test/md5/first_ver/md5.h @@ -0,0 +1,57 @@ +/************************************************************************* + > File Name: MD5.h + > Description: md5 encription + > Conclusion: + > Author: rh_Jameson + > Created Time: 2015年07月01日 星期三 21时46分19秒 + ************************************************************************/ + +#ifndef MD5_H +#define MD5_H + +typedef struct +{ + unsigned int count[2]; + unsigned int state[4]; + unsigned char buffer[64]; +}MD5_CTX; + + +#define F(x,y,z) ((x & y) | (~x & z)) +#define G(x,y,z) ((x & z) | (y & ~z)) +#define H(x,y,z) (x^y^z) +#define I(x,y,z) (y ^ (x | ~z)) +#define ROTATE_LEFT(x,n) ((x << n) | (x >> (32-n))) +#define FF(a,b,c,d,x,s,ac) \ +{ \ + a += F(b,c,d) + x + ac; \ + a = ROTATE_LEFT(a,s); \ + a += b; \ +} +#define GG(a,b,c,d,x,s,ac) \ +{ \ + a += G(b,c,d) + x + ac; \ + a = ROTATE_LEFT(a,s); \ + a += b; \ +} +#define HH(a,b,c,d,x,s,ac) \ +{ \ + a += H(b,c,d) + x + ac; \ + a = ROTATE_LEFT(a,s); \ + a += b; \ +} +#define II(a,b,c,d,x,s,ac) \ +{ \ + a += I(b,c,d) + x + ac; \ + a = ROTATE_LEFT(a,s); \ + a += b; \ +} + +void MD5Init(MD5_CTX *context); +void MD5Update(MD5_CTX *context,unsigned char *input,unsigned int inputlen); +void MD5Final(MD5_CTX *context,unsigned char digest[16]); +void MD5Transform(unsigned int state[4],unsigned char block[64]); +void MD5Encode(unsigned char *output,unsigned int *input,unsigned int len); +void MD5Decode(unsigned int *output,unsigned char *input,unsigned int len); + +#endif diff --git a/1_3.test_code/c_test/md5/first_ver/md5_main b/1_3.test_code/c_test/md5/first_ver/md5_main new file mode 100755 index 0000000000000000000000000000000000000000..0a0bb38b873b446a7dcb05372960303c21d45a41 GIT binary patch literal 17584 zcmeHPe|%KcmA^B|z~l$XkVYFs>nN~|XombCFcGUWNd{gpfe49;3XdU~gg`RM&PX=`<|6m5OcMrRt~Zy4~H+XO&Mxg+y$k?OJ13E!*OL(2vkWa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rmNo_H2w_ zirFrxpeotZbHrw8pC=Wmf8+QckoM(LkM<*WO8Y*IJ?_yM?e~EUF~Rt-(Eg26c1Zg& zqE*C7b)*sa)7sPX%VufM--T-o=>C)FLk4@geveA~976zPM=pP8u&3vtRJ+iieHYS~ zun@}*K@H<4{OP&LW(OgZzZ4{PG}=D}En52r>@KeRfSr@rclm;wh~Hso(Av{;*r>FB z3mY|s&L4^TpppfDa=OQ!*Xa9wqrQ>Hk+4lH;fON&VA2IAiFazAqnJ0u4||UvP1r|F-_55S`@8h`A*5EC;LJ3qz`G;WgMa~8%gyCX5&UyADLxP;dv zoZJQlbKx)6H`fq{)zaQd2C~h-azC_oH0JE~V!`n*&7pb){Na=!+$gW%`b^Y+Ul}w& KX)!b!`~P2n#f;+s literal 0 HcmV?d00001 diff --git a/1_3.test_code/c_test/md5/first_ver/md5_main.c b/1_3.test_code/c_test/md5/first_ver/md5_main.c new file mode 100644 index 0000000..6537934 --- /dev/null +++ b/1_3.test_code/c_test/md5/first_ver/md5_main.c @@ -0,0 +1,39 @@ +/************************************************************************* + > File Name: enc_upgr_key.c + > Description: + > Conclusion: + > Author: rh_Jameson + > Created Time: 2015年07月01日 星期三 20时41分53秒 + ************************************************************************/ +#include +#include +#include +#include "md5.h" +#include "md5.c" +unsigned char* get_encry_upg_key(char *serviceCode, char *sipToken, char *version) +{ + char key[] = "2635881a7ab0593849fe89e685fc56cd"; + static unsigned char res[16]; + unsigned char buffer[1024] = ""; + sprintf((char *)buffer, "%s%s%s%s", serviceCode, sipToken, version, key); + + MD5_CTX md5; + MD5Init(&md5); + MD5Update(&md5, buffer, strlen((char *)buffer)); //对欲加密的字符进行加密 + MD5Final(&md5, res); //获得最终结果 + + printf("加密前:%s\n加密后:",buffer); + for(int i = 0; i < 16; i++) + { + printf("%02x ",res[i]); + } + printf("\n\n\n加密结束!\n"); + return res; +} + +int main(int argc, char *argv[]) +{ + get_encry_upg_key("com.meizu.router", "R13PWGPFQRRV03A5100032", "9.0.15070216"); + return 0; +} + diff --git a/1_3.test_code/c_test/md5/first_ver/openssl_md5.c b/1_3.test_code/c_test/md5/first_ver/openssl_md5.c new file mode 100644 index 0000000..e899446 --- /dev/null +++ b/1_3.test_code/c_test/md5/first_ver/openssl_md5.c @@ -0,0 +1,43 @@ +/************************************************************************* + > File Name: openssl_md5.c + > Description: + > Conclusion: + > Author: rh_Jameson + > Created Time: 2015年07月02日 星期四 17时52分19秒 + ************************************************************************/ + +#include +#include +#include +#include + +int main() +{ + // use unsigned char + unsigned char digest[16]; + char *input = "hek2mgl"; + int length = strlen(input); + int i=0; + + // don't miss the underscore after MD5 + MD5_CTX md5; + MD5_Init(&md5); + + while (length > 0) { + if (length > 512) { + MD5_Update(&md5, input, 512); + } else { + MD5_Update(&md5, input, length); + } + length -= 512; + input += 512; + } + + MD5_Final(digest, &md5); + printf("digest is: "); + for(i = 0; i < 16; i++) { + printf("%02x", digest[i]); + } + printf("\n"); + return 0; +} diff --git a/1_3.test_code/c_test/md5/second_ver/get_encry_upg_key b/1_3.test_code/c_test/md5/second_ver/get_encry_upg_key new file mode 100755 index 0000000000000000000000000000000000000000..1ca81eede0d3f3e859e42c23046d7cedd962a69c GIT binary patch literal 17528 zcmeG^dwi6|wX?ekNq8g+jhYJRD$qtKOCBU7KI-PN;fqZmLV{2HvLqW4$;;gh4ODF~ zMp@U`)F?<^}Zn@mh5Gy66}Y$V=6B>rS<^m0N4EsrHJ2fKjH zWz&EX4?hQ$Amlj-M@7{VCJH_az&QBjnK>cP?4XQ<^EjDFC|igS^+l6IWI2pm%25d! zvk?L1u&q`*p#ZBXBjJc>$Ebi(4pEd#7jo%BPQpRaFbQSg&GLulsT@7;B&aaxRf^m(|H?Cbo|3(B9fGulm*pRz? zS!3aEoI%30i7H!z}b@gTUL)Z%D$ryntgGT~{ zQM!hX<42|p4PCYw%kngI?YiO6(6#eM(a^Q+tkBTq9LM^V&f|$nApSoW+nCbT>x&P4 zkBBcO?#EKb!a0vYQFzhg@JzYT0X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Ed@SZJ8h2O&&(<>&Z+dcn!R-`o~DYXih88xI-6@+YTXs}6-_r2UhF0uiUC(k))bUGRp+W= zFafuR%gX0-jkk?@ z4$AYOfh7&iu109h3dpNPmDe)0w6a`{TEDWq2yI{K+R*4`xGmzB?&ubu!yzx;;T=2G zO}i#uIlsqeU@+YIiM&Z>VJ;`=Nt z#gX`tXLbM>H-z)D6+XP(#xgJV96Ea$Pxj*)a3KvR7 z0gdv-K>rNhIi>y`W(RTZ5Cqx&c%nw%%LU3-K?dKkrF_ur01WO63c^9c_}yvjyYc;a z9nfH@i^$7;c@GjH$@h4UjkO=%JH>ZssbB8jt)inc7RvTZJ_$F0Jie1lT<-JJg}g&3 zo(53cenDniA%m<^UcL{|%}k)D2}Y^k*#A3)e4*fz?+qP7f3HR!|JGuZzYl2GE^Hqr z`F`OL3XMBqQ7vbNryqV=dHEhvE#&EMk`ZoL>8TpMk&QENj)GyzIY+q6S z4pJ^BA642u5C@hSDoad5<-U)~QNT?Pe^BtOTZxTGJ00&V*v?~fT=;#w&v zpp=vFgh5{JYdeH|he6(9z`p<->yrJC?E7$Gh9vcHjJH+h5#kFewqK}25>G<@Dv1jy z%t File Name: main.c + > Description: + > Conclusion: + > Author: rh_Jameson + > Created Time: 2015年07月02日 星期四 18时16分37秒 + ************************************************************************/ + +#include +#include +#include +//#include "md5.h" +#include "md5.c" + +void get_encry_upg_key(char *serviceCode, char *sipToken, char *version) +{ + char *key = "2635881a7ab0593849fe89e685fc56cd"; + unsigned char res[17]; + //unsigned char buffer[1024] = "com.meizu.routerR13PWGPFQRRV03A51000329.0.150702162635881a7ab0593849fe89e685fc56cd"; + unsigned char buffer[] ="cizu.routerR13PWGPFQRRV03A51000329.0.150702162635881a7ab0593849fe89e685fc56cd"; + //sprintf(buffer, "%s%s%s%s", serviceCode, sipToken, version, key); + + MD5_CTX md5; + MD5Init(&md5); + MD5Update(&md5, buffer, strlen((char *)buffer)); //对欲加密的字符进行加密 + MD5Final(res, &md5); //获得最终结果 + + printf("加密前:%s\n加密后:",buffer); + for(int i = 0; i < 16; i++) + { + printf("%02x ",res[i]); + } + printf("\n\n\n加密结束!\n"); + +} + + +int main(int argc, char* argv[]) +{ + get_encry_upg_key("123", "456", "789"); + return 0; +} diff --git a/1_3.test_code/c_test/md5/second_ver/main b/1_3.test_code/c_test/md5/second_ver/main new file mode 100755 index 0000000000000000000000000000000000000000..aa67a243d243d2e8418669bf166bea115f45f6ce GIT binary patch literal 17512 zcmeG^3v^V~wPz*?N%$lKjhaf;QN#v>Aqj#3+s90jfg74Y3W=pE+zgosi6)aYGtuCx zzR)4cbUK#$X|ZqlUTj@0TGx`US9$aB2}!U->!(qx(n{OdSLg)%prx3l$h^JxIp@y3 zHxuG|B&_w;dWSW4pS{oioU`}&-Q08dXLsdFtHr`(va)|-h&iV?iNv3b#lJ$Rpp~#} z=46+%*=!0>GT`T=5`;V_;fPQzVV2-a1DFoK5-TT^Se=xS@JpP`B$PEoi1w1nDY6`T z7jRTU#_U8uIjpPAK`6jF%1C%p)MG?IDTgS^6$rTkAt&LWsF;MZeb_eq)d+nxRwrPH zI}xyQdL|+AVyZqG^kQC_PbfeqWhC@+GLulseI4Ymo}V|_1mikkZ%n_4_MH?^0Jf;P zY4g(S7BzbpHaGb@Iu~}9EM2(tI!B<@QB3Vd{m8p&O)XiHezXIIbL~K`em}~=&}x2R-mI}|B|UtN0(y;%Sv=~{k-DT(e>j>(b4twtk%)x9Dw>a z=;+X3Eh(XQvy@0i$9y|ex_g5e@emX#q35y=YAlpVEZGb!iMd{Q=3e219O8{wHawJo zH1{UN(KW+^gs(#!T{7HD_-e$_6~lW7FGU<(Fx*4TLe!#fEtMjV?w+(r0&#IdQv zZG>NiI5u&(4)CJ)D#EXBQo?^xLVrD3T~jg8%jP?oGSIhk9)f{83!E(eBVat$kb6Zr zW3kMlI##PJWB`=VNRARddi(4cXd^ew+;{*B5<|ee9f@q?L2Pw{L*o0fyjI!vJ}Kxs zn+6J$@JXdFzCy7aQeH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lOU<@gRRak;NoguGM8PXVZ}zaXh^PdC%Uf7lyo9ey>ShzCY~|_J4)SbxFogl6oPN13%H-wf(%j zcW>r5<1c}1u1;R=kMkWsgk*+@D$MX@^XLMCFHwI@=g=} z3E-$pwqM)l;lvC{+Tj?tCG!aJ1r+TIb4cPz$gh^TfXItU!kLiQY*Pt;td{mAqbM_> qq(}CBojBW2%&}@*Tp-~m2vjNCBj+_7pQ-HcUIqn_mYWLA_WuXrU$kHV literal 0 HcmV?d00001 diff --git a/1_3.test_code/c_test/md5/second_ver/main.c b/1_3.test_code/c_test/md5/second_ver/main.c new file mode 100644 index 0000000..90db660 --- /dev/null +++ b/1_3.test_code/c_test/md5/second_ver/main.c @@ -0,0 +1,64 @@ +/************************************************************************* + > File Name: main.c + > Description: + > Conclusion: + > Author: rh_Jameson + > Created Time: 2015年07月02日 星期四 18时16分37秒 + ************************************************************************/ + +#include +#include +#include +//#include "md5.h" +#include "md5.c" + + +/* +void get_encry_upg_key(char *serviceCode, char *sipToken, char *version) +{ + //char *key = "2635881a7ab0593849fe89e685fc56cd"; + unsigned char *res = (unsigned char *)malloc(17 * sizeof(unsigned char *)); + char *buffer = (char *)malloc(120 * sizeof(char *)); + sprintf(buffer, "%s%s%s%s", serviceCode, sipToken, version, key); + + MD5_CTX md5; + MD5Init(&md5); + MD5Update(&md5, (unsigned char*)buffer, strlen((char *)buffer)); //对欲加密的字符进行加密 + MD5Final(res, &md5); //获得最终结果 + + printf("加密前:%s\n加密后:",buffer); + for(int i = 0; i < 16; i++) + { + printf("%02x ",res[i]); + } + + printf("\n\n\n加密结束!\n"); +} +*/ + + + +int main(int argc, char* argv[]) +{ + //get_encry_upg_key("123", "456", "789"); + + int i; + MD5_CTX md5; + MD5Init(&md5); //初始化用于md5加密的结构 + + unsigned char encrypt[1024]; //存放于加密的信息 + unsigned char decrypt[17]; //存放加密后的结果 + scanf("%s",encrypt); //输入加密的字符 + MD5Update(&md5,encrypt,strlen((char *)encrypt)); //对欲加密的字符进行加密 + MD5Final(decrypt,&md5); //获得最终结果 + + printf("加密前:%s\n加密后:",encrypt); + for(i=0; i<16; i++) + { + printf("%02x ",decrypt[i]); + } + + printf("\n\n\n加密结束!\n"); + + return 0; +} diff --git a/1_3.test_code/c_test/md5/second_ver/md5.c b/1_3.test_code/c_test/md5/second_ver/md5.c new file mode 100644 index 0000000..3c9bf45 --- /dev/null +++ b/1_3.test_code/c_test/md5/second_ver/md5.c @@ -0,0 +1,295 @@ +/************************************************************************* + > File Name: md5.c + > Description: + > Conclusion: + > Author: rh_Jameson + > Created Time: 2015年07月02日 星期四 18时15分33秒 + ************************************************************************/ + +#include "md5.h" +#include + +/*md5转换用到的常量,算法本身规定的*/ +#define S11 7 +#define S12 12 +#define S13 17 +#define S14 22 +#define S21 5 +#define S22 9 +#define S23 14 +#define S24 20 +#define S31 4 +#define S32 11 +#define S33 16 +#define S34 23 +#define S41 6 +#define S42 10 +#define S43 15 +#define S44 21 + +static void MD5Transform(UINT4 [4], unsigned char [64]); +static void Encode(unsigned char *, UINT4 *, unsigned int); +static void Decode(UINT4 *, unsigned char *, unsigned int); + +/* +用于bits填充的缓冲区,为什么要64个字节呢?因为当欲加密的信息的bits数被512除其余数为448时, +需要填充的bits的最大值为512=64*8 。 +*/ +static unsigned char PADDING[64] = { + 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +}; + +/* +接下来的这几个宏定义是md5算法规定的,就是对信息进行md5加密都要做的运算。 +据说有经验的高手跟踪程序时根据这几个特殊的操作就可以断定是不是用的md5 +*/ +/* F, G, H and I are basic MD5 functions. + */ +#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) +#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) +#define H(x, y, z) ((x) ^ (y) ^ (z)) +#define I(x, y, z) ((y) ^ ((x) | (~z))) + +/* ROTATE_LEFT rotates x left n bits. + */ +#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) + +/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. + Rotation is separate from addition to prevent recomputation. + */ +#define FF(a, b, c, d, x, s, ac) { (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); (a) = ROTATE_LEFT ((a), (s)); (a) += (b); } +#define GG(a, b, c, d, x, s, ac) { (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); (a) = ROTATE_LEFT ((a), (s)); (a) += (b); } +#define HH(a, b, c, d, x, s, ac) { (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); (a) = ROTATE_LEFT ((a), (s)); (a) += (b); } +#define II(a, b, c, d, x, s, ac) { (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); (a) = ROTATE_LEFT ((a), (s)); (a) += (b); } + +/* MD5 initialization. Begins an MD5 operation, writing a new context. */ +/*初始化md5的结构*/ +void MD5Init (MD5_CTX *context) +{ + /*将当前的有效信息的长度设成0,这个很简单,还没有有效信息,长度当然是0了*/ + context->count[0] = context->count[1] = 0; + + /* Load magic initialization constants.*/ + /*初始化链接变量,算法要求这样,这个没法解释了*/ + context->state[0] = 0x67452301; + context->state[1] = 0xefcdab89; + context->state[2] = 0x98badcfe; + context->state[3] = 0x10325476; +} + +/* MD5 block update operation. Continues an MD5 message-digest + operation, processing another message block, and updating the + context. */ +/*将与加密的信息传递给md5结构,可以多次调用 +context:初始化过了的md5结构 +input:欲加密的信息,可以任意长 +inputLen:指定input的长度 +*/ +void MD5Update(MD5_CTX *context,unsigned char * input,unsigned int inputLen) +{ + unsigned int i, index, partLen; + + /* Compute number of bytes mod 64 */ + /*计算已有信息的bits长度的字节数的模64, 64bytes=512bits。 + 用于判断已有信息加上当前传过来的信息的总长度能不能达到512bits, + 如果能够达到则对凑够的512bits进行一次处理*/ + index = (unsigned int)((context->count[0] >> 3) & 0x3F); + + /* Update number of bits *//*更新已有信息的bits长度*/ + if((context->count[0] += ((UINT4)inputLen << 3)) < ((UINT4)inputLen << 3)) + context->count[1]++; + context->count[1] += ((UINT4)inputLen >> 29); + + /*计算已有的字节数长度还差多少字节可以 凑成64的整倍数*/ + partLen = 64 - index; + + /* Transform as many times as possible. + */ + /*如果当前输入的字节数 大于 已有字节数长度补足64字节整倍数所差的字节数*/ + if(inputLen >= partLen) { + /*用当前输入的内容把context->buffer的内容补足512bits*/ + R_memcpy((POINTER)&context->buffer[index], (POINTER)input, partLen); + /*用基本函数对填充满的512bits(已经保存到context->buffer中) 做一次转换,转换结果保存到context->state中*/ + MD5Transform(context->state, context->buffer); + + /* + 对当前输入的剩余字节做转换(如果剩余的字节<在输入的input缓冲区中>大于512bits的话 ), + 转换结果保存到context->state中 + */ + for(i = partLen; i + 63 < inputLen; i += 64 )/*把i+63state, &input[i]); + + index = 0; + } else + i = 0; + + /* Buffer remaining input */ + /*将输入缓冲区中的不足填充满512bits的剩余内容填充到context->buffer中,留待以后再作处理*/ + R_memcpy((POINTER)&context->buffer[index], (POINTER)&input[i], inputLen-i); +} + +/* MD5 finalization. Ends an MD5 message-digest operation, writing the + the message digest and zeroizing the context. */ +/*获取加密 的最终结果 +digest:保存最终的加密串 +context:你前面初始化并填入了信息的md5结构 +*/ +void MD5Final (unsigned char digest[16],MD5_CTX *context) +{ + unsigned char bits[8]; + unsigned int index, padLen; + + /* Save number of bits */ + /*将要被转换的信息(所有的)的bits长度拷贝到bits中*/ + Encode(bits, context->count, 8); + + /* Pad out to 56 mod 64. */ + /* 计算所有的bits长度的字节数的模64, 64bytes=512bits*/ + index = (unsigned int)((context->count[0] >> 3) & 0x3f); + /*计算需要填充的字节数,padLen的取值范围在1-64之间*/ + padLen = (index < 56) ? (56 - index) : (120 - index); + /*这一次函数调用绝对不会再导致MD5Transform的被调用,因为这一次不会填满512bits*/ + MD5Update(context, PADDING, padLen); + + /* Append length (before padding) */ + /*补上原始信息的bits长度(bits长度固定的用64bits表示),这一次能够恰巧凑够512bits,不会多也不会少*/ + MD5Update(context, bits, 8); + + /* Store state in digest */ + /*将最终的结果保存到digest中。ok,终于大功告成了*/ + Encode(digest, context->state, 16); + + /* Zeroize sensitive information. */ + + R_memset((POINTER)context, 0, sizeof(*context)); +} + +/* MD5 basic transformation. Transforms state based on block. */ +/* +对512bits信息(即block缓冲区)进行一次处理,每次处理包括四轮 +state[4]:md5结构中的state[4],用于保存对512bits信息加密的中间结果或者最终结果 +block[64]:欲加密的512bits信息 +*/ +static void MD5Transform (UINT4 state[4], unsigned char block[64]) +{ + UINT4 a = state[0], b = state[1], c = state[2], d = state[3], x[16]; + + Decode(x, block, 64); + + /* Round 1 */ + FF(a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */ + FF(d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */ + FF(c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */ + FF(b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */ + FF(a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */ + FF(d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */ + FF(c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */ + FF(b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */ + FF(a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */ + FF(d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */ + FF(c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */ + FF(b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */ + FF(a, b, c, d, x[12], S11, 0x6b901122); /* 13 */ + FF(d, a, b, c, x[13], S12, 0xfd987193); /* 14 */ + FF(c, d, a, b, x[14], S13, 0xa679438e); /* 15 */ + FF(b, c, d, a, x[15], S14, 0x49b40821); /* 16 */ + + /* Round 2 */ + GG(a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */ + GG(d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */ + GG(c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */ + GG(b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */ + GG(a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */ + GG(d, a, b, c, x[10], S22, 0x2441453); /* 22 */ + GG(c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */ + GG(b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */ + GG(a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */ + GG(d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */ + GG(c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */ + GG(b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */ + GG(a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */ + GG(d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */ + GG(c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */ + GG(b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */ + + /* Round 3 */ + HH(a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */ + HH(d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */ + HH(c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */ + HH(b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */ + HH(a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */ + HH(d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */ + HH(c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */ + HH(b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */ + HH(a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */ + HH(d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */ + HH(c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */ + HH(b, c, d, a, x[ 6], S34, 0x4881d05); /* 44 */ + HH(a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */ + HH(d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */ + HH(c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */ + HH(b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */ + + /* Round 4 */ + II(a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */ + II(d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */ + II(c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */ + II(b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */ + II(a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */ + II(d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */ + II(c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */ + II(b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */ + II(a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */ + II(d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */ + II(c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */ + II(b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */ + II(a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */ + II(d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */ + II(c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */ + II(b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */ + + state[0] += a; + state[1] += b; + state[2] += c; + state[3] += d; + + /* Zeroize sensitive information. */ + R_memset((POINTER)x, 0, sizeof(x)); +} + +/* Encodes input (UINT4) into output (unsigned char). Assumes len is + a multiple of 4. */ +/*将4字节的整数copy到字符形式的缓冲区中 +output:用于输出的字符缓冲区 +input:欲转换的四字节的整数形式的数组 +len:output缓冲区的长度,要求是4的整数倍 +*/ +static void Encode(unsigned char *output, UINT4 *input,unsigned int len) +{ + unsigned int i, j; + + for(i = 0, j = 0; j < len; i++, j += 4) { + output[j] = (unsigned char)(input[i] & 0xff); + output[j+1] = (unsigned char)((input[i] >> 8) & 0xff); + output[j+2] = (unsigned char)((input[i] >> 16) & 0xff); + output[j+3] = (unsigned char)((input[i] >> 24) & 0xff); + } +} + +/* Decodes input (unsigned char) into output (UINT4). Assumes len is + a multiple of 4. */ +/*与上面的函数正好相反,这一个把字符形式的缓冲区中的数据copy到4字节的整数中(即以整数形式保存) +output:保存转换出的整数 +input:欲转换的字符缓冲区 +len:输入的字符缓冲区的长度,要求是4的整数倍 +*/ +static void Decode(UINT4 *output, unsigned char *input,unsigned int len) +{ + unsigned int i, j; + + for(i = 0, j = 0; j < len; i++, j += 4) + output[i] = ((UINT4)input[j]) | (((UINT4)input[j+1]) << 8) | + (((UINT4)input[j+2]) << 16) | (((UINT4)input[j+3]) << 24); +} diff --git a/1_3.test_code/c_test/md5/second_ver/md5.h b/1_3.test_code/c_test/md5/second_ver/md5.h new file mode 100644 index 0000000..26f15aa --- /dev/null +++ b/1_3.test_code/c_test/md5/second_ver/md5.h @@ -0,0 +1,38 @@ +/************************************************************************* + > File Name: md5.h + > Description: + > Conclusion: + > Author: rh_Jameson + > Created Time: 2015年07月02日 星期四 18时14分42秒 + ************************************************************************/ + +#ifndef _MD5_H_ +#define _MD5_H_ + +#define R_memset(x, y, z) memset(x, y, z) +#define R_memcpy(x, y, z) memcpy(x, y, z) +#define R_memcmp(x, y, z) memcmp(x, y, z) + +typedef unsigned long UINT4; +typedef unsigned char *POINTER; + +/* MD5 context. */ +typedef struct { + /* state (ABCD) */ + /*四个32bits数,用于存放最终计算得到的消息摘要。当消息长度〉512bits时,也用于存放每个512bits的中间结果*/ + UINT4 state[4]; + + /* number of bits, modulo 2^64 (lsb first) */ + /*存储原始信息的bits数长度,不包括填充的bits,最长为 2^64 bits,因为2^64是一个64位数的最大值*/ + UINT4 count[2]; + + /* input buffer */ + /*存放输入的信息的缓冲区,512bits*/ + unsigned char buffer[64]; +} MD5_CTX; + +void MD5Init(MD5_CTX *); +void MD5Update(MD5_CTX *, unsigned char *, unsigned int); +void MD5Final(unsigned char [16], MD5_CTX *); + +#endif /* _MD5_H_ */ diff --git a/1_3.test_code/c_test/testSprintf.c b/1_3.test_code/c_test/testSprintf.c deleted file mode 100644 index 25c9e67..0000000 --- a/1_3.test_code/c_test/testSprintf.c +++ /dev/null @@ -1,16 +0,0 @@ -/************************************************************************* - > File Name: testSprintf.c - > Description: - > Conclusion: - > Author: rh_Jameson - > Created Time: 2015年06月29日 星期一 13时34分48秒 - ************************************************************************/ - -#include -int main(){ - char buffer[50]; - int val = 10; - sprintf(buffer, "helloworld %d", val); - printf("%s", buffer); - printf("%d, %d", __LINE__, __func__); -}