1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-07-06 22:12:47 -05:00

Replace all uses of SHA*_Bytes / MD5Update.

In fact, those functions don't even exist any more. The only way to
get data into a primitive hash state is via the new put_* system. Of
course, that means put_data() is a viable replacement for every
previous call to one of the per-hash update functions - but just
mechanically doing that would have missed the opportunity to simplify
a lot of the call sites.
This commit is contained in:
Simon Tatham
2018-05-24 10:03:36 +01:00
parent f1b1b1d260
commit 4988fd410c
15 changed files with 138 additions and 203 deletions

View File

@ -1,3 +1,4 @@
#include <assert.h>
#include "ssh.h"
/*
@ -115,12 +116,7 @@ static void MD5_Block(MD5_Core_State * s, uint32 * block)
#define BLKSIZE 64
static void MD5_BinarySink_write(BinarySink *bs,
const void *data, size_t len)
{
struct MD5Context *s = BinarySink_DOWNCAST(bs, struct MD5Context);
MD5Update(s, data, len);
}
static void MD5_BinarySink_write(BinarySink *bs, const void *data, size_t len);
void MD5Init(struct MD5Context *s)
{
@ -130,13 +126,16 @@ void MD5Init(struct MD5Context *s)
BinarySink_INIT(s, MD5_BinarySink_write);
}
void MD5Update(struct MD5Context *s, unsigned char const *p, unsigned len)
static void MD5_BinarySink_write(BinarySink *bs, const void *data, size_t len)
{
unsigned char *q = (unsigned char *) p;
struct MD5Context *s = BinarySink_DOWNCAST(bs, struct MD5Context);
const unsigned char *q = (const unsigned char *)data;
uint32 wordblock[16];
uint32 lenw = len;
int i;
assert(lenw == len);
/*
* Update the length field.
*/
@ -190,7 +189,7 @@ void MD5Final(unsigned char output[16], struct MD5Context *s)
memset(c, 0, pad);
c[0] = 0x80;
MD5Update(s, c, pad);
put_data(s, c, pad);
c[7] = (lenhi >> 24) & 0xFF;
c[6] = (lenhi >> 16) & 0xFF;
@ -201,7 +200,7 @@ void MD5Final(unsigned char output[16], struct MD5Context *s)
c[1] = (lenlo >> 8) & 0xFF;
c[0] = (lenlo >> 0) & 0xFF;
MD5Update(s, c, 8);
put_data(s, c, 8);
for (i = 0; i < 4; i++) {
output[4 * i + 3] = (s->core.h[i] >> 24) & 0xFF;
@ -216,7 +215,7 @@ void MD5Simple(void const *p, unsigned len, unsigned char output[16])
struct MD5Context s;
MD5Init(&s);
MD5Update(&s, (unsigned char const *)p, len);
put_data(&s, (unsigned char const *)p, len);
MD5Final(output, &s);
smemclr(&s, sizeof(s));
}
@ -251,13 +250,13 @@ void hmacmd5_key(void *handle, void const *keyv, int len)
for (i = 0; i < len && i < 64; i++)
foo[i] ^= key[i];
MD5Init(&keys[0]);
MD5Update(&keys[0], foo, 64);
put_data(&keys[0], foo, 64);
memset(foo, 0x5C, 64);
for (i = 0; i < len && i < 64; i++)
foo[i] ^= key[i];
MD5Init(&keys[1]);
MD5Update(&keys[1], foo, 64);
put_data(&keys[1], foo, 64);
smemclr(foo, 64); /* burn the evidence */
}
@ -278,7 +277,7 @@ static void hmacmd5_start(void *handle)
static void hmacmd5_bytes(void *handle, unsigned char const *blk, int len)
{
struct MD5Context *keys = (struct MD5Context *)handle;
MD5Update(&keys[2], blk, len);
put_data(&keys[2], blk, len);
}
static void hmacmd5_genresult(void *handle, unsigned char *hmac)
@ -292,7 +291,7 @@ static void hmacmd5_genresult(void *handle, unsigned char *hmac)
MD5Final(intermediate, &s);
s = keys[1]; /* structure copy */
BinarySink_COPIED(&s);
MD5Update(&s, intermediate, 16);
put_data(&s, intermediate, 16);
MD5Final(hmac, &s);
}