[PATCH 1/4] hash: fix compiler warning on ARM

Jussi Kivilinna jussi.kivilinna at iki.fi
Tue Dec 23 16:36:21 CET 2014


* cipher/md.c (md_open, md_copy): Cast 'char *' to ctx through
'void *'.
* cipher/md4.c (md4_final): Use buf_put_* helper instead of
converting 'char *' to 'u32 *'.
* cipher/md5.c (md5_final): Ditto.
* cipher/rmd160.c (_gcry_rmd160_mixblock, rmd160_final): Ditto.
* cipher/sha1.c (sha1_final): Ditto.
* cipher/sha256.c (sha256_final): Ditto.
* cipher/sha512.c (sha512_final): Ditto.
* cipher/tiger.c (tiger_final): Ditto.
--

Patch fixes 'cast increases required alignment' warnings seen on GCC:

md.c: In function 'md_open':
md.c:318:23: warning: cast increases required alignment of target type [-Wcast-align]
       hd->ctx = ctx = (struct gcry_md_context *) ((char *) hd + n);
                       ^
md.c: In function 'md_copy':
md.c:491:22: warning: cast increases required alignment of target type [-Wcast-align]
       bhd->ctx = b = (struct gcry_md_context *) ((char *) bhd + n);
                      ^
md4.c: In function 'md4_final':
md4.c:258:20: warning: cast increases required alignment of target type [-Wcast-align]
 #define X(a) do { *(u32*)p = le_bswap32((*hd).a) ; p += 4; } while(0)
                    ^
md4.c:259:3: note: in expansion of macro 'X'
   X(A);
   ^
md4.c:258:20: warning: cast increases required alignment of target type [-Wcast-align]
 #define X(a) do { *(u32*)p = le_bswap32((*hd).a) ; p += 4; } while(0)
                    ^
md4.c:260:3: note: in expansion of macro 'X'
   X(B);
   ^
[removed the rest]

Signed-off-by: Jussi Kivilinna <jussi.kivilinna at iki.fi>
---
 cipher/md.c     |    4 ++--
 cipher/md4.c    |    2 +-
 cipher/md5.c    |    2 +-
 cipher/rmd160.c |    4 ++--
 cipher/sha1.c   |    2 +-
 cipher/sha256.c |    2 +-
 cipher/sha512.c |    2 +-
 cipher/tiger.c  |    4 ++--
 8 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/cipher/md.c b/cipher/md.c
