browserify-aes
Advanced tools
Comparing version 1.0.8 to 1.1.0
@@ -7,2 +7,3 @@ var aes = require('./aes') | ||
var xor = require('buffer-xor') | ||
var incr32 = require('./incr32') | ||
@@ -21,9 +22,35 @@ function xorTest (a, b) { | ||
function calcIv (self, iv, ck) { | ||
if (iv.length === 12) { | ||
self._finID = Buffer.concat([iv, Buffer.from([0, 0, 0, 1])]) | ||
return Buffer.concat([iv, Buffer.from([0, 0, 0, 2])]) | ||
} | ||
var ghash = new GHASH(ck) | ||
var len = iv.length | ||
var toPad = len % 16 | ||
ghash.update(iv) | ||
if (toPad) { | ||
toPad = 16 - toPad | ||
ghash.update(Buffer.alloc(toPad, 0)) | ||
} | ||
ghash.update(Buffer.alloc(8, 0)) | ||
var ivBits = len * 8 | ||
var tail = Buffer.alloc(8) | ||
tail.writeUIntBE(ivBits, 0, 8) | ||
ghash.update(tail) | ||
self._finID = ghash.state | ||
var out = Buffer.from(self._finID) | ||
incr32(out) | ||
return out | ||
} | ||
function StreamCipher (mode, key, iv, decrypt) { | ||
Transform.call(this) | ||
this._finID = Buffer.concat([iv, Buffer.from([0, 0, 0, 1])]) | ||
iv = Buffer.concat([iv, Buffer.from([0, 0, 0, 2])]) | ||
var h = Buffer.alloc(4, 0) | ||
this._cipher = new aes.AES(key) | ||
var ck = this._cipher.encryptBlock(h) | ||
this._ghash = new GHASH(ck) | ||
iv = calcIv(this, iv, ck) | ||
this._prev = Buffer.from(iv) | ||
@@ -37,4 +64,2 @@ this._cache = Buffer.allocUnsafe(0) | ||
var h = Buffer.alloc(4, 0) | ||
this._ghash = new GHASH(this._cipher.encryptBlock(h)) | ||
this._authTag = null | ||
@@ -41,0 +66,0 @@ this._called = false |
@@ -98,3 +98,3 @@ var AuthCipher = require('./authCipher') | ||
if (typeof iv === 'string') iv = Buffer.from(iv) | ||
if (iv.length !== config.iv) throw new TypeError('invalid iv length ' + iv.length) | ||
if (config.mode !== 'GCM' && iv.length !== config.iv) throw new TypeError('invalid iv length ' + iv.length) | ||
@@ -101,0 +101,0 @@ if (typeof password === 'string') password = Buffer.from(password) |
@@ -94,3 +94,3 @@ var MODES = require('./modes') | ||
if (typeof iv === 'string') iv = Buffer.from(iv) | ||
if (iv.length !== config.iv) throw new TypeError('invalid iv length ' + iv.length) | ||
if (config.mode !== 'GCM' && iv.length !== config.iv) throw new TypeError('invalid iv length ' + iv.length) | ||
@@ -97,0 +97,0 @@ if (config.type === 'stream') { |
var xor = require('buffer-xor') | ||
function incr32 (iv) { | ||
var len = iv.length | ||
var item | ||
while (len--) { | ||
item = iv.readUInt8(len) | ||
if (item === 255) { | ||
iv.writeUInt8(0, len) | ||
} else { | ||
item++ | ||
iv.writeUInt8(item, len) | ||
break | ||
} | ||
} | ||
} | ||
var incr32 = require('../incr32') | ||
@@ -18,0 +5,0 @@ function getBlock (self) { |
{ | ||
"name": "browserify-aes", | ||
"version": "1.0.8", | ||
"version": "1.1.0", | ||
"description": "aes, for browserify", | ||
@@ -5,0 +5,0 @@ "browser": "browser.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
29596
953