1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-09 17:38:00 +00:00

Add an 'extra' pointer field to ssh2_macalg.

Similar to the versions in ssh_cipheralg and ssh_keyalg, this allows a
set of vtables to share function pointers while providing varying
constant data that the shared function can use to vary its behaviour.

As an initial demonstration, I've used this to recombine the four
trivial text_name methods for the HMAC-SHA1 variants. I'm about to use
it for something more sensible, though.
This commit is contained in:
Simon Tatham 2019-01-20 11:37:05 +00:00
parent 1df39eb0a4
commit d73f692eea
2 changed files with 25 additions and 23 deletions

3
ssh.h
View File

@ -630,6 +630,9 @@ struct ssh2_macalg {
const char *(*text_name)(ssh2_mac *);
const char *name, *etm_name;
int len, keylen;
/* Pointer to any extra data used by a particular implementation. */
const void *extra;
};
#define ssh2_mac_new(alg, cipher) ((alg)->new(alg, cipher))

View File

@ -375,52 +375,51 @@ void hmac_sha1_simple(const void *key, int keylen,
SHA_Final(&states[1], output);
}
struct hmacsha1_extra {
const char *textname;
};
static const char *hmacsha1_text_name(ssh2_mac *mac)
{
return "HMAC-SHA1";
}
static const char *hmacsha196_text_name(ssh2_mac *mac)
{
return "HMAC-SHA1-96";
}
static const char *hmacsha1bug_text_name(ssh2_mac *mac)
{
return "bug-compatible HMAC-SHA1";
}
static const char *hmacsha196bug_text_name(ssh2_mac *mac)
{
return "bug-compatible HMAC-SHA1-96";
const struct hmacsha1_extra *extra =
(const struct hmacsha1_extra *)mac->vt->extra;
return extra->textname;
}
const struct hmacsha1_extra ssh_hmac_sha1_extra = { "HMAC-SHA1" };
const ssh2_macalg ssh_hmac_sha1 = {
hmacsha1_new, hmacsha1_free, hmacsha1_key,
hmacsha1_start, hmacsha1_genresult, hmacsha1_text_name,
"hmac-sha1", "hmac-sha1-etm@openssh.com",
20, 20,
20, 20, &ssh_hmac_sha1_extra,
};
const struct hmacsha1_extra ssh_hmac_sha1_96_extra = { "HMAC-SHA1-96" };
const ssh2_macalg ssh_hmac_sha1_96 = {
hmacsha1_new, hmacsha1_free, hmacsha1_key,
hmacsha1_start, hmacsha1_genresult, hmacsha196_text_name,
hmacsha1_start, hmacsha1_genresult, hmacsha1_text_name,
"hmac-sha1-96", "hmac-sha1-96-etm@openssh.com",
12, 20,
12, 20, &ssh_hmac_sha1_96_extra,
};
const struct hmacsha1_extra ssh_hmac_sha1_buggy_extra = {
"bug-compatible HMAC-SHA1",
};
const ssh2_macalg ssh_hmac_sha1_buggy = {
hmacsha1_new, hmacsha1_free, hmacsha1_key,
hmacsha1_start, hmacsha1_genresult, hmacsha1bug_text_name,
hmacsha1_start, hmacsha1_genresult, hmacsha1_text_name,
"hmac-sha1", NULL,
20, 16,
20, 16, &ssh_hmac_sha1_buggy_extra,
};
const struct hmacsha1_extra ssh_hmac_sha1_96_buggy_extra = {
"bug-compatible HMAC-SHA1-96",
};
const ssh2_macalg ssh_hmac_sha1_96_buggy = {
hmacsha1_new, hmacsha1_free, hmacsha1_key,
hmacsha1_start, hmacsha1_genresult, hmacsha196bug_text_name,
hmacsha1_start, hmacsha1_genresult, hmacsha1_text_name,
"hmac-sha1-96", NULL,
12, 16,
12, 16, &ssh_hmac_sha1_96_buggy_extra,
};
#ifdef COMPILER_SUPPORTS_SHA_NI