@ronomon/crypto-async
Advanced tools
Comparing version 2.3.0 to 3.0.0
@@ -153,3 +153,6 @@ var crypto = require('crypto'); | ||
} | ||
var hmac = crypto.createHmac(algorithm, key.slice(keyOffset, keyOffset + keySize)); | ||
var hmac = crypto.createHmac( | ||
algorithm, | ||
key.slice(keyOffset, keyOffset + keySize) | ||
); | ||
hmac.update(source.slice(sourceOffset, sourceOffset + sourceSize)); | ||
@@ -165,3 +168,3 @@ var targetSize = hmac.digest().copy(target, targetOffset); | ||
function copyBuffer(buffer) { | ||
var copy = new Buffer(buffer.length); | ||
var copy = Buffer.alloc(buffer.length); | ||
buffer.copy(copy, 0); | ||
@@ -171,7 +174,15 @@ return copy; | ||
function randomBuffer(size) { | ||
var buffer = new Buffer(size); | ||
buffer.fill(Math.floor(random() * 256)); | ||
return buffer; | ||
} | ||
var randomBuffer = (function() { | ||
var key = Buffer.alloc(32, 1); | ||
var iv = Buffer.alloc(16, 2); | ||
var cipher = crypto.createCipheriv('AES-256-CTR', key, iv); | ||
var buffer = Buffer.alloc(1024 * 1024); | ||
return function(size) { | ||
if (size <= buffer.length) { | ||
return cipher.update(buffer.slice(0, size)); | ||
} else { | ||
return cipher.update(Buffer.alloc(size)); | ||
} | ||
}; | ||
})(); | ||
@@ -236,3 +247,5 @@ function randomSize() { | ||
self.target = randomBuffer(targetLength); | ||
self.targetOffset = Math.floor(random() * (targetLength - sourceLength - 128)); | ||
self.targetOffset = Math.floor( | ||
random() * (targetLength - sourceLength - 128) | ||
); | ||
} | ||
@@ -290,5 +303,9 @@ }; | ||
self.sourceOffset = Math.floor(random() * sourceLength); | ||
self.sourceSize = Math.floor(random() * (sourceLength - self.sourceOffset)); | ||
self.sourceSize = Math.floor( | ||
random() * (sourceLength - self.sourceOffset) | ||
); | ||
self.target = randomBuffer(targetLength); | ||
self.targetOffset = Math.floor(random() * (targetLength - algorithm.targetSize)); | ||
self.targetOffset = Math.floor( | ||
random() * (targetLength - algorithm.targetSize) | ||
); | ||
} | ||
@@ -349,3 +366,5 @@ }; | ||
self.target = randomBuffer(targetLength); | ||
self.targetOffset = Math.floor(random() * (targetLength - algorithm.targetSize)); | ||
self.targetOffset = Math.floor( | ||
random() * (targetLength - algorithm.targetSize) | ||
); | ||
} | ||
@@ -352,0 +371,0 @@ }; |
{ | ||
"name": "@ronomon/crypto-async", | ||
"version": "2.3.0", | ||
"version": "3.0.0", | ||
"description": "Asynchronous cipher, hash, hmac", | ||
@@ -39,5 +39,8 @@ "main": "index.js", | ||
"@ronomon/queue": "^3.0.0", | ||
"nan": "^2.8.0" | ||
"nan": "^2.11.0" | ||
}, | ||
"engines": { | ||
"node": ">=10.0.0" | ||
}, | ||
"gypfile": true | ||
} |
@@ -194,3 +194,3 @@ var common = require('./common.js'); | ||
if (error) return end(error); | ||
var temp = new Buffer(vector.sourceSize + 128); | ||
var temp = Buffer.alloc(vector.sourceSize + 128); | ||
binding.cipher( | ||
@@ -311,3 +311,5 @@ vector.algorithm, | ||
if (error) throw error; | ||
console.log('PASSED ALL TESTS\r\n'); | ||
console.log(new Array(16 + 1).join('=')); | ||
console.log('PASSED ALL TESTS'); | ||
console.log(new Array(16 + 1).join('=')); | ||
}; | ||
@@ -314,0 +316,0 @@ var tests = []; |
Sorry, the diff of this file is not supported yet
56127
937
Updatednan@^2.11.0