]> andersk Git - openssh.git/blobdiff - umac.c
- djm@cvs.openbsd.org 2010/01/30 02:54:53
[openssh.git] / umac.c
diff --git a/umac.c b/umac.c
index 676705c9cbb5882bdb730a71e145f3f27059c24d..92902bc09b2f0250c5bbdcfe068d29b47f99938e 100644 (file)
--- 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 <sys/types.h>
 
+#include "xmalloc.h"
 #include "umac.h"
 #include <string.h>
 #include <stdlib.h>
@@ -122,7 +123,11 @@ typedef unsigned int       UWORD;  /* Register */
 /* --- Endian Conversion --- Forcing assembly on some platforms           */
 /* ---------------------------------------------------------------------- */
 
-#if 0
+#if HAVE_SWAP32
+#define LOAD_UINT32_REVERSED(p)                (swap32(*(UINT32 *)(p)))
+#define STORE_UINT32_REVERSED(p,v)     (*(UINT32 *)(p) = swap32(v))
+#else /* HAVE_SWAP32 */
+
 static UINT32 LOAD_UINT32_REVERSED(void *ptr)
 {
     UINT32 temp = *(UINT32 *)ptr;
@@ -131,21 +136,20 @@ 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
+# endif /* __LITTLE_ENDIAN */
+#endif /* HAVE_SWAP32 */
 
 /* The following definitions use the above reversal-primitives to do the right
  * thing on endian specific load and stores.
  */
 
-#define LOAD_UINT32_REVERSED(p)                (swap32(*(UINT32 *)(p)))
-#define STORE_UINT32_REVERSED(p,v)     (*(UINT32 *)(p) = swap32(v))
-
 #if (__LITTLE_ENDIAN__)
 #define LOAD_UINT32_LITTLE(ptr)     (*(UINT32 *)(ptr))
 #define STORE_UINT32_BIG(ptr,x)     STORE_UINT32_REVERSED(ptr,x)
@@ -154,8 +158,6 @@ static void STORE_UINT32_REVERSED(void *ptr, UINT32 x)
 #define STORE_UINT32_BIG(ptr,x)     (*(UINT32 *)(ptr) = (UINT32)(x))
 #endif
 
-
-
 /* ---------------------------------------------------------------------- */
 /* ---------------------------------------------------------------------- */
 /* ----- Begin KDF & PDF Section ---------------------------------------- */
@@ -166,7 +168,10 @@ static void STORE_UINT32_REVERSED(void *ptr, UINT32 x)
 #define AES_BLOCK_LEN  16
 
 /* OpenSSL's AES */
-#include <openssl/aes.h>
+#include "openbsd-compat/openssl-compat.h"
+#ifndef USE_BUILTIN_RIJNDAEL
+# include <openssl/aes.h>
+#endif
 typedef AES_KEY aes_int_key[1];
 #define aes_encryption(in,out,int_key)                  \
   AES_encrypt((u_char *)(in),(u_char *)(out),(AES_KEY *)int_key)
@@ -176,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 */
@@ -541,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.     */
@@ -563,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 */
@@ -1040,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);
@@ -1092,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) {
@@ -1194,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);
 }
@@ -1210,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 -
This page took 0.316814 seconds and 4 git commands to generate.