X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=blobdiff_plain;f=sshsha.c;h=c10a82177ced3d64294a51747ec0f3155bd72bd8;hb=12a080874fd9e5a4ae0a6dc39fb54b152927075d;hp=31d6daa992d11988ab68ebe24caeddbe9041c440;hpb=26d3ccdfc5500a8afdbd54938677ef4ef985caaa;p=PuTTY.git diff --git a/sshsha.c b/sshsha.c index 31d6daa9..c10a8217 100644 --- a/sshsha.c +++ b/sshsha.c @@ -214,6 +214,7 @@ void SHA_Simple(const void *p, int len, unsigned char *output) SHA_Init(&s); SHA_Bytes(&s, p, len); SHA_Final(&s, output); + smemclr(&s, sizeof(s)); } /* @@ -229,7 +230,25 @@ static void *sha1_init(void) return s; } -static void sha1_bytes(void *handle, void *p, int len) +static void *sha1_copy(const void *vold) +{ + const SHA_State *old = (const SHA_State *)vold; + SHA_State *s; + + s = snew(SHA_State); + *s = *old; + return s; +} + +static void sha1_free(void *handle) +{ + SHA_State *s = handle; + + smemclr(s, sizeof(*s)); + sfree(s); +} + +static void sha1_bytes(void *handle, const void *p, int len) { SHA_State *s = handle; @@ -241,11 +260,11 @@ static void sha1_final(void *handle, unsigned char *output) SHA_State *s = handle; SHA_Final(s, output); - sfree(s); + sha1_free(s); } const struct ssh_hash ssh_sha1 = { - sha1_init, sha1_bytes, sha1_final, 20, "SHA-1" + sha1_init, sha1_copy, sha1_bytes, sha1_final, sha1_free, 20, "SHA-1" }; /* ---------------------------------------------------------------------- @@ -253,13 +272,14 @@ const struct ssh_hash ssh_sha1 = { * HMAC wrapper on it. */ -static void *sha1_make_context(void) +static void *sha1_make_context(void *cipher_ctx) { return snewn(3, SHA_State); } static void sha1_free_context(void *handle) { + smemclr(handle, 3 * sizeof(SHA_State)); sfree(handle); } @@ -400,8 +420,8 @@ const struct ssh_mac ssh_hmac_sha1 = { sha1_make_context, sha1_free_context, sha1_key, sha1_generate, sha1_verify, hmacsha1_start, hmacsha1_bytes, hmacsha1_genresult, hmacsha1_verresult, - "hmac-sha1", - 20, + "hmac-sha1", "hmac-sha1-etm@openssh.com", + 20, 20, "HMAC-SHA1" }; @@ -410,8 +430,8 @@ const struct ssh_mac ssh_hmac_sha1_96 = { sha1_96_generate, sha1_96_verify, hmacsha1_start, hmacsha1_bytes, hmacsha1_96_genresult, hmacsha1_96_verresult, - "hmac-sha1-96", - 12, + "hmac-sha1-96", "hmac-sha1-96-etm@openssh.com", + 12, 20, "HMAC-SHA1-96" }; @@ -419,8 +439,8 @@ const struct ssh_mac ssh_hmac_sha1_buggy = { sha1_make_context, sha1_free_context, sha1_key_buggy, sha1_generate, sha1_verify, hmacsha1_start, hmacsha1_bytes, hmacsha1_genresult, hmacsha1_verresult, - "hmac-sha1", - 20, + "hmac-sha1", NULL, + 20, 16, "bug-compatible HMAC-SHA1" }; @@ -429,7 +449,7 @@ const struct ssh_mac ssh_hmac_sha1_96_buggy = { sha1_96_generate, sha1_96_verify, hmacsha1_start, hmacsha1_bytes, hmacsha1_96_genresult, hmacsha1_96_verresult, - "hmac-sha1-96", - 12, + "hmac-sha1-96", NULL, + 12, 16, "bug-compatible HMAC-SHA1-96" };