diff options
author | bitwiseshiftleft <github@shiftleft.org> | 2011-11-25 11:01:30 -0800 |
---|---|---|
committer | bitwiseshiftleft <github@shiftleft.org> | 2011-11-25 11:01:30 -0800 |
commit | 540fe8b5fcef813eaa614476e7ced42f66e15b23 (patch) | |
tree | bfbe17c026b3c8f71d05e019ced56fda39bb7b09 | |
parent | b59fb8260f6c2672fc4f92aeee8143fd9e9e0c8d (diff) | |
parent | 2efbfe6ee570681366eba2763a40492637c352dc (diff) | |
download | sjcl-540fe8b5fcef813eaa614476e7ced42f66e15b23.zip sjcl-540fe8b5fcef813eaa614476e7ced42f66e15b23.tar.gz sjcl-540fe8b5fcef813eaa614476e7ced42f66e15b23.tar.bz2 |
Merge pull request #39 from azer/master
CommonJS Support
-rw-r--r-- | core/sjcl.js | 4 | ||||
-rw-r--r-- | sjcl.js | 1 |
2 files changed, 5 insertions, 0 deletions
diff --git a/core/sjcl.js b/core/sjcl.js index 6ac1f0e..50e5307 100644 --- a/core/sjcl.js +++ b/core/sjcl.js @@ -67,3 +67,7 @@ var sjcl = { } } }; + +if(typeof module != 'undefined' && module.exports){ + module.exports = sjcl; +} @@ -1,4 +1,5 @@ "use strict";var sjcl={cipher:{},hash:{},keyexchange:{},mode:{},misc:{},codec:{},exception:{corrupt:function(a){this.toString=function(){return"CORRUPT: "+this.message};this.message=a},invalid:function(a){this.toString=function(){return"INVALID: "+this.message};this.message=a},bug:function(a){this.toString=function(){return"BUG: "+this.message};this.message=a},notReady:function(a){this.toString=function(){return"NOT READY: "+this.message};this.message=a}}}; +if(typeof module!="undefined"&&module.exports)module.exports=sjcl; sjcl.cipher.aes=function(a){this.h[0][0][0]||this.w();var b,c,d,e,f=this.h[0][4],g=this.h[1];b=a.length;var h=1;if(b!==4&&b!==6&&b!==8)throw new sjcl.exception.invalid("invalid aes key size");this.a=[d=a.slice(0),e=[]];for(a=b;a<4*b+28;a++){c=d[a-1];if(a%b===0||b===8&&a%b===4){c=f[c>>>24]<<24^f[c>>16&255]<<16^f[c>>8&255]<<8^f[c&255];if(a%b===0){c=c<<8^c>>>24^h<<24;h=h<<1^(h>>7)*283}}d[a]=d[a-b]^c}for(b=0;a;b++,a--){c=d[b&3?a:a-4];e[b]=a<=4||b<4?c:g[0][f[c>>>24]]^g[1][f[c>>16&255]]^g[2][f[c>>8&255]]^ g[3][f[c&255]]}}; sjcl.cipher.aes.prototype={encrypt:function(a){return this.H(a,0)},decrypt:function(a){return this.H(a,1)},h:[[[],[],[],[],[]],[[],[],[],[],[]]],w:function(){var a=this.h[0],b=this.h[1],c=a[4],d=b[4],e,f,g,h=[],i=[],k,j,l,m;for(e=0;e<0x100;e++)i[(h[e]=e<<1^(e>>7)*283)^e]=e;for(f=g=0;!c[f];f^=k||1,g=i[g]||1){l=g^g<<1^g<<2^g<<3^g<<4;l=l>>8^l&255^99;c[f]=l;d[l]=f;j=h[e=h[k=h[f]]];m=j*0x1010101^e*0x10001^k*0x101^f*0x1010100;j=h[l]*0x101^l*0x1010100;for(e=0;e<4;e++){a[e][f]=j=j<<24^j>>>8;b[e][l]=m=m<<24^m>>>8}}for(e= |