Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

aes-decrypter

Package Overview
Dependencies
Maintainers
6
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

aes-decrypter - npm Package Compare versions

Comparing version 3.0.0 to 3.0.1-0

scripts/karma.conf.js

2

CONTRIBUTING.md

@@ -7,3 +7,3 @@ # CONTRIBUTING

Make sure you have NodeJS 0.10 or higher and npm installed.
Make sure you have Node.js 4.8 or higher and npm installed.

@@ -10,0 +10,0 @@ 1. Fork this repository and clone your fork

@@ -0,71 +1,13 @@

/*! @name aes-decrypter @version 3.0.1-0 @license Apache-2.0 */
'use strict';
var pkcs7 = require('pkcs7');
Object.defineProperty(exports, '__esModule', { value: true });
var classCallCheck = function (instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
};
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
var createClass = function () {
function defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
}
var _createClass = _interopDefault(require('@babel/runtime/helpers/createClass'));
var _inheritsLoose = _interopDefault(require('@babel/runtime/helpers/inheritsLoose'));
var vhsUtils = require('@videojs/vhs-utils');
var pkcs7 = require('pkcs7');
return function (Constructor, protoProps, staticProps) {
if (protoProps) defineProperties(Constructor.prototype, protoProps);
if (staticProps) defineProperties(Constructor, staticProps);
return Constructor;
};
}();
var inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
};
var possibleConstructorReturn = function (self, call) {
if (!self) {
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
}
return call && (typeof call === "object" || typeof call === "function") ? call : self;
};
/**

@@ -121,15 +63,14 @@ * @file aes.js

var sboxInv = decTable[4];
var i = void 0;
var x = void 0;
var xInv = void 0;
var i;
var x;
var xInv;
var d = [];
var th = [];
var x2 = void 0;
var x4 = void 0;
var x8 = void 0;
var s = void 0;
var tEnc = void 0;
var tDec = void 0;
var x2;
var x4;
var x8;
var s;
var tEnc;
var tDec; // Compute double and third tables
// Compute double and third tables
for (i = 0; i < 256; i++) {

@@ -144,5 +85,4 @@ th[(d[i] = i << 1 ^ (i >> 7) * 283) ^ i] = i;

sbox[x] = s;
sboxInv[s] = x;
sboxInv[s] = x; // Compute MixColumns
// Compute MixColumns
x8 = d[x4 = d[x2 = d[x]]];

@@ -156,5 +96,5 @@ tDec = x8 * 0x1010101 ^ x4 * 0x10001 ^ x2 * 0x101 ^ x * 0x1010100;

}
}
} // Compactify. Considerable speedup on Firefox.
// Compactify. Considerable speedup on Firefox.
for (i = 0; i < 5; i++) {

@@ -164,6 +104,7 @@ encTable[i] = encTable[i].slice(0);

}
return tables;
};
var aesTables = null;
/**

@@ -177,18 +118,18 @@ * Schedule out an AES key for both encryption and decryption. This

var AES = function () {
var AES =
/*#__PURE__*/
function () {
function AES(key) {
classCallCheck(this, AES);
/**
* The expanded S-box and inverse S-box tables. These will be computed
* on the client so that we don't have to send them down the wire.
*
* There are two tables, _tables[0] is for encryption and
* _tables[1] is for decryption.
*
* The first 4 sub-tables are the expanded S-box with MixColumns. The
* last (_tables[01][4]) is the S-box itself.
*
* @private
*/
* The expanded S-box and inverse S-box tables. These will be computed
* on the client so that we don't have to send them down the wire.
*
* There are two tables, _tables[0] is for encryption and
* _tables[1] is for decryption.
*
* The first 4 sub-tables are the expanded S-box with MixColumns. The
* last (_tables[01][4]) is the S-box itself.
*
* @private
*/
// if we have yet to precompute the S-box tables

@@ -198,10 +139,9 @@ // do so now

aesTables = precompute();
}
// then make a copy of that object for use
} // then make a copy of that object for use
this._tables = [[aesTables[0][0].slice(), aesTables[0][1].slice(), aesTables[0][2].slice(), aesTables[0][3].slice(), aesTables[0][4].slice()], [aesTables[1][0].slice(), aesTables[1][1].slice(), aesTables[1][2].slice(), aesTables[1][3].slice(), aesTables[1][4].slice()]];
var i = void 0;
var j = void 0;
var tmp = void 0;
var encKey = void 0;
var decKey = void 0;
var i;
var j;
var tmp;
var sbox = this._tables[0][4];

@@ -216,15 +156,12 @@ var decTable = this._tables[1];

