sha1.js 2.5 KB

1
  1. (function(){function r(g){var v=g.jsustoolkitErrCode=g.jsustoolkitErrCode||{},e=g.sha1=g.sha1||{};g.md=g.md||{};g.md.algorithms=g.md.algorithms||{};g.md.sha1=g.md.algorithms.sha1=e;var p=null,q=!1,t=function(l,f,g){for(var a,b,c,k,h,m,e,d,p=g.length();64<=p;){b=l.h0;c=l.h1;k=l.h2;h=l.h3;m=l.h4;for(d=0;16>d;++d)a=g.getInt32(),f[d]=a,e=h^c&(k^h),a=(b<<5|b>>>27)+e+m+1518500249+a,m=h,h=k,k=c<<30|c>>>2,c=b,b=a;for(;20>d;++d)a=f[d-3]^f[d-8]^f[d-14]^f[d-16],a=a<<1|a>>>31,f[d]=a,e=h^c&(k^h),a=(b<<5|b>>>27)+e+m+1518500249+a,m=h,h=k,k=c<<30|c>>>2,c=b,b=a;for(;32>d;++d)a=f[d-3]^f[d-8]^f[d-14]^f[d-16],a=a<<1|a>>>31,f[d]=a,e=c^k^h,a=(b<<5|b>>>27)+e+m+1859775393+a,m=h,h=k,k=c<<30|c>>>2,c=b,b=a;for(;40>d;++d)a=f[d-6]^f[d-16]^f[d-28]^f[d-32],a=a<<2|a>>>30,f[d]=a,e=c^k^h,a=(b<<5|b>>>27)+e+m+1859775393+a,m=h,h=k,k=c<<30|c>>>2,c=b,b=a;for(;60>d;++d)a=f[d-6]^f[d-16]^f[d-28]^f[d-32],a=a<<2|a>>>30,f[d]=a,e=c&k|h&(c^k),a=(b<<5|b>>>27)+e+m+2400959708+a,m=h,h=k,k=c<<30|c>>>2,c=b,b=a;for(;80>d;++d)a=f[d-6]^f[d-16]^f[d-28]^f[d-32],a=a<<2|a>>>30,f[d]=a,e=c^k^h,a=(b<<5|b>>>27)+e+m+3395469782+a,m=h,h=k,k=c<<30|c>>>2,c=b,b=a;l.h0+=b;l.h1+=c;l.h2+=k;l.h3+=h;l.h4+=m;p-=64}};e.create=function(){q||(p=String.fromCharCode(128),p+=g.util.fillString(String.fromCharCode(0),64),q=!0);var e=null,f=g.util.createBuffer(),n=Array(80),a={algorithm:"sha1",blockLength:64,digestLength:20,messageLength:0,start:function(){a.messageLength=0;f=g.util.createBuffer();e={h0:1732584193,h1:4023233417,h2:2562383102,h3:271733878,h4:3285377520}}};a.start();a.update=function(b,c){if(null==b)throw{code:"102001",message:v["102001"]};"utf8"===c&&(b=g.util.encodeUtf8(b));a.messageLength+=b.length;f.putBytes(b);t(e,n,f);(2048<f.read||0===f.length())&&f.compact()};a.digest=function(){var b=a.messageLength,c=g.util.createBuffer();c.putBytes(f.bytes());c.putBytes(p.substr(0,64-(b+8)%64));c.putInt32(b>>>29&255);c.putInt32(b<<3&4294967295);b={h0:e.h0,h1:e.h1,h2:e.h2,h3:e.h3,h4:e.h4};t(b,n,c);c=g.util.createBuffer();c.putInt32(b.h0);c.putInt32(b.h1);c.putInt32(b.h2);c.putInt32(b.h3);c.putInt32(b.h4);return c};return a}}var u=["./util"],n=null;"function"!==typeof define&&("object"===typeof module&&module.exports?n=function(g,n){n(require,module)}:(crosscert=window.crosscert=window.crosscert||{},r(crosscert)));(n||"function"===typeof define)&&(n||define)(["require","module"].concat(u),function(g,n){n.exports=function(e){var n=u.map(function(e){return g(e)}).concat(r);e=e||{};e.defined=e.defined||{};if(e.defined.sha1)return e.sha1;e.defined.sha1=!0;for(var q=0;q<n.length;++q)n[q](e);return e.sha1}})})();