raster pushed a commit to branch master.

http://git.enlightenment.org/apps/rage.git/commit/?id=1d492a68475d9d3c387691445dbeaacafd92a384

commit 1d492a68475d9d3c387691445dbeaacafd92a384
Author: Carsten Haitzler (Rasterman) <ras...@rasterman.com>
Date:   Wed Sep 23 16:48:41 2015 +0900

    rage - avoid htonl due to windows issues - makes things simpler
---
 src/bin/sha1.c | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)

diff --git a/src/bin/sha1.c b/src/bin/sha1.c
index 94661c3..84a943b 100644
--- a/src/bin/sha1.c
+++ b/src/bin/sha1.c
@@ -1,8 +1,16 @@
-#include <string.h>
-#include <arpa/inet.h>
+#include <Eina.h>
 
 #define SHSH(n, v) ((((v) << (n)) & 0xffffffff) | ((v) >> (32 - (n))))
 
+static inline int
+int_to_bigendian(int in)
+{
+   static const unsigned char test[4] = { 0x11, 0x22, 0x33, 0x44 };
+   static const unsigned int *test_i = (const unsigned int *)test;
+   if (test_i[0] == 0x44332211) return eina_swap32(in);
+   return in;
+}
+
 int
 sha1(unsigned char *data, int size, unsigned char *dst)
 {
@@ -85,11 +93,11 @@ sha1(unsigned char *data, int size, unsigned char *dst)
           }
      }
 
-   t = htonl(digest[0]); digest[0] = t;
-   t = htonl(digest[1]); digest[1] = t;
-   t = htonl(digest[2]); digest[2] = t;
-   t = htonl(digest[3]); digest[3] = t;
-   t = htonl(digest[4]); digest[4] = t;
+   t = int_to_bigendian(digest[0]); digest[0] = t;
+   t = int_to_bigendian(digest[1]); digest[1] = t;
+   t = int_to_bigendian(digest[2]); digest[2] = t;
+   t = int_to_bigendian(digest[3]); digest[3] = t;
+   t = int_to_bigendian(digest[4]); digest[4] = t;
 
    memcpy(dst, digest, 5 * 4);
    return 1;

-- 


Reply via email to