encKey = key.slice(0);
decKey = [];
this._key = [encKey, decKey];
var encKey = key.slice(0);
var decKey = [];
this._key = [encKey, decKey]; // schedule encryption keys
// schedule encryption keys
for (i = keyLen; i < 4 * keyLen + 28; i++) {
tmp = encKey[i - 1];
tmp = encKey[i - 1]; // apply sbox
// apply sbox
if (i % keyLen === 0 || keyLen === 8 && i % keyLen === 4) {
tmp = sbox[tmp >>> 24] << 24 ^ sbox[tmp >> 16 & 255] << 16 ^ sbox[tmp >> 8 & 255] << 8 ^ sbox[tmp & 255];
tmp = sbox[tmp >>> 24] << 24 ^ sbox[tmp >> 16 & 255] << 16 ^ sbox[tmp >> 8 & 255] << 8 ^ sbox[tmp & 255]; // shift rows and add rcon
// shift rows and add rcon
if (i % keyLen === 0) {

@@ -237,7 +174,8 @@ tmp = tmp << 8 ^ tmp >>> 24 ^ rcon << 24;

encKey[i] = encKey[i - keyLen] ^ tmp;
}
} // schedule decryption keys
// schedule decryption keys
for (j = 0; i; j++, i--) {
tmp = encKey[j & 3 ? i : i - 4];
if (i <= 4 || j < 4) {

@@ -250,13 +188,12 @@ decKey[j] = tmp;

}
/**
* Decrypt 16 bytes, specified as four 32-bit words.
*
* @param {Number} encrypted0 the first word to decrypt
* @param {Number} encrypted1 the second word to decrypt
* @param {Number} encrypted2 the third word to decrypt
* @param {Number} encrypted3 the fourth word to decrypt
* @param {number} encrypted0 the first word to decrypt
* @param {number} encrypted1 the second word to decrypt
* @param {number} encrypted2 the third word to decrypt
* @param {number} encrypted3 the fourth word to decrypt
* @param {Int32Array} out the array to write the decrypted words
* into
* @param {Number} offset the offset into the output array to start
* @param {number} offset the offset into the output array to start
* writing results

@@ -267,5 +204,7 @@ * @return {Array} The plaintext.

AES.prototype.decrypt = function decrypt(encrypted0, encrypted1, encrypted2, encrypted3, out, offset) {
var key = this._key[1];
// state variables a,b,c,d are loaded with pre-whitened data
var _proto = AES.prototype;
_proto.decrypt = function decrypt(encrypted0, encrypted1, encrypted2, encrypted3, out, offset) {
var key = this._key[1]; // state variables a,b,c,d are loaded with pre-whitened data
var a = encrypted0 ^ key[0];

@@ -275,13 +214,11 @@ var b = encrypted3 ^ key[1];

var d = encrypted1 ^ key[3];
var a2 = void 0;
var b2 = void 0;
var c2 = void 0;
var a2;
var b2;
var c2; // key.length === 2 ?
// key.length === 2 ?
var nInnerRounds = key.length / 4 - 2;
var i = void 0;
var i;
var kIndex = 4;
var table = this._tables[1];
var table = this._tables[1]; // load up the tables
// load up the tables
var table0 = table[0];

@@ -291,5 +228,4 @@ var table1 = table[1];

var table3 = table[3];
var sbox = table[4];
var sbox = table[4]; // Inner rounds. Cribbed from OpenSSL.
// Inner rounds. Cribbed from OpenSSL.
for (i = 0; i < nInnerRounds; i++) {

@@ -301,9 +237,15 @@ a2 = table0[a >>> 24] ^ table1[b >> 16 & 255] ^ table2[c >> 8 & 255] ^ table3[d & 255] ^ key[kIndex];

kIndex += 4;
a = a2;b = b2;c = c2;
}
a = a2;
b = b2;
c = c2;
} // Last round.
// Last round.
for (i = 0; i < 4; i++) {
out[(3 & -i) + offset] = sbox[a >>> 24] << 24 ^ sbox[b >> 16 & 255] << 16 ^ sbox[c >> 8 & 255] << 8 ^ sbox[d & 255] ^ key[kIndex++];
a2 = a;a = b;b = c;c = d;d = a2;
a2 = a;
a = b;
b = c;
c = d;
d = a2;
}

@@ -316,120 +258,3 @@ };

/**
* @file stream.js
*/
/**
* A lightweight readable stream implemention that handles event dispatching.
*
* @class Stream
*/
var Stream = function () {
function Stream() {
classCallCheck(this, Stream);
this.listeners = {};
}
/**
* Add a listener for a specified event type.
*
* @param {String} type the event name
* @param {Function} listener the callback to be invoked when an event of
* the specified type occurs
*/
Stream.prototype.on = function on(type, listener) {
if (!this.listeners[type]) {
this.listeners[type] = [];
}
this.listeners[type].push(listener);
};
/**
* Remove a listener for a specified event type.
*
* @param {String} type the event name
* @param {Function} listener a function previously registered for this
* type of event through `on`
* @return {Boolean} if we could turn it off or not
*/
Stream.prototype.off = function off(type, listener) {
if (!this.listeners[type]) {
return false;
}
var index = this.listeners[type].indexOf(listener);
this.listeners[type].splice(index, 1);
return index > -1;
};
/**
* Trigger an event of the specified type on this stream. Any additional
* arguments to this function are passed as parameters to event listeners.
*
* @param {String} type the event name
*/
Stream.prototype.trigger = function trigger(type) {
var callbacks = this.listeners[type];
if (!callbacks) {
return;
}
// Slicing the arguments on every invocation of this method
// can add a significant amount of overhead. Avoid the
// intermediate object creation for the common case of a
// single callback argument
if (arguments.length === 2) {
var length = callbacks.length;
for (var i = 0; i < length; ++i) {
callbacks[i].call(this, arguments[1]);
}
} else {
var args = Array.prototype.slice.call(arguments, 1);
var _length = callbacks.length;
for (var _i = 0; _i < _length; ++_i) {
callbacks[_i].apply(this, args);
}
}
};
/**
* Destroys the stream and cleans up.
*/
Stream.prototype.dispose = function dispose() {
this.listeners = {};
};
/**
* Forwards all `data` events on this stream to the destination stream. The
* destination stream should provide a method `push` to receive the data
* events as they arrive.
*
* @param {Stream} destination the stream that will receive all `data` events
* @see http://nodejs.org/api/stream.html#stream_readable_pipe_destination_options
*/
Stream.prototype.pipe = function pipe(destination) {
this.on('data', function (data) {
destination.push(data);
});
};
return Stream;
}();
/**
* @file async-stream.js
*/
/**
* A wrapper around the Stream class to use setTiemout
* A wrapper around the Stream class to use setTimeout
* and run stream "jobs" Asynchronously

@@ -441,10 +266,11 @@ *

var AsyncStream = function (_Stream) {
inherits(AsyncStream, _Stream);
var AsyncStream =
/*#__PURE__*/
function (_Stream) {
_inheritsLoose(AsyncStream, _Stream);
function AsyncStream() {
classCallCheck(this, AsyncStream);
var _this;
var _this = possibleConstructorReturn(this, _Stream.call(this, Stream));
_this = _Stream.call(this, vhsUtils.Stream) || this;
_this.jobs = [];

@@ -455,3 +281,2 @@ _this.delay = 1;

}
/**

@@ -464,4 +289,7 @@ * process an async job

AsyncStream.prototype.processJob_ = function processJob_() {
var _proto = AsyncStream.prototype;
_proto.processJob_ = function processJob_() {
this.jobs.shift()();
if (this.jobs.length) {

@@ -472,4 +300,3 @@ this.timeout_ = setTimeout(this.processJob_.bind(this), this.delay);

}
};
}
/**

@@ -480,6 +307,7 @@ * push a job into the stream

*/
;
_proto.push = function push(job) {
this.jobs.push(job);
AsyncStream.prototype.push = function push(job) {
this.jobs.push(job);
if (!this.timeout_) {

@@ -491,19 +319,12 @@ this.timeout_ = setTimeout(this.processJob_.bind(this), this.delay);

return AsyncStream;
}(Stream);
}(vhsUtils.Stream);
/**
* @file decrypter.js
*
* An asynchronous implementation of AES-128 CBC decryption with
* PKCS#7 padding.
*/
/**
* Convert network-order (big-endian) bytes into their little-endian
* representation.
*/
var ntoh = function ntoh(word) {
return word << 24 | (word & 0xff00) << 8 | (word & 0xff0000) >> 8 | word >>> 24;
};
/**

@@ -522,35 +343,31 @@ * Decrypt bytes using AES-128 with CBC and PKCS#7 padding.

*/
var decrypt = function decrypt(encrypted, key, initVector) {
// word-level access to the encrypted bytes
var encrypted32 = new Int32Array(encrypted.buffer, encrypted.byteOffset, encrypted.byteLength >> 2);
var decipher = new AES(Array.prototype.slice.call(key)); // byte and word-level access for the decrypted output
var decipher = new AES(Array.prototype.slice.call(key));
// byte and word-level access for the decrypted output
var decrypted = new Uint8Array(encrypted.byteLength);
var decrypted32 = new Int32Array(decrypted.buffer);
// temporary variables for working with the IV, encrypted, and
var decrypted32 = new Int32Array(decrypted.buffer); // temporary variables for working with the IV, encrypted, and
// decrypted data
var init0 = void 0;
var init1 = void 0;
var init2 = void 0;
var init3 = void 0;
var encrypted0 = void 0;
var encrypted1 = void 0;
var encrypted2 = void 0;
var encrypted3 = void 0;
// iteration variable
var wordIx = void 0;
var init0;
var init1;
var init2;
var init3;
var encrypted0;
var encrypted1;
var encrypted2;
var encrypted3; // iteration variable
// pull out the words of the IV to ensure we don't modify the
var wordIx; // pull out the words of the IV to ensure we don't modify the
// passed-in reference and easier access
init0 = initVector[0];
init1 = initVector[1];
init2 = initVector[2];
init3 = initVector[3];
init3 = initVector[3]; // decrypt four word sequences, applying cipher-block chaining (CBC)
// to each decrypted block
// decrypt four word sequences, applying cipher-block chaining (CBC)
// to each decrypted block
for (wordIx = 0; wordIx < encrypted32.length; wordIx += 4) {

@@ -562,15 +379,12 @@ // convert big-endian (network order) words into little-endian

encrypted2 = ntoh(encrypted32[wordIx + 2]);
encrypted3 = ntoh(encrypted32[wordIx + 3]);
encrypted3 = ntoh(encrypted32[wordIx + 3]); // decrypt the block
// decrypt the block
decipher.decrypt(encrypted0, encrypted1, encrypted2, encrypted3, decrypted32, wordIx);
decipher.decrypt(encrypted0, encrypted1, encrypted2, encrypted3, decrypted32, wordIx); // XOR with the IV, and restore network byte-order to obtain the
// plaintext
// XOR with the IV, and restore network byte-order to obtain the
// plaintext
decrypted32[wordIx] = ntoh(decrypted32[wordIx] ^ init0);
decrypted32[wordIx + 1] = ntoh(decrypted32[wordIx + 1] ^ init1);
decrypted32[wordIx + 2] = ntoh(decrypted32[wordIx + 2] ^ init2);
decrypted32[wordIx + 3] = ntoh(decrypted32[wordIx + 3] ^ init3);
decrypted32[wordIx + 3] = ntoh(decrypted32[wordIx + 3] ^ init3); // setup the IV for the next round
// setup the IV for the next round
init0 = encrypted0;

@@ -584,3 +398,2 @@ init1 = encrypted1;

};
/**

@@ -598,6 +411,7 @@ * The `Decrypter` class that manages decryption of AES

var Decrypter = function () {
var Decrypter =
/*#__PURE__*/
function () {
function Decrypter(encrypted, key, initVector, done) {
classCallCheck(this, Decrypter);
var step = Decrypter.STEP;

@@ -607,12 +421,12 @@ var encrypted32 = new Int32Array(encrypted.buffer);

var i = 0;
this.asyncStream_ = new AsyncStream(); // split up the encryption job and do the individual chunks asynchronously
this.asyncStream_ = new AsyncStream();
this.asyncStream_.push(this.decryptChunk_(encrypted32.subarray(i, i + step), key, initVector, decrypted));
// split up the encryption job and do the individual chunks asynchronously
this.asyncStream_.push(this.decryptChunk_(encrypted32.subarray(i, i + step), key, initVector, decrypted));
for (i = step; i < encrypted32.length; i += step) {
initVector = new Uint32Array([ntoh(encrypted32[i - 4]), ntoh(encrypted32[i - 3]), ntoh(encrypted32[i - 2]), ntoh(encrypted32[i - 1])]);
this.asyncStream_.push(this.decryptChunk_(encrypted32.subarray(i, i + step), key, initVector, decrypted));
}
// invoke the done() callback when everything is finished
} // invoke the done() callback when everything is finished
this.asyncStream_.push(function () {

@@ -623,17 +437,17 @@ // remove pkcs#7 padding from the decrypted bytes

}
/**
* a getter for step the maximum number of bytes to process at one time
*
* @return {Number} the value of step 32000
* @return {number} the value of step 32000
*/
var _proto = Decrypter.prototype;
/**
* @private
*/
Decrypter.prototype.decryptChunk_ = function decryptChunk_(encrypted, key, initVector, decrypted) {
_proto.decryptChunk_ = function decryptChunk_(encrypted, key, initVector, decrypted) {
return function () {
var bytes = decrypt(encrypted, key, initVector);
decrypted.set(bytes, encrypted.byteOffset);

@@ -643,5 +457,5 @@ };

createClass(Decrypter, null, [{
key: 'STEP',
get: function get$$1() {
_createClass(Decrypter, null, [{
key: "STEP",
get: function get() {
// 4 * 8000;

@@ -651,18 +465,8 @@ return 32000;

}]);
return Decrypter;
}();
/**
* @file index.js
*
* Index module to easily import the primary components of AES-128
* decryption. Like this:
*
* ```js
* import {Decrypter, decrypt, AsyncStream} from 'aes-decrypter';
* ```
*/
exports.AsyncStream = AsyncStream;
exports.Decrypter = Decrypter;
exports.decrypt = decrypt;
exports.Decrypter = Decrypter;
exports.AsyncStream = AsyncStream;

@@ -0,69 +1,7 @@

/*! @name aes-decrypter @version 3.0.1-0 @license Apache-2.0 */
import _createClass from '@babel/runtime/helpers/createClass';
import _inheritsLoose from '@babel/runtime/helpers/inheritsLoose';
import { Stream } from '@videojs/vhs-utils';
import { unpad } from 'pkcs7';
var classCallCheck = function (instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
};
var createClass = function () {
function defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
}
return function (Constructor, protoProps, staticProps) {
if (protoProps) defineProperties(Constructor.prototype, protoProps);
if (staticProps) defineProperties(Constructor, staticProps);
return Constructor;
};
}();
var inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
};
var possibleConstructorReturn = function (self, call) {
if (!self) {
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
}
return call && (typeof call === "object" || typeof call === "function") ? call : self;
};
/**

@@ -119,15 +57,14 @@ * @file aes.js

var sboxInv = decTable[4];
var i = void 0;
var x = void 0;
var xInv = void 0;
var i;
var x;
var xInv;
var d = [];
var th = [];
var x2 = void 0;
var x4 = void 0;
var x8 = void 0;
var s = void 0;
var tEnc = void 0;
var tDec = void 0;
var x2;
var x4;
var x8;
var s;
var tEnc;
var tDec; // Compute double and third tables
// Compute double and third tables
for (i = 0; i < 256; i++) {

@@ -142,5 +79,4 @@ th[(d[i] = i << 1 ^ (i >> 7) * 283) ^ i] = i;

sbox[x] = s;
sboxInv[s] = x;
sboxInv[s] = x; // Compute MixColumns
// Compute MixColumns
x8 = d[x4 = d[x2 = d[x]]];

@@ -154,5 +90,5 @@ tDec = x8 * 0x1010101 ^ x4 * 0x10001 ^ x2 * 0x101 ^ x * 0x1010100;

}
}
} // Compactify. Considerable speedup on Firefox.
// Compactify. Considerable speedup on Firefox.
for (i = 0; i < 5; i++) {

@@ -162,6 +98,7 @@ encTable[i] = encTable[i].slice(0);

}
return tables;
};
var aesTables = null;
/**

@@ -175,18 +112,18 @@ * Schedule out an AES key for both encryption and decryption. This

var AES = function () {
var AES =
/*#__PURE__*/
function () {
function AES(key) {
classCallCheck(this, AES);
/**
* The expanded S-box and inverse S-box tables. These will be computed
* on the client so that we don't have to send them down the wire.
*
* There are two tables, _tables[0] is for encryption and
* _tables[1] is for decryption.
*
* The first 4 sub-tables are the expanded S-box with MixColumns. The
* last (_tables[01][4]) is the S-box itself.
*
* @private
*/
* The expanded S-box and inverse S-box tables. These will be computed
* on the client so that we don't have to send them down the wire.
*
* There are two tables, _tables[0] is for encryption and
* _tables[1] is for decryption.
*
* The first 4 sub-tables are the expanded S-box with MixColumns. The
* last (_tables[01][4]) is the S-box itself.
*
* @private
*/
// if we have yet to precompute the S-box tables

@@ -196,10 +133,9 @@ // do so now

aesTables = precompute();
}
// then make a copy of that object for use
} // then make a copy of that object for use
this._tables = [[aesTables[0][0].slice(), aesTables[0][1].slice(), aesTables[0][2].slice(), aesTables[0][3].slice(), aesTables[0][4].slice()], [aesTables[1][0].slice(), aesTables[1][1].slice(), aesTables[1][2].slice(), aesTables[1][3].slice(), aesTables[1][4].slice()]];
var i = void 0;
var j = void 0;
var tmp = void 0;
var encKey = void 0;
var decKey = void 0;
var i;
var j;
var tmp;
var sbox = this._tables[0][4];

@@ -214,15 +150,12 @@ var decTable = this._tables[1];

encKey = key.slice(0);
decKey = [];
this._key = [encKey, decKey];
var encKey = key.slice(0);
var decKey = [];
this._key = [encKey, decKey]; // schedule encryption keys
// schedule encryption keys
for (i = keyLen; i < 4 * keyLen + 28; i++) {
tmp = encKey[i - 1];
tmp = encKey[i - 1]; // apply sbox
// apply sbox
if (i % keyLen === 0 || keyLen === 8 && i % keyLen === 4) {
tmp = sbox[tmp >>> 24] << 24 ^ sbox[tmp >> 16 & 255] << 16 ^ sbox[tmp >> 8 & 255] << 8 ^ sbox[tmp & 255];
tmp = sbox[tmp >>> 24] << 24 ^ sbox[tmp >> 16 & 255] << 16 ^ sbox[tmp >> 8 & 255] << 8 ^ sbox[tmp & 255]; // shift rows and add rcon
// shift rows and add rcon
if (i % keyLen === 0) {

@@ -235,7 +168,8 @@ tmp = tmp << 8 ^ tmp >>> 24 ^ rcon << 24;

encKey[i] = encKey[i - keyLen] ^ tmp;
}
} // schedule decryption keys
// schedule decryption keys
for (j = 0; i; j++, i--) {
tmp = encKey[j & 3 ? i : i - 4];
if (i <= 4 || j < 4) {

@@ -248,13 +182,12 @@ decKey[j] = tmp;

}
/**
* Decrypt 16 bytes, specified as four 32-bit words.
*
* @param {Number} encrypted0 the first word to decrypt
* @param {Number} encrypted1 the second word to decrypt
* @param {Number} encrypted2 the third word to decrypt
* @param {Number} encrypted3 the fourth word to decrypt
* @param {number} encrypted0 the first word to decrypt
* @param {number} encrypted1 the second word to decrypt
* @param {number} encrypted2 the third word to decrypt
* @param {number} encrypted3 the fourth word to decrypt
* @param {Int32Array} out the array to write the decrypted words
* into
* @param {Number} offset the offset into the output array to start
* @param {number} offset the offset into the output array to start
* writing results

@@ -265,5 +198,7 @@ * @return {Array} The plaintext.

AES.prototype.decrypt = function decrypt(encrypted0, encrypted1, encrypted2, encrypted3, out, offset) {
var key = this._key[1];
// state variables a,b,c,d are loaded with pre-whitened data
var _proto = AES.prototype;
_proto.decrypt = function decrypt(encrypted0, encrypted1, encrypted2, encrypted3, out, offset) {
var key = this._key[1]; // state variables a,b,c,d are loaded with pre-whitened data
var a = encrypted0 ^ key[0];

@@ -273,13 +208,11 @@ var b = encrypted3 ^ key[1];

var d = encrypted1 ^ key[3];
var a2 = void 0;
var b2 = void 0;
var c2 = void 0;
var a2;
var b2;
var c2; // key.length === 2 ?
// key.length === 2 ?
var nInnerRounds = key.length / 4 - 2;
var i = void 0;
var i;
var kIndex = 4;
var table = this._tables[1];
var table = this._tables[1]; // load up the tables
// load up the tables
var table0 = table[0];

@@ -289,5 +222,4 @@ var table1 = table[1];

var table3 = table[3];
var sbox = table[4];
var sbox = table[4]; // Inner rounds. Cribbed from OpenSSL.
// Inner rounds. Cribbed from OpenSSL.
for (i = 0; i < nInnerRounds; i++) {

@@ -299,9 +231,15 @@ a2 = table0[a >>> 24] ^ table1[b >> 16 & 255] ^ table2[c >> 8 & 255] ^ table3[d & 255] ^ key[kIndex];

kIndex += 4;
a = a2;b = b2;c = c2;
}
a = a2;
b = b2;
c = c2;
} // Last round.
// Last round.
for (i = 0; i < 4; i++) {
out[(3 & -i) + offset] = sbox[a >>> 24] << 24 ^ sbox[b >> 16 & 255] << 16 ^ sbox[c >> 8 & 255] << 8 ^ sbox[d & 255] ^ key[kIndex++];
a2 = a;a = b;b = c;c = d;d = a2;
a2 = a;
a = b;
b = c;
c = d;
d = a2;
}

@@ -314,120 +252,3 @@ };

/**
* @file stream.js
*/
/**
* A lightweight readable stream implemention that handles event dispatching.
*
* @class Stream
*/
var Stream = function () {
function Stream() {
classCallCheck(this, Stream);
this.listeners = {};
}
/**
* Add a listener for a specified event type.
*
* @param {String} type the event name
* @param {Function} listener the callback to be invoked when an event of
* the specified type occurs
*/
Stream.prototype.on = function on(type, listener) {
if (!this.listeners[type]) {
this.listeners[type] = [];
}
this.listeners[type].push(listener);
};
/**
* Remove a listener for a specified event type.
*
* @param {String} type the event name
* @param {Function} listener a function previously registered for this
* type of event through `on`
* @return {Boolean} if we could turn it off or not
*/
Stream.prototype.off = function off(type, listener) {
if (!this.listeners[type]) {
return false;
}
var index = this.listeners[type].indexOf(listener);
this.listeners[type].splice(index, 1);
return index > -1;
};
/**
* Trigger an event of the specified type on this stream. Any additional
* arguments to this function are passed as parameters to event listeners.
*
* @param {String} type the event name
*/
Stream.prototype.trigger = function trigger(type) {
var callbacks = this.listeners[type];
if (!callbacks) {
return;
}
// Slicing the arguments on every invocation of this method
// can add a significant amount of overhead. Avoid the
// intermediate object creation for the common case of a
// single callback argument
if (arguments.length === 2) {
var length = callbacks.length;
for (var i = 0; i < length; ++i) {
callbacks[i].call(this, arguments[1]);
}
} else {
var args = Array.prototype.slice.call(arguments, 1);
var _length = callbacks.length;
for (var _i = 0; _i < _length; ++_i) {
callbacks[_i].apply(this, args);
}
}
};
/**
* Destroys the stream and cleans up.
*/
Stream.prototype.dispose = function dispose() {
this.listeners = {};
};
/**
* Forwards all `data` events on this stream to the destination stream. The
* destination stream should provide a method `push` to receive the data
* events as they arrive.
*
* @param {Stream} destination the stream that will receive all `data` events
* @see http://nodejs.org/api/stream.html#stream_readable_pipe_destination_options
*/
Stream.prototype.pipe = function pipe(destination) {
this.on('data', function (data) {
destination.push(data);
});
};
return Stream;
}();
/**
* @file async-stream.js
*/
/**
* A wrapper around the Stream class to use setTiemout
* A wrapper around the Stream class to use setTimeout
* and run stream "jobs" Asynchronously

@@ -439,10 +260,11 @@ *

var AsyncStream = function (_Stream) {
inherits(AsyncStream, _Stream);
var AsyncStream =
/*#__PURE__*/
function (_Stream) {
_inheritsLoose(AsyncStream, _Stream);
function AsyncStream() {
classCallCheck(this, AsyncStream);
var _this;
var _this = possibleConstructorReturn(this, _Stream.call(this, Stream));
_this = _Stream.call(this, Stream) || this;
_this.jobs = [];

@@ -453,3 +275,2 @@ _this.delay = 1;

}
/**

@@ -462,4 +283,7 @@ * process an async job

AsyncStream.prototype.processJob_ = function processJob_() {
var _proto = AsyncStream.prototype;
_proto.processJob_ = function processJob_() {
this.jobs.shift()();
if (this.jobs.length) {

@@ -470,4 +294,3 @@ this.timeout_ = setTimeout(this.processJob_.bind(this), this.delay);

}
};
}
/**

@@ -478,6 +301,7 @@ * push a job into the stream

*/
;
_proto.push = function push(job) {
this.jobs.push(job);
AsyncStream.prototype.push = function push(job) {
this.jobs.push(job);
if (!this.timeout_) {

@@ -492,16 +316,9 @@ this.timeout_ = setTimeout(this.processJob_.bind(this), this.delay);

/**
* @file decrypter.js
*
* An asynchronous implementation of AES-128 CBC decryption with
* PKCS#7 padding.
*/
/**
* Convert network-order (big-endian) bytes into their little-endian
* representation.
*/
var ntoh = function ntoh(word) {
return word << 24 | (word & 0xff00) << 8 | (word & 0xff0000) >> 8 | word >>> 24;
};
/**

@@ -520,35 +337,31 @@ * Decrypt bytes using AES-128 with CBC and PKCS#7 padding.

*/
var decrypt = function decrypt(encrypted, key, initVector) {
// word-level access to the encrypted bytes
var encrypted32 = new Int32Array(encrypted.buffer, encrypted.byteOffset, encrypted.byteLength >> 2);
var decipher = new AES(Array.prototype.slice.call(key)); // byte and word-level access for the decrypted output
var decipher = new AES(Array.prototype.slice.call(key));
// byte and word-level access for the decrypted output
var decrypted = new Uint8Array(encrypted.byteLength);
var decrypted32 = new Int32Array(decrypted.buffer);
// temporary variables for working with the IV, encrypted, and
var decrypted32 = new Int32Array(decrypted.buffer); // temporary variables for working with the IV, encrypted, and
// decrypted data
var init0 = void 0;
var init1 = void 0;
var init2 = void 0;
var init3 = void 0;
var encrypted0 = void 0;
var encrypted1 = void 0;
var encrypted2 = void 0;
var encrypted3 = void 0;
// iteration variable
var wordIx = void 0;
var init0;
var init1;
var init2;
var init3;
var encrypted0;
var encrypted1;
var encrypted2;
var encrypted3; // iteration variable
// pull out the words of the IV to ensure we don't modify the
var wordIx; // pull out the words of the IV to ensure we don't modify the
// passed-in reference and easier access
init0 = initVector[0];
init1 = initVector[1];
init2 = initVector[2];
init3 = initVector[3];
init3 = initVector[3]; // decrypt four word sequences, applying cipher-block chaining (CBC)
// to each decrypted block
// decrypt four word sequences, applying cipher-block chaining (CBC)
// to each decrypted block
for (wordIx = 0; wordIx < encrypted32.length; wordIx += 4) {

@@ -560,15 +373,12 @@ // convert big-endian (network order) words into little-endian

encrypted2 = ntoh(encrypted32[wordIx + 2]);
encrypted3 = ntoh(encrypted32[wordIx + 3]);
encrypted3 = ntoh(encrypted32[wordIx + 3]); // decrypt the block
// decrypt the block
decipher.decrypt(encrypted0, encrypted1, encrypted2, encrypted3, decrypted32, wordIx);
decipher.decrypt(encrypted0, encrypted1, encrypted2, encrypted3, decrypted32, wordIx); // XOR with the IV, and restore network byte-order to obtain the
// plaintext
// XOR with the IV, and restore network byte-order to obtain the
// plaintext
decrypted32[wordIx] = ntoh(decrypted32[wordIx] ^ init0);
decrypted32[wordIx + 1] = ntoh(decrypted32[wordIx + 1] ^ init1);
decrypted32[wordIx + 2] = ntoh(decrypted32[wordIx + 2] ^ init2);
decrypted32[wordIx + 3] = ntoh(decrypted32[wordIx + 3] ^ init3);
decrypted32[wordIx + 3] = ntoh(decrypted32[wordIx + 3] ^ init3); // setup the IV for the next round
// setup the IV for the next round
init0 = encrypted0;

@@ -582,3 +392,2 @@ init1 = encrypted1;

};
/**

@@ -596,6 +405,7 @@ * The `Decrypter` class that manages decryption of AES

var Decrypter = function () {
var Decrypter =
/*#__PURE__*/
function () {
function Decrypter(encrypted, key, initVector, done) {
classCallCheck(this, Decrypter);
var step = Decrypter.STEP;

@@ -605,12 +415,12 @@ var encrypted32 = new Int32Array(encrypted.buffer);

var i = 0;
this.asyncStream_ = new AsyncStream(); // split up the encryption job and do the individual chunks asynchronously
this.asyncStream_ = new AsyncStream();
this.asyncStream_.push(this.decryptChunk_(encrypted32.subarray(i, i + step), key, initVector, decrypted));
// split up the encryption job and do the individual chunks asynchronously
this.asyncStream_.push(this.decryptChunk_(encrypted32.subarray(i, i + step), key, initVector, decrypted));
for (i = step; i < encrypted32.length; i += step) {
initVector = new Uint32Array([ntoh(encrypted32[i - 4]), ntoh(encrypted32[i - 3]), ntoh(encrypted32[i - 2]), ntoh(encrypted32[i - 1])]);
this.asyncStream_.push(this.decryptChunk_(encrypted32.subarray(i, i + step), key, initVector, decrypted));
}
// invoke the done() callback when everything is finished
} // invoke the done() callback when everything is finished
this.asyncStream_.push(function () {

@@ -621,17 +431,17 @@ // remove pkcs#7 padding from the decrypted bytes

}
/**
* a getter for step the maximum number of bytes to process at one time
*
* @return {Number} the value of step 32000
* @return {number} the value of step 32000
*/
var _proto = Decrypter.prototype;
/**
* @private
*/
Decrypter.prototype.decryptChunk_ = function decryptChunk_(encrypted, key, initVector, decrypted) {
_proto.decryptChunk_ = function decryptChunk_(encrypted, key, initVector, decrypted) {
return function () {
var bytes = decrypt(encrypted, key, initVector);
decrypted.set(bytes, encrypted.byteOffset);

@@ -641,5 +451,5 @@ };

createClass(Decrypter, null, [{
key: 'STEP',
get: function get$$1() {
_createClass(Decrypter, null, [{
key: "STEP",
get: function get() {
// 4 * 8000;

@@ -649,16 +459,6 @@ return 32000;

}]);
return Decrypter;
}();
/**
* @file index.js
*
* Index module to easily import the primary components of AES-128
* decryption. Like this:
*
* ```js
* import {Decrypter, decrypt, AsyncStream} from 'aes-decrypter';
* ```
*/
export { decrypt, Decrypter, AsyncStream };
export { AsyncStream, Decrypter, decrypt };

@@ -1,21 +0,11 @@

/**
* aes-decrypter
* @version 3.0.0
* @copyright 2017 Brightcove, Inc.
* @license Apache-2.0
*/
/*! @name aes-decrypter @version 3.0.1-0 @license Apache-2.0 */
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(factory((global.aesDecrypter = global.aesDecrypter || {})));
}(this, (function (exports) { 'use strict';
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('global/window')) :
typeof define === 'function' && define.amd ? define(['exports', 'global/window'], factory) :
(global = global || self, factory(global.aesDecrypter = {}, global.window));
}(this, function (exports, window) { 'use strict';
var classCallCheck = function (instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
};
window = window && window.hasOwnProperty('default') ? window['default'] : window;
var createClass = function () {
function defineProperties(target, props) {
function _defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {

@@ -30,645 +20,755 @@ var descriptor = props[i];

return function (Constructor, protoProps, staticProps) {
if (protoProps) defineProperties(Constructor.prototype, protoProps);
if (staticProps) defineProperties(Constructor, staticProps);
function _createClass(Constructor, protoProps, staticProps) {
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
if (staticProps) _defineProperties(Constructor, staticProps);
return Constructor;
};
}();
}
var createClass = _createClass;
/**
* @file aes.js
*
* This file contains an adaptation of the AES decryption algorithm
* from the Standford Javascript Cryptography Library. That work is
* covered by the following copyright and permissions notice:
*
* Copyright 2009-2010 Emily Stark, Mike Hamburg, Dan Boneh.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation
* are those of the authors and should not be interpreted as representing
* official policies, either expressed or implied, of the authors.
*/
/**
* Expand the S-box tables.
*
* @private
*/
var precompute = function precompute() {
var tables = [[[], [], [], [], []], [[], [], [], [], []]];
var encTable = tables[0];
var decTable = tables[1];
var sbox = encTable[4];
var sboxInv = decTable[4];
var i;
var x;
var xInv;
var d = [];
var th = [];
var x2;
var x4;
var x8;
var s;
var tEnc;
var tDec; // Compute double and third tables
for (i = 0; i < 256; i++) {
th[(d[i] = i << 1 ^ (i >> 7) * 283) ^ i] = i;
}
for (x = xInv = 0; !sbox[x]; x ^= x2 || 1, xInv = th[xInv] || 1) {
// Compute sbox
s = xInv ^ xInv << 1 ^ xInv << 2 ^ xInv << 3 ^ xInv << 4;
s = s >> 8 ^ s & 255 ^ 99;
sbox[x] = s;
sboxInv[s] = x; // Compute MixColumns
x8 = d[x4 = d[x2 = d[x]]];
tDec = x8 * 0x1010101 ^ x4 * 0x10001 ^ x2 * 0x101 ^ x * 0x1010100;
tEnc = d[s] * 0x101 ^ s * 0x1010100;
for (i = 0; i < 4; i++) {
encTable[i][x] = tEnc = tEnc << 24 ^ tEnc >>> 8;
decTable[i][s] = tDec = tDec << 24 ^ tDec >>> 8;
}
} // Compactify. Considerable speedup on Firefox.
var inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
for (i = 0; i < 5; i++) {
encTable[i] = encTable[i].slice(0);
decTable[i] = decTable[i].slice(0);
}
});
if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
};
return tables;
};
var aesTables = null;
/**
* Schedule out an AES key for both encryption and decryption. This
* is a low-level class. Use a cipher mode to do bulk encryption.
*
* @class AES
* @param key {Array} The key as an array of 4, 6 or 8 words.
*/
var AES =
/*#__PURE__*/
function () {
function AES(key) {
/**
* The expanded S-box and inverse S-box tables. These will be computed
* on the client so that we don't have to send them down the wire.
*
* There are two tables, _tables[0] is for encryption and
* _tables[1] is for decryption.
*
* The first 4 sub-tables are the expanded S-box with MixColumns. The
* last (_tables[01][4]) is the S-box itself.
*
* @private
*/
// if we have yet to precompute the S-box tables
// do so now
if (!aesTables) {
aesTables = precompute();
} // then make a copy of that object for use
this._tables = [[aesTables[0][0].slice(), aesTables[0][1].slice(), aesTables[0][2].slice(), aesTables[0][3].slice(), aesTables[0][4].slice()], [aesTables[1][0].slice(), aesTables[1][1].slice(), aesTables[1][2].slice(), aesTables[1][3].slice(), aesTables[1][4].slice()]];
var i;
var j;
var tmp;
var sbox = this._tables[0][4];
var decTable = this._tables[1];
var keyLen = key.length;
var rcon = 1;
if (keyLen !== 4 && keyLen !== 6 && keyLen !== 8) {
throw new Error('Invalid aes key size');
}
var encKey = key.slice(0);
var decKey = [];
this._key = [encKey, decKey]; // schedule encryption keys
for (i = keyLen; i < 4 * keyLen + 28; i++) {
tmp = encKey[i - 1]; // apply sbox
if (i % keyLen === 0 || keyLen === 8 && i % keyLen === 4) {
tmp = sbox[tmp >>> 24] << 24 ^ sbox[tmp >> 16 & 255] << 16 ^ sbox[tmp >> 8 & 255] << 8 ^ sbox[tmp & 255]; // shift rows and add rcon
if (i % keyLen === 0) {
tmp = tmp << 8 ^ tmp >>> 24 ^ rcon << 24;
rcon = rcon << 1 ^ (rcon >> 7) * 283;
}
}
var possibleConstructorReturn = function (self, call) {
if (!self) {
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
}
encKey[i] = encKey[i - keyLen] ^ tmp;
} // schedule decryption keys
return call && (typeof call === "object" || typeof call === "function") ? call : self;
};
/**
* @file aes.js
*
* This file contains an adaptation of the AES decryption algorithm
* from the Standford Javascript Cryptography Library. That work is
* covered by the following copyright and permissions notice:
*
* Copyright 2009-2010 Emily Stark, Mike Hamburg, Dan Boneh.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation
* are those of the authors and should not be interpreted as representing
* official policies, either expressed or implied, of the authors.
*/
for (j = 0; i; j++, i--) {
tmp = encKey[j & 3 ? i : i - 4];
/**
* Expand the S-box tables.
*
* @private
*/
var precompute = function precompute() {
var tables = [[[], [], [], [], []], [[], [], [], [], []]];
var encTable = tables[0];
var decTable = tables[1];
var sbox = encTable[4];
var sboxInv = decTable[4];
var i = void 0;
var x = void 0;
var xInv = void 0;
var d = [];
var th = [];
var x2 = void 0;
var x4 = void 0;
var x8 = void 0;
var s = void 0;
var tEnc = void 0;
var tDec = void 0;
if (i <= 4 || j < 4) {
decKey[j] = tmp;
} else {
decKey[j] = decTable[0][sbox[tmp >>> 24]] ^ decTable[1][sbox[tmp >> 16 & 255]] ^ decTable[2][sbox[tmp >> 8 & 255]] ^ decTable[3][sbox[tmp & 255]];
}
}
}
/**
* Decrypt 16 bytes, specified as four 32-bit words.
*
* @param {number} encrypted0 the first word to decrypt
* @param {number} encrypted1 the second word to decrypt
* @param {number} encrypted2 the third word to decrypt
* @param {number} encrypted3 the fourth word to decrypt
* @param {Int32Array} out the array to write the decrypted words
* into
* @param {number} offset the offset into the output array to start
* writing results
* @return {Array} The plaintext.
*/
// Compute double and third tables
for (i = 0; i < 256; i++) {
th[(d[i] = i << 1 ^ (i >> 7) * 283) ^ i] = i;
}
for (x = xInv = 0; !sbox[x]; x ^= x2 || 1, xInv = th[xInv] || 1) {
// Compute sbox
s = xInv ^ xInv << 1 ^ xInv << 2 ^ xInv << 3 ^ xInv << 4;
s = s >> 8 ^ s & 255 ^ 99;
sbox[x] = s;
sboxInv[s] = x;
var _proto = AES.prototype;
// Compute MixColumns
x8 = d[x4 = d[x2 = d[x]]];
tDec = x8 * 0x1010101 ^ x4 * 0x10001 ^ x2 * 0x101 ^ x * 0x1010100;
tEnc = d[s] * 0x101 ^ s * 0x1010100;
_proto.decrypt = function decrypt(encrypted0, encrypted1, encrypted2, encrypted3, out, offset) {
var key = this._key[1]; // state variables a,b,c,d are loaded with pre-whitened data
for (i = 0; i < 4; i++) {
encTable[i][x] = tEnc = tEnc << 24 ^ tEnc >>> 8;
decTable[i][s] = tDec = tDec << 24 ^ tDec >>> 8;
}
}
var a = encrypted0 ^ key[0];
var b = encrypted3 ^ key[1];
var c = encrypted2 ^ key[2];
var d = encrypted1 ^ key[3];
var a2;
var b2;
var c2; // key.length === 2 ?
// Compactify. Considerable speedup on Firefox.
for (i = 0; i < 5; i++) {
encTable[i] = encTable[i].slice(0);
decTable[i] = decTable[i].slice(0);
}
return tables;
};
var aesTables = null;
var nInnerRounds = key.length / 4 - 2;
var i;
var kIndex = 4;
var table = this._tables[1]; // load up the tables
/**
* Schedule out an AES key for both encryption and decryption. This
* is a low-level class. Use a cipher mode to do bulk encryption.
*
* @class AES
* @param key {Array} The key as an array of 4, 6 or 8 words.
*/
var table0 = table[0];
var table1 = table[1];
var table2 = table[2];
var table3 = table[3];
var sbox = table[4]; // Inner rounds. Cribbed from OpenSSL.
var AES = function () {
function AES(key) {
classCallCheck(this, AES);
for (i = 0; i < nInnerRounds; i++) {
a2 = table0[a >>> 24] ^ table1[b >> 16 & 255] ^ table2[c >> 8 & 255] ^ table3[d & 255] ^ key[kIndex];
b2 = table0[b >>> 24] ^ table1[c >> 16 & 255] ^ table2[d >> 8 & 255] ^ table3[a & 255] ^ key[kIndex + 1];
c2 = table0[c >>> 24] ^ table1[d >> 16 & 255] ^ table2[a >> 8 & 255] ^ table3[b & 255] ^ key[kIndex + 2];
d = table0[d >>> 24] ^ table1[a >> 16 & 255] ^ table2[b >> 8 & 255] ^ table3[c & 255] ^ key[kIndex + 3];
kIndex += 4;
a = a2;
b = b2;
c = c2;
} // Last round.
/**
* The expanded S-box and inverse S-box tables. These will be computed
* on the client so that we don't have to send them down the wire.
*
* There are two tables, _tables[0] is for encryption and
* _tables[1] is for decryption.
*
* The first 4 sub-tables are the expanded S-box with MixColumns. The
* last (_tables[01][4]) is the S-box itself.
*
* @private
*/
// if we have yet to precompute the S-box tables
// do so now
if (!aesTables) {
aesTables = precompute();
}
// then make a copy of that object for use
this._tables = [[aesTables[0][0].slice(), aesTables[0][1].slice(), aesTables[0][2].slice(), aesTables[0][3].slice(), aesTables[0][4].slice()], [aesTables[1][0].slice(), aesTables[1][1].slice(), aesTables[1][2].slice(), aesTables[1][3].slice(), aesTables[1][4].slice()]];
var i = void 0;
var j = void 0;
var tmp = void 0;
var encKey = void 0;
var decKey = void 0;
var sbox = this._tables[0][4];
var decTable = this._tables[1];
var keyLen = key.length;
var rcon = 1;
if (keyLen !== 4 && keyLen !== 6 && keyLen !== 8) {
throw new Error('Invalid aes key size');
}
for (i = 0; i < 4; i++) {
out[(3 & -i) + offset] = sbox[a >>> 24] << 24 ^ sbox[b >> 16 & 255] << 16 ^ sbox[c >> 8 & 255] << 8 ^ sbox[d & 255] ^ key[kIndex++];
a2 = a;
a = b;
b = c;
c = d;
d = a2;
}
};
encKey = key.slice(0);
decKey = [];
this._key = [encKey, decKey];
return AES;
}();
// schedule encryption keys
for (i = keyLen; i < 4 * keyLen + 28; i++) {
tmp = encKey[i - 1];
function _inheritsLoose(subClass, superClass) {
subClass.prototype = Object.create(superClass.prototype);
subClass.prototype.constructor = subClass;
subClass.__proto__ = superClass;
}
// apply sbox
if (i % keyLen === 0 || keyLen === 8 && i % keyLen === 4) {
tmp = sbox[tmp >>> 24] << 24 ^ sbox[tmp >> 16 & 255] << 16 ^ sbox[tmp >> 8 & 255] << 8 ^ sbox[tmp & 255];
var inheritsLoose = _inheritsLoose;
// shift rows and add rcon
if (i % keyLen === 0) {
tmp = tmp << 8 ^ tmp >>> 24 ^ rcon << 24;
rcon = rcon << 1 ^ (rcon >> 7) * 283;
function createCommonjsModule(fn, module) {
return module = { exports: {} }, fn(module, module.exports), module.exports;
}
var urlToolkit = createCommonjsModule(function (module, exports) {
// see https://tools.ietf.org/html/rfc1808
/* jshint ignore:start */
(function(root) {
/* jshint ignore:end */
var URL_REGEX = /^((?:[a-zA-Z0-9+\-.]+:)?)(\/\/[^\/?#]*)?((?:[^\/\?#]*\/)*.*?)??(;.*?)?(\?.*?)?(#.*?)?$/;
var FIRST_SEGMENT_REGEX = /^([^\/?#]*)(.*)$/;
var SLASH_DOT_REGEX = /(?:\/|^)\.(?=\/)/g;
var SLASH_DOT_DOT_REGEX = /(?:\/|^)\.\.\/(?!\.\.\/).*?(?=\/)/g;
var URLToolkit = { // jshint ignore:line
// If opts.alwaysNormalize is true then the path will always be normalized even when it starts with / or //
// E.g
// With opts.alwaysNormalize = false (default, spec compliant)
// http://a.com/b/cd + /e/f/../g => http://a.com/e/f/../g
// With opts.alwaysNormalize = true (not spec compliant)
// http://a.com/b/cd + /e/f/../g => http://a.com/e/g
buildAbsoluteURL: function(baseURL, relativeURL, opts) {
opts = opts || {};
// remove any remaining space and CRLF
baseURL = baseURL.trim();
relativeURL = relativeURL.trim();
if (!relativeURL) {
// 2a) If the embedded URL is entirely empty, it inherits the
// entire base URL (i.e., is set equal to the base URL)
// and we are done.
if (!opts.alwaysNormalize) {
return baseURL;
}
var basePartsForNormalise = URLToolkit.parseURL(baseURL);
if (!basePartsForNormalise) {
throw new Error('Error trying to parse base URL.');
}
basePartsForNormalise.path = URLToolkit.normalizePath(basePartsForNormalise.path);
return URLToolkit.buildURLFromParts(basePartsForNormalise);
}
var relativeParts = URLToolkit.parseURL(relativeURL);
if (!relativeParts) {
throw new Error('Error trying to parse relative URL.');
}
if (relativeParts.scheme) {
// 2b) If the embedded URL starts with a scheme name, it is
// interpreted as an absolute URL and we are done.
if (!opts.alwaysNormalize) {
return relativeURL;
}
relativeParts.path = URLToolkit.normalizePath(relativeParts.path);
return URLToolkit.buildURLFromParts(relativeParts);
}
var baseParts = URLToolkit.parseURL(baseURL);
if (!baseParts) {
throw new Error('Error trying to parse base URL.');
}
if (!baseParts.netLoc && baseParts.path && baseParts.path[0] !== '/') {
// If netLoc missing and path doesn't start with '/', assume everthing before the first '/' is the netLoc
// This causes 'example.com/a' to be handled as '//example.com/a' instead of '/example.com/a'
var pathParts = FIRST_SEGMENT_REGEX.exec(baseParts.path);
baseParts.netLoc = pathParts[1];
baseParts.path = pathParts[2];
}
if (baseParts.netLoc && !baseParts.path) {
baseParts.path = '/';
}
var builtParts = {
// 2c) Otherwise, the embedded URL inherits the scheme of
// the base URL.
scheme: baseParts.scheme,
netLoc: relativeParts.netLoc,
path: null,
params: relativeParts.params,
query: relativeParts.query,
fragment: relativeParts.fragment
};
if (!relativeParts.netLoc) {
// 3) If the embedded URL's <net_loc> is non-empty, we skip to
// Step 7. Otherwise, the embedded URL inherits the <net_loc>
// (if any) of the base URL.
builtParts.netLoc = baseParts.netLoc;
// 4) If the embedded URL path is preceded by a slash "/", the
// path is not relative and we skip to Step 7.
if (relativeParts.path[0] !== '/') {
if (!relativeParts.path) {
// 5) If the embedded URL path is empty (and not preceded by a
// slash), then the embedded URL inherits the base URL path
builtParts.path = baseParts.path;
// 5a) if the embedded URL's <params> is non-empty, we skip to
// step 7; otherwise, it inherits the <params> of the base
// URL (if any) and
if (!relativeParts.params) {
builtParts.params = baseParts.params;
// 5b) if the embedded URL's <query> is non-empty, we skip to
// step 7; otherwise, it inherits the <query> of the base
// URL (if any) and we skip to step 7.
if (!relativeParts.query) {
builtParts.query = baseParts.query;
}
}
} else {
// 6) The last segment of the base URL's path (anything
// following the rightmost slash "/", or the entire path if no
// slash is present) is removed and the embedded URL's path is
// appended in its place.
var baseURLPath = baseParts.path;
var newPath = baseURLPath.substring(0, baseURLPath.lastIndexOf('/') + 1) + relativeParts.path;
builtParts.path = URLToolkit.normalizePath(newPath);
}
}
}
if (builtParts.path === null) {
builtParts.path = opts.alwaysNormalize ? URLToolkit.normalizePath(relativeParts.path) : relativeParts.path;
}
return URLToolkit.buildURLFromParts(builtParts);
},
parseURL: function(url) {
var parts = URL_REGEX.exec(url);
if (!parts) {
return null;
}
return {
scheme: parts[1] || '',
netLoc: parts[2] || '',
path: parts[3] || '',
params: parts[4] || '',
query: parts[5] || '',
fragment: parts[6] || ''
};
},
normalizePath: function(path) {
// The following operations are
// then applied, in order, to the new path:
// 6a) All occurrences of "./", where "." is a complete path
// segment, are removed.
// 6b) If the path ends with "." as a complete path segment,
// that "." is removed.
path = path.split('').reverse().join('').replace(SLASH_DOT_REGEX, '');
// 6c) All occurrences of "<segment>/../", where <segment> is a
// complete path segment not equal to "..", are removed.
// Removal of these path segments is performed iteratively,
// removing the leftmost matching pattern on each iteration,
// until no matching pattern remains.
// 6d) If the path ends with "<segment>/..", where <segment> is a
// complete path segment not equal to "..", that
// "<segment>/.." is removed.
while (path.length !== (path = path.replace(SLASH_DOT_DOT_REGEX, '')).length) {} // jshint ignore:line
return path.split('').reverse().join('');
},
buildURLFromParts: function(parts) {
return parts.scheme + parts.netLoc + parts.path + parts.params + parts.query + parts.fragment;
}
};
encKey[i] = encKey[i - keyLen] ^ tmp;
}
/* jshint ignore:start */
module.exports = URLToolkit;
})();
/* jshint ignore:end */
});
// schedule decryption keys
for (j = 0; i; j++, i--) {
tmp = encKey[j & 3 ? i : i - 4];
if (i <= 4 || j < 4) {
decKey[j] = tmp;
} else {
decKey[j] = decTable[0][sbox[tmp >>> 24]] ^ decTable[1][sbox[tmp >> 16 & 255]] ^ decTable[2][sbox[tmp >> 8 & 255]] ^ decTable[3][sbox[tmp & 255]];
}
}
}
/*! @name @videojs/vhs-utils @version 0.0.0 @license MIT */
/**
* Decrypt 16 bytes, specified as four 32-bit words.
* @file stream.js
*/
/**
* A lightweight readable stream implemention that handles event dispatching.
*
* @param {Number} encrypted0 the first word to decrypt
* @param {Number} encrypted1 the second word to decrypt
* @param {Number} encrypted2 the third word to decrypt
* @param {Number} encrypted3 the fourth word to decrypt
* @param {Int32Array} out the array to write the decrypted words
* into
* @param {Number} offset the offset into the output array to start
* writing results
* @return {Array} The plaintext.
* @class Stream
*/
var Stream =
/*#__PURE__*/
function () {
function Stream() {
this.listeners = {};
}
/**
* Add a listener for a specified event type.
*
* @param {string} type the event name
* @param {Function} listener the callback to be invoked when an event of
* the specified type occurs
*/
AES.prototype.decrypt = function decrypt(encrypted0, encrypted1, encrypted2, encrypted3, out, offset) {
var key = this._key[1];
// state variables a,b,c,d are loaded with pre-whitened data
var a = encrypted0 ^ key[0];
var b = encrypted3 ^ key[1];
var c = encrypted2 ^ key[2];
var d = encrypted1 ^ key[3];
var a2 = void 0;
var b2 = void 0;
var c2 = void 0;
var _proto = Stream.prototype;
// key.length === 2 ?
var nInnerRounds = key.length / 4 - 2;
var i = void 0;
var kIndex = 4;
var table = this._tables[1];
_proto.on = function on(type, listener) {
if (!this.listeners[type]) {
this.listeners[type] = [];
}
// load up the tables
var table0 = table[0];
var table1 = table[1];
var table2 = table[2];
var table3 = table[3];
var sbox = table[4];
// Inner rounds. Cribbed from OpenSSL.
for (i = 0; i < nInnerRounds; i++) {
a2 = table0[a >>> 24] ^ table1[b >> 16 & 255] ^ table2[c >> 8 & 255] ^ table3[d & 255] ^ key[kIndex];
b2 = table0[b >>> 24] ^ table1[c >> 16 & 255] ^ table2[d >> 8 & 255] ^ table3[a & 255] ^ key[kIndex + 1];
c2 = table0[c >>> 24] ^ table1[d >> 16 & 255] ^ table2[a >> 8 & 255] ^ table3[b & 255] ^ key[kIndex + 2];
d = table0[d >>> 24] ^ table1[a >> 16 & 255] ^ table2[b >> 8 & 255] ^ table3[c & 255] ^ key[kIndex + 3];
kIndex += 4;
a = a2;b = b2;c = c2;
this.listeners[type].push(listener);
}
/**
* Remove a listener for a specified event type.
*
* @param {string} type the event name
* @param {Function} listener a function previously registered for this
* type of event through `on`
* @return {boolean} if we could turn it off or not
*/
;
// Last round.
for (i = 0; i < 4; i++) {
out[(3 & -i) + offset] = sbox[a >>> 24] << 24 ^ sbox[b >> 16 & 255] << 16 ^ sbox[c >> 8 & 255] << 8 ^ sbox[d & 255] ^ key[kIndex++];
a2 = a;a = b;b = c;c = d;d = a2;
_proto.off = function off(type, listener) {
if (!this.listeners[type]) {
return false;
}
var index = this.listeners[type].indexOf(listener); // TODO: which is better?
// In Video.js we slice listener functions
// on trigger so that it does not mess up the order
// while we loop through.
//
// Here we slice on off so that the loop in trigger
// can continue using it's old reference to loop without
// messing up the order.
this.listeners[type] = this.listeners[type].slice(0);
this.listeners[type].splice(index, 1);
return index > -1;
}
};
/**
* Trigger an event of the specified type on this stream. Any additional
* arguments to this function are passed as parameters to event listeners.
*
* @param {string} type the event name
*/
;
return AES;
}();
_proto.trigger = function trigger(type) {
var callbacks = this.listeners[type];
/**
* @file stream.js
*/
/**
* A lightweight readable stream implemention that handles event dispatching.
*
* @class Stream
*/
var Stream = function () {
function Stream() {
classCallCheck(this, Stream);
if (!callbacks) {
return;
} // Slicing the arguments on every invocation of this method
// can add a significant amount of overhead. Avoid the
// intermediate object creation for the common case of a
// single callback argument
this.listeners = {};
}
/**
* Add a listener for a specified event type.
*
* @param {String} type the event name
* @param {Function} listener the callback to be invoked when an event of
* the specified type occurs
*/
if (arguments.length === 2) {
var length = callbacks.length;
for (var i = 0; i < length; ++i) {
callbacks[i].call(this, arguments[1]);
}
} else {
var args = Array.prototype.slice.call(arguments, 1);
var _length = callbacks.length;
Stream.prototype.on = function on(type, listener) {
if (!this.listeners[type]) {
this.listeners[type] = [];
for (var _i = 0; _i < _length; ++_i) {
callbacks[_i].apply(this, args);
}
}
}
this.listeners[type].push(listener);
};
/**
* Destroys the stream and cleans up.
*/
;
/**
* Remove a listener for a specified event type.
*
* @param {String} type the event name
* @param {Function} listener a function previously registered for this
* type of event through `on`
* @return {Boolean} if we could turn it off or not
*/
_proto.dispose = function dispose() {
this.listeners = {};
}
/**
* Forwards all `data` events on this stream to the destination stream. The
* destination stream should provide a method `push` to receive the data
* events as they arrive.
*
* @param {Stream} destination the stream that will receive all `data` events
* @see http://nodejs.org/api/stream.html#stream_readable_pipe_destination_options
*/
;
_proto.pipe = function pipe(destination) {
this.on('data', function (data) {
destination.push(data);
});
};
Stream.prototype.off = function off(type, listener) {
if (!this.listeners[type]) {
return false;
}
return Stream;
}();
var index = this.listeners[type].indexOf(listener);
var Stream$1 = Stream;
this.listeners[type].splice(index, 1);
return index > -1;
};
/**
* Trigger an event of the specified type on this stream. Any additional
* arguments to this function are passed as parameters to event listeners.
* A wrapper around the Stream class to use setTimeout
* and run stream "jobs" Asynchronously
*
* @param {String} type the event name
* @class AsyncStream
* @extends Stream
*/
var AsyncStream =
/*#__PURE__*/
function (_Stream) {
inheritsLoose(AsyncStream, _Stream);
Stream.prototype.trigger = function trigger(type) {
var callbacks = this.listeners[type];
function AsyncStream() {
var _this;
if (!callbacks) {
return;
_this = _Stream.call(this, Stream$1) || this;
_this.jobs = [];
_this.delay = 1;
_this.timeout_ = null;
return _this;
}
/**
* process an async job
*
* @private
*/
// Slicing the arguments on every invocation of this method
// can add a significant amount of overhead. Avoid the
// intermediate object creation for the common case of a
// single callback argument
if (arguments.length === 2) {
var length = callbacks.length;
for (var i = 0; i < length; ++i) {
callbacks[i].call(this, arguments[1]);
}
} else {
var args = Array.prototype.slice.call(arguments, 1);
var _length = callbacks.length;
var _proto = AsyncStream.prototype;
for (var _i = 0; _i < _length; ++_i) {
callbacks[_i].apply(this, args);
_proto.processJob_ = function processJob_() {
this.jobs.shift()();
if (this.jobs.length) {
this.timeout_ = setTimeout(this.processJob_.bind(this), this.delay);
} else {
this.timeout_ = null;
}
}
};
/**
* push a job into the stream
*
* @param {Function} job the job to push into the stream
*/
;
/**
* Destroys the stream and cleans up.
*/
_proto.push = function push(job) {
this.jobs.push(job);
if (!this.timeout_) {
this.timeout_ = setTimeout(this.processJob_.bind(this), this.delay);
}
};
Stream.prototype.dispose = function dispose() {
this.listeners = {};
};
return AsyncStream;
}(Stream$1);
/*! @name pkcs7 @version 1.0.3-1 @license Apache-2.0 */
/**
* Forwards all `data` events on this stream to the destination stream. The
* destination stream should provide a method `push` to receive the data
* events as they arrive.
* Returns the subarray of a Uint8Array without PKCS#7 padding.
*
* @param {Stream} destination the stream that will receive all `data` events
* @see http://nodejs.org/api/stream.html#stream_readable_pipe_destination_options
* @param padded {Uint8Array} unencrypted bytes that have been padded
* @return {Uint8Array} the unpadded bytes
* @see http://tools.ietf.org/html/rfc5652
*/
Stream.prototype.pipe = function pipe(destination) {
this.on('data', function (data) {
destination.push(data);
});
};
return Stream;
}();
/**
* @file async-stream.js
*/
/**
* A wrapper around the Stream class to use setTiemout
* and run stream "jobs" Asynchronously
*
* @class AsyncStream
* @extends Stream
*/
var AsyncStream = function (_Stream) {
inherits(AsyncStream, _Stream);
function AsyncStream() {
classCallCheck(this, AsyncStream);
var _this = possibleConstructorReturn(this, _Stream.call(this, Stream));
_this.jobs = [];
_this.delay = 1;
_this.timeout_ = null;
return _this;
function unpad(padded) {
return padded.subarray(0, padded.byteLength - padded[padded.byteLength - 1]);
}
/**
* process an async job
*
* @private
* Convert network-order (big-endian) bytes into their little-endian
* representation.
*/
AsyncStream.prototype.processJob_ = function processJob_() {
this.jobs.shift()();
if (this.jobs.length) {
this.timeout_ = setTimeout(this.processJob_.bind(this), this.delay);
} else {
this.timeout_ = null;
}
var ntoh = function ntoh(word) {
return word << 24 | (word & 0xff00) << 8 | (word & 0xff0000) >> 8 | word >>> 24;
};
/**
* push a job into the stream
* Decrypt bytes using AES-128 with CBC and PKCS#7 padding.
*
* @param {Function} job the job to push into the stream
* @param {Uint8Array} encrypted the encrypted bytes
* @param {Uint32Array} key the bytes of the decryption key
* @param {Uint32Array} initVector the initialization vector (IV) to
* use for the first round of CBC.
* @return {Uint8Array} the decrypted bytes
*
* @see http://en.wikipedia.org/wiki/Advanced_Encryption_Standard
* @see http://en.wikipedia.org/wiki/Block_cipher_mode_of_operation#Cipher_Block_Chaining_.28CBC.29
* @see https://tools.ietf.org/html/rfc2315
*/
AsyncStream.prototype.push = function push(job) {
this.jobs.push(job);
if (!this.timeout_) {
this.timeout_ = setTimeout(this.processJob_.bind(this), this.delay);
}
};
var decrypt = function decrypt(encrypted, key, initVector) {
// word-level access to the encrypted bytes
var encrypted32 = new Int32Array(encrypted.buffer, encrypted.byteOffset, encrypted.byteLength >> 2);
var decipher = new AES(Array.prototype.slice.call(key)); // byte and word-level access for the decrypted output
return AsyncStream;
}(Stream);
var decrypted = new Uint8Array(encrypted.byteLength);
var decrypted32 = new Int32Array(decrypted.buffer); // temporary variables for working with the IV, encrypted, and
// decrypted data
/*
* pkcs7.pad
* https://github.com/brightcove/pkcs7
*
* Copyright (c) 2014 Brightcove
* Licensed under the apache2 license.
*/
var init0;
var init1;
var init2;
var init3;
var encrypted0;
var encrypted1;
var encrypted2;
var encrypted3; // iteration variable
var PADDING = void 0;
var wordIx; // pull out the words of the IV to ensure we don't modify the
// passed-in reference and easier access
// pre-define the padding values
PADDING = [[16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16], [15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15], [14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14], [13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13], [12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12], [11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11], [10, 10, 10, 10, 10, 10, 10, 10, 10, 10], [9, 9, 9, 9, 9, 9, 9, 9, 9], [8, 8, 8, 8, 8, 8, 8, 8], [7, 7, 7, 7, 7, 7, 7], [6, 6, 6, 6, 6, 6], [5, 5, 5, 5, 5], [4, 4, 4, 4], [3, 3, 3], [2, 2], [1]];
init0 = initVector[0];
init1 = initVector[1];
init2 = initVector[2];
init3 = initVector[3]; // decrypt four word sequences, applying cipher-block chaining (CBC)
// to each decrypted block
/**
* Returns the subarray of a Uint8Array without PKCS#7 padding.
* @param padded {Uint8Array} unencrypted bytes that have been padded
* @return {Uint8Array} the unpadded bytes
* @see http://tools.ietf.org/html/rfc5652
*/
function unpad(padded) {
return padded.subarray(0, padded.byteLength - padded[padded.byteLength - 1]);
}
for (wordIx = 0; wordIx < encrypted32.length; wordIx += 4) {
// convert big-endian (network order) words into little-endian
// (javascript order)
encrypted0 = ntoh(encrypted32[wordIx]);
encrypted1 = ntoh(encrypted32[wordIx + 1]);
encrypted2 = ntoh(encrypted32[wordIx + 2]);
encrypted3 = ntoh(encrypted32[wordIx + 3]); // decrypt the block
/**
* @file decrypter.js
*
* An asynchronous implementation of AES-128 CBC decryption with
* PKCS#7 padding.
*/
decipher.decrypt(encrypted0, encrypted1, encrypted2, encrypted3, decrypted32, wordIx); // XOR with the IV, and restore network byte-order to obtain the
// plaintext
/**
* Convert network-order (big-endian) bytes into their little-endian
* representation.
*/
var ntoh = function ntoh(word) {
return word << 24 | (word & 0xff00) << 8 | (word & 0xff0000) >> 8 | word >>> 24;
};
decrypted32[wordIx] = ntoh(decrypted32[wordIx] ^ init0);
decrypted32[wordIx + 1] = ntoh(decrypted32[wordIx + 1] ^ init1);
decrypted32[wordIx + 2] = ntoh(decrypted32[wordIx + 2] ^ init2);
decrypted32[wordIx + 3] = ntoh(decrypted32[wordIx + 3] ^ init3); // setup the IV for the next round
/**
* Decrypt bytes using AES-128 with CBC and PKCS#7 padding.
*
* @param {Uint8Array} encrypted the encrypted bytes
* @param {Uint32Array} key the bytes of the decryption key
* @param {Uint32Array} initVector the initialization vector (IV) to
* use for the first round of CBC.
* @return {Uint8Array} the decrypted bytes
*
* @see http://en.wikipedia.org/wiki/Advanced_Encryption_Standard
* @see http://en.wikipedia.org/wiki/Block_cipher_mode_of_operation#Cipher_Block_Chaining_.28CBC.29
* @see https://tools.ietf.org/html/rfc2315
*/
var decrypt = function decrypt(encrypted, key, initVector) {
// word-level access to the encrypted bytes
var encrypted32 = new Int32Array(encrypted.buffer, encrypted.byteOffset, encrypted.byteLength >> 2);
init0 = encrypted0;
init1 = encrypted1;
init2 = encrypted2;
init3 = encrypted3;
}
var decipher = new AES(Array.prototype.slice.call(key));
return decrypted;
};
/**
* The `Decrypter` class that manages decryption of AES
* data through `AsyncStream` objects and the `decrypt`
* function
*
* @param {Uint8Array} encrypted the encrypted bytes
* @param {Uint32Array} key the bytes of the decryption key
* @param {Uint32Array} initVector the initialization vector (IV) to
* @param {Function} done the function to run when done
* @class Decrypter
*/
// byte and word-level access for the decrypted output
var decrypted = new Uint8Array(encrypted.byteLength);
var decrypted32 = new Int32Array(decrypted.buffer);
// temporary variables for working with the IV, encrypted, and
// decrypted data
var init0 = void 0;
var init1 = void 0;
var init2 = void 0;
var init3 = void 0;
var encrypted0 = void 0;
var encrypted1 = void 0;
var encrypted2 = void 0;
var encrypted3 = void 0;
var Decrypter =
/*#__PURE__*/
function () {
function Decrypter(encrypted, key, initVector, done) {
var step = Decrypter.STEP;
var encrypted32 = new Int32Array(encrypted.buffer);
var decrypted = new Uint8Array(encrypted.byteLength);
var i = 0;
this.asyncStream_ = new AsyncStream(); // split up the encryption job and do the individual chunks asynchronously
// iteration variable
var wordIx = void 0;
this.asyncStream_.push(this.decryptChunk_(encrypted32.subarray(i, i + step), key, initVector, decrypted));
// pull out the words of the IV to ensure we don't modify the
// passed-in reference and easier access
init0 = initVector[0];
init1 = initVector[1];
init2 = initVector[2];
init3 = initVector[3];
for (i = step; i < encrypted32.length; i += step) {
initVector = new Uint32Array([ntoh(encrypted32[i - 4]), ntoh(encrypted32[i - 3]), ntoh(encrypted32[i - 2]), ntoh(encrypted32[i - 1])]);
this.asyncStream_.push(this.decryptChunk_(encrypted32.subarray(i, i + step), key, initVector, decrypted));
} // invoke the done() callback when everything is finished
// decrypt four word sequences, applying cipher-block chaining (CBC)
// to each decrypted block
for (wordIx = 0; wordIx < encrypted32.length; wordIx += 4) {
// convert big-endian (network order) words into little-endian
// (javascript order)
encrypted0 = ntoh(encrypted32[wordIx]);
encrypted1 = ntoh(encrypted32[wordIx + 1]);
encrypted2 = ntoh(encrypted32[wordIx + 2]);
encrypted3 = ntoh(encrypted32[wordIx + 3]);
// decrypt the block
decipher.decrypt(encrypted0, encrypted1, encrypted2, encrypted3, decrypted32, wordIx);
// XOR with the IV, and restore network byte-order to obtain the
// plaintext
decrypted32[wordIx] = ntoh(decrypted32[wordIx] ^ init0);
decrypted32[wordIx + 1] = ntoh(decrypted32[wordIx + 1] ^ init1);
decrypted32[wordIx + 2] = ntoh(decrypted32[wordIx + 2] ^ init2);
decrypted32[wordIx + 3] = ntoh(decrypted32[wordIx + 3] ^ init3);
// setup the IV for the next round
init0 = encrypted0;
init1 = encrypted1;
init2 = encrypted2;
init3 = encrypted3;
}
return decrypted;
};
/**
* The `Decrypter` class that manages decryption of AES
* data through `AsyncStream` objects and the `decrypt`
* function
*
* @param {Uint8Array} encrypted the encrypted bytes
* @param {Uint32Array} key the bytes of the decryption key
* @param {Uint32Array} initVector the initialization vector (IV) to
* @param {Function} done the function to run when done
* @class Decrypter
*/
var Decrypter = function () {
function Decrypter(encrypted, key, initVector, done) {
classCallCheck(this, Decrypter);
var step = Decrypter.STEP;
var encrypted32 = new Int32Array(encrypted.buffer);
var decrypted = new Uint8Array(encrypted.byteLength);
var i = 0;
this.asyncStream_ = new AsyncStream();
// split up the encryption job and do the individual chunks asynchronously
this.asyncStream_.push(this.decryptChunk_(encrypted32.subarray(i, i + step), key, initVector, decrypted));
for (i = step; i < encrypted32.length; i += step) {
initVector = new Uint32Array([ntoh(encrypted32[i - 4]), ntoh(encrypted32[i - 3]), ntoh(encrypted32[i - 2]), ntoh(encrypted32[i - 1])]);
this.asyncStream_.push(this.decryptChunk_(encrypted32.subarray(i, i + step), key, initVector, decrypted));
this.asyncStream_.push(function () {
// remove pkcs#7 padding from the decrypted bytes
done(null, unpad(decrypted));
});
}
// invoke the done() callback when everything is finished
this.asyncStream_.push(function () {
// remove pkcs#7 padding from the decrypted bytes
done(null, unpad(decrypted));
});
}
/**
* a getter for step the maximum number of bytes to process at one time
*
* @return {number} the value of step 32000
*/
/**
* a getter for step the maximum number of bytes to process at one time
*
* @return {Number} the value of step 32000
*/
var _proto = Decrypter.prototype;
/**
* @private
*/
Decrypter.prototype.decryptChunk_ = function decryptChunk_(encrypted, key, initVector, decrypted) {
return function () {
var bytes = decrypt(encrypted, key, initVector);
decrypted.set(bytes, encrypted.byteOffset);
/**
* @private
*/
_proto.decryptChunk_ = function decryptChunk_(encrypted, key, initVector, decrypted) {
return function () {
var bytes = decrypt(encrypted, key, initVector);
decrypted.set(bytes, encrypted.byteOffset);
};
};
};
createClass(Decrypter, null, [{
key: 'STEP',
get: function get$$1() {
// 4 * 8000;
return 32000;
}
}]);
return Decrypter;
}();
createClass(Decrypter, null, [{
key: "STEP",
get: function get() {
// 4 * 8000;
return 32000;
}
}]);
/**
* @file index.js
*
* Index module to easily import the primary components of AES-128
* decryption. Like this:
*
* ```js
* import {Decrypter, decrypt, AsyncStream} from 'aes-decrypter';
* ```
*/
return Decrypter;
}();
exports.decrypt = decrypt;
exports.Decrypter = Decrypter;
exports.AsyncStream = AsyncStream;
exports.AsyncStream = AsyncStream;
exports.Decrypter = Decrypter;
exports.decrypt = decrypt;
})));
Object.defineProperty(exports, '__esModule', { value: true });
}));

@@ -1,7 +0,5 @@

/**
* aes-decrypter
* @version 3.0.0
* @copyright 2017 Brightcove, Inc.
* @license Apache-2.0
*/
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(t.aesDecrypter=t.aesDecrypter||{})}(this,function(t){"use strict";function e(t){return t.subarray(0,t.byteLength-t[t.byteLength-1])}var n=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},i=function(){function t(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}return function(e,n,i){return n&&t(e.prototype,n),i&&t(e,i),e}}(),r=function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)},o=function(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e},s=function(){var t=[[[],[],[],[],[]],[[],[],[],[],[]]],e=t[0],n=t[1],i=e[4],r=n[4],o=void 0,s=void 0,u=void 0,c=[],f=[],l=void 0,a=void 0,h=void 0,p=void 0,y=void 0;for(o=0;o<256;o++)f[(c[o]=o<<1^283*(o>>7))^o]=o;for(s=u=0;!i[s];s^=l||1,u=f[u]||1)for(h=(h=u^u<<1^u<<2^u<<3^u<<4)>>8^255&h^99,i[s]=h,r[h]=s,y=16843009*c[a=c[l=c[s]]]^65537*a^257*l^16843008*s,p=257*c[h]^16843008*h,o=0;o<4;o++)e[o][s]=p=p<<24^p>>>8,n[o][h]=y=y<<24^y>>>8;for(o=0;o<5;o++)e[o]=e[o].slice(0),n[o]=n[o].slice(0);return t},u=null,c=function(){function t(e){n(this,t),u||(u=s()),this._tables=[[u[0][0].slice(),u[0][1].slice(),u[0][2].slice(),u[0][3].slice(),u[0][4].slice()],[u[1][0].slice(),u[1][1].slice(),u[1][2].slice(),u[1][3].slice(),u[1][4].slice()]];var i=void 0,r=void 0,o=void 0,c=void 0,f=void 0,l=this._tables[0][4],a=this._tables[1],h=e.length,p=1;if(4!==h&&6!==h&&8!==h)throw new Error("Invalid aes key size");for(c=e.slice(0),f=[],this._key=[c,f],i=h;i<4*h+28;i++)o=c[i-1],(i%h==0||8===h&&i%h==4)&&(o=l[o>>>24]<<24^l[o>>16&255]<<16^l[o>>8&255]<<8^l[255&o],i%h==0&&(o=o<<8^o>>>24^p<<24,p=p<<1^283*(p>>7))),c[i]=c[i-h]^o;for(r=0;i;r++,i--)o=c[3&r?i:i-4],f[r]=i<=4||r<4?o:a[0][l[o>>>24]]^a[1][l[o>>16&255]]^a[2][l[o>>8&255]]^a[3][l[255&o]]}return t.prototype.decrypt=function(t,e,n,i,r,o){var s=this._key[1],u=t^s[0],c=i^s[1],f=n^s[2],l=e^s[3],a=void 0,h=void 0,p=void 0,y=s.length/4-2,d=void 0,v=4,b=this._tables[1],_=b[0],g=b[1],m=b[2],w=b[3],j=b[4];for(d=0;d<y;d++)a=_[u>>>24]^g[c>>16&255]^m[f>>8&255]^w[255&l]^s[v],h=_[c>>>24]^g[f>>16&255]^m[l>>8&255]^w[255&u]^s[v+1],p=_[f>>>24]^g[l>>16&255]^m[u>>8&255]^w[255&c]^s[v+2],l=_[l>>>24]^g[u>>16&255]^m[c>>8&255]^w[255&f]^s[v+3],v+=4,u=a,c=h,f=p;for(d=0;d<4;d++)r[(3&-d)+o]=j[u>>>24]<<24^j[c>>16&255]<<16^j[f>>8&255]<<8^j[255&l]^s[v++],a=u,u=c,c=f,f=l,l=a},t}(),f=function(){function t(){n(this,t),this.listeners={}}return t.prototype.on=function(t,e){this.listeners[t]||(this.listeners[t]=[]),this.listeners[t].push(e)},t.prototype.off=function(t,e){if(!this.listeners[t])return!1;var n=this.listeners[t].indexOf(e);return this.listeners[t].splice(n,1),n>-1},t.prototype.trigger=function(t){var e=this.listeners[t];if(e)if(2===arguments.length)for(var n=e.length,i=0;i<n;++i)e[i].call(this,arguments[1]);else for(var r=Array.prototype.slice.call(arguments,1),o=e.length,s=0;s<o;++s)e[s].apply(this,r)},t.prototype.dispose=function(){this.listeners={}},t.prototype.pipe=function(t){this.on("data",function(e){t.push(e)})},t}(),l=function(t){function e(){n(this,e);var i=o(this,t.call(this,f));return i.jobs=[],i.delay=1,i.timeout_=null,i}return r(e,t),e.prototype.processJob_=function(){this.jobs.shift()(),this.jobs.length?this.timeout_=setTimeout(this.processJob_.bind(this),this.delay):this.timeout_=null},e.prototype.push=function(t){this.jobs.push(t),this.timeout_||(this.timeout_=setTimeout(this.processJob_.bind(this),this.delay))},e}(f);var a=function(t){return t<<24|(65280&t)<<8|(16711680&t)>>8|t>>>24},h=function(t,e,n){var i=new Int32Array(t.buffer,t.byteOffset,t.byteLength>>2),r=new c(Array.prototype.slice.call(e)),o=new Uint8Array(t.byteLength),s=new Int32Array(o.buffer),u=void 0,f=void 0,l=void 0,h=void 0,p=void 0,y=void 0,d=void 0,v=void 0,b=void 0;for(u=n[0],f=n[1],l=n[2],h=n[3],b=0;b<i.length;b+=4)p=a(i[b]),y=a(i[b+1]),d=a(i[b+2]),v=a(i[b+3]),r.decrypt(p,y,d,v,s,b),s[b]=a(s[b]^u),s[b+1]=a(s[b+1]^f),s[b+2]=a(s[b+2]^l),s[b+3]=a(s[b+3]^h),u=p,f=y,l=d,h=v;return o},p=function(){function t(i,r,o,s){n(this,t);var u=t.STEP,c=new Int32Array(i.buffer),f=new Uint8Array(i.byteLength),h=0;for(this.asyncStream_=new l,this.asyncStream_.push(this.decryptChunk_(c.subarray(h,h+u),r,o,f)),h=u;h<c.length;h+=u)o=new Uint32Array([a(c[h-4]),a(c[h-3]),a(c[h-2]),a(c[h-1])]),this.asyncStream_.push(this.decryptChunk_(c.subarray(h,h+u),r,o,f));this.asyncStream_.push(function(){s(null,e(f))})}return t.prototype.decryptChunk_=function(t,e,n,i){return function(){var r=h(t,e,n);i.set(r,t.byteOffset)}},i(t,null,[{key:"STEP",get:function(){return 32e3}}]),t}();t.decrypt=h,t.Decrypter=p,t.AsyncStream=l});
/*! @name aes-decrypter @version 3.0.1-0 @license Apache-2.0 */
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("global/window")):"function"==typeof define&&define.amd?define(["exports","global/window"],e):e((t=t||self).aesDecrypter={},t.window)}(this,function(t,e){"use strict";function r(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}e=e&&e.hasOwnProperty("default")?e.default:e;var n=function(t,e,n){return e&&r(t.prototype,e),n&&r(t,n),t},i=function(){var t,e,r,n,i,s,a,o,u=[[[],[],[],[],[]],[[],[],[],[],[]]],l=u[0],h=u[1],c=l[4],p=h[4],f=[],y=[];for(t=0;t<256;t++)y[(f[t]=t<<1^283*(t>>7))^t]=t;for(e=r=0;!c[e];e^=n||1,r=y[r]||1)for(s=(s=r^r<<1^r<<2^r<<3^r<<4)>>8^255&s^99,c[e]=s,p[s]=e,o=16843009*f[i=f[n=f[e]]]^65537*i^257*n^16843008*e,a=257*f[s]^16843008*s,t=0;t<4;t++)l[t][e]=a=a<<24^a>>>8,h[t][s]=o=o<<24^o>>>8;for(t=0;t<5;t++)l[t]=l[t].slice(0),h[t]=h[t].slice(0);return u},s=null,a=function(){function t(t){var e,r,n;s||(s=i()),this._tables=[[s[0][0].slice(),s[0][1].slice(),s[0][2].slice(),s[0][3].slice(),s[0][4].slice()],[s[1][0].slice(),s[1][1].slice(),s[1][2].slice(),s[1][3].slice(),s[1][4].slice()]];var a=this._tables[0][4],o=this._tables[1],u=t.length,l=1;if(4!==u&&6!==u&&8!==u)throw new Error("Invalid aes key size");var h=t.slice(0),c=[];for(this._key=[h,c],e=u;e<4*u+28;e++)n=h[e-1],(e%u==0||8===u&&e%u==4)&&(n=a[n>>>24]<<24^a[n>>16&255]<<16^a[n>>8&255]<<8^a[255&n],e%u==0&&(n=n<<8^n>>>24^l<<24,l=l<<1^283*(l>>7))),h[e]=h[e-u]^n;for(r=0;e;r++,e--)n=h[3&r?e:e-4],c[r]=e<=4||r<4?n:o[0][a[n>>>24]]^o[1][a[n>>16&255]]^o[2][a[n>>8&255]]^o[3][a[255&n]]}return t.prototype.decrypt=function(t,e,r,n,i,s){var a,o,u,l,h=this._key[1],c=t^h[0],p=n^h[1],f=r^h[2],y=e^h[3],m=h.length/4-2,b=4,d=this._tables[1],v=d[0],g=d[1],w=d[2],L=d[3],_=d[4];for(l=0;l<m;l++)a=v[c>>>24]^g[p>>16&255]^w[f>>8&255]^L[255&y]^h[b],o=v[p>>>24]^g[f>>16&255]^w[y>>8&255]^L[255&c]^h[b+1],u=v[f>>>24]^g[y>>16&255]^w[c>>8&255]^L[255&p]^h[b+2],y=v[y>>>24]^g[c>>16&255]^w[p>>8&255]^L[255&f]^h[b+3],b+=4,c=a,p=o,f=u;for(l=0;l<4;l++)i[(3&-l)+s]=_[c>>>24]<<24^_[p>>16&255]<<16^_[f>>8&255]<<8^_[255&y]^h[b++],a=c,c=p,p=f,f=y,y=a},t}();var o=function(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,t.__proto__=e};!function(t,e){t(e={exports:{}},e.exports)}(function(t,e){var r,n,i,s,a;r=/^((?:[a-zA-Z0-9+\-.]+:)?)(\/\/[^\/?#]*)?((?:[^\/\?#]*\/)*.*?)??(;.*?)?(\?.*?)?(#.*?)?$/,n=/^([^\/?#]*)(.*)$/,i=/(?:\/|^)\.(?=\/)/g,s=/(?:\/|^)\.\.\/(?!\.\.\/).*?(?=\/)/g,a={buildAbsoluteURL:function(t,e,r){if(r=r||{},t=t.trim(),!(e=e.trim())){if(!r.alwaysNormalize)return t;var i=a.parseURL(t);if(!i)throw new Error("Error trying to parse base URL.");return i.path=a.normalizePath(i.path),a.buildURLFromParts(i)}var s=a.parseURL(e);if(!s)throw new Error("Error trying to parse relative URL.");if(s.scheme)return r.alwaysNormalize?(s.path=a.normalizePath(s.path),a.buildURLFromParts(s)):e;var o=a.parseURL(t);if(!o)throw new Error("Error trying to parse base URL.");if(!o.netLoc&&o.path&&"/"!==o.path[0]){var u=n.exec(o.path);o.netLoc=u[1],o.path=u[2]}o.netLoc&&!o.path&&(o.path="/");var l={scheme:o.scheme,netLoc:s.netLoc,path:null,params:s.params,query:s.query,fragment:s.fragment};if(!s.netLoc&&(l.netLoc=o.netLoc,"/"!==s.path[0]))if(s.path){var h=o.path,c=h.substring(0,h.lastIndexOf("/")+1)+s.path;l.path=a.normalizePath(c)}else l.path=o.path,s.params||(l.params=o.params,s.query||(l.query=o.query));return null===l.path&&(l.path=r.alwaysNormalize?a.normalizePath(s.path):s.path),a.buildURLFromParts(l)},parseURL:function(t){var e=r.exec(t);return e?{scheme:e[1]||"",netLoc:e[2]||"",path:e[3]||"",params:e[4]||"",query:e[5]||"",fragment:e[6]||""}:null},normalizePath:function(t){for(t=t.split("").reverse().join("").replace(i,"");t.length!==(t=t.replace(s,"")).length;);return t.split("").reverse().join("")},buildURLFromParts:function(t){return t.scheme+t.netLoc+t.path+t.params+t.query+t.fragment}},t.exports=a});
/*! @name @videojs/vhs-utils @version 0.0.0 @license MIT */var u=function(){function t(){this.listeners={}}var e=t.prototype;return e.on=function(t,e){this.listeners[t]||(this.listeners[t]=[]),this.listeners[t].push(e)},e.off=function(t,e){if(!this.listeners[t])return!1;var r=this.listeners[t].indexOf(e);return this.listeners[t]=this.listeners[t].slice(0),this.listeners[t].splice(r,1),r>-1},e.trigger=function(t){var e=this.listeners[t];if(e)if(2===arguments.length)for(var r=e.length,n=0;n<r;++n)e[n].call(this,arguments[1]);else for(var i=Array.prototype.slice.call(arguments,1),s=e.length,a=0;a<s;++a)e[a].apply(this,i)},e.dispose=function(){this.listeners={}},e.pipe=function(t){this.on("data",function(e){t.push(e)})},t}(),l=function(t){function e(){var e;return(e=t.call(this,u)||this).jobs=[],e.delay=1,e.timeout_=null,e}o(e,t);var r=e.prototype;return r.processJob_=function(){this.jobs.shift()(),this.jobs.length?this.timeout_=setTimeout(this.processJob_.bind(this),this.delay):this.timeout_=null},r.push=function(t){this.jobs.push(t),this.timeout_||(this.timeout_=setTimeout(this.processJob_.bind(this),this.delay))},e}(u);var h=function(t){return t<<24|(65280&t)<<8|(16711680&t)>>8|t>>>24},c=function(t,e,r){var n,i,s,o,u,l,c,p,f,y=new Int32Array(t.buffer,t.byteOffset,t.byteLength>>2),m=new a(Array.prototype.slice.call(e)),b=new Uint8Array(t.byteLength),d=new Int32Array(b.buffer);for(n=r[0],i=r[1],s=r[2],o=r[3],f=0;f<y.length;f+=4)u=h(y[f]),l=h(y[f+1]),c=h(y[f+2]),p=h(y[f+3]),m.decrypt(u,l,c,p,d,f),d[f]=h(d[f]^n),d[f+1]=h(d[f+1]^i),d[f+2]=h(d[f+2]^s),d[f+3]=h(d[f+3]^o),n=u,i=l,s=c,o=p;return b},p=function(){function t(e,r,n,i){var s=t.STEP,a=new Int32Array(e.buffer),o=new Uint8Array(e.byteLength),u=0;for(this.asyncStream_=new l,this.asyncStream_.push(this.decryptChunk_(a.subarray(u,u+s),r,n,o)),u=s;u<a.length;u+=s)n=new Uint32Array([h(a[u-4]),h(a[u-3]),h(a[u-2]),h(a[u-1])]),this.asyncStream_.push(this.decryptChunk_(a.subarray(u,u+s),r,n,o));this.asyncStream_.push(function(){
/*! @name pkcs7 @version 1.0.3-1 @license Apache-2.0 */
var t;i(null,(t=o).subarray(0,t.byteLength-t[t.byteLength-1]))})}return t.prototype.decryptChunk_=function(t,e,r,n){return function(){var i=c(t,e,r);n.set(i,t.byteOffset)}},n(t,null,[{key:"STEP",get:function(){return 32e3}}]),t}();t.AsyncStream=l,t.Decrypter=p,t.decrypt=c,Object.defineProperty(t,"__esModule",{value:!0})});
{
"name": "aes-decrypter",
"version": "3.0.0",
"version": "3.0.1-0",
"description": "decrypt aes-128 content using a key",

@@ -14,43 +14,21 @@ "main": "dist/aes-decrypter.cjs.js",

"scripts": {
"prebuild": "npm run clean",
"build": "npm-run-all -p build:*",
"build:js": "npm-run-all build:js:rollup-modules build:js:rollup-umd build:js:bannerize build:js:uglify",
"build:js:babel": "babel src -d es5",
"build:js:bannerize": "bannerize dist/aes-decrypter.js --banner=scripts/banner.ejs",
"build:js:browserify": "browserify . -s aes-decrypter -o dist/aes-decrypter.js",
"build:js:rollup-modules": "rollup -c scripts/modules.rollup.config.js",
"build:js:rollup-umd": "rollup -c scripts/umd.rollup.config.js",
"build:js:uglify": "uglifyjs dist/aes-decrypter.js --comments --mangle --compress -o dist/aes-decrypter.min.js",
"build:test": "rollup -c scripts/test.rollup.config.js",
"change": "chg add",
"clean": "rimraf dist test/dist",
"postclean": "mkdirp dist test/dist",
"assets": "babel-node scripts/assets.js",
"docs": "npm-run-all docs:*",
"docs:api": "jsdoc src -r -d docs/api",
"docs:toc": "doctoc README.md",
"build-test": "cross-env-shell TEST_BUNDLE_ONLY=1 'npm run build'",
"build-prod": "cross-env-shell NO_TEST_BUNDLE=1 'npm run build'",
"build": "npm-run-all -s clean -p build:*",
"build:js": "rollup -c scripts/rollup.config.js",
"clean": "shx rm -rf ./dist ./test/dist && shx mkdir -p ./dist ./test/dist",
"lint": "vjsstandard",
"prestart": "npm run build",
"start": "npm-run-all -p start:server watch",
"start:server": "static -a 0.0.0.0 -p 9999 -H '{\"Cache-Control\": \"no-cache, must-revalidate\"}' .",
"pretest": "npm-run-all lint build",
"test": "karma start test/karma.conf.js",
"test:chrome": "npm run pretest && karma start test/karma.conf.js --browsers Chrome",
"test:firefox": "npm run pretest && karma start test/karma.conf.js --browsers Firefox",
"test:ie": "npm run pretest && karma start test/karma.conf.js --browsers IE",
"test:safari": "npm run pretest && karma start test/karma.conf.js --browsers Safari",
"prepublishOnly": "npm-run-all build-prod && vjsverify --verbose",
"start": "npm-run-all -p server watch",
"server": "karma start scripts/karma.conf.js --singleRun=false --auto-watch",
"test": "npm-run-all lint build-test && karma start scripts/karma.conf.js",
"posttest": "shx cat test/dist/coverage/text.txt",
"preversion": "npm test",
"version": "node scripts/version.js",
"version": "is-prerelease || npm run update-changelog && git add CHANGELOG.md",
"update-changelog": "conventional-changelog -p videojs -i CHANGELOG.md -s",
"watch": "npm-run-all -p watch:*",
"watch:js-modules": "rollup -c scripts/modules.rollup.config.js -w",
"watch:js-umd": "rollup -c scripts/umd.rollup.config.js -w",
"watch:test": "rollup -c scripts/test.rollup.config.js -w",
"prepublish": "npm run build"
"watch:js": "npm run build:js -- -w"
},
"author": "Brightcove, Inc.",
"license": "Apache-2.0",
"browserify-shim": {
"qunit": "global:QUnit",
"sinon": "global:sinon"
},
"vjsstandard": {

@@ -60,6 +38,3 @@ "ignore": [

"docs",
"test/dist",
"test/karma.conf.js",
"scripts",
"src/aes.js"
"test/dist"
]

@@ -77,53 +52,21 @@ },

"dependencies": {
"commander": "^2.9.0",
"@babel/runtime": "^7.5.5",
"@videojs/vhs-utils": "github:videojs/vhs-utils#force-dist",
"global": "^4.3.2",
"pkcs7": "^1.0.2"
"pkcs7": "^1.0.3-1"
},
"devDependencies": {
"babel-cli": "^6.24.1",
"babel-plugin-external-helpers": "^6.22.0",
"babel-plugin-transform-object-assign": "^6.8.0",
"babel-preset-es2015": "^6.14.0",
"babel-preset-es3": "^1.0.1",
"babelify": "^7.3.0",
"bannerize": "^1.0.2",
"bluebird": "^3.2.2",
"browserify": "^12.0.2",
"browserify-shim": "^3.8.12",
"budo": "^8.0.4",
"chg": "^0.3.2",
"cli-table": "^0.3.1",
"conventional-changelog-cli": "^1.3.1",
"conventional-changelog-videojs": "^3.0.0",
"doctoc": "^0.15.0",
"filesize": "^3.5.10",
"glob": "^6.0.3",
"jsdoc": "^3.4.0",
"karma": "^1.7.0",
"karma-chrome-launcher": "^2.1.1",
"karma-detect-browsers": "^2.2.5",
"karma-firefox-launcher": "^1.0.1",
"karma-ie-launcher": "^1.0.0",
"karma-qunit": "^1.2.1",
"karma-safari-launcher": "^1.0.0",
"klaw-sync": "^2.1.0",
"mkdirp": "^0.5.1",
"node-static": "^0.7.9",
"npm-run-all": "^4.0.2",
"qunitjs": "^2.3.2",
"rimraf": "^2.6.1",
"rollup": "^0.41.6",
"rollup-plugin-babel": "^2.7.1",
"rollup-plugin-commonjs": "^8.0.2",
"rollup-plugin-json": "^2.1.1",
"rollup-plugin-multi-entry": "^2.0.1",
"rollup-plugin-node-resolve": "^3.0.0",
"rollup-watch": "^3.2.2",
"semver": "^5.3.0",
"sinon": "^2.2.0",
"uglify-js": "^3.0.7",
"videojs-standard": "^6.0.0"
"rollup": "^1.19.4",
"@videojs/generator-helpers": "~1.2.0",
"karma": "^4.0.0",
"postcss-cli": "^6.0.0",
"sinon": "^7.2.2",
"videojs-generate-karma-config": "~5.3.0",
"videojs-generator-verify": "~1.2.0",
"videojs-generate-rollup-config": "~5.0.1",
"videojs-languages": "^2.0.0",
"videojs-standard": "^8.0.3"
},
"generator-videojs-plugin": {
"version": "5.0.0"
"version": "7.7.0"
},

@@ -140,3 +83,26 @@ "directories": {

},
"homepage": "https://github.com/videojs/aes-decrypter#readme"
"homepage": "https://github.com/videojs/aes-decrypter#readme",
"browserslist": [
"defaults",
"ie 11"
],
"keywords": [
"videojs",
"videojs-plugin"
],
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"*.js": [
"vjsstandard --fix",
"git add"
],
"README.md": [
"doctoc --notitle",
"git add"
]
}
}

@@ -1,9 +0,18 @@

# decrypter
# aes-decrypter
[![Build Status](https://travis-ci.org/videojs/aes-decrypter.svg?branch=master)](https://travis-ci.org/videojs/aes-decrypter)
[![Greenkeeper badge](https://badges.greenkeeper.io/videojs/aes-decrypter.svg)](https://greenkeeper.io/)
[![Slack Status](http://slack.videojs.com/badge.svg)](http://slack.videojs.com)
[![NPM](https://nodei.co/npm/aes-decrypter.png?downloads=true&downloadRank=true)](https://nodei.co/npm/aes-decrypter/)
## Table of Contents
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
<!-- START doctoc -->
<!-- END doctoc -->
- [Installation](#installation)
- [Usage](#usage)
- [License](#license)
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
## Installation

@@ -10,0 +19,0 @@

@@ -46,12 +46,12 @@ /**

const precompute = function() {
let tables = [[[], [], [], [], []], [[], [], [], [], []]];
let encTable = tables[0];
let decTable = tables[1];
let sbox = encTable[4];
let sboxInv = decTable[4];
const tables = [[[], [], [], [], []], [[], [], [], [], []]];
const encTable = tables[0];
const decTable = tables[1];
const sbox = encTable[4];
const sboxInv = decTable[4];
let i;
let x;
let xInv;
let d = [];
let th = [];
const d = [];
const th = [];
let x2;

@@ -105,3 +105,3 @@ let x4;

constructor(key) {
/**
/**
* The expanded S-box and inverse S-box tables. These will be computed

@@ -125,19 +125,17 @@ * on the client so that we don't have to send them down the wire.

this._tables = [[aesTables[0][0].slice(),
aesTables[0][1].slice(),
aesTables[0][2].slice(),
aesTables[0][3].slice(),
aesTables[0][4].slice()],
[aesTables[1][0].slice(),
aesTables[1][1].slice(),
aesTables[1][2].slice(),
aesTables[1][3].slice(),
aesTables[1][4].slice()]];
aesTables[0][1].slice(),
aesTables[0][2].slice(),
aesTables[0][3].slice(),
aesTables[0][4].slice()],
[aesTables[1][0].slice(),
aesTables[1][1].slice(),
aesTables[1][2].slice(),
aesTables[1][3].slice(),
aesTables[1][4].slice()]];
let i;
let j;
let tmp;
let encKey;
let decKey;
let sbox = this._tables[0][4];
let decTable = this._tables[1];
let keyLen = key.length;
const sbox = this._tables[0][4];
const decTable = this._tables[1];
const keyLen = key.length;
let rcon = 1;

@@ -149,4 +147,5 @@

encKey = key.slice(0);
decKey = [];
const encKey = key.slice(0);
const decKey = [];
this._key = [encKey, decKey];

@@ -192,9 +191,9 @@

*
* @param {Number} encrypted0 the first word to decrypt
* @param {Number} encrypted1 the second word to decrypt
* @param {Number} encrypted2 the third word to decrypt
* @param {Number} encrypted3 the fourth word to decrypt
* @param {number} encrypted0 the first word to decrypt
* @param {number} encrypted1 the second word to decrypt
* @param {number} encrypted2 the third word to decrypt
* @param {number} encrypted3 the fourth word to decrypt
* @param {Int32Array} out the array to write the decrypted words
* into
* @param {Number} offset the offset into the output array to start
* @param {number} offset the offset into the output array to start
* writing results

@@ -204,3 +203,3 @@ * @return {Array} The plaintext.

decrypt(encrypted0, encrypted1, encrypted2, encrypted3, out, offset) {
let key = this._key[1];
const key = this._key[1];
// state variables a,b,c,d are loaded with pre-whitened data

@@ -216,13 +215,13 @@ let a = encrypted0 ^ key[0];

// key.length === 2 ?
let nInnerRounds = key.length / 4 - 2;
const nInnerRounds = key.length / 4 - 2;
let i;
let kIndex = 4;
let table = this._tables[1];
const table = this._tables[1];
// load up the tables
let table0 = table[0];
let table1 = table[1];
let table2 = table[2];
let table3 = table[3];
let sbox = table[4];
const table0 = table[0];
const table1 = table[1];
const table2 = table[2];
const table3 = table[3];
const sbox = table[4];

@@ -229,0 +228,0 @@ // Inner rounds. Cribbed from OpenSSL.

/**
* @file async-stream.js
*/
import Stream from './stream';
import {Stream} from '@videojs/vhs-utils';
/**
* A wrapper around the Stream class to use setTiemout
* A wrapper around the Stream class to use setTimeout
* and run stream "jobs" Asynchronously

@@ -29,4 +29,6 @@ *

if (this.jobs.length) {
this.timeout_ = setTimeout(this.processJob_.bind(this),
this.delay);
this.timeout_ = setTimeout(
this.processJob_.bind(this),
this.delay
);
} else {

@@ -45,4 +47,6 @@ this.timeout_ = null;

if (!this.timeout_) {
this.timeout_ = setTimeout(this.processJob_.bind(this),
this.delay);
this.timeout_ = setTimeout(
this.processJob_.bind(this),
this.delay
);
}

@@ -49,0 +53,0 @@ }

@@ -38,5 +38,7 @@ /**

// word-level access to the encrypted bytes
const encrypted32 = new Int32Array(encrypted.buffer,
encrypted.byteOffset,
encrypted.byteLength >> 2);
const encrypted32 = new Int32Array(
encrypted.buffer,
encrypted.byteOffset,
encrypted.byteLength >> 2
);

@@ -81,8 +83,10 @@ const decipher = new AES(Array.prototype.slice.call(key));

// decrypt the block
decipher.decrypt(encrypted0,
encrypted1,
encrypted2,
encrypted3,
decrypted32,
wordIx);
decipher.decrypt(
encrypted0,
encrypted1,
encrypted2,
encrypted3,
decrypted32,
wordIx
);

@@ -127,15 +131,19 @@ // XOR with the IV, and restore network byte-order to obtain the

// split up the encryption job and do the individual chunks asynchronously
this.asyncStream_.push(this.decryptChunk_(encrypted32.subarray(i, i + step),
key,
initVector,
decrypted));
this.asyncStream_.push(this.decryptChunk_(
encrypted32.subarray(i, i + step),
key,
initVector,
decrypted
));
for (i = step; i < encrypted32.length; i += step) {
initVector = new Uint32Array([ntoh(encrypted32[i - 4]),
ntoh(encrypted32[i - 3]),
ntoh(encrypted32[i - 2]),
ntoh(encrypted32[i - 1])]);
this.asyncStream_.push(this.decryptChunk_(encrypted32.subarray(i, i + step),
key,
initVector,
decrypted));
ntoh(encrypted32[i - 3]),
ntoh(encrypted32[i - 2]),
ntoh(encrypted32[i - 1])]);
this.asyncStream_.push(this.decryptChunk_(
encrypted32.subarray(i, i + step),
key,
initVector,
decrypted
));
}

@@ -152,3 +160,3 @@ // invoke the done() callback when everything is finished

*
* @return {Number} the value of step 32000
* @return {number} the value of step 32000
*/

@@ -155,0 +163,0 @@ static get STEP() {

@@ -29,5 +29,6 @@ // see docs/hlse.md for instructions on how test data was generated

assert.deepEqual('howdy folks',
stringFromBytes(unpad(decrypt(encrypted, key, initVector))),
'decrypted with a byte array key'
assert.deepEqual(
'howdy folks',
stringFromBytes(unpad(decrypt(encrypted, key, initVector))),
'decrypted with a byte array key'
);

@@ -52,43 +53,49 @@ });

assert.deepEqual('0123456789abcdef01234',
stringFromBytes(unpad(decrypt(encrypted, key, initVector))),
'decrypted multiple blocks');
assert.deepEqual(
'0123456789abcdef01234',
stringFromBytes(unpad(decrypt(encrypted, key, initVector))),
'decrypted multiple blocks'
);
});
QUnit.test(
'verify that the deepcopy works by doing two decrypts in the same test',
function(assert) {
const key = new Uint32Array([0, 0, 0, 0]);
const initVector = key;
// the string "howdy folks" encrypted
const pkcs7Block = new Uint8Array([
0xce, 0x90, 0x97, 0xd0,
0x08, 0x46, 0x4d, 0x18,
0x4f, 0xae, 0x01, 0x1c,
0x82, 0xa8, 0xf0, 0x67
]);
'verify that the deepcopy works by doing two decrypts in the same test',
function(assert) {
const key = new Uint32Array([0, 0, 0, 0]);
const initVector = key;
// the string "howdy folks" encrypted
const pkcs7Block = new Uint8Array([
0xce, 0x90, 0x97, 0xd0,
0x08, 0x46, 0x4d, 0x18,
0x4f, 0xae, 0x01, 0x1c,
0x82, 0xa8, 0xf0, 0x67
]);
assert.deepEqual('howdy folks',
stringFromBytes(unpad(decrypt(pkcs7Block, key, initVector))),
'decrypted with a byte array key'
);
assert.deepEqual(
'howdy folks',
stringFromBytes(unpad(decrypt(pkcs7Block, key, initVector))),
'decrypted with a byte array key'
);
// the string "0123456789abcdef01234" encrypted
const cbcBlocks = new Uint8Array([
0x14, 0xf5, 0xfe, 0x74,
0x69, 0x66, 0xf2, 0x92,
0x65, 0x1c, 0x22, 0x88,
0xbb, 0xff, 0x46, 0x09,
// the string "0123456789abcdef01234" encrypted
const cbcBlocks = new Uint8Array([
0x14, 0xf5, 0xfe, 0x74,
0x69, 0x66, 0xf2, 0x92,
0x65, 0x1c, 0x22, 0x88,
0xbb, 0xff, 0x46, 0x09,
0x0b, 0xde, 0x5e, 0x71,
0x77, 0x87, 0xeb, 0x84,
0xa9, 0x54, 0xc2, 0x45,
0xe9, 0x4e, 0x29, 0xb3
]);
0x0b, 0xde, 0x5e, 0x71,
0x77, 0x87, 0xeb, 0x84,
0xa9, 0x54, 0xc2, 0x45,
0xe9, 0x4e, 0x29, 0xb3
]);
assert.deepEqual('0123456789abcdef01234',
stringFromBytes(unpad(decrypt(cbcBlocks, key, initVector))),
'decrypted multiple blocks');
assert.deepEqual(
'0123456789abcdef01234',
stringFromBytes(unpad(decrypt(cbcBlocks, key, initVector))),
'decrypted multiple blocks'
);
});
}
);

@@ -149,15 +156,17 @@ QUnit.module('Incremental Processing', {

const encrypted = new Uint8Array([0xce, 0x90, 0x97, 0xd0,
0x08, 0x46, 0x4d, 0x18,
0x4f, 0xae, 0x01, 0x1c,
0x82, 0xa8, 0xf0, 0x67]);
0x08, 0x46, 0x4d, 0x18,
0x4f, 0xae, 0x01, 0x1c,
0x82, 0xa8, 0xf0, 0x67]);
let decrypted;
const decrypter = new Decrypter(encrypted,
key,
initVector,
function(error, result) {
if (error) {
throw new Error(error);
}
decrypted = result;
});
const decrypter = new Decrypter(
encrypted,
key,
initVector,
function(error, result) {
if (error) {
throw new Error(error);
}
decrypted = result;
}
);

@@ -168,5 +177,7 @@ assert.ok(!decrypted, 'asynchronously decrypts');

assert.ok(decrypted, 'completed decryption');
assert.deepEqual('howdy folks',
stringFromBytes(decrypted),
'decrypts and unpads the result');
assert.deepEqual(
'howdy folks',
stringFromBytes(decrypted),
'decrypts and unpads the result'
);
});

@@ -177,8 +188,10 @@

let done = false;
const decrypter = new Decrypter(encrypted,
new Uint32Array(4),
new Uint32Array(4),
function() {
done = true;
});
const decrypter = new Decrypter(
encrypted,
new Uint32Array(4),
new Uint32Array(4),
function() {
done = true;
}
);

@@ -185,0 +198,0 @@ this.clock.tick(decrypter.asyncStream_.delay * 2);

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc