Skip to contentSkip to conversation

generate_key_expansion: make assumption explicit, use C99 features

PATCH In review Steffan Karger 2 participants 2 messages Nov 22, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 generate_key_expansion: make assumption explicit, use C99 features

This function potentially allocates memory, and can therefor not be run again on an initialized key_ctx_bi. Make this explicit by adding an error if someone tries do to this anyway.

While touching the function, cleanup it up a bit to make up for the added lines of code.

---
 src/openvpn/ssl.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
src/openvpn/ssl.c +8 -6
index 3c137d8..fe6493e 100644
@@ -1622,13 +1622,15 @@ generate_key_expansion (struct key_ctx_bi *key,
 			const struct session_id *server_sid,
 			bool server)
 {
-  uint8_t master[48];
-  struct key2 key2;
+  uint8_t master[48] = { 0 };
+  struct key2 key2 = { 0 };
   bool ret = false;
-  int i;
 
-  CLEAR (master);
-  CLEAR (key2);
+  if (key->initialized)
+    {
+      msg (D_TLS_ERRORS, "TLS Error: key already initialized");
+      goto exit;
+    }
 
   /* debugging print of source key material */
   key_source2_print (key_src);
@@ -1664,7 +1666,7 @@ generate_key_expansion (struct key_ctx_bi *key,
   key2_print (&key2, key_type, "Master Encrypt", "Master Decrypt");
 
   /* check for weak keys */
-  for (i = 0; i < 2; ++i)
+  for (int i = 0; i < 2; ++i)
     {
       fixup_key (&key2.keys[i], key_type);
       if (!check_key (&key2.keys[i], key_type))
Signature · 1 line
2.7.4
#1 lore raw

ACK. Except for the check, it boils down to "the same code", and the check makes sense.

Your patch has been applied to the master branch.

commit 48d41413c4b181e00769cdb83ccfe179299ad8e4

Author: Steffan Karger
Date:   Tue Nov 22 21:09:26 2016 +0100
     generate_key_expansion: make assumption explicit, use C99 features

     Signed-off-by: Steffan Karger <[email protected]...>
     Acked-by: Gert Doering <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg13202.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering