X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=blobdiff_plain;f=sshmd5.c;h=e5187a661662b4b793330055f717222b503a0572;hb=3e22c99c9a3c28e042f2dc3a50fadf95e7c277e7;hp=8913340877bb53976792adc450e7739dd72018c2;hpb=3af7d333401755a7decbb74c23037fc07017002c;p=PuTTY.git diff --git a/sshmd5.c b/sshmd5.c index 89133408..e5187a66 100644 --- a/sshmd5.c +++ b/sshmd5.c @@ -222,7 +222,7 @@ void MD5Simple(void const *p, unsigned len, unsigned char output[16]) void *hmacmd5_make_context(void) { - return snewn(2, struct MD5Context); + return snewn(3, struct MD5Context); } void hmacmd5_free_context(void *handle) @@ -230,10 +230,11 @@ void hmacmd5_free_context(void *handle) sfree(handle); } -void hmacmd5_key(void *handle, unsigned char const *key, int len) +void hmacmd5_key(void *handle, void const *keyv, int len) { struct MD5Context *keys = (struct MD5Context *)handle; unsigned char foo[64]; + unsigned char const *key = (unsigned char const *)keyv; int i; memset(foo, 0x36, 64); @@ -248,7 +249,7 @@ void hmacmd5_key(void *handle, unsigned char const *key, int len) MD5Init(&keys[1]); MD5Update(&keys[1], foo, 64); - memset(foo, 0, 64); /* burn the evidence */ + smemclr(foo, 64); /* burn the evidence */ } static void hmacmd5_key_16(void *handle, unsigned char *key) @@ -256,24 +257,50 @@ static void hmacmd5_key_16(void *handle, unsigned char *key) hmacmd5_key(handle, key, 16); } -static void hmacmd5_do_hmac_internal(void *handle, - unsigned char const *blk, int len, - unsigned char const *blk2, int len2, - unsigned char *hmac) +static void hmacmd5_start(void *handle) +{ + struct MD5Context *keys = (struct MD5Context *)handle; + + keys[2] = keys[0]; /* structure copy */ +} + +static void hmacmd5_bytes(void *handle, unsigned char const *blk, int len) +{ + struct MD5Context *keys = (struct MD5Context *)handle; + MD5Update(&keys[2], blk, len); +} + +static void hmacmd5_genresult(void *handle, unsigned char *hmac) { struct MD5Context *keys = (struct MD5Context *)handle; struct MD5Context s; unsigned char intermediate[16]; - s = keys[0]; /* structure copy */ - MD5Update(&s, blk, len); - if (blk2) MD5Update(&s, blk2, len2); + s = keys[2]; /* structure copy */ MD5Final(intermediate, &s); s = keys[1]; /* structure copy */ MD5Update(&s, intermediate, 16); MD5Final(hmac, &s); } +static int hmacmd5_verresult(void *handle, unsigned char const *hmac) +{ + unsigned char correct[16]; + hmacmd5_genresult(handle, correct); + return !memcmp(correct, hmac, 16); +} + +static void hmacmd5_do_hmac_internal(void *handle, + unsigned char const *blk, int len, + unsigned char const *blk2, int len2, + unsigned char *hmac) +{ + hmacmd5_start(handle); + hmacmd5_bytes(handle, blk, len); + if (blk2) hmacmd5_bytes(handle, blk2, len2); + hmacmd5_genresult(handle, hmac); +} + void hmacmd5_do_hmac(void *handle, unsigned char const *blk, int len, unsigned char *hmac) { @@ -307,9 +334,11 @@ static int hmacmd5_verify(void *handle, unsigned char *blk, int len, return !memcmp(correct, blk + len, 16); } -const struct ssh_mac ssh_md5 = { +const struct ssh_mac ssh_hmac_md5 = { hmacmd5_make_context, hmacmd5_free_context, hmacmd5_key_16, hmacmd5_generate, hmacmd5_verify, + hmacmd5_start, hmacmd5_bytes, hmacmd5_genresult, hmacmd5_verresult, "hmac-md5", - 16 + 16, + "HMAC-MD5" };