diff options
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | misc.c | 26 | ||||
-rw-r--r-- | misc.h | 8 | ||||
-rw-r--r-- | umac.c | 48 |
4 files changed, 49 insertions, 37 deletions
@@ -122,6 +122,10 @@ | |||
122 | [ssh.1] | 122 | [ssh.1] |
123 | delete .xr to hosts.equiv. there's still an unfortunate amount of | 123 | delete .xr to hosts.equiv. there's still an unfortunate amount of |
124 | documentation referring to rhosts equivalency in here. | 124 | documentation referring to rhosts equivalency in here. |
125 | - djm@cvs.openbsd.org 2014/04/20 02:30:25 | ||
126 | [misc.c misc.h umac.c] | ||
127 | use get/put_u32 to load values rather than *((UINT32 *)p) that breaks on | ||
128 | strict-alignment architectures; reported by and ok stsp@ | ||
125 | 129 | ||
126 | 20140401 | 130 | 20140401 |
127 | - (djm) On platforms that support it, use prctl() to prevent sftp-server | 131 | - (djm) On platforms that support it, use prctl() to prevent sftp-server |
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: misc.c,v 1.92 2013/10/14 23:28:23 djm Exp $ */ | 1 | /* $OpenBSD: misc.c,v 1.93 2014/04/20 02:30:25 djm Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2000 Markus Friedl. All rights reserved. | 3 | * Copyright (c) 2000 Markus Friedl. All rights reserved. |
4 | * Copyright (c) 2005,2006 Damien Miller. All rights reserved. | 4 | * Copyright (c) 2005,2006 Damien Miller. All rights reserved. |
@@ -788,6 +788,20 @@ get_u32(const void *vp) | |||
788 | return (v); | 788 | return (v); |
789 | } | 789 | } |
790 | 790 | ||
791 | u_int32_t | ||
792 | get_u32_le(const void *vp) | ||
793 | { | ||
794 | const u_char *p = (const u_char *)vp; | ||
795 | u_int32_t v; | ||
796 | |||
797 | v = (u_int32_t)p[0]; | ||
798 | v |= (u_int32_t)p[1] << 8; | ||
799 | v |= (u_int32_t)p[2] << 16; | ||
800 | v |= (u_int32_t)p[3] << 24; | ||
801 | |||
802 | return (v); | ||
803 | } | ||
804 | |||
791 | u_int16_t | 805 | u_int16_t |
792 | get_u16(const void *vp) | 806 | get_u16(const void *vp) |
793 | { | 807 | { |
@@ -826,6 +840,16 @@ put_u32(void *vp, u_int32_t v) | |||
826 | p[3] = (u_char)v & 0xff; | 840 | p[3] = (u_char)v & 0xff; |
827 | } | 841 | } |
828 | 842 | ||
843 | void | ||
844 | put_u32_le(void *vp, u_int32_t v) | ||
845 | { | ||
846 | u_char *p = (u_char *)vp; | ||
847 | |||
848 | p[0] = (u_char)v & 0xff; | ||
849 | p[1] = (u_char)(v >> 8) & 0xff; | ||
850 | p[2] = (u_char)(v >> 16) & 0xff; | ||
851 | p[3] = (u_char)(v >> 24) & 0xff; | ||
852 | } | ||
829 | 853 | ||
830 | void | 854 | void |
831 | put_u16(void *vp, u_int16_t v) | 855 | put_u16(void *vp, u_int16_t v) |
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: misc.h,v 1.51 2014/03/26 04:55:35 djm Exp $ */ | 1 | /* $OpenBSD: misc.h,v 1.52 2014/04/20 02:30:25 djm Exp $ */ |
2 | 2 | ||
3 | /* | 3 | /* |
4 | * Author: Tatu Ylonen <ylo@cs.hut.fi> | 4 | * Author: Tatu Ylonen <ylo@cs.hut.fi> |
@@ -82,6 +82,12 @@ void put_u32(void *, u_int32_t) | |||
82 | void put_u16(void *, u_int16_t) | 82 | void put_u16(void *, u_int16_t) |
83 | __bounded(( __minbytes__, 1, 2)); | 83 | __bounded(( __minbytes__, 1, 2)); |
84 | 84 | ||
85 | /* Little-endian store/load, used by umac.c */ | ||
86 | u_int32_t get_u32_le(const void *) | ||
87 | __bounded(( __minbytes__, 1, 4)); | ||
88 | void put_u32_le(void *, u_int32_t) | ||
89 | __bounded(( __minbytes__, 1, 4)); | ||
90 | |||
85 | struct bwlimit { | 91 | struct bwlimit { |
86 | size_t buflen; | 92 | size_t buflen; |
87 | u_int64_t rate, thresh, lamt; | 93 | u_int64_t rate, thresh, lamt; |
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: umac.c,v 1.8 2013/11/08 00:39:15 djm Exp $ */ | 1 | /* $OpenBSD: umac.c,v 1.9 2014/04/20 02:30:25 djm Exp $ */ |
2 | /* ----------------------------------------------------------------------- | 2 | /* ----------------------------------------------------------------------- |
3 | * | 3 | * |
4 | * umac.c -- C Implementation UMAC Message Authentication | 4 | * umac.c -- C Implementation UMAC Message Authentication |
@@ -73,13 +73,15 @@ | |||
73 | 73 | ||
74 | #include "includes.h" | 74 | #include "includes.h" |
75 | #include <sys/types.h> | 75 | #include <sys/types.h> |
76 | |||
77 | #include "xmalloc.h" | ||
78 | #include "umac.h" | ||
79 | #include <string.h> | 76 | #include <string.h> |
77 | #include <stdio.h> | ||
80 | #include <stdlib.h> | 78 | #include <stdlib.h> |
81 | #include <stddef.h> | 79 | #include <stddef.h> |
82 | 80 | ||
81 | #include "xmalloc.h" | ||
82 | #include "umac.h" | ||
83 | #include "misc.h" | ||
84 | |||
83 | /* ---------------------------------------------------------------------- */ | 85 | /* ---------------------------------------------------------------------- */ |
84 | /* --- Primitive Data Types --- */ | 86 | /* --- Primitive Data Types --- */ |
85 | /* ---------------------------------------------------------------------- */ | 87 | /* ---------------------------------------------------------------------- */ |
@@ -131,41 +133,17 @@ typedef unsigned int UWORD; /* Register */ | |||
131 | /* --- Endian Conversion --- Forcing assembly on some platforms */ | 133 | /* --- Endian Conversion --- Forcing assembly on some platforms */ |
132 | /* ---------------------------------------------------------------------- */ | 134 | /* ---------------------------------------------------------------------- */ |
133 | 135 | ||
134 | #if HAVE_SWAP32 | ||
135 | #define LOAD_UINT32_REVERSED(p) (swap32(*(const UINT32 *)(p))) | ||
136 | #define STORE_UINT32_REVERSED(p,v) (*(UINT32 *)(p) = swap32(v)) | ||
137 | #else /* HAVE_SWAP32 */ | ||
138 | |||
139 | static UINT32 LOAD_UINT32_REVERSED(const void *ptr) | ||
140 | { | ||
141 | UINT32 temp = *(const UINT32 *)ptr; | ||
142 | temp = (temp >> 24) | ((temp & 0x00FF0000) >> 8 ) | ||
143 | | ((temp & 0x0000FF00) << 8 ) | (temp << 24); | ||
144 | return (UINT32)temp; | ||
145 | } | ||
146 | |||
147 | # if (__LITTLE_ENDIAN__) | ||
148 | static void STORE_UINT32_REVERSED(void *ptr, UINT32 x) | ||
149 | { | ||
150 | UINT32 i = (UINT32)x; | ||
151 | *(UINT32 *)ptr = (i >> 24) | ((i & 0x00FF0000) >> 8 ) | ||
152 | | ((i & 0x0000FF00) << 8 ) | (i << 24); | ||
153 | } | ||
154 | # endif /* __LITTLE_ENDIAN */ | ||
155 | #endif /* HAVE_SWAP32 */ | ||
156 | |||
157 | /* The following definitions use the above reversal-primitives to do the right | ||
158 | * thing on endian specific load and stores. | ||
159 | */ | ||
160 | |||
161 | #if (__LITTLE_ENDIAN__) | 136 | #if (__LITTLE_ENDIAN__) |
162 | #define LOAD_UINT32_LITTLE(ptr) (*(const UINT32 *)(ptr)) | 137 | #define LOAD_UINT32_REVERSED(p) get_u32(p) |
163 | #define STORE_UINT32_BIG(ptr,x) STORE_UINT32_REVERSED(ptr,x) | 138 | #define STORE_UINT32_REVERSED(p,v) put_u32(p,v) |
164 | #else | 139 | #else |
165 | #define LOAD_UINT32_LITTLE(ptr) LOAD_UINT32_REVERSED(ptr) | 140 | #define LOAD_UINT32_REVERSED(p) get_u32_le(p) |
166 | #define STORE_UINT32_BIG(ptr,x) (*(UINT32 *)(ptr) = (UINT32)(x)) | 141 | #define STORE_UINT32_REVERSED(p,v) put_u32_le(p,v) |
167 | #endif | 142 | #endif |
168 | 143 | ||
144 | #define LOAD_UINT32_LITTLE(p) (get_u32_le(p)) | ||
145 | #define STORE_UINT32_BIG(p,v) put_u32(p, v) | ||
146 | |||
169 | /* ---------------------------------------------------------------------- */ | 147 | /* ---------------------------------------------------------------------- */ |
170 | /* ---------------------------------------------------------------------- */ | 148 | /* ---------------------------------------------------------------------- */ |
171 | /* ----- Begin KDF & PDF Section ---------------------------------------- */ | 149 | /* ----- Begin KDF & PDF Section ---------------------------------------- */ |