Comparing version 0.7.4 to 0.7.5
{ | ||
"name": "rusha", | ||
"version": "0.7.4", | ||
"version": "0.7.5", | ||
"description": "A high-performance pure-javascript SHA1 implementation suitable for large binary data.", | ||
@@ -5,0 +5,0 @@ "main": "rusha.js", |
20
rusha.js
@@ -122,4 +122,18 @@ | ||
var nextPow2 = function (v) { | ||
var p = 1; while (p < v) p = p << 1; return p; | ||
var ceilHeapSize = function (v) { | ||
// The asm.js spec says: | ||
// The heap object's byteLength must be either | ||
// 2^n for n in [12, 24) or 2^24 * n for n ≥ 1. | ||
var p; | ||
// If v is smaller than 2^12, the smallest possible solution | ||
// is 2^12. | ||
if (v <= 4096) return 4096; | ||
// If v < 2^24, we round up to 2^n, | ||
// otherwise we round up to 2^24 * n. | ||
if (v < 16777216) { | ||
for (p = 1; p < v; p = p << 1); | ||
} else { | ||
for (p = 16777216; p < v; p += p); | ||
} | ||
return p; | ||
}; | ||
@@ -130,3 +144,3 @@ | ||
self.sizeHint = size; | ||
self.heap = new ArrayBuffer(nextPow2(padlen(size) + 320)); | ||
self.heap = new ArrayBuffer(ceilHeapSize(padlen(size) + 320)); | ||
self.core = RushaCore({Int32Array: Int32Array, DataView: DataView}, {}, self.heap); | ||
@@ -133,0 +147,0 @@ }; |
@@ -9,3 +9,4 @@ | ||
hex_tab.charAt((x>>0)&0xF);} | ||
return res.join('');};var nextPow2=function(v){var p=1;while(p<v)p=p<<1;return p;};var resize=function(size){self.sizeHint=size;self.heap=new ArrayBuffer(nextPow2(padlen(size)+320));self.core=RushaCore({Int32Array:Int32Array,DataView:DataView},{},self.heap);};resize(sizeHint||0);var coreCall=function(len){var h=new Int32Array(self.heap,len<<2,5);h[0]=1732584193;h[1]=-271733879;h[2]=-1732584194;h[3]=271733878;h[4]=-1009589776;self.core.hash(len);};var rawDigest=this.rawDigest=function(str){var len=str.byteLength||str.length;if(len>self.sizeHint){resize(len);} | ||
return res.join('');};var ceilHeapSize=function(v){var p;if(v<=4096)return 4096;if(v<16777216){for(p=1;p<v;p=p<<1);}else{for(p=16777216;p<v;p+=p);} | ||
return p;};var resize=function(size){self.sizeHint=size;self.heap=new ArrayBuffer(ceilHeapSize(padlen(size)+320));self.core=RushaCore({Int32Array:Int32Array,DataView:DataView},{},self.heap);};resize(sizeHint||0);var coreCall=function(len){var h=new Int32Array(self.heap,len<<2,5);h[0]=1732584193;h[1]=-271733879;h[2]=-1732584194;h[3]=271733878;h[4]=-1009589776;self.core.hash(len);};var rawDigest=this.rawDigest=function(str){var len=str.byteLength||str.length;if(len>self.sizeHint){resize(len);} | ||
var view=new Int32Array(self.heap,0,padlen(len)>>2);padZeroes(view,len);conv(str,view,len);padData(view,len);coreCall(view.length);var out=new Int32Array(5);var arr=new DataView(out.buffer);arr.setInt32(0,view[0],false);arr.setInt32(4,view[1],false);arr.setInt32(8,view[2],false);arr.setInt32(12,view[3],false);arr.setInt32(16,view[4],false);return out;};this.digest=this.digestFromString=this.digestFromBuffer=this.digestFromArrayBuffer=function(str){return hex(rawDigest(str).buffer);};};function RushaCore(stdlib,foreign,heap){"use asm";var H=new stdlib.Int32Array(heap);function hash(k){k=k|0;var i=0,j=0,y0=0,z0=0,y1=0,z1=0,y2=0,z2=0,y3=0,z3=0,y4=0,z4=0,t0=0,t1=0;y0=H[k+0<<2>>2]|0;y1=H[k+1<<2>>2]|0;y2=H[k+2<<2>>2]|0;y3=H[k+3<<2>>2]|0;y4=H[k+4<<2>>2]|0;for(i=0;(i|0)<(k|0);i=i+16|0){z0=y0;z1=y1;z2=y2;z3=y3;z4=y4;for(j=0;(j|0)<16;j=j+1|0){t1=H[i+j<<2>>2]|0;t0=((((y0)<<5|(y0)>>>27)+(y1&y2|~y1&y3)|0)+((t1+y4|0)+1518500249|0)|0);y4=y3;y3=y2;y2=((y1)<<30|(y1)>>>2);y1=y0;y0=t0;H[k+j<<2>>2]=t1;} | ||
@@ -12,0 +13,0 @@ for(j=k+16|0;(j|0)<(k+20|0);j=j+1|0){t1=(((H[j-3<<2>>2]^H[j-8<<2>>2]^H[j-14<<2>>2]^H[j-16<<2>>2])<<1|(H[j-3<<2>>2]^H[j-8<<2>>2]^H[j-14<<2>>2]^H[j-16<<2>>2])>>>31));t0=((((y0)<<5|(y0)>>>27)+(y1&y2|~y1&y3)|0)+((t1+y4|0)+1518500249|0)|0);y4=y3;y3=y2;y2=((y1)<<30|(y1)>>>2);y1=y0;y0=t0;H[j<<2>>2]=t1;} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
26790
9
341