summaryrefslogtreecommitdiff
path: root/mac.c
diff options
context:
space:
mode:
authorDarren Tucker <dtucker@zip.com.au>2013-06-06 08:12:37 +1000
committerDarren Tucker <dtucker@zip.com.au>2013-06-06 08:12:37 +1000
commit4ac66af091cf6db5a42c18e43738ca9c41e338e5 (patch)
tree541bce15520b26aa1a16e28ccbe4ab1d50349449 /mac.c
parentea8342c248ad6c0a4fe1a70de133f954973bd2b2 (diff)
- dtucker@cvs.openbsd.org 2013/06/03 00:03:18
[mac.c] force the MAC output to be 64-bit aligned so umac won't see unaligned accesses on strict-alignment architectures. bz#2101, patch from tomas.kuthan at oracle.com, ok djm@
Diffstat (limited to 'mac.c')
-rw-r--r--mac.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/mac.c b/mac.c
index 907e19781..c4dfb501d 100644
--- a/mac.c
+++ b/mac.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: mac.c,v 1.23 2013/05/17 00:13:13 djm Exp $ */ 1/* $OpenBSD: mac.c,v 1.24 2013/06/03 00:03:18 dtucker Exp $ */
2/* 2/*
3 * Copyright (c) 2001 Markus Friedl. All rights reserved. 3 * Copyright (c) 2001 Markus Friedl. All rights reserved.
4 * 4 *
@@ -174,12 +174,15 @@ mac_init(Mac *mac)
174u_char * 174u_char *
175mac_compute(Mac *mac, u_int32_t seqno, u_char *data, int datalen) 175mac_compute(Mac *mac, u_int32_t seqno, u_char *data, int datalen)
176{ 176{
177 static u_char m[EVP_MAX_MD_SIZE]; 177 static union {
178 u_char m[EVP_MAX_MD_SIZE];
179 u_int64_t for_align;
180 } u;
178 u_char b[4], nonce[8]; 181 u_char b[4], nonce[8];
179 182
180 if (mac->mac_len > sizeof(m)) 183 if (mac->mac_len > sizeof(u))
181 fatal("mac_compute: mac too long %u %lu", 184 fatal("mac_compute: mac too long %u %lu",
182 mac->mac_len, (u_long)sizeof(m)); 185 mac->mac_len, (u_long)sizeof(u));
183 186
184 switch (mac->type) { 187 switch (mac->type) {
185 case SSH_EVP: 188 case SSH_EVP:
@@ -188,22 +191,22 @@ mac_compute(Mac *mac, u_int32_t seqno, u_char *data, int datalen)
188 HMAC_Init(&mac->evp_ctx, NULL, 0, NULL); 191 HMAC_Init(&mac->evp_ctx, NULL, 0, NULL);
189 HMAC_Update(&mac->evp_ctx, b, sizeof(b)); 192 HMAC_Update(&mac->evp_ctx, b, sizeof(b));
190 HMAC_Update(&mac->evp_ctx, data, datalen); 193 HMAC_Update(&mac->evp_ctx, data, datalen);
191 HMAC_Final(&mac->evp_ctx, m, NULL); 194 HMAC_Final(&mac->evp_ctx, u.m, NULL);
192 break; 195 break;
193 case SSH_UMAC: 196 case SSH_UMAC:
194 put_u64(nonce, seqno); 197 put_u64(nonce, seqno);
195 umac_update(mac->umac_ctx, data, datalen); 198 umac_update(mac->umac_ctx, data, datalen);
196 umac_final(mac->umac_ctx, m, nonce); 199 umac_final(mac->umac_ctx, u.m, nonce);
197 break; 200 break;
198 case SSH_UMAC128: 201 case SSH_UMAC128:
199 put_u64(nonce, seqno); 202 put_u64(nonce, seqno);
200 umac128_update(mac->umac_ctx, data, datalen); 203 umac128_update(mac->umac_ctx, data, datalen);
201 umac128_final(mac->umac_ctx, m, nonce); 204 umac128_final(mac->umac_ctx, u.m, nonce);
202 break; 205 break;
203 default: 206 default:
204 fatal("mac_compute: unknown MAC type"); 207 fatal("mac_compute: unknown MAC type");
205 } 208 }
206 return (m); 209 return (u.m);
207} 210}
208 211
209void 212void