diff options
author | Minteck <contact@minteck.org> | 2023-02-23 19:34:56 +0100 |
---|---|---|
committer | Minteck <contact@minteck.org> | 2023-02-23 19:34:56 +0100 |
commit | 3d1cd02f27518f1a04374c7c8320cd5d82ede6e9 (patch) | |
tree | 75be5fba4368472fb11c8015aee026b2b9a71888 /includes/external/school/node_modules/node-forge/tests/aes-speed.js | |
parent | 8cc1f13c17fa2fb5a4410542d39e650e02945634 (diff) | |
download | pluralconnect-3d1cd02f27518f1a04374c7c8320cd5d82ede6e9.tar.gz pluralconnect-3d1cd02f27518f1a04374c7c8320cd5d82ede6e9.tar.bz2 pluralconnect-3d1cd02f27518f1a04374c7c8320cd5d82ede6e9.zip |
Updated 40 files, added 37 files, deleted 1103 files and renamed 3905 files (automated)
Diffstat (limited to 'includes/external/school/node_modules/node-forge/tests/aes-speed.js')
-rw-r--r-- | includes/external/school/node_modules/node-forge/tests/aes-speed.js | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/includes/external/school/node_modules/node-forge/tests/aes-speed.js b/includes/external/school/node_modules/node-forge/tests/aes-speed.js new file mode 100644 index 0000000..2049a8a --- /dev/null +++ b/includes/external/school/node_modules/node-forge/tests/aes-speed.js @@ -0,0 +1,62 @@ +var forge = require('../js/forge'); + +console.log('Times in 1000s of bytes/sec processed.'); + +aes_128('AES-CBC'); +aes_128('AES-CFB'); +aes_128('AES-OFB'); +aes_128('AES-CTR'); +aes_128('AES-GCM'); + +function aes_128(algorithm) { + console.log('Running ' + algorithm + ' for 5 seconds...'); + + var size = 1024; + var key = forge.random.getBytesSync(16); + var iv = forge.random.getBytes(algorithm === 'AES-GCM' ? 12 : 16); + var plain = forge.random.getBytesSync(size); + + // run for 5 seconds + var start = new Date().getTime(); + + var now; + var totalEncrypt = 0; + var totalDecrypt = 0; + var cipher; + var count = 0; + var passed = 0; + while(passed < 5000) { + var input = forge.util.createBuffer(plain); + + // encrypt, only measuring update() and finish() + cipher = forge.cipher.createCipher(algorithm, key); + cipher.start({iv: iv}); + now = new Date().getTime(); + cipher.update(input); + cipher.finish(); + totalEncrypt += new Date().getTime() - now; + + var ciphertext = cipher.output; + var tag = cipher.mode.tag; + count += cipher.output.length(); + + // decrypt, only measuring update() and finish() + cipher = forge.cipher.createDecipher(algorithm, key); + cipher.start({iv: iv, tag: tag}); + now = new Date().getTime(); + cipher.update(ciphertext); + if(!cipher.finish()) { + throw new Error('Decryption error.'); + } + totalDecrypt += new Date().getTime() - now; + + passed = new Date().getTime() - start; + } + + count = count / 1000; + totalEncrypt /= 1000; + totalDecrypt /= 1000; + console.log('encrypt: ' + (count / totalEncrypt) + ' k/sec'); + console.log('decrypt: ' + (count / totalDecrypt) + ' k/sec'); + console.log(); +} |