From 627a6ef46e1f9e8b9243d65019257b5158c85a99 Mon Sep 17 00:00:00 2001 From: Daniel Huigens Date: Mon, 9 Apr 2018 16:06:11 +0200 Subject: [PATCH] Only calculate AES key schedules once in cipher/aes.js --- src/crypto/cipher/aes.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/crypto/cipher/aes.js b/src/crypto/cipher/aes.js index dcd2bd03..8749a718 100644 --- a/src/crypto/cipher/aes.js +++ b/src/crypto/cipher/aes.js @@ -2,19 +2,20 @@ * @requires asmcrypto.js */ -import { AES_ECB } from 'asmcrypto.js/src/aes/ecb/exports'; +import { _AES_asm_instance, _AES_heap_instance } from 'asmcrypto.js/src/aes/exports'; +import { AES_ECB } from 'asmcrypto.js/src/aes/ecb/ecb'; // TODO use webCrypto or nodeCrypto when possible. function aes(length) { const c = function(key) { - this.key = key; + const aes_ecb = new AES_ECB(key, _AES_heap_instance, _AES_asm_instance); this.encrypt = function(block) { - return AES_ECB.encrypt(block, this.key, false); + return aes_ecb.encrypt(block).result; }; this.decrypt = function(block) { - return AES_ECB.decrypt(block, this.key, false); + return aes_ecb.decrypt(block).result; }; };