root / trunk / web / dojo / dojox / encoding / digests / MD5.js
History | View | Annotate | Download (4.24 KB)
1 | 9 | andrej.cim | /*
|
---|---|---|---|
2 | Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
|
||
3 | Available via Academic Free License >= 2.1 OR the modified BSD license.
|
||
4 | see: http://dojotoolkit.org/license for details
|
||
5 | */
|
||
6 | |||
7 | |||
8 | if(!dojo._hasResource["dojox.encoding.digests.MD5"]){ |
||
9 | dojo._hasResource["dojox.encoding.digests.MD5"]=true; |
||
10 | dojo.provide("dojox.encoding.digests.MD5");
|
||
11 | dojo.require("dojox.encoding.digests._base");
|
||
12 | (function(){
|
||
13 | var _1=dojox.encoding.digests;
|
||
14 | var _2=8; |
||
15 | function R(n,c){ |
||
16 | return (n<<c)|(n>>>(32-c)); |
||
17 | }; |
||
18 | function C(q,a,b,x,s,t){ |
||
19 | return _1.addWords(R(_1.addWords(_1.addWords(a,q),_1.addWords(x,t)),s),b);
|
||
20 | }; |
||
21 | function FF(a,b,c,d,x,s,t){ |
||
22 | return C((b&c)|((~b)&d),a,b,x,s,t);
|
||
23 | }; |
||
24 | function GG(a,b,c,d,x,s,t){ |
||
25 | return C((b&d)|(c&(~d)),a,b,x,s,t);
|
||
26 | }; |
||
27 | function HH(a,b,c,d,x,s,t){ |
||
28 | return C(b^c^d,a,b,x,s,t);
|
||
29 | }; |
||
30 | function II(a,b,c,d,x,s,t){ |
||
31 | return C(c^(b|(~d)),a,b,x,s,t);
|
||
32 | }; |
||
33 | function _3(x,_4){ |
||
34 | x[_4>>5]|=128<<((_4)%32); |
||
35 | x[(((_4+64)>>>9)<<4)+14]=_4; |
||
36 | var a=1732584193; |
||
37 | var b=-271733879; |
||
38 | var c=-1732584194; |
||
39 | var d=271733878; |
||
40 | for(var i=0;i<x.length;i+=16){ |
||
41 | var _5=a;
|
||
42 | var _6=b;
|
||
43 | var _7=c;
|
||
44 | var _8=d;
|
||
45 | a=FF(a,b,c,d,x[i+0],7,-680876936); |
||
46 | d=FF(d,a,b,c,x[i+1],12,-389564586); |
||
47 | c=FF(c,d,a,b,x[i+2],17,606105819); |
||
48 | b=FF(b,c,d,a,x[i+3],22,-1044525330); |
||
49 | a=FF(a,b,c,d,x[i+4],7,-176418897); |
||
50 | d=FF(d,a,b,c,x[i+5],12,1200080426); |
||
51 | c=FF(c,d,a,b,x[i+6],17,-1473231341); |
||
52 | b=FF(b,c,d,a,x[i+7],22,-45705983); |
||
53 | a=FF(a,b,c,d,x[i+8],7,1770035416); |
||
54 | d=FF(d,a,b,c,x[i+9],12,-1958414417); |
||
55 | c=FF(c,d,a,b,x[i+10],17,-42063); |
||
56 | b=FF(b,c,d,a,x[i+11],22,-1990404162); |
||
57 | a=FF(a,b,c,d,x[i+12],7,1804603682); |
||
58 | d=FF(d,a,b,c,x[i+13],12,-40341101); |
||
59 | c=FF(c,d,a,b,x[i+14],17,-1502002290); |
||
60 | b=FF(b,c,d,a,x[i+15],22,1236535329); |
||
61 | a=GG(a,b,c,d,x[i+1],5,-165796510); |
||
62 | d=GG(d,a,b,c,x[i+6],9,-1069501632); |
||
63 | c=GG(c,d,a,b,x[i+11],14,643717713); |
||
64 | b=GG(b,c,d,a,x[i+0],20,-373897302); |
||
65 | a=GG(a,b,c,d,x[i+5],5,-701558691); |
||
66 | d=GG(d,a,b,c,x[i+10],9,38016083); |
||
67 | c=GG(c,d,a,b,x[i+15],14,-660478335); |
||
68 | b=GG(b,c,d,a,x[i+4],20,-405537848); |
||
69 | a=GG(a,b,c,d,x[i+9],5,568446438); |
||
70 | d=GG(d,a,b,c,x[i+14],9,-1019803690); |
||
71 | c=GG(c,d,a,b,x[i+3],14,-187363961); |
||
72 | b=GG(b,c,d,a,x[i+8],20,1163531501); |
||
73 | a=GG(a,b,c,d,x[i+13],5,-1444681467); |
||
74 | d=GG(d,a,b,c,x[i+2],9,-51403784); |
||
75 | c=GG(c,d,a,b,x[i+7],14,1735328473); |
||
76 | b=GG(b,c,d,a,x[i+12],20,-1926607734); |
||
77 | a=HH(a,b,c,d,x[i+5],4,-378558); |
||
78 | d=HH(d,a,b,c,x[i+8],11,-2022574463); |
||
79 | c=HH(c,d,a,b,x[i+11],16,1839030562); |
||
80 | b=HH(b,c,d,a,x[i+14],23,-35309556); |
||
81 | a=HH(a,b,c,d,x[i+1],4,-1530992060); |
||
82 | d=HH(d,a,b,c,x[i+4],11,1272893353); |
||
83 | c=HH(c,d,a,b,x[i+7],16,-155497632); |
||
84 | b=HH(b,c,d,a,x[i+10],23,-1094730640); |
||
85 | a=HH(a,b,c,d,x[i+13],4,681279174); |
||
86 | d=HH(d,a,b,c,x[i+0],11,-358537222); |
||
87 | c=HH(c,d,a,b,x[i+3],16,-722521979); |
||
88 | b=HH(b,c,d,a,x[i+6],23,76029189); |
||
89 | a=HH(a,b,c,d,x[i+9],4,-640364487); |
||
90 | d=HH(d,a,b,c,x[i+12],11,-421815835); |
||
91 | c=HH(c,d,a,b,x[i+15],16,530742520); |
||
92 | b=HH(b,c,d,a,x[i+2],23,-995338651); |
||
93 | a=II(a,b,c,d,x[i+0],6,-198630844); |
||
94 | d=II(d,a,b,c,x[i+7],10,1126891415); |
||
95 | c=II(c,d,a,b,x[i+14],15,-1416354905); |
||
96 | b=II(b,c,d,a,x[i+5],21,-57434055); |
||
97 | a=II(a,b,c,d,x[i+12],6,1700485571); |
||
98 | d=II(d,a,b,c,x[i+3],10,-1894986606); |
||
99 | c=II(c,d,a,b,x[i+10],15,-1051523); |
||
100 | b=II(b,c,d,a,x[i+1],21,-2054922799); |
||
101 | a=II(a,b,c,d,x[i+8],6,1873313359); |
||
102 | d=II(d,a,b,c,x[i+15],10,-30611744); |
||
103 | c=II(c,d,a,b,x[i+6],15,-1560198380); |
||
104 | b=II(b,c,d,a,x[i+13],21,1309151649); |
||
105 | a=II(a,b,c,d,x[i+4],6,-145523070); |
||
106 | d=II(d,a,b,c,x[i+11],10,-1120210379); |
||
107 | c=II(c,d,a,b,x[i+2],15,718787259); |
||
108 | b=II(b,c,d,a,x[i+9],21,-343485551); |
||
109 | a=_1.addWords(a,_5); |
||
110 | b=_1.addWords(b,_6); |
||
111 | c=_1.addWords(c,_7); |
||
112 | d=_1.addWords(d,_8); |
||
113 | } |
||
114 | return [a,b,c,d];
|
||
115 | }; |
||
116 | function _9(_a,_b){ |
||
117 | var wa=_1.stringToWord(_b);
|
||
118 | if(wa.length>16){ |
||
119 | wa=_3(wa,_b.length*_2); |
||
120 | } |
||
121 | var l=[],r=[];
|
||
122 | for(var i=0;i<16;i++){ |
||
123 | l[i]=wa[i]^909522486;
|
||
124 | r[i]=wa[i]^1549556828;
|
||
125 | } |
||
126 | var h=_3(l.concat(_1.stringToWord(_a)),512+_a.length*_2); |
||
127 | return _3(r.concat(h),640); |
||
128 | }; |
||
129 | _1.MD5=function(_c,_d){ |
||
130 | var _e=_d||_1.outputTypes.Base64;
|
||
131 | var wa=_3(_1.stringToWord(_c),_c.length*_2);
|
||
132 | switch(_e){
|
||
133 | case _1.outputTypes.Raw:
|
||
134 | return wa;
|
||
135 | case _1.outputTypes.Hex:
|
||
136 | return _1.wordToHex(wa);
|
||
137 | case _1.outputTypes.String:
|
||
138 | return _1.wordToString(wa);
|
||
139 | default:
|
||
140 | return _1.wordToBase64(wa);
|
||
141 | } |
||
142 | }; |
||
143 | _1.MD5._hmac=function(_f,key,_10){ |
||
144 | var out=_10||_1.outputTypes.Base64;
|
||
145 | var wa=_9(_f,key);
|
||
146 | switch(out){
|
||
147 | case _1.outputTypes.Raw:
|
||
148 | return wa;
|
||
149 | case _1.outputTypes.Hex:
|
||
150 | return _1.wordToHex(wa);
|
||
151 | case _1.outputTypes.String:
|
||
152 | return _1.wordToString(wa);
|
||
153 | default:
|
||
154 | return _1.wordToBase64(wa);
|
||
155 | } |
||
156 | }; |
||
157 | })(); |
||
158 | } |