summaryrefslogtreecommitdiff
path: root/umac.c
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>2014-04-20 13:33:19 +1000
committerDamien Miller <djm@mindrot.org>2014-04-20 13:33:19 +1000
commit888566913933a802f3a329ace123ebcb7154cf78 (patch)
treecdd8baba05c5505cf41d2e13c774f7e63e693dbc /umac.c
parent16f85cbc7e5139950e6a38317e7c8b368beafa5d (diff)
downloadopenssh-git-888566913933a802f3a329ace123ebcb7154cf78.tar.gz
- djm@cvs.openbsd.org 2014/04/20 02:30:25
[misc.c misc.h umac.c] use get/put_u32 to load values rather than *((UINT32 *)p) that breaks on strict-alignment architectures; reported by and ok stsp@
Diffstat (limited to 'umac.c')
-rw-r--r--umac.c48
1 files changed, 13 insertions, 35 deletions
diff --git a/umac.c b/umac.c
index 0c62145f..0cb64321 100644
--- a/umac.c
+++ b/umac.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: umac.c,v 1.8 2013/11/08 00:39:15 djm Exp $ */
+/* $OpenBSD: umac.c,v 1.9 2014/04/20 02:30:25 djm Exp $ */
/* -----------------------------------------------------------------------
*
* umac.c -- C Implementation UMAC Message Authentication
@@ -73,13 +73,15 @@
#include "includes.h"
#include <sys/types.h>
-
-#include "xmalloc.h"
-#include "umac.h"
#include <string.h>
+#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
+#include "xmalloc.h"
+#include "umac.h"
+#include "misc.h"
+
/* ---------------------------------------------------------------------- */
/* --- Primitive Data Types --- */
/* ---------------------------------------------------------------------- */
@@ -131,41 +133,17 @@ typedef unsigned int UWORD; /* Register */
/* --- Endian Conversion --- Forcing assembly on some platforms */
/* ---------------------------------------------------------------------- */
-#if HAVE_SWAP32
-#define LOAD_UINT32_REVERSED(p) (swap32(*(const UINT32 *)(p)))
-#define STORE_UINT32_REVERSED(p,v) (*(UINT32 *)(p) = swap32(v))
-#else /* HAVE_SWAP32 */
-
-static UINT32 LOAD_UINT32_REVERSED(const void *ptr)
-{
- UINT32 temp = *(const UINT32 *)ptr;
- temp = (temp >> 24) | ((temp & 0x00FF0000) >> 8 )
- | ((temp & 0x0000FF00) << 8 ) | (temp << 24);
- 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
- * thing on endian specific load and stores.
- */
-
#if (__LITTLE_ENDIAN__)
-#define LOAD_UINT32_LITTLE(ptr) (*(const UINT32 *)(ptr))
-#define STORE_UINT32_BIG(ptr,x) STORE_UINT32_REVERSED(ptr,x)
+#define LOAD_UINT32_REVERSED(p) get_u32(p)
+#define STORE_UINT32_REVERSED(p,v) put_u32(p,v)
#else
-#define LOAD_UINT32_LITTLE(ptr) LOAD_UINT32_REVERSED(ptr)
-#define STORE_UINT32_BIG(ptr,x) (*(UINT32 *)(ptr) = (UINT32)(x))
+#define LOAD_UINT32_REVERSED(p) get_u32_le(p)
+#define STORE_UINT32_REVERSED(p,v) put_u32_le(p,v)
#endif
+#define LOAD_UINT32_LITTLE(p) (get_u32_le(p))
+#define STORE_UINT32_BIG(p,v) put_u32(p, v)
+
/* ---------------------------------------------------------------------- */
/* ---------------------------------------------------------------------- */
/* ----- Begin KDF & PDF Section ---------------------------------------- */