summaryrefslogtreecommitdiff
path: root/src/protocol/internal/ssh_diffie-hellman.c
diff options
context:
space:
mode:
authorIru Cai <mytbk920423@gmail.com>2016-11-08 14:59:15 +0800
committerIru Cai <mytbk920423@gmail.com>2016-11-08 15:17:41 +0800
commit88fed792b68835ea7805bcfed6762f0ee9496bab (patch)
treea1c1abfe0afc3759be0acedd0313bee1fcfcf4fb /src/protocol/internal/ssh_diffie-hellman.c
parent50d144a7305c6f454a8f8f1a10ac7234eac2ceeb (diff)
downloadfqterm-88fed792b68835ea7805bcfed6762f0ee9496bab.tar.xz
better handling of errors when KEX fails, use EVP digest
Diffstat (limited to 'src/protocol/internal/ssh_diffie-hellman.c')
-rw-r--r--src/protocol/internal/ssh_diffie-hellman.c23
1 files changed, 19 insertions, 4 deletions
diff --git a/src/protocol/internal/ssh_diffie-hellman.c b/src/protocol/internal/ssh_diffie-hellman.c
index 1866b2f..72bd253 100644
--- a/src/protocol/internal/ssh_diffie-hellman.c
+++ b/src/protocol/internal/ssh_diffie-hellman.c
@@ -63,6 +63,7 @@ ssh_dh_free(SSH_DH *dh)
{
BN_free(dh->g);
BN_free(dh->p);
+ ssh_md_ctx_free(dh->digest.mdctx);
free(dh);
}
@@ -72,8 +73,11 @@ ssh_dh_group1_sha1(void)
SSH_DH *dh = (SSH_DH*)malloc(sizeof(SSH_DH));
dh->g = BN_new();
dh->p = BN_new();
- dh->hash = SHA1;
- dh->hashlen = SHA_DIGEST_LENGTH;
+ dh->digest = (evp_md_t) {
+ .mdctx = ssh_md_ctx_new(),
+ .md = EVP_sha1(),
+ .hashlen = SHA_DIGEST_LENGTH
+ };
BN_set_word(dh->g, g);
BN_bin2bn(prime_group1, 128, dh->p);
return dh;
@@ -85,13 +89,24 @@ ssh_dh_group14_sha1(void)
SSH_DH *dh = (SSH_DH*)malloc(sizeof(SSH_DH));
dh->g = BN_new();
dh->p = BN_new();
- dh->hash = SHA1;
- dh->hashlen = SHA_DIGEST_LENGTH;
+ dh->digest = (evp_md_t) {
+ .mdctx = ssh_md_ctx_new(),
+ .md = EVP_sha1(),
+ .hashlen = SHA_DIGEST_LENGTH
+ };
BN_set_word(dh->g, g);
BN_bin2bn(prime_group14, 256, dh->p);
return dh;
}
+void
+ssh_dh_hash(SSH_DH *dh, const unsigned char *in, unsigned char *out, size_t n)
+{
+ EVP_DigestInit_ex(dh->digest.mdctx, dh->digest.md, NULL);
+ EVP_DigestUpdate(dh->digest.mdctx, in, n);
+ EVP_DigestFinal_ex(dh->digest.mdctx, out, NULL);
+}
+
struct
{
const char *name;