]> git.ipfire.org Git - thirdparty/nettle.git/commitdiff
nettle-benchmark: avoid -Wmaybe-uninitialized warnings
authorDaiki Ueno <dueno@redhat.com>
Sat, 27 Mar 2021 07:36:01 +0000 (08:36 +0100)
committerDaiki Ueno <dueno@redhat.com>
Sat, 27 Mar 2021 07:39:59 +0000 (08:39 +0100)
Otherwise GCC 11 prints the following warning:

  nettle-benchmark.c: In function ‘time_umac’:
  ../umac.h:42:25: warning: ‘key’ may be used uninitialized [-Wmaybe-uninitialized]
     42 | #define umac32_set_key  nettle_umac32_set_key
  nettle-benchmark.c:395:3: note: in expansion of macro ‘umac32_set_key’
    395 |   umac32_set_key (&ctx32, key);
        |   ^~~~~~~~~~~~~~

Although this should be harmless as it's in the benchmarking code and
the content of the key doesn't matter, it wouldn't hurt to explicitly
initialize it.  This patch also uses predefined constants for key
sizes.

examples/nettle-benchmark.c

index ca6346e0eb92828e39fb24084a266ca412147c92..9ce3a733a0f094b31e2acf5ee2e61c22fad02c8b 100644 (file)
@@ -390,7 +390,9 @@ time_umac(void)
   struct umac96_ctx ctx96;
   struct umac128_ctx ctx128;
 
-  uint8_t key[16];
+  uint8_t key[UMAC_KEY_SIZE];
+
+  init_key (sizeof(key), key);
 
   umac32_set_key (&ctx32, key);
   info.ctx = &ctx32;
@@ -432,7 +434,9 @@ time_cmac(void)
   struct bench_hash_info info;
   struct cmac_aes128_ctx ctx;
 
-  uint8_t key[16];
+  uint8_t key[AES128_KEY_SIZE];
+
+  init_key (sizeof(key), key);
 
   cmac_aes128_set_key (&ctx, key);
   info.ctx = &ctx;
@@ -449,7 +453,9 @@ time_poly1305_aes(void)
   static uint8_t data[BENCH_BLOCK];
   struct bench_hash_info info;
   struct poly1305_aes_ctx ctx;
-  uint8_t key[32];
+  uint8_t key[POLY1305_AES_KEY_SIZE];
+
+  init_key (sizeof(key), key);
 
   poly1305_aes_set_key (&ctx, key);
   info.ctx = &ctx;