From f3f140e65f0e58fc37b04dbe4173d6ecda0127ac Mon Sep 17 00:00:00 2001 From: Jan-Niklas Burfeind Date: Thu, 9 Aug 2018 11:00:00 +0200 Subject: dh: Add SSH_PUBLICKEY_HASH_SHA256 to ssh_get_publickey_hash() Signed-off-by: Jan-Niklas Burfeind Reviewed-by: Andreas Schneider (cherry picked from commit 1499b38aef17beac8b438522535daf428600d529) --- include/libssh/libssh.h | 3 ++- src/dh.c | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/include/libssh/libssh.h b/include/libssh/libssh.h index 37214898..320dc032 100644 --- a/include/libssh/libssh.h +++ b/include/libssh/libssh.h @@ -444,7 +444,8 @@ LIBSSH_API int ssh_get_publickey(ssh_session session, ssh_key *key); enum ssh_publickey_hash_type { SSH_PUBLICKEY_HASH_SHA1, - SSH_PUBLICKEY_HASH_MD5 + SSH_PUBLICKEY_HASH_MD5, + SSH_PUBLICKEY_HASH_SHA256 }; LIBSSH_API int ssh_get_publickey_hash(const ssh_key key, enum ssh_publickey_hash_type type, diff --git a/src/dh.c b/src/dh.c index d27b66eb..bf1ade8b 100644 --- a/src/dh.c +++ b/src/dh.c @@ -1039,6 +1039,29 @@ int ssh_get_publickey_hash(const ssh_key key, *hlen = SHA_DIGEST_LEN; } break; + case SSH_PUBLICKEY_HASH_SHA256: + { + SHA256CTX ctx; + + h = malloc(SHA256_DIGEST_LEN); + if (h == NULL) { + rc = -1; + goto out; + } + + ctx = sha256_init(); + if (ctx == NULL) { + free(h); + rc = -1; + goto out; + } + + sha256_update(ctx, ssh_string_data(blob), ssh_string_len(blob)); + sha256_final(h, ctx); + + *hlen = SHA256_DIGEST_LEN; + } + break; case SSH_PUBLICKEY_HASH_MD5: { MD5CTX ctx; -- cgit v1.2.3