1
0
mirror of https://git.libssh.org/projects/libssh.git synced 2025-12-11 03:42:35 +03:00

CVE-2023-6918: kdf: Reformat

Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
This commit is contained in:
Jakub Jelen
2023-12-15 10:30:09 +01:00
committed by Andreas Schneider
parent a8b9d13687
commit a16f34c57a

View File

@@ -58,7 +58,7 @@ static ssh_mac_ctx ssh_mac_ctx_init(enum ssh_kdf_digest type)
} }
ctx->digest_type = type; ctx->digest_type = type;
switch(type){ switch (type) {
case SSH_KDF_SHA1: case SSH_KDF_SHA1:
ctx->ctx.sha1_ctx = sha1_init(); ctx->ctx.sha1_ctx = sha1_init();
return ctx; 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) 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: case SSH_KDF_SHA1:
sha1_update(ctx->ctx.sha1_ctx, data, len); sha1_update(ctx->ctx.sha1_ctx, data, len);
break; 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) static void ssh_mac_final(unsigned char *md, ssh_mac_ctx ctx)
{ {
switch(ctx->digest_type){ switch (ctx->digest_type) {
case SSH_KDF_SHA1: case SSH_KDF_SHA1:
sha1_final(md,ctx->ctx.sha1_ctx); sha1_final(md, ctx->ctx.sha1_ctx);
break; break;
case SSH_KDF_SHA256: case SSH_KDF_SHA256:
sha256_final(md,ctx->ctx.sha256_ctx); sha256_final(md, ctx->ctx.sha256_ctx);
break; break;
case SSH_KDF_SHA384: case SSH_KDF_SHA384:
sha384_final(md,ctx->ctx.sha384_ctx); sha384_final(md, ctx->ctx.sha384_ctx);
break; break;
case SSH_KDF_SHA512: case SSH_KDF_SHA512:
sha512_final(md,ctx->ctx.sha512_ctx); sha512_final(md, ctx->ctx.sha512_ctx);
break; break;
} }
SAFE_FREE(ctx); SAFE_FREE(ctx);
} }
int sshkdf_derive_key(struct ssh_crypto_struct *crypto, int sshkdf_derive_key(struct ssh_crypto_struct *crypto,
unsigned char *key, size_t key_len, unsigned char *key,
uint8_t key_type, unsigned char *output, size_t key_len,
uint8_t key_type,
unsigned char *output,
size_t requested_len) size_t requested_len)
{ {
/* Can't use VLAs with Visual Studio, so allocate the biggest /* Can't use VLAs with Visual Studio, so allocate the biggest