X-Git-Url: http://andersk.mit.edu/gitweb/openssh.git/blobdiff_plain/cc43e89444eec868f2c8bd9de9f8bac4bd40d727..82aeff0ca62bfec5731c4611eac59d2af39ebe3d:/umac.c diff --git a/umac.c b/umac.c index c2fdcf44..92902bc0 100644 --- a/umac.c +++ b/umac.c @@ -1,4 +1,4 @@ -/* $OpenBSD: umac.c,v 1.1 2007/06/07 19:37:34 pvalchev Exp $ */ +/* $OpenBSD: umac.c,v 1.3 2008/05/12 20:52:20 pvalchev Exp $ */ /* ----------------------------------------------------------------------- * * umac.c -- C Implementation UMAC Message Authentication @@ -66,6 +66,7 @@ #include "includes.h" #include +#include "xmalloc.h" #include "umac.h" #include #include @@ -135,12 +136,14 @@ static UINT32 LOAD_UINT32_REVERSED(void *ptr) return (UINT32)temp; } +# if (__LITTLE_ENDIAN__) static void STORE_UINT32_REVERSED(void *ptr, UINT32 x) { UINT32 i = (UINT32)x; *(UINT32 *)ptr = (i >> 24) | ((i & 0x00FF0000) >> 8 ) | ((i & 0x0000FF00) << 8 ) | (i << 24); } +# endif /* __LITTLE_ENDIAN */ #endif /* HAVE_SWAP32 */ /* The following definitions use the above reversal-primitives to do the right @@ -178,14 +181,14 @@ typedef AES_KEY aes_int_key[1]; /* The user-supplied UMAC key is stretched using AES in a counter * mode to supply all random bits needed by UMAC. The kdf function takes * an AES internal key representation 'key' and writes a stream of - * 'nbytes' bytes to the memory pointed at by 'buffer_ptr'. Each distinct + * 'nbytes' bytes to the memory pointed at by 'bufp'. Each distinct * 'ndx' causes a distinct byte stream. */ -static void kdf(void *buffer_ptr, aes_int_key key, UINT8 ndx, int nbytes) +static void kdf(void *bufp, aes_int_key key, UINT8 ndx, int nbytes) { UINT8 in_buf[AES_BLOCK_LEN] = {0}; UINT8 out_buf[AES_BLOCK_LEN]; - UINT8 *dst_buf = (UINT8 *)buffer_ptr; + UINT8 *dst_buf = (UINT8 *)bufp; int i; /* Setup the initial value */ @@ -543,6 +546,7 @@ static void nh_transform(nh_ctx *hc, UINT8 *buf, UINT32 nbytes) /* ---------------------------------------------------------------------- */ +#if (__LITTLE_ENDIAN__) static void endian_convert(void *buf, UWORD bpw, UINT32 num_bytes) /* We endian convert the keys on little-endian computers to */ /* compensate for the lack of big-endian memory reads during hashing. */ @@ -565,7 +569,6 @@ static void endian_convert(void *buf, UWORD bpw, UINT32 num_bytes) } while (--iters); } } -#if (__LITTLE_ENDIAN__) #define endian_convert_if_le(x,y,z) endian_convert((x),(y),(z)) #else #define endian_convert_if_le(x,y,z) do{}while(0) /* Do nothing */ @@ -1042,7 +1045,8 @@ static int uhash_update(uhash_ctx_t ctx, u_char *input, long len) */ { UWORD bytes_hashed, bytes_remaining; - UINT8 nh_result[STREAMS*sizeof(UINT64)]; + UINT64 result_buf[STREAMS]; + UINT8 *nh_result = (UINT8 *)&result_buf; if (ctx->msg_len + len <= L1_KEY_LEN) { nh_update(&ctx->hash, (UINT8 *)input, len); @@ -1094,7 +1098,8 @@ static int uhash_update(uhash_ctx_t ctx, u_char *input, long len) static int uhash_final(uhash_ctx_t ctx, u_char *res) /* Incorporate any pending data, pad, and generate tag */ { - UINT8 nh_result[STREAMS*sizeof(UINT64)]; + UINT64 result_buf[STREAMS]; + UINT8 *nh_result = (UINT8 *)&result_buf; if (ctx->msg_len > L1_KEY_LEN) { if (ctx->msg_len % L1_KEY_LEN) { @@ -1196,7 +1201,7 @@ int umac_delete(struct umac_ctx *ctx) if (ctx) { if (ALLOC_BOUNDARY) ctx = (struct umac_ctx *)ctx->free_ptr; - free(ctx); + xfree(ctx); } return (1); } @@ -1212,7 +1217,7 @@ struct umac_ctx *umac_new(u_char key[]) size_t bytes_to_add; aes_int_key prf_key; - octx = ctx = malloc(sizeof(*ctx) + ALLOC_BOUNDARY); + octx = ctx = xmalloc(sizeof(*ctx) + ALLOC_BOUNDARY); if (ctx) { if (ALLOC_BOUNDARY) { bytes_to_add = ALLOC_BOUNDARY -