From 8fa0c7bc77203f5aa8a4e9507b11a55e34200684 Mon Sep 17 00:00:00 2001 From: Martin Willi Date: Tue, 10 Nov 2015 07:57:48 +0100 Subject: [PATCH] byteorder: Add 32-bit unaligned little-endian conversion functions --- .../plugins/chapoly/chapoly_drv_portable.c | 21 --------------- src/libstrongswan/utils/utils/byteorder.h | 27 +++++++++++++++++++ 2 files changed, 27 insertions(+), 21 deletions(-) diff --git a/src/libstrongswan/plugins/chapoly/chapoly_drv_portable.c b/src/libstrongswan/plugins/chapoly/chapoly_drv_portable.c index 54e934e6a..dfed4d53d 100644 --- a/src/libstrongswan/plugins/chapoly/chapoly_drv_portable.c +++ b/src/libstrongswan/plugins/chapoly/chapoly_drv_portable.c @@ -57,27 +57,6 @@ struct private_chapoly_drv_portable_t { u_int32_t s[4]; }; -/** - * Convert unaligned little endian to host byte order - */ -static inline u_int32_t uletoh32(void *p) -{ - u_int32_t ret; - - memcpy(&ret, p, sizeof(ret)); - ret = le32toh(ret); - return ret; -} - -/** - * Convert host byte order to unaligned little endian - */ -static inline void htoule32(void *p, u_int32_t v) -{ - v = htole32(v); - memcpy(p, &v, sizeof(v)); -} - /** * XOR a 32-bit integer into an unaligned destination */ diff --git a/src/libstrongswan/utils/utils/byteorder.h b/src/libstrongswan/utils/utils/byteorder.h index 48cf1d526..ef2bddbf7 100644 --- a/src/libstrongswan/utils/utils/byteorder.h +++ b/src/libstrongswan/utils/utils/byteorder.h @@ -158,4 +158,31 @@ static inline u_int64_t untoh64(void *network) #endif } +/** + * Read a 32-bit value in little-endian order from unaligned address. + * + * @param network unaligned address to read little endian value from + * @return host order value + */ +static inline u_int32_t uletoh32(void *p) +{ + u_int32_t ret; + + memcpy(&ret, p, sizeof(ret)); + ret = le32toh(ret); + return ret; +} + +/** + * Write a 32-bit value in little-endian to an unaligned address. + * + * @param host host order 32-bit value + * @param network unaligned address to write little endian value to + */ +static inline void htoule32(void *p, u_int32_t v) +{ + v = htole32(v); + memcpy(p, &v, sizeof(v)); +} + #endif /** BYTEORDER_H_ @} */