byteorder: Add 32-bit unaligned little-endian conversion functions

This commit is contained in:
Martin Willi
2015-12-04 10:29:09 +01:00
parent 9709418871
commit 8fa0c7bc77
2 changed files with 27 additions and 21 deletions
@@ -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
*/
+27
View File
@@ -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_ @} */