summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/pki.c54
1 files changed, 42 insertions, 12 deletions
diff --git a/src/pki.c b/src/pki.c
index b8d0d6b9..27fe53f6 100644
--- a/src/pki.c
+++ b/src/pki.c
@@ -1299,6 +1299,11 @@ int ssh_pki_signature_verify_blob(ssh_session session,
evp(key->ecdsa_nid, digest, dlen, ehash, &elen);
+#ifdef DEBUG_CRYPTO
+ ssh_print_hexa("Hash to be verified with ecdsa",
+ ehash, elen);
+#endif
+
rc = pki_signature_verify(session,
sig,
key,
@@ -1365,6 +1370,10 @@ ssh_string ssh_pki_do_sign(ssh_session session,
evp_update(ctx, buffer_get_rest(sigbuf), buffer_get_rest_len(sigbuf));
evp_final(ctx, ehash, &elen);
+#ifdef DEBUG_CRYPTO
+ ssh_print_hexa("Hash being signed", ehash, elen);
+#endif
+
sig = pki_do_sign(privkey, ehash, elen);
#endif
} else {
@@ -1458,10 +1467,8 @@ ssh_string ssh_srv_pki_do_sign_sessionid(ssh_session session,
const ssh_key privkey)
{
struct ssh_crypto_struct *crypto;
- unsigned char hash[SHA_DIGEST_LEN] = {0};
ssh_signature sig;
ssh_string sig_blob;
- SHACTX ctx;
int rc;
if (session == NULL || privkey == NULL || !ssh_key_is_private(privkey)) {
@@ -1470,24 +1477,47 @@ ssh_string ssh_srv_pki_do_sign_sessionid(ssh_session session,
crypto = session->next_crypto ? session->next_crypto :
session->current_crypto;
- ctx = sha1_init();
- if (ctx == NULL) {
- return NULL;
- }
if (crypto->secret_hash == NULL){
ssh_set_error(session,SSH_FATAL,"Missing secret_hash");
return NULL;
}
- sha1_update(ctx, crypto->secret_hash, crypto->digest_len);
- sha1_final(hash, ctx);
+
+ if (privkey->type == SSH_KEYTYPE_ECDSA) {
+#ifdef HAVE_ECC
+ unsigned char ehash[EVP_DIGEST_LEN] = {0};
+ uint32_t elen;
+
+ evp(privkey->ecdsa_nid, crypto->secret_hash, crypto->digest_len,
+ ehash, &elen);
#ifdef DEBUG_CRYPTO
- ssh_print_hexa("Hash being signed", hash, SHA_DIGEST_LEN);
+ ssh_print_hexa("Hash being signed", ehash, elen);
#endif
- sig = pki_do_sign_sessionid(privkey, hash, SHA_DIGEST_LEN);
- if (sig == NULL) {
- return NULL;
+ sig = pki_do_sign_sessionid(privkey, ehash, elen);
+ if (sig == NULL) {
+ return NULL;
+ }
+#endif
+ } else {
+ unsigned char hash[SHA_DIGEST_LEN] = {0};
+ SHACTX ctx;
+
+ ctx = sha1_init();
+ if (ctx == NULL) {
+ return NULL;
+ }
+ sha1_update(ctx, crypto->secret_hash, crypto->digest_len);
+ sha1_final(hash, ctx);
+
+#ifdef DEBUG_CRYPTO
+ ssh_print_hexa("Hash being signed", hash, SHA_DIGEST_LEN);
+#endif
+
+ sig = pki_do_sign_sessionid(privkey, hash, SHA_DIGEST_LEN);
+ if (sig == NULL) {
+ return NULL;
+ }
}
rc = ssh_pki_export_signature_blob(sig, &sig_blob);