dojo.provide("dojox.encoding.digests.MD5"); dojo.require("dojox.encoding.digests._base"); /* A port of Paul Johnstone's MD5 implementation * http://pajhome.org.uk/crypt/md5/index.html * * Copyright (C) Paul Johnston 1999 - 2002. * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet * Distributed under the BSD License * * Dojo port by Tom Trenka */ (function(){ var dxd=dojox.encoding.digests; var chrsz=8; // MD5 rounds functions function R(n,c){ return (n<>>(32-c)); } function C(q,a,b,x,s,t){ return dxd.addWords(R(dxd.addWords(dxd.addWords(a, q), dxd.addWords(x, t)), s), b); } function FF(a,b,c,d,x,s,t){ return C((b&c)|((~b)&d),a,b,x,s,t); } function GG(a,b,c,d,x,s,t){ return C((b&d)|(c&(~d)),a,b,x,s,t); } function HH(a,b,c,d,x,s,t){ return C(b^c^d,a,b,x,s,t); } function II(a,b,c,d,x,s,t){ return C(c^(b|(~d)),a,b,x,s,t); } // the core MD5 rounds method function core(x,len){ x[len>>5]|=0x80<<((len)%32); x[(((len+64)>>>9)<<4)+14]=len; var a= 1732584193; var b=-271733879; var c=-1732584194; var d= 271733878; for(var i=0; i16){ wa=core(wa, key.length*chrsz); } var l=[], r=[]; for(var i=0; i<16; i++){ l[i]=wa[i]^0x36363636; r[i]=wa[i]^0x5c5c5c5c; } var h=core(l.concat(dxd.stringToWord(data)), 512+data.length*chrsz); return core(r.concat(h), 640); } // public function dxd.MD5=function(/* string */data, /* dojox.encoding.digests.outputTypes? */outputType){ // summary // computes the digest of data, and returns the result according to type outputType var out=outputType || dxd.outputTypes.Base64; var wa=core(dxd.stringToWord(data), data.length*chrsz); switch(out){ case dxd.outputTypes.Raw:{ return wa; // word[] } case dxd.outputTypes.Hex:{ return dxd.wordToHex(wa); // string } case dxd.outputTypes.String:{ return dxd.wordToString(wa); // string } default:{ return dxd.wordToBase64(wa); // string } } }; // make this private, for later use with a generic HMAC calculator. dxd.MD5._hmac=function(/* string */data, /* string */key, /* dojox.encoding.digests.outputTypes? */outputType){ // summary // computes the digest of data, and returns the result according to type outputType var out=outputType || dxd.outputTypes.Base64; var wa=hmac(data, key); switch(out){ case dxd.outputTypes.Raw:{ return wa; // word[] } case dxd.outputTypes.Hex:{ return dxd.wordToHex(wa); // string } case dxd.outputTypes.String:{ return dxd.wordToString(wa); // string } default:{ return dxd.wordToBase64(wa); // string } } }; })();