From af3a2788aad87d9b018ea5c4125404242927e47d Mon Sep 17 00:00:00 2001 From: Juan RP Date: Tue, 4 May 2010 14:36:32 +0200 Subject: [PATCH] Provide stubs for htobe{32,64}() and be32toh() macros if they aren't defined on Linux. Tested and verified by Jimmy on xbps@googlegroups.com. --- lib/sha256.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/lib/sha256.c b/lib/sha256.c index dfa4f52a..985f3397 100644 --- a/lib/sha256.c +++ b/lib/sha256.c @@ -36,6 +36,7 @@ * */ +#include #include #include #include @@ -51,6 +52,34 @@ #include #include "sha256.h" +/* Workaround byte swap cludge on Linux systems */ +#ifdef _BSD +#include +#elif defined(__linux__) +#include +# if __BYTE_ORDER == __LITTLE_ENDIAN +# ifndef htobe32 +# define htobe32(x) bswap_32 (x) +# endif +# ifndef be32toh +# define be32toh(x) bswap_32 (x) +# endif +# ifndef htobe64 +# define htobe64(x) bswap_64 (x) +# endif +# else +# ifndef htobe32 +# define htobe32(x) (x) +# endif +# ifndef be32toh +# define be32toh(x) (x) +# endif +# ifndef htobe64 +# define htobe64(x) (x) +# endif +# endif +#endif + /*** SHA-256 Various Length Definitions ***********************/ /* NOTE: Most of these are in sha2.h */ #define SHA256_SHORT_BLOCK_LENGTH (SHA256_BLOCK_LENGTH - 8)