diff --git a/src/aes/ecb.ts b/src/aes/ecb.ts deleted file mode 100644 index 6fa6719..0000000 --- a/src/aes/ecb.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { AES } from './aes.js'; -import { joinBytes } from '../other/utils.js'; - -export class AES_ECB { - private aes: AES; - static encrypt(data: Uint8Array, key: Uint8Array, padding: boolean = false): Uint8Array { - return new AES_ECB(key, padding).encrypt(data); - } - - static decrypt(data: Uint8Array, key: Uint8Array, padding: boolean = false): Uint8Array { - return new AES_ECB(key, padding).decrypt(data); - } - - constructor(key: Uint8Array, padding: boolean = false, aes?: AES) { - this.aes = aes ? aes : new AES(key, undefined, padding, 'ECB'); - } - - encrypt(data: Uint8Array): Uint8Array { - const r1 = this.aes.AES_Encrypt_process(data); - const r2 = this.aes.AES_Encrypt_finish(); - - return joinBytes(r1, r2); - } - - decrypt(data: Uint8Array): Uint8Array { - const r1 = this.aes.AES_Decrypt_process(data); - const r2 = this.aes.AES_Decrypt_finish(); - - return joinBytes(r1, r2); - } -} diff --git a/test/aes.js b/test/aes.js index 8cc81c1..0d69ca6 100644 --- a/test/aes.js +++ b/test/aes.js @@ -1,4 +1,3 @@ -import { AES_ECB } from '@openpgp/asmcrypto.js/aes/ecb.js'; import { AES_CBC } from '@openpgp/asmcrypto.js/aes/cbc.js'; import { AES_CFB } from '@openpgp/asmcrypto.js/aes/cfb.js'; import { AES_GCM } from '@openpgp/asmcrypto.js/aes/gcm.js'; @@ -12,77 +11,6 @@ function base64_to_bytes(str) { } describe('AES', () => { - describe('ECB', () => { - const ecb_aes_vectors = [ - // AES-ECB-128 - [ - '2b7e151628aed2a6abf7158809cf4f3c', // key - '6bc1bee22e409f96e93d7e117393172a', // clear text - '3ad77bb40d7a3660a89ecaf32466ef97', // cipher text - ], - [ - '2b7e151628aed2a6abf7158809cf4f3c', // key - 'ae2d8a571e03ac9c9eb76fac45af8e51', // clear text - 'f5d3d58503b9699de785895a96fdbaaf', // cipher text - ], - [ - '2b7e151628aed2a6abf7158809cf4f3c', // key - '30c81c46a35ce411e5fbc1191a0a52ef', // clear text - '43b1cd7f598ece23881b00e3ed030688', // cipher text - ], - [ - '2b7e151628aed2a6abf7158809cf4f3c', // key - 'f69f2445df4f9b17ad2b417be66c3710', // clear text - '7b0c785e27e8ad3f8223207104725dd4', // cipher text - ], - [ - // Two blocks - '2b7e151628aed2a6abf7158809cf4f3c', // key - 'f69f2445df4f9b17ad2b417be66c3710f69f2445df4f9b17ad2b417be66c3710', // clear text - '7b0c785e27e8ad3f8223207104725dd47b0c785e27e8ad3f8223207104725dd4', // cipher text - ], - // AES-ECB-256 - [ - '603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4', // key - '6bc1bee22e409f96e93d7e117393172a', // clear text - 'f3eed1bdb5d2a03c064b5a7e3db181f8', // cipher text - ], - [ - '603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4', // key - 'ae2d8a571e03ac9c9eb76fac45af8e51', // clear text - '591ccb10d410ed26dc5ba74a31362870', // cipher text - ], - [ - '603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4', // key - '30c81c46a35ce411e5fbc1191a0a52ef', // clear text - 'b6ed21b99ca6f4f9f153e7b1beafed1d', // cipher text - ], - [ - // Two blocks - '603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4', // key - '30c81c46a35ce411e5fbc1191a0a52ef30c81c46a35ce411e5fbc1191a0a52ef', // clear text - 'b6ed21b99ca6f4f9f153e7b1beafed1db6ed21b99ca6f4f9f153e7b1beafed1d', // cipher text - ], - [ - '603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4', // key - 'f69f2445df4f9b17ad2b417be66c3710', // clear text - '23304b7a39f9f3ff067d8d8f9e24ecc7', // cipher text - ], - ]; - - it('AES_ECB.encrypt / AES_ECB.decrypt', function () { - for (let i = 0; i < ecb_aes_vectors.length; ++i) { - const key = new Uint8Array(utils.hex_to_bytes(ecb_aes_vectors[i][0])); - const clear = new Uint8Array(utils.hex_to_bytes(ecb_aes_vectors[i][1])); - const cipher = new Uint8Array(utils.hex_to_bytes(ecb_aes_vectors[i][2])); - - expect(AES_ECB.encrypt(clear, key), `encrypt vector ${i}`).to.deep.equal(cipher); - - expect(AES_ECB.decrypt(cipher, key), `decrypt vector ${i}`).to.deep.equal(clear); - } - }); - }); - describe('CBC', () => { const cbc_aes_vectors = [ [ // key @@ -375,7 +303,7 @@ describe('AES', () => { ], ]; - it("AES_GCM.encrypt", function () { + it("AES_GCM.encrypt / AES_GCM.decrypt", function () { for (let i = 0; i < gcm_aes_vectors.length; ++i) { const key = gcm_aes_vectors[i][0]; const nonce = gcm_aes_vectors[i][1];