From 690ad7280e655654a3bcca2ca5ced9caacf75c8b Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Tue, 22 May 2012 15:45:16 +0000 Subject: Added libbu++ endianness support. It's probably not as fast as system endianness, but on gnu it'll use the libc versions, if you don't have those, at least libbu++ will compile. --- src/config.h | 111 ++++++++++++++++++++++++++++++++++++++++++-- src/experimental/blowfish.h | 1 + 2 files changed, 107 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/config.h b/src/config.h index 8a79166..fa304bb 100644 --- a/src/config.h +++ b/src/config.h @@ -18,13 +18,114 @@ #include "bu/extratypes.h" #ifndef WIN32 -#include "bu/autoconfig.h" +# include "bu/autoconfig.h" #else -#define __LITTLE_ENDIAN 1234 -#define __BIG_ENDIAN 4321 -#define __PDP_ENDIAN 3412 -#define __BYTE_ORDER __LITTLE_ENDIAN +# define __LITTLE_ENDIAN 1234 +# define __BIG_ENDIAN 4321 +# define __PDP_ENDIAN 3412 +# define __BYTE_ORDER __LITTLE_ENDIAN + +# ifndef LITTLE_ENDIAN +# define LITTLE_ENDIAN __LITTLE_ENDIAN +# endif +# ifndef BIG_ENDIAN +# define BIG_ENDIAN __BIG_ENDIAN +# endif +# ifndef PDP_ENDIAN +# define PDP_ENDIAN __PDP_ENDIAN +# endif +# ifndef BYTE_ORDER +# define BYTE_ORDER __BYTE_ORDER +# endif #endif +// At this point the system endian.h should be included, but if it's missing +// an endian conversion macro, lets fix that now... + +#define bu_byte_swap16(x) (((x&0xffu)<<8)|((x&0xff00u)>>8)) +#define bu_byte_swap32(x) (((x&0xfful)<<24)|((x&0xff00ul)<<8)|((x&0xff0000ul)>>8)|((x&0xff000000ul)>>24)) +#define bu_byte_swap64(x) (((x&0xffull)<<56)|((x&0xff00ull)<<40)|((x&0xff0000ull)<<24)|((x&0xff000000ull)<<8)|((x&0xff00000000000000ull)>>56)|((x&0xff000000000000ull)>>40)|((x&0xff0000000000ull)>>24)|((x&0xff00000000ull)>>8)) + +#if BYTE_ORDER == LITTLE_ENDIAN +# ifndef htobe16 +# define htobe16(x) bu_byte_swap16(x) +# endif +# ifndef htole16 +# define htole16(x) (x) +# endif +# ifndef be16toh +# define be16toh(x) bu_byte_swap16(x) +# endif +# ifndef le16toh +# define le16toh(x) (x) +# endif + +# ifndef htobe32 +# define htobe32(x) bu_byte_swap32(x) +# endif +# ifndef htole32 +# define htole32(x) (x) +# endif +# ifndef be32toh +# define be32toh(x) bu_byte_swap32(x) +# endif +# ifndef le32toh +# define le32toh(x) (x) +# endif + +# ifndef htobe64 +# define htobe64(x) bu_byte_swap64(x) +# endif +# ifndef htole64 +# define htole64(x) (x) +# endif +# ifndef be64toh +# define be64toh(x) bu_byte_swap64(x) +# endif +# ifndef le64toh +# define le64toh(x) (x) +# endif +#elif BYTE_ORDER == BIG_ENDIAN +# ifndef htole16 +# define htole16(x) bu_byte_swap16(x) +# endif +# ifndef htobe16 +# define htobe16(x) (x) +# endif +# ifndef le16toh +# define le16toh(x) bu_byte_swap16(x) +# endif +# ifndef be16toh +# define be16toh(x) (x) +# endif + +# ifndef htole32 +# define htole32(x) bu_byte_swap32(x) +# endif +# ifndef htobe32 +# define htobe32(x) (x) +# endif +# ifndef le32toh +# define le32toh(x) bu_byte_swap32(x) +# endif +# ifndef be32toh +# define be32toh(x) (x) +# endif + +# ifndef htole64 +# define htole64(x) bu_byte_swap64(x) +# endif +# ifndef htobe64 +# define htobe64(x) (x) +# endif +# ifndef le64toh +# define le64toh(x) bu_byte_swap64(x) +# endif +# ifndef be64toh +# define be64toh(x) (x) +# endif +#else +#error Unhandled endianness detected +#endif #endif diff --git a/src/experimental/blowfish.h b/src/experimental/blowfish.h index 7e816ca..c2a8be5 100644 --- a/src/experimental/blowfish.h +++ b/src/experimental/blowfish.h @@ -8,6 +8,7 @@ #ifndef BU_BLOWFISH_H #define BU_BLOWFISH_H +#include "bu/config.h" #include "bu/cipher.h" #include "bu/ciphermodeecb.h" -- cgit v1.2.3