mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-07-16 02:27:32 -05:00
Make lots more algorithm structures globally visible.
Previously, lots of individual ssh2_cipheralg structures were declared static, and only available to the rest of the code via a smaller number of 'ssh2_ciphers' objects that wrapped them into lists. But I'm going to want to access individual ciphers directly in the testing system I'm currently working on, so I'm giving all those objects external linkage and declaring them in ssh.h. Also, I've made up an entirely new one, namely exposing MD5 as an instance of the general ssh_hashalg abstraction, which it has no need to be for the purposes of actually using it in SSH. But, again, this will let me treat it the same as all the other hashes in the test system. No functional change, for the moment.
This commit is contained in:
51
sshmd5.c
51
sshmd5.c
@ -211,6 +211,57 @@ void MD5Simple(void const *p, unsigned len, unsigned char output[16])
|
||||
smemclr(&s, sizeof(s));
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
* Thin abstraction for things where hashes are pluggable.
|
||||
*/
|
||||
|
||||
struct md5_hash {
|
||||
struct MD5Context state;
|
||||
ssh_hash hash;
|
||||
};
|
||||
|
||||
static ssh_hash *md5_new(const struct ssh_hashalg *alg)
|
||||
{
|
||||
struct md5_hash *h = snew(struct md5_hash);
|
||||
MD5Init(&h->state);
|
||||
h->hash.vt = alg;
|
||||
BinarySink_DELEGATE_INIT(&h->hash, &h->state);
|
||||
return &h->hash;
|
||||
}
|
||||
|
||||
static ssh_hash *md5_copy(ssh_hash *hashold)
|
||||
{
|
||||
struct md5_hash *hold, *hnew;
|
||||
ssh_hash *hashnew = md5_new(hashold->vt);
|
||||
|
||||
hold = container_of(hashold, struct md5_hash, hash);
|
||||
hnew = container_of(hashnew, struct md5_hash, hash);
|
||||
|
||||
hnew->state = hold->state;
|
||||
BinarySink_COPIED(&hnew->state);
|
||||
|
||||
return hashnew;
|
||||
}
|
||||
|
||||
static void md5_free(ssh_hash *hash)
|
||||
{
|
||||
struct md5_hash *h = container_of(hash, struct md5_hash, hash);
|
||||
|
||||
smemclr(h, sizeof(*h));
|
||||
sfree(h);
|
||||
}
|
||||
|
||||
static void md5_final(ssh_hash *hash, unsigned char *output)
|
||||
{
|
||||
struct md5_hash *h = container_of(hash, struct md5_hash, hash);
|
||||
MD5Final(output, &h->state);
|
||||
md5_free(hash);
|
||||
}
|
||||
|
||||
const struct ssh_hashalg ssh_md5 = {
|
||||
md5_new, md5_copy, md5_final, md5_free, 16, "MD5"
|
||||
};
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
* The above is the MD5 algorithm itself. Now we implement the
|
||||
* HMAC wrapper on it.
|
||||
|
Reference in New Issue
Block a user