changeset 2506:91f57d346f38 draft

Fix compile on Linux
author Roy Marples <roy@marples.name>
date Mon, 02 Jun 2014 17:10:13 +0000
parents a258c02383fb
children c72abf8ed304
files configure crypt/sha256.c
diffstat 2 files changed, 34 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/configure	Mon Jun 02 16:31:37 2014 +0000
+++ b/configure	Mon Jun 02 17:10:13 2014 +0000
@@ -844,7 +844,7 @@
 EOF
 		# We only want to link to libmd if it exists in /lib
 		set -- $(ls /lib/libmd.so.* 2>/dev/null)
-		if $XCC	_sha256.c -o _sha256 3>/dev/null; then
+		if $XCC	_sha256.c -o _sha256 2>/dev/null; then
 			SHA2=yes
 			SHA2_RENAMED=yes
 		elif [ -e "$1" ] && $XCC _sha256.c -lmd -o _sha256 2>/dev/null
--- a/crypt/sha256.c	Mon Jun 02 16:31:37 2014 +0000
+++ b/crypt/sha256.c	Mon Jun 02 17:10:13 2014 +0000
@@ -24,8 +24,7 @@
  * SUCH DAMAGE.
  */
 
-#include <sys/endian.h>
-#include <sys/types.h>
+#include <inttypes.h>
 
 #include <string.h>
 
@@ -43,6 +42,38 @@
 
 #else /* BYTE_ORDER != BIG_ENDIAN */
 
+static inline void
+be32enc(uint8_t *buf, uint32_t u)
+{
+
+	buf[0] = (uint8_t)((u >> 24) & 0xff);
+	buf[1] = (uint8_t)((u >> 16) & 0xff);
+	buf[2] = (uint8_t)((u >> 8) & 0xff);
+	buf[3] = (uint8_t)(u & 0xff);
+}
+
+static inline void
+be64enc(uint8_t *buf, uint64_t u)
+{
+
+	be32enc(buf, (uint32_t)(u >> 32));
+	be32enc(buf + sizeof(uint32_t), (uint32_t)(u & 0xffffffffULL));
+}
+
+static inline uint16_t
+be16dec(const uint8_t *buf)
+{
+
+	return (uint16_t)(buf[0] << 8 | buf[1]);
+}
+
+static inline uint32_t
+be32dec(const uint8_t *buf)
+{
+
+	return (uint32_t)(be16dec(buf) << 16 | be16dec(buf + 2));
+}
+
 /*
  * Encode a length len/4 vector of (uint32_t) into a length len vector of
  * (unsigned char) in big-endian form.  Assumes len is a multiple of 4.