summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>2010-09-21 15:28:09 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2010-09-22 10:32:09 +0200
commit14f5e927f44e539c15ac60c9310e0d8a5e224b50 (patch)
treeb9dcb6c08dd73eddd47f8c51d8c6e6058ff9d3e2
parent7a1033c3a3eaf34079ea44f75cce97257214dd21 (diff)
downloadbarebox-14f5e927f44e539c15ac60c9310e0d8a5e224b50.tar.gz
barebox-14f5e927f44e539c15ac60c9310e0d8a5e224b50.tar.xz
sha1/sha256: use be32_to_cpu and cpu_to_be32
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r--lib/sha1.c20
-rw-r--r--lib/sha256.c19
2 files changed, 6 insertions, 33 deletions
diff --git a/lib/sha1.c b/lib/sha1.c
index 0e8aed14de..b4e2abc003 100644
--- a/lib/sha1.c
+++ b/lib/sha1.c
@@ -29,6 +29,7 @@
#include <digest.h>
#include <init.h>
#include <linux/string.h>
+#include <asm/byteorder.h>
#define SHA1_SUM_POS -0x20
#define SHA1_SUM_LEN 20
@@ -44,23 +45,8 @@ sha1_context;
/*
* 32-bit integer manipulation macros (big endian)
*/
-#ifndef GET_UINT32_BE
-#define GET_UINT32_BE(n,b,i) { \
- (n) = ( (uint32_t) (b)[(i) ] << 24 ) \
- | ( (uint32_t) (b)[(i) + 1] << 16 ) \
- | ( (uint32_t) (b)[(i) + 2] << 8 ) \
- | ( (uint32_t) (b)[(i) + 3] ); \
-}
-#endif
-
-#ifndef PUT_UINT32_BE
-#define PUT_UINT32_BE(n,b,i) { \
- (b)[(i) ] = (unsigned char) ( (n) >> 24 ); \
- (b)[(i) + 1] = (unsigned char) ( (n) >> 16 ); \
- (b)[(i) + 2] = (unsigned char) ( (n) >> 8 ); \
- (b)[(i) + 3] = (unsigned char) ( (n) ); \
-}
-#endif
+#define GET_UINT32_BE(n,b,i) (n) = be32_to_cpu(((uint32_t*)(b))[i / 4])
+#define PUT_UINT32_BE(n,b,i) ((uint32_t*)(b))[i / 4] = cpu_to_be32(n)
/*
* SHA-1 context setup
diff --git a/lib/sha256.c b/lib/sha256.c
index 78064da138..975ebe9f94 100644
--- a/lib/sha256.c
+++ b/lib/sha256.c
@@ -22,6 +22,7 @@
#include <digest.h>
#include <init.h>
#include <linux/string.h>
+#include <asm/byteorder.h>
#define SHA256_SUM_LEN 32
@@ -34,22 +35,8 @@ typedef struct {
/*
* 32-bit integer manipulation macros (big endian)
*/
-#ifndef GET_UINT32_BE
-#define GET_UINT32_BE(n,b,i) { \
- (n) = ( (unsigned long) (b)[(i) ] << 24 ) \
- | ( (unsigned long) (b)[(i) + 1] << 16 ) \
- | ( (unsigned long) (b)[(i) + 2] << 8 ) \
- | ( (unsigned long) (b)[(i) + 3] ); \
-}
-#endif
-#ifndef PUT_UINT32_BE
-#define PUT_UINT32_BE(n,b,i) { \
- (b)[(i) ] = (unsigned char) ( (n) >> 24 ); \
- (b)[(i) + 1] = (unsigned char) ( (n) >> 16 ); \
- (b)[(i) + 2] = (unsigned char) ( (n) >> 8 ); \
- (b)[(i) + 3] = (unsigned char) ( (n) ); \
-}
-#endif
+#define GET_UINT32_BE(n,b,i) (n) = be32_to_cpu(((uint32_t*)(b))[i / 4])
+#define PUT_UINT32_BE(n,b,i) ((uint32_t*)(b))[i / 4] = cpu_to_be32(n)
static void sha256_starts(sha256_context * ctx)
{