mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
To: barebox@lists.infradead.org
Subject: [PATCH 2/2] sha1/sha256: use be32_to_cpu and cpu_to_be32
Date: Tue, 21 Sep 2010 15:28:09 +0200	[thread overview]
Message-ID: <1285075689-11071-2-git-send-email-plagnioj@jcrosoft.com> (raw)
In-Reply-To: <1285075689-11071-1-git-send-email-plagnioj@jcrosoft.com>

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 lib/sha1.c   |   20 +++-----------------
 lib/sha256.c |   19 +++----------------
 2 files changed, 6 insertions(+), 33 deletions(-)

diff --git a/lib/sha1.c b/lib/sha1.c
index 0e8aed1..b4e2abc 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 78064da..975ebe9 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)
 {
-- 
1.7.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  reply	other threads:[~2010-09-21 13:29 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-21 13:28 [PATCH 1/2] sha1: use unit32_t and uint8_t Jean-Christophe PLAGNIOL-VILLARD
2010-09-21 13:28 ` Jean-Christophe PLAGNIOL-VILLARD [this message]
2010-09-24  7:00   ` [PATCH 2/2] sha1/sha256: use be32_to_cpu and cpu_to_be32 Andre
2010-09-24  7:26     ` Jean-Christophe PLAGNIOL-VILLARD
2010-09-24  7:43     ` Sascha Hauer
2010-09-24  8:34       ` Jean-Christophe PLAGNIOL-VILLARD
2010-09-24 10:16         ` Andre
2010-09-24 11:00           ` Jean-Christophe PLAGNIOL-VILLARD
2010-09-24 11:15             ` Sascha Hauer
2010-09-24 11:43               ` Jean-Christophe PLAGNIOL-VILLARD
2010-09-24 12:52                 ` Sascha Hauer
2010-09-24 12:56                   ` Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1285075689-11071-2-git-send-email-plagnioj@jcrosoft.com \
    --to=plagnioj@jcrosoft.com \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox