[git] GCRYPT - branch, master, updated. libgcrypt-1.5.0-338-g51f1bea

by Jussi Kivilinna cvs at cvs.gnupg.org
Sat Oct 26 13:56:41 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, master has been updated
       via  51f1beab3d1e879942a95f58b08de7dbcce75dce (commit)
       via  d9431725952e40f201c7eda000d3c8511ebd5b33 (commit)
      from  6c6d4810927de7310ae7bac61b4ff5467d7cb485 (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 51f1beab3d1e879942a95f58b08de7dbcce75dce
Author: Jussi Kivilinna <jussi.kivilinna at iki.fi>
Date:   Sat Oct 26 14:51:44 2013 +0300

    Deduplicate code for ECB encryption and decryption
    
    * cipher/cipher.c (do_ecb_crypt): New, based on old 'do_ecb_encrypt'.
    (do_ecb_encrypt): Use 'do_ecb_crypt', pass encryption function.
    (do_ecb_decrypt): Use 'do_ecb_crypt', pass decryption function.
    --
    
    Signed-off-by: Jussi Kivilinna <jussi.kivilinna at iki.fi>

diff --git a/cipher/cipher.c b/cipher/cipher.c
index df6d202..73a97b1 100644
--- a/cipher/cipher.c
+++ b/cipher/cipher.c
@@ -627,11 +627,11 @@ cipher_reset (gcry_cipher_hd_t c)
 
 
 static gcry_err_code_t
-do_ecb_encrypt (gcry_cipher_hd_t c,
-                unsigned char *outbuf, unsigned int outbuflen,
-                const unsigned char *inbuf, unsigned int inbuflen)
+do_ecb_crypt (gcry_cipher_hd_t c,
+              unsigned char *outbuf, unsigned int outbuflen,
+              const unsigned char *inbuf, unsigned int inbuflen,
+              gcry_cipher_encrypt_t crypt_fn)
 {
-  gcry_cipher_encrypt_t enc_fn = c->spec->encrypt;
   unsigned int blocksize = c->spec->blocksize;
   unsigned int n, nblocks;
   unsigned int burn, nburn;
@@ -646,7 +646,7 @@ do_ecb_encrypt (gcry_cipher_hd_t c,
 
   for (n=0; n < nblocks; n++ )
     {
-      nburn = enc_fn (&c->context.c, outbuf, (byte*)/*arggg*/inbuf);
+      nburn = crypt_fn (&c->context.c, outbuf, inbuf);
       burn = nburn > burn ? nburn : burn;
       inbuf  += blocksize;
       outbuf += blocksize;
@@ -659,35 +659,19 @@ do_ecb_encrypt (gcry_cipher_hd_t c,
 }
 
 static gcry_err_code_t
-do_ecb_decrypt (gcry_cipher_hd_t c,
+do_ecb_encrypt (gcry_cipher_hd_t c,
                 unsigned char *outbuf, unsigned int outbuflen,
                 const unsigned char *inbuf, unsigned int inbuflen)
 {
-  gcry_cipher_decrypt_t dec_fn = c->spec->decrypt;
-  unsigned int blocksize = c->spec->blocksize;
-  unsigned int n, nblocks;
-  unsigned int burn, nburn;
-
-  if (outbuflen < inbuflen)
-    return GPG_ERR_BUFFER_TOO_SHORT;
-  if ((inbuflen % blocksize))
-    return GPG_ERR_INV_LENGTH;
-
-  nblocks = inbuflen / blocksize;
-  burn = 0;
-
-  for (n=0; n < nblocks; n++ )
-    {
-      nburn = dec_fn (&c->context.c, outbuf, (byte*)/*arggg*/inbuf);
-      burn = nburn > burn ? nburn : burn;
-      inbuf  += blocksize;
-      outbuf += blocksize;
-    }
-
-  if (burn > 0)
-    _gcry_burn_stack (burn + 4 * sizeof(void *));
+  return do_ecb_crypt (c, outbuf, outbuflen, inbuf, inbuflen, c->spec->encrypt);
+}
 
-  return 0;
+static gcry_err_code_t
+do_ecb_decrypt (gcry_cipher_hd_t c,
+                unsigned char *outbuf, unsigned int outbuflen,
+                const unsigned char *inbuf, unsigned int inbuflen)
+{
+  return do_ecb_crypt (c, outbuf, outbuflen, inbuf, inbuflen, c->spec->decrypt);
 }
 
 

commit d9431725952e40f201c7eda000d3c8511ebd5b33
Author: Dmitry Eremin-Solenikov <dbaryshkov at gmail.com>
Date:   Sat Oct 26 14:51:44 2013 +0300

    Drop _gcry_cipher_ofb_decrypt as it duplicates _gcry_cipher_ofb_encrypt
    
    * cipher/cipher.c (cipher_decrypt): Use _gcry_cipher_ofb_encrypt for OFB
      decryption.
    * cipher/cipher-internal.h: Remove _gcry_cipher_ofb_decrypt declaration.
    * cipher/cipher-ofb.c (_gcry_cipher_ofb_decrypt): Remove.
      (_gcry_cipher_ofb_encrypt): remove copying of IV to lastiv, it's
      unused there.
    
    Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov at gmail.com>

diff --git a/cipher/cipher-internal.h b/cipher/cipher-internal.h
index 981caa8..f528c84 100644
--- a/cipher/cipher-internal.h
+++ b/cipher/cipher-internal.h
@@ -173,10 +173,6 @@ gcry_err_code_t _gcry_cipher_ofb_encrypt
 /*           */ (gcry_cipher_hd_t c,
                  unsigned char *outbuf, unsigned int outbuflen,
                  const unsigned char *inbuf, unsigned int inbuflen);
-gcry_err_code_t _gcry_cipher_ofb_decrypt
-/*           */ (gcry_cipher_hd_t c,
-                 unsigned char *outbuf, unsigned int outbuflen,
-                 const unsigned char *inbuf, unsigned int inbuflen);
 
 /*-- cipher-ctr.c --*/
 gcry_err_code_t _gcry_cipher_ctr_encrypt
diff --git a/cipher/cipher-ofb.c b/cipher/cipher-ofb.c
index 333a748..c6d84dd 100644
--- a/cipher/cipher-ofb.c
+++ b/cipher/cipher-ofb.c
@@ -70,7 +70,6 @@ _gcry_cipher_ofb_encrypt (gcry_cipher_hd_t c,
   while ( inbuflen >= blocksize )
     {
       /* Encrypt the IV (and save the current one). */
-      buf_cpy( c->lastiv, c->u_iv.iv, blocksize );
       nburn = enc_fn ( &c->context.c, c->u_iv.iv, c->u_iv.iv );
       burn = nburn > burn ? nburn : burn;
       buf_xor(outbuf, c->u_iv.iv, inbuf, blocksize);
@@ -80,74 +79,6 @@ _gcry_cipher_ofb_encrypt (gcry_cipher_hd_t c,
     }
   if ( inbuflen )
     { /* process the remaining bytes */
-      buf_cpy( c->lastiv, c->u_iv.iv, blocksize );
-      nburn = enc_fn ( &c->context.c, c->u_iv.iv, c->u_iv.iv );
-      burn = nburn > burn ? nburn : burn;
-      c->unused = blocksize;
-      c->unused -= inbuflen;
-      buf_xor(outbuf, c->u_iv.iv, inbuf, inbuflen);
-      outbuf += inbuflen;
-      inbuf += inbuflen;
-      inbuflen = 0;
-    }
-
-  if (burn > 0)
-    _gcry_burn_stack (burn + 4 * sizeof(void *));
-
-  return 0;
-}
-
-
-gcry_err_code_t
-_gcry_cipher_ofb_decrypt (gcry_cipher_hd_t c,
-                          unsigned char *outbuf, unsigned int outbuflen,
-                          const unsigned char *inbuf, unsigned int inbuflen)
-{
-  unsigned char *ivp;
-  gcry_cipher_encrypt_t enc_fn = c->spec->encrypt;
-  size_t blocksize = c->spec->blocksize;
-  unsigned int burn, nburn;
-
-  if (outbuflen < inbuflen)
-    return GPG_ERR_BUFFER_TOO_SHORT;
-
-  if( inbuflen <= c->unused )
-    {
-      /* Short enough to be encoded by the remaining XOR mask. */
-      ivp = c->u_iv.iv + blocksize - c->unused;
-      buf_xor(outbuf, ivp, inbuf, inbuflen);
-      c->unused -= inbuflen;
-      return 0;
-    }
-
-  burn = 0;
-
-  if ( c->unused )
-    {
-      inbuflen -= c->unused;
-      ivp = c->u_iv.iv + blocksize - c->unused;
-      buf_xor(outbuf, ivp, inbuf, c->unused);
-      outbuf += c->unused;
-      inbuf += c->unused;
-      c->unused = 0;
-    }
-
-  /* Now we can process complete blocks. */
-  while ( inbuflen >= blocksize )
-    {
-      /* Encrypt the IV (and save the current one). */
-      buf_cpy( c->lastiv, c->u_iv.iv, blocksize );
-      nburn = enc_fn ( &c->context.c, c->u_iv.iv, c->u_iv.iv );
-      burn = nburn > burn ? nburn : burn;
-      buf_xor(outbuf, c->u_iv.iv, inbuf, blocksize);
-      outbuf += blocksize;
-      inbuf += blocksize;
-      inbuflen -= blocksize;
-    }
-  if ( inbuflen )
-    { /* Process the remaining bytes. */
-      /* Encrypt the IV (and save the current one). */
-      buf_cpy( c->lastiv, c->u_iv.iv, blocksize );
       nburn = enc_fn ( &c->context.c, c->u_iv.iv, c->u_iv.iv );
       burn = nburn > burn ? nburn : burn;
       c->unused = blocksize;
diff --git a/cipher/cipher.c b/cipher/cipher.c
index c0d1d0b..df6d202 100644
--- a/cipher/cipher.c
+++ b/cipher/cipher.c
@@ -814,7 +814,7 @@ cipher_decrypt (gcry_cipher_hd_t c, byte *outbuf, unsigned int outbuflen,
       break;
 
     case GCRY_CIPHER_MODE_OFB:
-      rc = _gcry_cipher_ofb_decrypt (c, outbuf, outbuflen, inbuf, inbuflen);
+      rc = _gcry_cipher_ofb_encrypt (c, outbuf, outbuflen, inbuf, inbuflen);
       break;
 
     case GCRY_CIPHER_MODE_CTR:

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

Summary of changes:
 cipher/cipher-internal.h |    4 ---
 cipher/cipher-ofb.c      |   69 ----------------------------------------------
 cipher/cipher.c          |   46 ++++++++++---------------------
 3 files changed, 15 insertions(+), 104 deletions(-)


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


_______________________________________________
Gnupg-commits mailing list
Gnupg-commits at gnupg.org
http://lists.gnupg.org/mailman/listinfo/gnupg-commits




More information about the Gcrypt-devel mailing list