diff --git a/include/libssh/libssh.h b/include/libssh/libssh.h index cce9e748..843846d5 100644 --- a/include/libssh/libssh.h +++ b/include/libssh/libssh.h @@ -528,7 +528,8 @@ LIBSSH_API int ssh_get_server_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 e0d2965a..4dc0419c 100644 --- a/src/dh.c +++ b/src/dh.c @@ -1142,6 +1142,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;