Skip to content

Instantly share code, notes, and snippets.

@cwyang
Created May 24, 2024 16:01
Show Gist options
  • Save cwyang/a4ea1e4e724384cf4e44d499cbd51aaa to your computer and use it in GitHub Desktop.
Save cwyang/a4ea1e4e724384cf4e44d499cbd51aaa to your computer and use it in GitHub Desktop.
bug reporting on VPP native aes_gcm
// src/plugins/crypto_native/aes_gcm.c
static void test_aes_gcm()
{
  u8 src[32] = {0}, dst[32] = {0}, check[32] = {0};
  u8 aad[32] = {0}, iv[12] = {0}, tag[16] = {0}, key[32];
  aes_key_size_t ks = AES_KEY_256;
  aes_gcm_key_data_t kd;
  // prepare key
  for (int i = 0; i < 32; i++)
    key[i] = i;
  clib_aes_gcm_key_expand (&kd, key, ks);
  for (i32 len = 32; len >= 0; len -= 16)
    {
      clib_warning("testing for len %d", len);
      aes_gcm (src, dst,
               aad, iv, tag, len, 32, 16,
               &kd, AES_KEY_ROUNDS (ks),
               AES_GCM_OP_ENCRYPT);
      int rv = aes_gcm (dst, check,
                        aad, iv, tag, len, 32, 16,
                        &kd, AES_KEY_ROUNDS (ks),
                        AES_GCM_OP_DECRYPT);
      int rv2 = memcmp(src, check, len);
      ASSERT(rv2 == 0);
      ASSERT(rv != 0);
      clib_warning("testing for len %d OK!", len);
    }
}
...
crypto_native aes_gcm_init() {
    crypto_native_main_t *cm = &crypto_native_main;
    test_aes_gcm();
    ...
}
@cwyang
Copy link
Author

cwyang commented May 24, 2024

You can see where the above test function fails: 

May 24 15:50:48 mars vpp[293594]: test_aes_gcm:148: testing for len 32
May 24 15:50:48 mars vpp[293594]: test_aes_gcm:160: testing for len 32 OK!
May 24 15:50:48 mars vpp[293594]: test_aes_gcm:148: testing for len 16
May 24 15:50:48 mars vpp[293594]: test_aes_gcm:160: testing for len 16 OK!
May 24 15:50:48 mars vpp[293594]: test_aes_gcm:148: testing for len 0
May 24 15:50:48 mars vpp[293594]: /home/ubuntu/vpp-dev/src/plugins/crypto_native/aes_gcm.c:159 (test_aes_gcm) assertion `rv != 0' fails
May 24 15:50:48 mars vpp[293594]: received signal SIGABRT, PC 0x7fa3d081b9fc
May 24 15:50:48 mars vpp[293594]: #0  0x00007fa3d0c547ec unix_signal_handler + 0x1ec
May 24 15:50:48 mars vpp[293594]: #1  0x00007fa3d07c7520 0x7fa3d07c7520
May 24 15:50:48 mars vpp[293594]: #2  0x00007fa3d081b9fc pthread_kill + 0x12c
May 24 15:50:48 mars vpp[293594]: #3  0x00007fa3d07c7476 raise + 0x16
May 24 15:50:48 mars vpp[293594]: #4  0x00007fa3d07ad7f3 abort + 0xd3
May 24 15:50:48 mars vpp[293594]: #5  0x000055a10b9ad123 0x55a10b9ad123
May 24 15:50:48 mars vpp[293594]: #6  0x00007fa3d0acd859 debugger + 0x9
May 24 15:50:48 mars vpp[293594]: #7  0x00007fa3d0acd610 _clib_error + 0x210
May 24 15:50:48 mars vpp[293594]: #8  0x00007fa38f451fee test_aes_gcm + 0x2ae
May 24 15:50:48 mars vpp[293594]: #9  0x00007fa38f451adc crypto_native_aes_gcm_init_hsw + 0x1c
May 24 15:50:48 mars vpp[293594]: #10 0x00007fa38f46eb7b crypto_native_init + 0x2ab
May 24 15:50:48 mars vpp[293594]: #11 0x00007fa3d0bdaf61 call_init_exit_functions_internal + 0x151
May 24 15:50:48 mars vpp[293594]: #12 0x00007fa3d0bdadff vlib_call_init_exit_functions + 0x2f
May 24 15:50:48 mars vpp[293594]: #13 0x00007fa3d0bdb02a vlib_call_all_init_functions + 0x3a
May 24 15:50:48 mars vpp[293594]: #14 0x00007fa3d0bf48cc vlib_main + 0x33c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment