From 8863857944ae2fc7073f96d7d0fcb3b88b1581b3 Mon Sep 17 00:00:00 2001 From: Ken Raeburn Date: Sat, 24 Jan 2009 01:27:16 +0000 Subject: [PATCH] Change 16/32/64-bit big-/little-endian/native unaligned load/store routines to take void pointers, so they can operate on both plain and unsigned char buffers, or other types. Remove some now-unneeded casts. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@21793 dc483132-0cff-0310-8789-dd5450dbe970 --- src/include/k5-platform.h | 44 +++++++++++++++++---------- src/lib/crypto/arcfour/arcfour_aead.c | 4 +-- src/lib/krb5/krb/pac.c | 2 +- 3 files changed, 31 insertions(+), 19 deletions(-) diff --git a/src/include/k5-platform.h b/src/include/k5-platform.h index f4511278e..23ddf6967 100644 --- a/src/include/k5-platform.h +++ b/src/include/k5-platform.h @@ -1,7 +1,7 @@ /* * k5-platform.h * - * Copyright 2003, 2004, 2005, 2007, 2008 Massachusetts Institute of Technology. + * Copyright 2003, 2004, 2005, 2007, 2008, 2009 Massachusetts Institute of Technology. * All Rights Reserved. * * Export of this software from the United States of America may @@ -534,8 +534,9 @@ static inline unsigned int k5_swap16 (unsigned int x) { #endif static inline void -store_16_be (unsigned int val, unsigned char *p) +store_16_be (unsigned int val, void *vp) { + unsigned char *p = vp; #if defined(__GNUC__) && defined(K5_BE) PUT(16,p,val); #elif defined(__GNUC__) && defined(K5_LE) && defined(SWAP16) @@ -546,8 +547,9 @@ store_16_be (unsigned int val, unsigned char *p) #endif } static inline void -store_32_be (unsigned int val, unsigned char *p) +store_32_be (unsigned int val, void *vp) { + unsigned char *p = vp; #if defined(__GNUC__) && defined(K5_BE) PUT(32,p,val); #elif defined(__GNUC__) && defined(K5_LE) && defined(SWAP32) @@ -560,8 +562,9 @@ store_32_be (unsigned int val, unsigned char *p) #endif } static inline void -store_64_be (UINT64_TYPE val, unsigned char *p) +store_64_be (UINT64_TYPE val, void *vp) { + unsigned char *p = vp; #if defined(__GNUC__) && defined(K5_BE) PUT(64,p,val); #elif defined(__GNUC__) && defined(K5_LE) && defined(SWAP64) @@ -578,8 +581,9 @@ store_64_be (UINT64_TYPE val, unsigned char *p) #endif } static inline unsigned short -load_16_be (const unsigned char *p) +load_16_be (const void *cvp) { + const unsigned char *p = cvp; #if defined(__GNUC__) && defined(K5_BE) return GET(16,p); #elif defined(__GNUC__) && defined(K5_LE) && defined(SWAP16) @@ -589,8 +593,9 @@ load_16_be (const unsigned char *p) #endif } static inline unsigned int -load_32_be (const unsigned char *p) +load_32_be (const void *cvp) { + const unsigned char *p = cvp; #if defined(__GNUC__) && defined(K5_BE) return GET(32,p); #elif defined(__GNUC__) && defined(K5_LE) && defined(SWAP32) @@ -602,8 +607,9 @@ load_32_be (const unsigned char *p) #endif } static inline UINT64_TYPE -load_64_be (const unsigned char *p) +load_64_be (const void *cvp) { + const unsigned char *p = cvp; #if defined(__GNUC__) && defined(K5_BE) return GET(64,p); #elif defined(__GNUC__) && defined(K5_LE) && defined(SWAP64) @@ -613,8 +619,9 @@ load_64_be (const unsigned char *p) #endif } static inline void -store_16_le (unsigned int val, unsigned char *p) +store_16_le (unsigned int val, void *vp) { + unsigned char *p = vp; #if defined(__GNUC__) && defined(K5_LE) PUT(16,p,val); #elif defined(__GNUC__) && defined(K5_BE) && defined(SWAP16) @@ -625,8 +632,9 @@ store_16_le (unsigned int val, unsigned char *p) #endif } static inline void -store_32_le (unsigned int val, unsigned char *p) +store_32_le (unsigned int val, void *vp) { + unsigned char *p = vp; #if defined(__GNUC__) && defined(K5_LE) PUT(32,p,val); #elif defined(__GNUC__) && defined(K5_BE) && defined(SWAP32) @@ -639,8 +647,9 @@ store_32_le (unsigned int val, unsigned char *p) #endif } static inline void -store_64_le (UINT64_TYPE val, unsigned char *p) +store_64_le (UINT64_TYPE val, void *vp) { + unsigned char *p = vp; #if defined(__GNUC__) && defined(K5_LE) PUT(64,p,val); #elif defined(__GNUC__) && defined(K5_BE) && defined(SWAP64) @@ -657,8 +666,9 @@ store_64_le (UINT64_TYPE val, unsigned char *p) #endif } static inline unsigned short -load_16_le (const unsigned char *p) +load_16_le (const void *cvp) { + const unsigned char *p = cvp; #if defined(__GNUC__) && defined(K5_LE) return GET(16,p); #elif defined(__GNUC__) && defined(K5_BE) && defined(SWAP16) @@ -668,8 +678,9 @@ load_16_le (const unsigned char *p) #endif } static inline unsigned int -load_32_le (const unsigned char *p) +load_32_le (const void *cvp) { + const unsigned char *p = cvp; #if defined(__GNUC__) && defined(K5_LE) return GET(32,p); #elif defined(__GNUC__) && defined(K5_BE) && defined(SWAP32) @@ -679,8 +690,9 @@ load_32_le (const unsigned char *p) #endif } static inline UINT64_TYPE -load_64_le (const unsigned char *p) +load_64_le (const void *cvp) { + const unsigned char *p = cvp; #if defined(__GNUC__) && defined(K5_LE) return GET(64,p); #elif defined(__GNUC__) && defined(K5_BE) && defined(SWAP64) @@ -691,7 +703,7 @@ load_64_le (const unsigned char *p) } static inline unsigned short -load_16_n (const unsigned char *p) +load_16_n (const void *p) { #ifdef _WIN32 unsigned __int16 n; @@ -702,7 +714,7 @@ load_16_n (const unsigned char *p) return n; } static inline unsigned int -load_32_n (const unsigned char *p) +load_32_n (const void *p) { #ifdef _WIN32 unsigned __int32 n; @@ -713,7 +725,7 @@ load_32_n (const unsigned char *p) return n; } static inline UINT64_TYPE -load_64_n (const unsigned char *p) +load_64_n (const void *p) { UINT64_TYPE n; memcpy(&n, p, 8); diff --git a/src/lib/crypto/arcfour/arcfour_aead.c b/src/lib/crypto/arcfour/arcfour_aead.c index 025118ed7..cff7d66d6 100644 --- a/src/lib/crypto/arcfour/arcfour_aead.c +++ b/src/lib/crypto/arcfour/arcfour_aead.c @@ -146,10 +146,10 @@ krb5int_arcfour_encrypt_iov(const struct krb5_aead_provider *aead, if (key->enctype == ENCTYPE_ARCFOUR_HMAC_EXP) { strncpy(salt.data, krb5int_arcfour_l40, salt.length); - store_32_le(ms_usage, (unsigned char *)salt.data + 10); + store_32_le(ms_usage, salt.data + 10); } else { salt.length = 4; - store_32_le(ms_usage, (unsigned char *)salt.data); + store_32_le(ms_usage, salt.data); } ret = krb5_hmac(hash, key, 1, &salt, &d1); if (ret != 0) diff --git a/src/lib/krb5/krb/pac.c b/src/lib/krb5/krb/pac.c index 196b627d8..30a63bf35 100644 --- a/src/lib/krb5/krb/pac.c +++ b/src/lib/krb5/krb/pac.c @@ -730,7 +730,7 @@ k5_insert_checksum(krb5_context context, } /* Encode checksum type into buffer */ - store_32_le((krb5_ui_4)*cksumtype, (unsigned char *)cksumdata.data); + store_32_le((krb5_ui_4)*cksumtype, cksumdata.data); return 0; } -- 2.26.2