From e44a7e37b6c7b5961adaffc62b9042b8d442938e Mon Sep 17 00:00:00 2001 From: mensonge Date: Thu, 13 Nov 2008 09:49:11 +0000 Subject: New feature: basic Ajax suggestion for tags and implementation of Dojo toolkit git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@151 b3834d28-1941-0410-a4f8-b48e95affb8f --- includes/js/dojox/encoding/digests/MD5.js | 177 ++++++++++++++++++++++++++++++ 1 file changed, 177 insertions(+) create mode 100644 includes/js/dojox/encoding/digests/MD5.js (limited to 'includes/js/dojox/encoding/digests/MD5.js') diff --git a/includes/js/dojox/encoding/digests/MD5.js b/includes/js/dojox/encoding/digests/MD5.js new file mode 100644 index 0000000..eb72d59 --- /dev/null +++ b/includes/js/dojox/encoding/digests/MD5.js @@ -0,0 +1,177 @@ +if(!dojo._hasResource["dojox.encoding.digests.MD5"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code. +dojo._hasResource["dojox.encoding.digests.MD5"] = true; +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 + } + } + }; +})(); + +} -- cgit v1.2.3