summaryrefslogtreecommitdiffhomepage
path: root/common-kex.c
diff options
context:
space:
mode:
authorMatt Johnston <matt@ucc.asn.au>2012-05-10 08:38:37 +0800
committerMatt Johnston <matt@ucc.asn.au>2012-05-10 08:38:37 +0800
commitc62e53807f6e7cf49544cbd7103929282a628311 (patch)
tree4877f61931c74cf0182d35dca67193049a2ccb95 /common-kex.c
parent10d7a358416e4125b05b0e28f4175659febdcb32 (diff)
- Add hmac-sha2-256 and hmac-sha2-512. Needs debugging, seems to be
getting keyed incorrectly --HG-- branch : sha2
Diffstat (limited to 'common-kex.c')
-rw-r--r--common-kex.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/common-kex.c b/common-kex.c
index 2b3472b..c53fdf8 100644
--- a/common-kex.c
+++ b/common-kex.c
@@ -248,26 +248,28 @@ static void kexinitialise() {
* already initialised hash_state hs, which should already have processed
* the dh_K and hash, since these are common. X is the letter 'A', 'B' etc.
* out must have at least min(SHA1_HASH_SIZE, outlen) bytes allocated.
- * The output will only be expanded once, as we are assured that
- * outlen <= 2*SHA1_HASH_SIZE for all known hashes.
*
* See Section 7.2 of rfc4253 (ssh transport) for details */
static void hashkeys(unsigned char *out, int outlen,
const hash_state * hs, const unsigned char X) {
hash_state hs2;
- unsigned char k2[SHA1_HASH_SIZE]; /* used to extending */
+ int offset;
memcpy(&hs2, hs, sizeof(hash_state));
sha1_process(&hs2, &X, 1);
sha1_process(&hs2, ses.session_id, SHA1_HASH_SIZE);
sha1_done(&hs2, out);
- if (SHA1_HASH_SIZE < outlen) {
+ for (offset = SHA1_HASH_SIZE;
+ offset < outlen;
+ offset += SHA1_HASH_SIZE)
+ {
/* need to extend */
+ unsigned char k2[SHA1_HASH_SIZE];
memcpy(&hs2, hs, sizeof(hash_state));
- sha1_process(&hs2, out, SHA1_HASH_SIZE);
+ sha1_process(&hs2, out, offset);
sha1_done(&hs2, k2);
- memcpy(&out[SHA1_HASH_SIZE], k2, outlen - SHA1_HASH_SIZE);
+ memcpy(&out[offset], k2, MIN(outlen - offset, SHA1_HASH_SIZE));
}
}