mirror of
https://git.libssh.org/projects/libssh.git
synced 2025-08-08 19:02:06 +03:00
pki: Refactor ssh_pki_do_sign().
This commit is contained in:
21
src/pki.c
21
src/pki.c
@@ -1079,34 +1079,35 @@ ssh_string ssh_pki_do_sign(ssh_session session,
|
|||||||
session->next_crypto;
|
session->next_crypto;
|
||||||
unsigned char hash[SHA_DIGEST_LEN] = {0};
|
unsigned char hash[SHA_DIGEST_LEN] = {0};
|
||||||
ssh_signature sig;
|
ssh_signature sig;
|
||||||
ssh_string sig_blob = NULL;
|
ssh_string sig_blob;
|
||||||
ssh_string str = NULL;
|
ssh_string session_id;
|
||||||
SHACTX ctx = NULL;
|
SHACTX ctx;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
if (privkey == NULL || !ssh_key_is_private(privkey)) {
|
if (privkey == NULL || !ssh_key_is_private(privkey)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
str = ssh_string_new(SHA_DIGEST_LEN);
|
session_id = ssh_string_new(SHA_DIGEST_LEN);
|
||||||
if (str == NULL) {
|
if (session_id == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
ssh_string_fill(str, crypto->session_id, SHA_DIGEST_LEN);
|
ssh_string_fill(session_id, crypto->session_id, SHA_DIGEST_LEN);
|
||||||
|
|
||||||
ctx = sha1_init();
|
ctx = sha1_init();
|
||||||
if (ctx == NULL) {
|
if (ctx == NULL) {
|
||||||
ssh_string_free(str);
|
ssh_string_free(session_id);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
sha1_update(ctx, str, ssh_string_len(str) + 4);
|
sha1_update(ctx, session_id, ssh_string_len(session_id) + 4);
|
||||||
ssh_string_free(str);
|
ssh_string_free(session_id);
|
||||||
|
|
||||||
sha1_update(ctx, buffer_get_rest(sigbuf), buffer_get_rest_len(sigbuf));
|
sha1_update(ctx, buffer_get_rest(sigbuf), buffer_get_rest_len(sigbuf));
|
||||||
sha1_final(hash, ctx);
|
sha1_final(hash, ctx);
|
||||||
|
|
||||||
#ifdef DEBUG_CRYPTO
|
#ifdef DEBUG_CRYPTO
|
||||||
ssh_print_hexa("Hash being signed with dsa", hash, SHA_DIGEST_LEN);
|
ssh_print_hexa("Hash being signed", hash, SHA_DIGEST_LEN);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
sig = pki_do_sign(privkey, hash, SHA_DIGEST_LEN);
|
sig = pki_do_sign(privkey, hash, SHA_DIGEST_LEN);
|
||||||
|
Reference in New Issue
Block a user