X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=blobdiff_plain;f=sshcrcda.c;h=8d77cbb6052cf7e76256c6c628be7c8ec7a857dd;hb=01ead8590b5459393e6a87b5f591bce6fb8de8d3;hp=28210209b2496e451d7d1be1ac7a5bb5403a1769;hpb=107d1d875de8a2b19f71b6b4254f297c830591ac;p=PuTTY.git diff --git a/sshcrcda.c b/sshcrcda.c index 28210209..8d77cbb6 100644 --- a/sshcrcda.c +++ b/sshcrcda.c @@ -42,12 +42,6 @@ typedef unsigned short uint16; #define HASH_MINBLOCKS (7*SSH_BLOCKSIZE) -#define GET_32BIT_MSB_FIRST(cp) \ - (((unsigned long)(unsigned char)(cp)[0] << 24) | \ - ((unsigned long)(unsigned char)(cp)[1] << 16) | \ - ((unsigned long)(unsigned char)(cp)[2] << 8) | \ - ((unsigned long)(unsigned char)(cp)[3])) - /* Hash function (Input keys are cipher results) */ #define HASH(x) GET_32BIT_MSB_FIRST(x) @@ -63,7 +57,7 @@ struct crcda_ctx { void *crcda_make_context(void) { - struct crcda_ctx *ret = smalloc(sizeof(struct crcda_ctx)); + struct crcda_ctx *ret = snew(struct crcda_ctx); ret->h = NULL; ret->n = HASH_MINSIZE / HASH_ENTRYSIZE; return ret; @@ -71,7 +65,12 @@ void *crcda_make_context(void) void crcda_free_context(void *handle) { - sfree(handle); + struct crcda_ctx *ctx = (struct crcda_ctx *)handle; + if (ctx) { + sfree(ctx->h); + ctx->h = NULL; + sfree(ctx); + } } static void crc_update(uint32 *a, void *b) @@ -118,11 +117,11 @@ int detect_attack(void *handle, uchar *buf, uint32 len, uchar *IV) if (ctx->h == NULL) { ctx->n = l; - ctx->h = (uint16 *) smalloc(ctx->n * HASH_ENTRYSIZE); + ctx->h = snewn(ctx->n, uint16); } else { if (l > ctx->n) { ctx->n = l; - ctx->h = (uint16 *) srealloc(ctx->h, ctx->n * HASH_ENTRYSIZE); + ctx->h = sresize(ctx->h, ctx->n, uint16); } }