| 18 | } |
| 19 | |
| 20 | function AEAD_Bench(cipher, message, associate_data, key, iv, n, len) { |
| 21 | const written = n * len; |
| 22 | const bits = written * 8; |
| 23 | const mbits = bits / (1024 * 1024); |
| 24 | |
| 25 | for (let i = 0; i < n; i++) { |
| 26 | const alice = crypto.createCipheriv(cipher, key, iv); |
| 27 | alice.setAAD(associate_data); |
| 28 | const enc = alice.update(message); |
| 29 | alice.final(); |
| 30 | const tag = alice.getAuthTag(); |
| 31 | const bob = crypto.createDecipheriv(cipher, key, iv); |
| 32 | bob.setAuthTag(tag); |
| 33 | bob.setAAD(associate_data); |
| 34 | bob.update(enc); |
| 35 | bob.final(); |
| 36 | } |
| 37 | |
| 38 | bench.end(mbits); |
| 39 | } |