#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)
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;
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)
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);
}
}