1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-07-14 09:37:34 -05:00

Make ssh_hash and ssh_mac expose a BinarySink.

Just as I did a few commits ago with the low-level SHA_Bytes type
functions, the ssh_hash and ssh_mac abstract types now no longer have
a direct foo->bytes() update method at all. Instead, each one has a
foo->sink() function that returns a BinarySink with the same lifetime
as the hash context, and then the caller can feed data into that in
the usual way.

This lets me get rid of a couple more duplicate marshalling routines
in ssh.c: hash_string(), hash_uint32(), hash_mpint().
This commit is contained in:
Simon Tatham
2018-05-24 13:05:48 +01:00
parent 67de463cca
commit e27ddf6d28
9 changed files with 105 additions and 133 deletions

View File

@ -355,11 +355,10 @@ static void sha512_free(void *handle)
sfree(s);
}
static void sha512_bytes(void *handle, const void *p, int len)
static BinarySink *sha512_sink(void *handle)
{
SHA512_State *s = handle;
put_data(s, p, len);
return BinarySink_UPCAST(s);
}
static void sha512_final(void *handle, unsigned char *output)
@ -371,7 +370,7 @@ static void sha512_final(void *handle, unsigned char *output)
}
const struct ssh_hash ssh_sha512 = {
sha512_init, sha512_copy, sha512_bytes, sha512_final, sha512_free,
sha512_init, sha512_copy, sha512_sink, sha512_final, sha512_free,
64, "SHA-512"
};
@ -394,7 +393,7 @@ static void sha384_final(void *handle, unsigned char *output)
}
const struct ssh_hash ssh_sha384 = {
sha384_init, sha512_copy, sha512_bytes, sha384_final, sha512_free,
sha384_init, sha512_copy, sha512_sink, sha384_final, sha512_free,
48, "SHA-384"
};