diff options
author | Andrea Grandi <agrandi@google.com> | 2022-11-16 14:19:44 -0800 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2022-11-23 03:38:44 +0000 |
commit | e1889643c5ee339920add2b9cb9b34912d6c232d (patch) | |
tree | ad09c61e50737eb4575ba7e69d16545ec704dadb /test | |
parent | cb77fd22364bad47e3b04687f43f5292f1568dbd (diff) | |
download | chrome-ec-e1889643c5ee339920add2b9cb9b34912d6c232d.tar.gz |
test: Add AES-GCM decrypt benchmark
BUG=b:235476822
TEST=test/run_device_tests.py -b bloonchipper -t aes
TEST=make run-aes
BRANCH=none
Signed-off-by: Andrea Grandi <agrandi@google.com>
Change-Id: Ic117d7a137065729e284b3c435062d4ce473e8d0
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4032755
Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com>
Reviewed-by: Bobby Casey <bobbycasey@google.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/aes.cc | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/test/aes.cc b/test/aes.cc index b5fda52d93..6986abd148 100644 --- a/test/aes.cc +++ b/test/aes.cc @@ -431,7 +431,7 @@ static void test_aes_gcm_speed(void) 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }; const int key_size = sizeof(key); - static const uint8_t plaintext[512] = { 0 }; + static uint8_t plaintext[512] = { 0 }; const auto plaintext_size = sizeof(plaintext); static const uint8_t nonce[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -441,20 +441,33 @@ static void test_aes_gcm_speed(void) uint8_t tag[16] = { 0 }; const int tag_size = sizeof(tag); - uint8_t *out = tmp; + uint8_t *encrypted_data = tmp; static AES_KEY aes_key; static GCM128_CONTEXT ctx; assert(plaintext_size <= sizeof(tmp)); - benchmark.run("AES-GCM", [&]() { + benchmark.run("AES-GCM encrypt", [&]() { AES_set_encrypt_key(key, 8 * key_size, &aes_key); CRYPTO_gcm128_init(&ctx, &aes_key, (block128_f)AES_encrypt, 0); CRYPTO_gcm128_setiv(&ctx, &aes_key, nonce, nonce_size); - CRYPTO_gcm128_encrypt(&ctx, &aes_key, plaintext, out, + CRYPTO_gcm128_encrypt(&ctx, &aes_key, plaintext, encrypted_data, plaintext_size); CRYPTO_gcm128_tag(&ctx, tag, tag_size); }); + + benchmark.run("AES-GCM decrypt", [&]() { + AES_set_encrypt_key(key, 8 * key_size, &aes_key); + CRYPTO_gcm128_init(&ctx, &aes_key, (block128_f)AES_encrypt, 0); + CRYPTO_gcm128_setiv(&ctx, &aes_key, nonce, nonce_size); + auto decrypt_res = + CRYPTO_gcm128_decrypt(&ctx, &aes_key, encrypted_data, + plaintext, plaintext_size); + + auto finish_res = CRYPTO_gcm128_finish(&ctx, tag, tag_size); + assert(decrypt_res); + assert(finish_res); + }); benchmark.print_results(); } |