mirror of
https://git.libssh.org/projects/libssh.git
synced 2026-02-09 09:54:25 +09:00
dh: Add SSH_PUBLICKEY_HASH_SHA256 to ssh_get_publickey_hash()
Signed-off-by: Jan-Niklas Burfeind <libssh@aiyionpri.me>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
(cherry picked from commit 1499b38aef)
This commit is contained in:
committed by
Andreas Schneider
parent
c977a97093
commit
f3f140e65f
@@ -444,7 +444,8 @@ LIBSSH_API int ssh_get_publickey(ssh_session session, ssh_key *key);
|
|||||||
|
|
||||||
enum ssh_publickey_hash_type {
|
enum ssh_publickey_hash_type {
|
||||||
SSH_PUBLICKEY_HASH_SHA1,
|
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,
|
LIBSSH_API int ssh_get_publickey_hash(const ssh_key key,
|
||||||
enum ssh_publickey_hash_type type,
|
enum ssh_publickey_hash_type type,
|
||||||
|
|||||||
23
src/dh.c
23
src/dh.c
@@ -1039,6 +1039,29 @@ int ssh_get_publickey_hash(const ssh_key key,
|
|||||||
*hlen = SHA_DIGEST_LEN;
|
*hlen = SHA_DIGEST_LEN;
|
||||||
}
|
}
|
||||||
break;
|
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:
|
case SSH_PUBLICKEY_HASH_MD5:
|
||||||
{
|
{
|
||||||
MD5CTX ctx;
|
MD5CTX ctx;
|
||||||
|
|||||||
Reference in New Issue
Block a user