index df8b027..f9414de 100644
--- a/cipher/md.c
+++ b/cipher/md.c
@@ -315,7 +315,7 @@ md_open (gcry_md_hd_t *h, int algo, unsigned int flags)
 
   if (! err)
     {
-      hd->ctx = ctx = (struct gcry_md_context *) ((char *) hd + n);
+      hd->ctx = ctx = (void *) ((char *) hd + n);
       /* Setup the globally visible data (bctl in the diagram).*/
       hd->bufsize = n - sizeof (struct gcry_md_handle) + 1;
       hd->bufpos = 0;
@@ -488,7 +488,7 @@ md_copy (gcry_md_hd_t ahd, gcry_md_hd_t *b_hd)
 
   if (! err)
     {
-      bhd->ctx = b = (struct gcry_md_context *) ((char *) bhd + n);
+      bhd->ctx = b = (void *) ((char *) bhd + n);
       /* No need to copy the buffer due to the write above. */
       gcry_assert (ahd->bufsize == (n - sizeof (struct gcry_md_handle) + 1));
       bhd->bufsize = ahd->bufsize;
diff --git a/cipher/md4.c b/cipher/md4.c
index 7291254..c9b4154 100644
--- a/cipher/md4.c
+++ b/cipher/md4.c
@@ -255,7 +255,7 @@ md4_final( void *context )
   _gcry_burn_stack (burn);
 
   p = hd->bctx.buf;
-#define X(a) do { *(u32*)p = le_bswap32((*hd).a) ; p += 4; } while(0)
+#define X(a) do { buf_put_le32(p, hd->a); p += 4; } while(0)
   X(A);
   X(B);
   X(C);
diff --git a/cipher/md5.c b/cipher/md5.c
index 73ad968..f17af7a 100644
--- a/cipher/md5.c
+++ b/cipher/md5.c
@@ -279,7 +279,7 @@ md5_final( void *context)
   _gcry_burn_stack (burn);
 
   p = hd->bctx.buf;
-#define X(a) do { *(u32*)p = le_bswap32((*hd).a) ; p += 4; } while(0)
+#define X(a) do { buf_put_le32(p, hd->a); p += 4; } while(0)
   X(A);
   X(B);
   X(C);
diff --git a/cipher/rmd160.c b/cipher/rmd160.c
index e6d02f5..2b1f321 100644
--- a/cipher/rmd160.c
+++ b/cipher/rmd160.c
@@ -411,7 +411,7 @@ _gcry_rmd160_mixblock ( RMD160_CONTEXT *hd, void *blockof64byte )
   char *p = blockof64byte;
 
   transform ( hd, blockof64byte, 1 );
-#define X(a) do { *(u32*)p = hd->h##a ; p += 4; } while(0)
+#define X(a) do { buf_put_le32(p, hd->h##a); p += 4; } while(0)
   X(0);
   X(1);
   X(2);
@@ -474,7 +474,7 @@ rmd160_final( void *context )
   _gcry_burn_stack (burn);
 
   p = hd->bctx.buf;
-#define X(a) do { *(u32*)p = le_bswap32(hd->h##a) ; p += 4; } while(0)
+#define X(a) do { buf_put_le32(p, hd->h##a); p += 4; } while(0)
   X(0);
   X(1);
   X(2);
diff --git a/cipher/sha1.c b/cipher/sha1.c
index 00c57dd..6ccf0e8 100644
--- a/cipher/sha1.c
+++ b/cipher/sha1.c
@@ -401,7 +401,7 @@ sha1_final(void *context)
   _gcry_burn_stack (burn);
 
   p = hd->bctx.buf;
-#define X(a) do { *(u32*)p = be_bswap32(hd->h##a) ; p += 4; } while(0)
+#define X(a) do { buf_put_be32(p, hd->h##a); p += 4; } while(0)
   X(0);
   X(1);
   X(2);
diff --git a/cipher/sha256.c b/cipher/sha256.c
index 4efaec6..d3af172 100644
--- a/cipher/sha256.c
+++ b/cipher/sha256.c
@@ -428,7 +428,7 @@ sha256_final(void *context)
   _gcry_burn_stack (burn);
 
   p = hd->bctx.buf;
-#define X(a) do { *(u32*)p = be_bswap32(hd->h##a); p += 4; } while(0)
+#define X(a) do { buf_put_be32(p, hd->h##a); p += 4; } while(0)
   X(0);
   X(1);
   X(2);
diff --git a/cipher/sha512.c b/cipher/sha512.c
index 7d60df0..5a6af80 100644
--- a/cipher/sha512.c
+++ b/cipher/sha512.c
@@ -669,7 +669,7 @@ sha512_final (void *context)
   _gcry_burn_stack (stack_burn_depth);
 
   p = hd->bctx.buf;
-#define X(a) do { *(u64*)p = be_bswap64(hd->state.h##a) ; p += 8; } while (0)
+#define X(a) do { buf_put_be64(p, hd->state.h##a); p += 8; } while (0)
   X (0);
   X (1);
   X (2);
diff --git a/cipher/tiger.c b/cipher/tiger.c
index 91db4e6..8a08953 100644
--- a/cipher/tiger.c
+++ b/cipher/tiger.c
@@ -805,8 +805,8 @@ tiger_final( void *context )
   _gcry_burn_stack (burn);
 
   p = hd->bctx.buf;
-#define X(a) do { *(u64*)p = be_bswap64(hd->a); p += 8; } while(0)
-#define Y(a) do { *(u64*)p = le_bswap64(hd->a); p += 8; } while(0)
+#define X(a) do { buf_put_be64(p, hd->a); p += 8; } while(0)
+#define Y(a) do { buf_put_le64(p, hd->a); p += 8; } while(0)
   if (hd->variant == 0)
     {
       X(a);




More information about the Gcrypt-devel mailing list