1/** 2 * Supported cipher modes. 3 * 4 * @author Dave Longley 5 * 6 * Copyright (c) 2010-2014 Digital Bazaar, Inc. 7 */ 8!function(){function t(t){function i(i){if("string"==typeof i&&(i=t.util.createBuffer(i)),t.util.isArray(i)&&i.length>4){var e=i;i=t.util.createBuffer();for(var s=0;s<e.length;++s)i.putByte(e[s])}return t.util.isArray(i)||(i=[i.getInt32(),i.getInt32(),i.getInt32(),i.getInt32()]),i}function e(t){t[t.length-1]=t[t.length-1]+1&4294967295}function s(t){return[t/4294967296|0,4294967295&t]}t.cipher=t.cipher||{};var h=t.cipher.modes=t.cipher.modes||{};h.ecb=function(t){t=t||{},this.name="ECB",this.cipher=t.cipher,this.blockSize=t.blockSize||16,this._ints=this.blockSize/4,this._inBlock=new Array(this._ints),this._outBlock=new Array(this._ints)},h.ecb.prototype.start=function(){},h.ecb.prototype.encrypt=function(t,i,e){if(t.length()<this.blockSize&&!(e&&t.length()>0))return!0;for(var s=0;s<this._ints;++s)this._inBlock[s]=t.getInt32();this.cipher.encrypt(this._inBlock,this._outBlock);for(var s=0;s<this._ints;++s)i.putInt32(this._outBlock[s])},h.ecb.prototype.decrypt=function(t,i,e){if(t.length()<this.blockSize&&!(e&&t.length()>0))return!0;for(var s=0;s<this._ints;++s)this._inBlock[s]=t.getInt32();this.cipher.decrypt(this._inBlock,this._outBlock);for(var s=0;s<this._ints;++s)i.putInt32(this._outBlock[s])},h.ecb.prototype.pad=function(t){var i=t.length()===this.blockSize?this.blockSize:this.blockSize-t.length();return t.fillWithByte(i,i),!0},h.ecb.prototype.unpad=function(t,i){if(i.overflow>0)return!1;
8var e=t.length(),s=t.at(e-1);return s>this.blockSize<<2?!1:(t.truncate(s),!0)},h.cbc=function(t){t=t||{},this.name="CBC",this.cipher=t.cipher,this.blockSize=t.blockSize||16,this._ints=this.blockSize/4,this._inBlock=new Array(this._ints),this._outBlock=new Array(this._ints)},h.cbc.prototype.start=function(t){if(null===t.iv){if(!this._prev)throw new Error("Invalid IV parameter.");this._iv=this._prev.slice(0)}else{if(!("iv"in t))throw new Error("Invalid IV parameter.");this._iv=i(t.iv),this._prev=this._iv.slice(0)}},h.cbc.prototype.encrypt=function(t,i,e){if(t.length()<this.blockSize&&!(e&&t.length()>0))return!0;for(var s=0;s<this._ints;++s)this._inBlock[s]=this._prev[s]^t.getInt32();this.cipher.encrypt(this._inBlock,this._outBlock);for(var s=0;s<this._ints;++s)i.putInt32(this._outBlock[s]);this._prev=this._outBlock},h.cbc.prototype.decrypt=function(t,i,e){if(t.length()<this.blockSize&&!(e&&t.length()>0))return!0;for(var s=0;s<this._ints;++s)this._inBlock[s]=t.getInt32();this.cipher.decrypt(this._inBlock,this._outBlock);for(var s=0;s<this._ints;++s)i.putInt32(this._prev[s]^this._outBlock[s]);this._prev=this._inBlock.slice(0)},h.cbc.prototype.pad=function(t){var i=t.length()===this.blockSize?this.blockSize:this.blockSize-t.length();return t.fillWithByte(i,i),!0},h.cbc.prototype.unpad=function(t,i){if(i.overflow>0)return!1;
vendor: 6,415 bytes, line 8
8var e=t.length(),s=t.at(e-1);return s>this.blockSize<<2?!1:(t.truncate(s),!0)},h.cfb=function(i){i=i||{},this.name="CFB",this.cipher=i.cipher,this.blockSize=i.blockSize||16,this._ints=this.blockSize/4,this._inBlock=null,this._outBlock=new Array(this._ints),this._partialBlock=new Array(this._ints),this._partialOutput=t.util.createBuffer(),this._partialBytes=0},h.cfb.prototype.start=function(t){if(!("iv"in t))throw new Error("Invalid IV parameter.");this._iv=i(t.iv),this._inBlock=this._iv.slice(0),this._partialBytes=0},h.cfb.prototype.encrypt=function(t,i,e){var s=t.length();if(0===s)return!0;if(this.cipher.encrypt(this._inBlock,this._outBlock),0===this._partialBytes&&s>=this.blockSize)for(var h=0;h<this._ints;++h)this._inBlock[h]=t.getInt32()^this._outBlock[h],i.putInt32(this._inBlock[h]);else{var r=(this.blockSize-s)%this.blockSize;r>0&&(r=this.blockSize-r),this._partialOutput.clear();for(var h=0;h<this._ints;++h)this._partialBlock[h]=t.getInt32()^this._outBlock[h],this._partialOutput.putInt32(this._partialBlock[h]);if(r>0)t.read-=this.blockSize;else for(var h=0;h<this._ints;++h)this._inBlock[h]=this._partialBlock[h];if(this._partialBytes>0&&this._partialOutput.getBytes(this._partialBytes),r>0&&!e)return i.putBytes(this._partialOutput.getBytes(r-this._partialBytes)),this._partialBytes=r,!0;i.putBytes(this._partialOutput.getBytes(s-this._partialBytes)),this._partialBytes=0}},h.cfb.prototype.decrypt=function(t,i,e){var s=t.length();if(0===s)return!0;if(this.cipher.encrypt(this._inBlock,this._outBlock),0===this._partialBytes&&s>=this.blockSize)for(var h=0;h<this._ints;++h)this._inBlock[h]=t.getInt32(),i.putInt32(this._inBlock[h]^this._outBlock[h]);else{var r=(this.blockSize-s)%this.blockSize;r>0&&(r=this.blockSize-r),this._partialOutput.clear();for(var h=0;h<this._ints;++h)this._partialBlock[h]=t.getInt32(),this._partialOutput.putInt32(this._partialBlock[h]^this._outBlock[h]);if(r>0)t.read-=this.blockSize;else for(var h=0;h<this._ints;++h)this._inBlock[h]=this._partialBlock[h];if(this._partialBytes>0&&this._partialOutput.getBytes(this._partialBytes),r>0&&!e)return i.putBytes(this._partialOutput.getBytes(r-this._partialBytes)),this._partialBytes=r,!0;i.putBytes(this._partialOutput.getBytes(s-this._partialBytes)),this._partialBytes=0}},h.ofb=function(i){i=i||{},this.name="OFB",this.cipher=i.cipher,this.blockSize=i.blockSize||16,this._ints=this.blockSize/4,this._inBlock=null,this._outBlock=new Array(this._ints),this._partialOutput=t.util.createBuffer(),this._partialBytes=0},h.ofb.prototype.start=function(t){if(!("iv"in t))throw new Error("Invalid IV parameter.");this._iv=i(t.iv),this._inBlock=this._iv.slice(0),this._partialBytes=0},h.ofb.prototype.encrypt=function(t,i,e){var s=t.length();if(0===t.length())return!0;if(this.cipher.encrypt(this._inBlock,this._outBlock),0===this._partialBytes&&s>=this.blockSize)for(var h=0;h<this._ints;++h)i.putInt32(t.getInt32()^this._outBlock[h]),this._inBlock[h]=this._outBlock[h];else{var r=(this.blockSize-s)%this.blockSize;r>0&&(r=this.blockSize-r),this._partialOutput.clear();for(var h=0;h<this._ints;++h)this._partialOutput.putInt32(t.getInt32()^this._outBlock[h]);if(r>0)t.read-=this.blockSize;else for(var h=0;h<this._ints;++h)this._inBlock[h]=this._outBlock[h];if(this._partialBytes>0&&this._partialOutput.getBytes(this._partialBytes),r>0&&!e)return i.putBytes(this._partialOutput.getBytes(r-this._partialBytes)),this._partialBytes=r,!0;i.putBytes(this._partialOutput.getBytes(s-this._partialBytes)),this._partialBytes=0}},h.ofb.prototype.decrypt=h.ofb.prototype.encrypt,h.ctr=function(i){i=i||{},this.name="CTR",this.cipher=i.cipher,this.blockSize=i.blockSize||16,this._ints=this.blockSize/4,this._inBlock=null,this._outBlock=new Array(this._ints),this._partialOutput=t.util.createBuffer(),this._partialBytes=0},h.ctr.prototype.start=function(t){if(!("iv"in t))throw new Error("Invalid IV parameter.");this._iv=i(t.iv),this._inBlock=this._iv.slice(0),this._partialBytes=0},h.ctr.prototype.encrypt=function(t,i,s){var h=t.length();if(0===h)return!0;if(this.cipher.encrypt(this._inBlock,this._outBlock),0===this._partialBytes&&h>=this.blockSize)for(var r=0;r<this._ints;++r)i.putInt32(t.getInt32()^this._outBlock[r]);else{var n=(this.blockSize-h)%this.blockSize;n>0&&(n=this.blockSize-n),this._partialOutput.clear();for(var r=0;r<this._ints;++r)this._partialOutput.putInt32(t.getInt32()^this._outBlock[r]);if(n>0&&(t.read-=this.blockSize),this._partialBytes>0&&this._partialOutput.getBytes(this._partialBytes),n>0&&!s)return i.putBytes(this._partialOutput.getBytes(n-this._partialBytes)),this._partialBytes=n,!0;i.putBytes(this._partialOutput.getBytes(h-this._partialBytes)),this._partialBytes=0}e(this._inBlock)},h.ctr.prototype.decrypt=h.ctr.prototype.encrypt,h.gcm=function(i){i=i||{},this.name="GCM",this.cipher=i.cipher,this.blockSize=i.blockSize||16,this._ints=this.blockSize/4,this._inBlock=new Array(this._ints),this._outBlock=new Array(this._ints),this._partialOutput=t.util.createBuffer(),this._partialBytes=0,this._R=3774873600},h.gcm.prototype.start=function(i){if(!("iv"in i))throw new Error("Invalid IV parameter.");var h=t.util.createBuffer(i.iv);this._cipherLength=0;var r;if(r="additionalData"in i?t.util.createBuffer(i.additionalData):t.util.createBuffer(),this._tagLength="tagLength"in i?i.tagLength:128,this._tag=null,i.decrypt&&(this._tag=t.util.createBuffer(i.tag).getBytes(),this._tag.length!==this._tagLength/8))throw new Error("Authentication tag does not match tag length.");this._hashBlock=new Array(this._ints),this.tag=null,this._hashSubkey=new Array(this._ints),this.cipher.encrypt([0,0,0,0],this._hashSubkey),this.componentBits=4,this._m=this.generateHashTable(this._hashSubkey,this.componentBits);var n=h.length();if(12===n)this._j0=[h.getInt32(),h.getInt32(),h.getInt32(),1];else{for(this._j0=[0,0,0,0];h.length()>0;)this._j0=this.ghash(this._hashSubkey,this._j0,[h.getInt32(),h.getInt32(),h.getInt32(),h.getInt32()]);this._j0=this.ghash(this._hashSubkey,this._j0,[0,0].concat(s(8*n)))}this._inBlock=this._j0.slice(0),e(this._inBlock),this._partialBytes=0,r=t.util.createBuffer(r),this._aDataLength=s(8*r.length());var a=r.length()%this.blockSize;for(a&&r.fillWithByte(0,this.blockSize-a),this._s=[0,0,0,0];r.length()>0;)this._s=this.ghash(this._hashSubkey,this._s,[r.getInt32(),r.getInt32(),r.getInt32(),r.getInt32()])},h.gcm.prototype.encrypt=function(t,i,s){var h=t.length();if(0===h)return!0;
8if(this.cipher.encrypt(this._inBlock,this._outBlock),0===this._partialBytes&&h>=this.blockSize){for(var r=0;r<this._ints;++r)i.putInt32(this._outBlock[r]^=t.getInt32());this._cipherLength+=this.blockSize}else{var n=(this.blockSize-h)%this.blockSize;n>0&&(n=this.blockSize-n),this._partialOutput.clear();for(var r=0;r<this._ints;++r)this._partialOutput.putInt32(t.getInt32()^this._outBlock[r]);if(0===n||s){if(s){var a=h%this.blockSize;this._cipherLength+=a,this._partialOutput.truncate(this.blockSize-a)}else this._cipherLength+=this.blockSize;for(var r=0;r<this._ints;++r)this._outBlock[r]=this._partialOutput.getInt32();this._partialOutput.read-=this.blockSize}if(this._partialBytes>0&&this._partialOutput.getBytes(this._partialBytes),n>0&&!s)return t.read-=this.blockSize,i.putBytes(this._partialOutput.getBytes(n-this._partialBytes)),this._partialBytes=n,!0;i.putBytes(this._partialOutput.getBytes(h-this._partialBytes)),this._partialBytes=0}this._s=this.ghash(this._hashSubkey,this._s,this._outBlock),e(this._inBlock)},h.gcm.prototype.decrypt=function(t,i,s){var h=t.length();if(h<this.blockSize&&!(s&&h>0))return!0;this.cipher.encrypt(this._inBlock,this._outBlock),e(this._inBlock),this._hashBlock[0]=t.getInt32(),this._hashBlock[1]=t.getInt32(),this._hashBlock[2]=t.getInt32(),this._hashBlock[3]=t.getInt32(),this._s=this.ghash(this._hashSubkey,this._s,this._hashBlock);for(var r=0;r<this._ints;++r)i.putInt32(this._outBlock[r]^this._hashBlock[r]);this._cipherLength+=h<this.blockSize?h%this.blockSize:this.blockSize},h.gcm.prototype.afterFinish=function(i,e){var h=!0;e.decrypt&&e.overflow&&i.truncate(this.blockSize-e.overflow),this.tag=t.util.createBuffer();var r=this._aDataLength.concat(s(8*this._cipherLength));this._s=this.ghash(this._hashSubkey,this._s,r);var n=[];this.cipher.encrypt(this._j0,n);for(var a=0;a<this._ints;++a)this.tag.putInt32(this._s[a]^n[a]);return this.tag.truncate(this.tag.length()%(this._tagLength/8)),e.decrypt&&this.tag.bytes()!==this._tag&&(h=!1),h},h.gcm.prototype.multiply=function(t,i){for(var e=[0,0,0,0],s=i.slice(0),h=0;128>h;++h){var r=t[h/32|0]&1<<31-h%32;r&&(e[0]^=s[0],e[1]^=s[1],e[2]^=s[2],e[3]^=s[3]),this.pow(s,s)}return e},h.gcm.prototype.pow=function(t,i){for(var e=1&t[3],s=3;s>0;--s)i[s]=t[s]>>>1|(1&t[s-1])<<31;i[0]=t[0]>>>1,e&&(i[0]^=this._R)},h.gcm.prototype.tableMultiply=function(t){for(var i=[0,0,0,0],e=0;32>e;++e){var s=e/8|0,h=t[s]>>>4*(7-e%8)&15,r=this._m[e][h];i[0]^=r[0],i[1]^=r[1],i[2]^=r[2],i[3]^=r[3]}return i},h.gcm.prototype.ghash=function(t,i,e){return i[0]^=e[0],i[1]^=e[1],i[2]^=e[2],i[3]^=e[3],this.tableMultiply(i)},h.gcm.prototype.generateHashTable=function(t,i){for(var e=8/i,s=4*e,h=16*e,r=new Array(h),n=0;h>n;++n){var a=[0,0,0,0],o=n/s|0,l=(s-1-n%s)*i;a[o]=1<<i-1<<l,r[n]=this.generateSubHashTable(this.multiply(a,t),i)}return r},h.gcm.prototype.generateSubHashTable=function(t,i){var e=1<<i,s=e>>>1,h=new Array(e);h[s]=t.slice(0);for(var r=s>>>1;r>0;)this.pow(h[2*r],h[r]=[]),r>>=1;for(r=2;s>r;){for(var n=1;r>n;++n){var a=h[r],o=h[n];h[r+n]=[a[0]^o[0],a[1]^o[1],a[2]^o[2],a[3]^o[3]]}r*=2}for(h[0]=[0,0,0,0],r=s+1;e>r;++r){var l=h[r^s];h[r]=[t[0]^l[0],t[1]^l[1],t[2]^l[2],t[3]^l[3]]}return h}}var i="cipherModes";if("function"!=typeof define){if("object"!=typeof module||!module.exports)return"undefined"==typeof forge&&(forge={}),t(forge);var e=!0;define=function(t,i){i(require,module)}}var s,h=function(e,h){h.exports=function(h){var r=s.map(function(t){return e(t)}).concat(t);if(h=h||{},h.defined=h.defined||{},h.defined[i])return h[i];h.defined[i]=!0;for(var n=0;n<r.length;++n)r[n](h);return h[i]}},r=define;define=function(t,i){return s="string"==typeof t?i.slice(2):t.slice(2),e?(delete define,r.apply(null,Array.prototype.slice.call(arguments,0))):(define=r,define.apply(null,Array.prototype.slice.call(arguments,0)))},define(["require","module","./util"],function(){h.apply(null,Array.prototype.slice.call(arguments,0))})}();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.