From 93c1dbd69f07f324c6aa1ab9296a632489cd3ead Mon Sep 17 00:00:00 2001
From: Jakub Jelen <jjelen@redhat.com>
Date: Fri, 15 Dec 2023 10:30:09 +0100
Subject: [PATCH 1/5] CVE-2023-6918: kdf: Reformat

Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>

Conflict: NA
Reference:https://gitlab.com/libssh/libssh-mirror/-/commit/93c1dbd69f07f324c6aa1ab9296a632489cd3ead
---
 src/kdf.c | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/src/kdf.c b/src/kdf.c
index 09644739..656a38ed 100644
--- a/src/kdf.c
+++ b/src/kdf.c
@@ -58,7 +58,7 @@ static ssh_mac_ctx ssh_mac_ctx_init(enum ssh_kdf_digest type)
     }
 
     ctx->digest_type = type;
-    switch(type){
+    switch (type) {
     case SSH_KDF_SHA1:
         ctx->ctx.sha1_ctx = sha1_init();
         return ctx;
@@ -79,7 +79,7 @@ static ssh_mac_ctx ssh_mac_ctx_init(enum ssh_kdf_digest type)
 
 static void ssh_mac_update(ssh_mac_ctx ctx, const void *data, size_t len)
 {
-    switch(ctx->digest_type){
+    switch (ctx->digest_type) {
     case SSH_KDF_SHA1:
         sha1_update(ctx->ctx.sha1_ctx, data, len);
         break;
@@ -97,26 +97,28 @@ static void ssh_mac_update(ssh_mac_ctx ctx, const void *data, size_t len)
 
 static void ssh_mac_final(unsigned char *md, ssh_mac_ctx ctx)
 {
-    switch(ctx->digest_type){
+    switch (ctx->digest_type) {
     case SSH_KDF_SHA1:
-        sha1_final(md,ctx->ctx.sha1_ctx);
+        sha1_final(md, ctx->ctx.sha1_ctx);
         break;
     case SSH_KDF_SHA256:
-        sha256_final(md,ctx->ctx.sha256_ctx);
+        sha256_final(md, ctx->ctx.sha256_ctx);
         break;
     case SSH_KDF_SHA384:
-        sha384_final(md,ctx->ctx.sha384_ctx);
+        sha384_final(md, ctx->ctx.sha384_ctx);
         break;
     case SSH_KDF_SHA512:
-        sha512_final(md,ctx->ctx.sha512_ctx);
+        sha512_final(md, ctx->ctx.sha512_ctx);
         break;
     }
     SAFE_FREE(ctx);
 }
 
 int sshkdf_derive_key(struct ssh_crypto_struct *crypto,
-                      unsigned char *key, size_t key_len,
-                      uint8_t key_type, unsigned char *output,
+                      unsigned char *key, 
+                      size_t key_len,
+                      int key_type, 
+                      unsigned char *output,
                       size_t requested_len)
 {
     /* Can't use VLAs with Visual Studio, so allocate the biggest
-- 
2.33.0

