diff options
author | Shigeki Ohtsu <ohtsu@iij.ad.jp> | 2015-04-02 13:30:35 +0900 |
---|---|---|
committer | Shigeki Ohtsu <ohtsu@iij.ad.jp> | 2015-04-04 12:37:26 +0900 |
commit | 3a69b7689bdcbb5602bd0f8083c403eb77cc0db0 (patch) | |
tree | 8904a3b382eda860e6295e7d887e086e6159ea82 /benchmark/crypto/aes-gcm-throughput.js | |
parent | 1c709f3aa98954b6462bd7feee1f87c1bc94ba67 (diff) | |
download | android-node-v8-3a69b7689bdcbb5602bd0f8083c403eb77cc0db0.tar.gz android-node-v8-3a69b7689bdcbb5602bd0f8083c403eb77cc0db0.tar.bz2 android-node-v8-3a69b7689bdcbb5602bd0f8083c403eb77cc0db0.zip |
benchmark: add rsa/aes-gcm performance test
PR-URL: https://github.com/iojs/io.js/pull/1325
Reviewed-By: Fedor Indutny <fedor@indutny.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Diffstat (limited to 'benchmark/crypto/aes-gcm-throughput.js')
-rw-r--r-- | benchmark/crypto/aes-gcm-throughput.js | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/benchmark/crypto/aes-gcm-throughput.js b/benchmark/crypto/aes-gcm-throughput.js new file mode 100644 index 0000000000..65e1713f0e --- /dev/null +++ b/benchmark/crypto/aes-gcm-throughput.js @@ -0,0 +1,38 @@ +var common = require('../common.js'); +var crypto = require('crypto'); +var keylen = {'aes-128-gcm': 16, 'aes-192-gcm': 24, 'aes-256-gcm': 32}; +var bench = common.createBenchmark(main, { + n: [500], + cipher: ['aes-128-gcm', 'aes-192-gcm', 'aes-256-gcm'], + len: [1024, 4 * 1024, 16 * 1024, 64 * 1024, 256 * 1024, 1024 * 1024] +}); + +function main(conf) { + var message = (new Buffer(conf.len)).fill('b'); + var key = crypto.randomBytes(keylen[conf.cipher]); + var iv = crypto.randomBytes(12); + var associate_data = (new Buffer(16)).fill('z'); + bench.start(); + AEAD_Bench(conf.cipher, message, associate_data, key, iv, conf.n, conf.len); +} + +function AEAD_Bench(cipher, message, associate_data, key, iv, n, len) { + var written = n * len; + var bits = written * 8; + var mbits = bits / (1024 * 1024); + + for (var i = 0; i < n; i++) { + var alice = crypto.createCipheriv(cipher, key, iv); + alice.setAAD(associate_data); + var enc = alice.update(message); + alice.final(); + var tag = alice.getAuthTag(); + var bob = crypto.createDecipheriv(cipher, key, iv); + bob.setAuthTag(tag); + bob.setAAD(associate_data); + var clear = bob.update(enc); + bob.final(); + } + + bench.end(mbits); +} |