[git] GCRYPT - branch, LIBGCRYPT-1-5-BRANCH, updated. libgcrypt-1.5.1-10-g4cd2795

by Werner Koch cvs at cvs.gnupg.org
Thu Apr 18 15:00:27 CEST 2013


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "The GNU crypto library".

The branch, LIBGCRYPT-1-5-BRANCH has been updated
       via  4cd279556777e02eda79973f68efaa4b741f9175 (commit)
       via  a412a949555db737bac87999403fcf526166effe (commit)
       via  8eab66ad6852ec985bfb1e7fec35981d5e31148a (commit)
      from  cc2f85116226bf9e2b77c4949eb1e7ea2357f67d (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 4cd279556777e02eda79973f68efaa4b741f9175
Author: Werner Koch <wk at gnupg.org>
Date:   Thu Apr 18 14:40:43 2013 +0200

    Fix alignment problem in idea.c.
    
    * cipher/idea.c (cipher): Rework parameter use to fix alignment
    problems.
    
    * cipher/idea.c (FNCCAST_SETKEY, FNCCAST_CRYPT): Remove unused macros.
    
    Signed-off-by: Werner Koch <wk at gnupg.org>

diff --git a/cipher/idea.c b/cipher/idea.c
index 39c9720..c025c95 100644
--- a/cipher/idea.c
+++ b/cipher/idea.c
@@ -1,5 +1,6 @@
 /* idea.c  -  IDEA function
- *	Copyright (c) 1997, 1998, 1999, 2001 by Werner Koch (dd9jn)
+ * Copyright 1997, 1998, 1999, 2001 Werner Koch (dd9jn)
+ * Copyright 2013 g10 Code GmbH
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
@@ -49,9 +50,6 @@
 #include "cipher.h"
 
 
-#define FNCCAST_SETKEY(f)  ((int(*)(void*, byte*, unsigned int))(f))
-#define FNCCAST_CRYPT(f)   ((void(*)(void*, byte*, byte*))(f))
-
 #define IDEA_KEYSIZE 16
 #define IDEA_BLOCKSIZE 8
 #define IDEA_ROUNDS 8
@@ -161,10 +159,14 @@ invert_key( u16 *ek, u16 dk[IDEA_KEYLEN] )
 static void
 cipher( byte *outbuf, const byte *inbuf, u16 *key )
 {
-    u16 x1, x2, x3,x4, s2, s3;
-    u16 *in, *out;
+    u16 s2, s3;
+    u16 in[4];
     int r = IDEA_ROUNDS;
-  #define MUL(x,y) \
+#define x1 (in[0])
+#define x2 (in[1])
+#define x3 (in[2])
+#define x4 (in[3])
+#define MUL(x,y) \
 	do {u16 _t16; u32 _t32; 		    \
 	    if( (_t16 = (y)) ) {		    \
 		if( (x = (x)&0xffff) ) {	    \
@@ -182,17 +184,13 @@ cipher( byte *outbuf, const byte *inbuf, u16 *key )
 	    }					    \
 	} while(0)
 
-    in = (u16*)inbuf;
-    x1 = *in++;
-    x2 = *in++;
-    x3 = *in++;
-    x4 = *in;
-  #ifndef WORDS_BIGENDIAN
+    memcpy (in, inbuf, sizeof in);
+#ifndef WORDS_BIGENDIAN
     x1 = (x1>>8) | (x1<<8);
     x2 = (x2>>8) | (x2<<8);
     x3 = (x3>>8) | (x3<<8);
     x4 = (x4>>8) | (x4<<8);
-  #endif
+#endif
     do {
 	MUL(x1, *key++);
 	x2 += *key++;
@@ -219,19 +217,21 @@ cipher( byte *outbuf, const byte *inbuf, u16 *key )
     x2 += *key++;
     MUL(x4, *key);
 
-    out = (u16*)outbuf;
-  #ifndef WORDS_BIGENDIAN
-    *out++ = (x1>>8) | (x1<<8);
-    *out++ = (x3>>8) | (x3<<8);
-    *out++ = (x2>>8) | (x2<<8);
-    *out   = (x4>>8) | (x4<<8);
-  #else
-    *out++ = x1;
-    *out++ = x3;
-    *out++ = x2;
-    *out   = x4;
-  #endif
-  #undef MUL
+#ifndef WORDS_BIGENDIAN
+    x1 = (x1>>8) | (x1<<8);
+    x2 = (x2>>8) | (x2<<8);
+    x3 = (x3>>8) | (x3<<8);
+    x4 = (x4>>8) | (x4<<8);
+#endif
+    memcpy (outbuf+0, &x1, 2);
+    memcpy (outbuf+2, &x3, 2);
+    memcpy (outbuf+4, &x2, 2);
+    memcpy (outbuf+6, &x4, 2);
+#undef MUL
+#undef x1
+#undef x2
+#undef x3
+#undef x4
 }
 
 

commit a412a949555db737bac87999403fcf526166effe
Author: Vladimir Serbinenko <phcoder at gmail.com>
Date:   Thu Apr 18 13:37:49 2013 +0200

    Add some const attributes.
    
    * cipher/md4.c (transform): Add const attribute.
    * cipher/md5.c (transform): Ditto.
    * cipher/rmd160.c (transform): Ditto.
    --
    
    This is the same as
      http://bzr.savannah.gnu.org/lh/grub/trunk/grub/revision/3685
    
    Signed-off-by: Werner Koch <wk at gnupg.org>

diff --git a/cipher/md4.c b/cipher/md4.c
index 8909ec4..22fbf8d 100644
--- a/cipher/md4.c
+++ b/cipher/md4.c
@@ -100,7 +100,8 @@ transform ( MD4_CONTEXT *ctx, const unsigned char *data )
 #ifdef WORDS_BIGENDIAN
   {
     int i;
-    byte *p2, *p1;
+    byte *p2;
+    const byte *p1;
     for(i=0, p1=data, p2=(byte*)in; i < 16; i++, p2 += 4 )
       {
 	p2[3] = *p1++;
diff --git a/cipher/md5.c b/cipher/md5.c
index 4793882..a98678a 100644
--- a/cipher/md5.c
+++ b/cipher/md5.c
@@ -91,7 +91,8 @@ transform ( MD5_CONTEXT *ctx, const unsigned char *data )
 #ifdef WORDS_BIGENDIAN
   {
     int i;
-    byte *p2, *p1;
+    byte *p2;
+    const byte *p1;
     for(i=0, p1=data, p2=(byte*)correct_words; i < 16; i++, p2 += 4 )
       {
         p2[3] = *p1++;
diff --git a/cipher/rmd160.c b/cipher/rmd160.c
index 552cff9..179a4d9 100644
--- a/cipher/rmd160.c
+++ b/cipher/rmd160.c
@@ -168,7 +168,8 @@ transform ( RMD160_CONTEXT *hd, const unsigned char *data )
   u32 x[16];
   {
     int i;
-    byte *p2, *p1;
+    byte *p2;
+    const byte *p1;
     for (i=0, p1=data, p2=(byte*)x; i < 16; i++, p2 += 4 )
       {
         p2[3] = *p1++;

commit 8eab66ad6852ec985bfb1e7fec35981d5e31148a
Author: Vladimir Serbinenko <phcoder at gmail.com>
Date:   Thu Apr 18 13:22:34 2013 +0200

    Fix alignment problem in serpent.c.
    
    * cipher/serpent.c (serpent_key_prepare): Fix misaligned access.
    (serpent_setkey): Likewise.
    (serpent_encrypt_internal): Likewise.
    (serpent_decrypt_internal): Likewise.
    (serpent_encrypt): Don't put an alignment-increasing cast.
    (serpent_decrypt): Likewise.
    (serpent_test): Likewise.
    --
    
    This is a port of the fix for the Libgcrypt code in GRUB:
      http://bzr.savannah.gnu.org/lh/grub/trunk/grub/revision/3685
    GRUB is FSF copyrighted and thus we can use this code without a DCO.
    
    Note that the above fix was not correct and failed the selftests, thus
    I fixed this fix.
    
    GnuPG-bug-id: 1384
    Signed-off-by: Werner Koch <wk at gnupg.org>

diff --git a/AUTHORS b/AUTHORS
index b7c1800..5eab32a 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -98,6 +98,11 @@ Assigns Past and Future Changes
 openpgp at brainhub.org
 (cipher/ecc.c and related files)
 
+LIBGCRYPT       Vladimir Serbinenko  2012-04-26
+Assigns Past and Future Changes
+phcoder at gmail.com
+(cipher/serpent.c)
+
 
 Authors with a DCO
 ==================
diff --git a/cipher/serpent.c b/cipher/serpent.c
index a78e018..ea14c7e 100644
--- a/cipher/serpent.c
+++ b/cipher/serpent.c
@@ -585,15 +585,14 @@ serpent_key_prepare (const byte *key, unsigned int key_length,
   int i;
 
   /* Copy key.  */
-  for (i = 0; i < key_length / 4; i++)
-    {
+  memcpy (key_prepared, key, key_length);
+  key_length /= 4;
 #ifdef WORDS_BIGENDIAN
-      key_prepared[i] = byte_swap_32 (((u32 *) key)[i]);
+  for (i = 0; i < key_length; i++)
+    key_prepared[i] = byte_swap_32 (key_prepared[i]);
 #else
-      key_prepared[i] = ((u32 *) key)[i];
+  i = key_length;
 #endif
-    }
-
   if (i < 8)
     {
       /* Key must be padded according to the Serpent
@@ -707,21 +706,17 @@ serpent_setkey (void *ctx,
 
 static void
 serpent_encrypt_internal (serpent_context_t *context,
-			  const serpent_block_t input, serpent_block_t output)
+			  const byte *input, byte *output)
 {
   serpent_block_t b, b_next;
   int round = 0;
 
+  memcpy (b, input, sizeof (b));
 #ifdef WORDS_BIGENDIAN
-  b[0] = byte_swap_32 (input[0]);
-  b[1] = byte_swap_32 (input[1]);
-  b[2] = byte_swap_32 (input[2]);
-  b[3] = byte_swap_32 (input[3]);
-#else
-  b[0] = input[0];
-  b[1] = input[1];
-  b[2] = input[2];
-  b[3] = input[3];
+  b[0] = byte_swap_32 (b[0]);
+  b[1] = byte_swap_32 (b[1]);
+  b[2] = byte_swap_32 (b[2]);
+  b[3] = byte_swap_32 (b[3]);
 #endif
 
   ROUND (0, context->keys, b, b_next);
@@ -759,35 +754,27 @@ serpent_encrypt_internal (serpent_context_t *context,
   ROUND_LAST (7, context->keys, b, b_next);
 
 #ifdef WORDS_BIGENDIAN
-  output[0] = byte_swap_32 (b_next[0]);
-  output[1] = byte_swap_32 (b_next[1]);
-  output[2] = byte_swap_32 (b_next[2]);
-  output[3] = byte_swap_32 (b_next[3]);
-#else
-  output[0] = b_next[0];
-  output[1] = b_next[1];
-  output[2] = b_next[2];
-  output[3] = b_next[3];
+  b_next[0] = byte_swap_32 (b_next[0]);
+  b_next[1] = byte_swap_32 (b_next[1]);
+  b_next[2] = byte_swap_32 (b_next[2]);
+  b_next[3] = byte_swap_32 (b_next[3]);
 #endif
+  memcpy (output, b_next, sizeof (b_next));
 }
 
 static void
 serpent_decrypt_internal (serpent_context_t *context,
-			  const serpent_block_t input, serpent_block_t output)
+			  const byte *input, byte *output)
 {
   serpent_block_t b, b_next;
   int round = ROUNDS;
 
+  memcpy (b_next, input, sizeof (b));
 #ifdef WORDS_BIGENDIAN
-  b_next[0] = byte_swap_32 (input[0]);
-  b_next[1] = byte_swap_32 (input[1]);
-  b_next[2] = byte_swap_32 (input[2]);
-  b_next[3] = byte_swap_32 (input[3]);
-#else
-  b_next[0] = input[0];
-  b_next[1] = input[1];
-  b_next[2] = input[2];
-  b_next[3] = input[3];
+  b_next[0] = byte_swap_32 (b_next[0]);
+  b_next[1] = byte_swap_32 (b_next[1]);
+  b_next[2] = byte_swap_32 (b_next[2]);
+  b_next[3] = byte_swap_32 (b_next[3]);
 #endif
 
   ROUND_FIRST_INVERSE (7, context->keys, b_next, b);
@@ -824,18 +811,13 @@ serpent_decrypt_internal (serpent_context_t *context,
   ROUND_INVERSE (1, context->keys, b, b_next);
   ROUND_INVERSE (0, context->keys, b, b_next);
 
-
 #ifdef WORDS_BIGENDIAN
-  output[0] = byte_swap_32 (b_next[0]);
-  output[1] = byte_swap_32 (b_next[1]);
-  output[2] = byte_swap_32 (b_next[2]);
-  output[3] = byte_swap_32 (b_next[3]);
-#else
-  output[0] = b_next[0];
-  output[1] = b_next[1];
-  output[2] = b_next[2];
-  output[3] = b_next[3];
+  b_next[0] = byte_swap_32 (b_next[0]);
+  b_next[1] = byte_swap_32 (b_next[1]);
+  b_next[2] = byte_swap_32 (b_next[2]);
+  b_next[3] = byte_swap_32 (b_next[3]);
 #endif
+  memcpy (output, b_next, sizeof (b_next));
 }
 
 static void
@@ -843,8 +825,7 @@ serpent_encrypt (void *ctx, byte *buffer_out, const byte *buffer_in)
 {
   serpent_context_t *context = ctx;
 
-  serpent_encrypt_internal (context,
-			    (const u32 *) buffer_in, (u32 *) buffer_out);
+  serpent_encrypt_internal (context, buffer_in, buffer_out);
   _gcry_burn_stack (2 * sizeof (serpent_block_t));
 }
 
@@ -853,9 +834,7 @@ serpent_decrypt (void *ctx, byte *buffer_out, const byte *buffer_in)
 {
   serpent_context_t *context = ctx;
 
-  serpent_decrypt_internal (context,
-			    (const u32 *) buffer_in,
-			    (u32 *) buffer_out);
+  serpent_decrypt_internal (context, buffer_in, buffer_out);
   _gcry_burn_stack (2 * sizeof (serpent_block_t));
 }
 
@@ -914,9 +893,7 @@ serpent_test (void)
     {
       serpent_setkey_internal (&context, test_data[i].key,
                                test_data[i].key_length);
-      serpent_encrypt_internal (&context,
-				(const u32 *) test_data[i].text_plain,
-				(u32 *) scratch);
+      serpent_encrypt_internal (&context, test_data[i].text_plain, scratch);
 
       if (memcmp (scratch, test_data[i].text_cipher, sizeof (serpent_block_t)))
 	switch (test_data[i].key_length)
@@ -929,9 +906,7 @@ serpent_test (void)
 	    return "Serpent-256 test encryption failed.";
 	  }
 
-    serpent_decrypt_internal (&context,
-			      (const u32 *) test_data[i].text_cipher,
-			      (u32 *) scratch);
+    serpent_decrypt_internal (&context, test_data[i].text_cipher, scratch);
     if (memcmp (scratch, test_data[i].text_plain, sizeof (serpent_block_t)))
       switch (test_data[i].key_length)
 	{

-----------------------------------------------------------------------

Summary of changes:
 AUTHORS          |    5 +++
 cipher/idea.c    |   54 +++++++++++++++++-----------------
 cipher/md4.c     |    3 +-
 cipher/md5.c     |    3 +-
 cipher/rmd160.c  |    3 +-
 cipher/serpent.c |   87 +++++++++++++++++++----------------------------------
 6 files changed, 69 insertions(+), 86 deletions(-)


hooks/post-receive
-- 
The GNU crypto library
http://git.gnupg.org




More information about the Gnupg-commits mailing list