From b7847c072a6a21850213204690f430b91438c208 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Obernd=C3=B6rfer?= Date: Fri, 25 Apr 2014 16:35:43 +0200 Subject: [PATCH] Fix twofish cipher: did not accept typed arrays. --- src/crypto/cipher/twofish.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/crypto/cipher/twofish.js b/src/crypto/cipher/twofish.js index d744d11d..7ff3bb5f 100644 --- a/src/crypto/cipher/twofish.js +++ b/src/crypto/cipher/twofish.js @@ -337,7 +337,7 @@ var util = require('../../util.js'); // added by Recurity Labs function TFencrypt(block, key) { - var block_copy = [].concat(block); + var block_copy = toArray(block); var tf = createTwofish(); tf.open(util.str2bin(key), 0); var result = tf.encrypt(block_copy, 0); @@ -350,10 +350,19 @@ function TF(key) { this.tf.open(util.str2bin(key), 0); this.encrypt = function(block) { - return this.tf.encrypt([].concat(block), 0); + return this.tf.encrypt(toArray(block), 0); }; } +function toArray(typedArray) { + // Array.apply([], typedArray) does not work in PhantomJS 1.9 + var result = []; + for (var i = 0; i < typedArray.length; i++) { + result[i] = typedArray[i]; + } + return result; +} + module.exports = TF; module.exports.keySize = TF.prototype.keySize = 32;