Browse code

Add algorithm and bits used in key_print2 method and refactor method

This adds the the algorithm that is being used. This does not avoid the
empty hmac key output but makes it more obvious, why there is no output.

Master Decrypt (cipher, AES-256-GCM, 256 bits): 705923be f6e44923 a4920a64
434e575c 6ff8d2db d8e74f07 86c010cf 2cf3923e
Master Decrypt (hmac, [null-digest], 0 bits):

Signed-off-by: Arne Schwabe <arne@rfc2549.org>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20221109123501.1252554-1-arne@rfc2549.org>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25495.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>

Arne Schwabe authored on 2022/11/09 21:35:01
Showing 1 changed files
... ...
@@ -996,8 +996,22 @@ generate_key_random(struct key *key, const struct key_type *kt)
996 996
     gc_free(&gc);
997 997
 }
998 998
 
999
-/*
1000
- * Print key material
999
+static void
1000
+key_print(const struct key *key,
1001
+          const struct key_type *kt,
1002
+          const char *prefix)
1003
+{
1004
+    struct gc_arena gc = gc_new();
1005
+    dmsg(D_SHOW_KEY_SOURCE, "%s (cipher, %s, %d bits): %s",
1006
+         prefix, cipher_kt_name(kt->cipher), cipher_kt_key_size(kt->cipher) * 8,
1007
+         format_hex(key->cipher, cipher_kt_key_size(kt->cipher), 0, &gc));
1008
+    dmsg(D_SHOW_KEY_SOURCE, "%s (hmac, %s, %d bits): %s",
1009
+         prefix, md_kt_name(kt->digest), md_kt_size(kt->digest) * 8,
1010
+         format_hex(key->hmac, md_kt_size(kt->digest), 0, &gc));
1011
+    gc_free(&gc);
1012
+}
1013
+/**
1014
+ * Prints the keys in a key2 structure.
1001 1015
  */
1002 1016
 void
1003 1017
 key2_print(const struct key2 *k,
... ...
@@ -1005,21 +1019,9 @@ key2_print(const struct key2 *k,
1005 1005
            const char *prefix0,
1006 1006
            const char *prefix1)
1007 1007
 {
1008
-    struct gc_arena gc = gc_new();
1009 1008
     ASSERT(k->n == 2);
1010
-    dmsg(D_SHOW_KEY_SOURCE, "%s (cipher): %s",
1011
-         prefix0,
1012
-         format_hex(k->keys[0].cipher, cipher_kt_key_size(kt->cipher), 0, &gc));
1013
-    dmsg(D_SHOW_KEY_SOURCE, "%s (hmac): %s",
1014
-         prefix0,
1015
-         format_hex(k->keys[0].hmac, md_kt_size(kt->digest), 0, &gc));
1016
-    dmsg(D_SHOW_KEY_SOURCE, "%s (cipher): %s",
1017
-         prefix1,
1018
-         format_hex(k->keys[1].cipher, cipher_kt_key_size(kt->cipher), 0, &gc));
1019
-    dmsg(D_SHOW_KEY_SOURCE, "%s (hmac): %s",
1020
-         prefix1,
1021
-         format_hex(k->keys[1].hmac, md_kt_size(kt->digest), 0, &gc));
1022
-    gc_free(&gc);
1009
+    key_print(&k->keys[0], kt, prefix0);
1010
+    key_print(&k->keys[1], kt, prefix1);
1023 1011
 }
1024 1012
 
1025 1013
 void