Karsten Hopp 547f73
To: vim_dev@googlegroups.com
Karsten Hopp 547f73
Subject: Patch 7.4.172
Karsten Hopp 547f73
Fcc: outbox
Karsten Hopp 547f73
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp 547f73
Mime-Version: 1.0
Karsten Hopp 547f73
Content-Type: text/plain; charset=UTF-8
Karsten Hopp 547f73
Content-Transfer-Encoding: 8bit
Karsten Hopp 547f73
------------
Karsten Hopp 547f73
Karsten Hopp 547f73
Patch 7.4.172
Karsten Hopp 547f73
Problem:    The blowfish code mentions output feedback, but the code is
Karsten Hopp 547f73
	    actually doing cipher feedback.
Karsten Hopp 547f73
Solution:   Adjust names and comments.
Karsten Hopp 547f73
Files:	    src/blowfish.c, src/fileio.c, src/proto/blowfish.pro,
Karsten Hopp 547f73
	    src/memline.c
Karsten Hopp 547f73
Karsten Hopp 547f73
Karsten Hopp 547f73
*** ../vim-7.4.171/src/blowfish.c	2010-12-17 19:58:18.000000000 +0100
Karsten Hopp 547f73
--- src/blowfish.c	2014-02-11 15:18:12.882118804 +0100
Karsten Hopp 547f73
***************
Karsten Hopp 547f73
*** 6,12 ****
Karsten Hopp 547f73
   * Do ":help credits" in Vim to see a list of people who contributed.
Karsten Hopp 547f73
   * See README.txt for an overview of the Vim source code.
Karsten Hopp 547f73
   *
Karsten Hopp 547f73
!  * Blowfish encryption for Vim; in Blowfish output feedback mode.
Karsten Hopp 547f73
   * Contributed by Mohsin Ahmed, http://www.cs.albany.edu/~mosh
Karsten Hopp 547f73
   * Based on http://www.schneier.com/blowfish.html by Bruce Schneier.
Karsten Hopp 547f73
   */
Karsten Hopp 547f73
--- 6,12 ----
Karsten Hopp 547f73
   * Do ":help credits" in Vim to see a list of people who contributed.
Karsten Hopp 547f73
   * See README.txt for an overview of the Vim source code.
Karsten Hopp 547f73
   *
Karsten Hopp 547f73
!  * Blowfish encryption for Vim; in Blowfish cipher feedback mode.
Karsten Hopp 547f73
   * Contributed by Mohsin Ahmed, http://www.cs.albany.edu/~mosh
Karsten Hopp 547f73
   * Based on http://www.schneier.com/blowfish.html by Bruce Schneier.
Karsten Hopp 547f73
   */
Karsten Hopp 547f73
***************
Karsten Hopp 547f73
*** 19,25 ****
Karsten Hopp 547f73
  
Karsten Hopp 547f73
  #define BF_BLOCK    8
Karsten Hopp 547f73
  #define BF_BLOCK_MASK 7
Karsten Hopp 547f73
! #define BF_OFB_LEN  (8*(BF_BLOCK))
Karsten Hopp 547f73
  
Karsten Hopp 547f73
  typedef union {
Karsten Hopp 547f73
      UINT32_T ul[2];
Karsten Hopp 547f73
--- 19,25 ----
Karsten Hopp 547f73
  
Karsten Hopp 547f73
  #define BF_BLOCK    8
Karsten Hopp 547f73
  #define BF_BLOCK_MASK 7
Karsten Hopp 547f73
! #define BF_CFB_LEN  (8*(BF_BLOCK))
Karsten Hopp 547f73
  
Karsten Hopp 547f73
  typedef union {
Karsten Hopp 547f73
      UINT32_T ul[2];
Karsten Hopp 547f73
***************
Karsten Hopp 547f73
*** 554,595 ****
Karsten Hopp 547f73
      return err > 0 ? FAIL : OK;
Karsten Hopp 547f73
  }
Karsten Hopp 547f73
  
Karsten Hopp 547f73
! /* Output feedback mode. */
Karsten Hopp 547f73
  static int randbyte_offset = 0;
Karsten Hopp 547f73
  static int update_offset = 0;
Karsten Hopp 547f73
! static char_u ofb_buffer[BF_OFB_LEN]; /* 64 bytes */
Karsten Hopp 547f73
  
Karsten Hopp 547f73
  /*
Karsten Hopp 547f73
   * Initialize with seed "iv[iv_len]".
Karsten Hopp 547f73
   */
Karsten Hopp 547f73
      void
Karsten Hopp 547f73
! bf_ofb_init(iv, iv_len)
Karsten Hopp 547f73
      char_u *iv;
Karsten Hopp 547f73
      int    iv_len;
Karsten Hopp 547f73
  {
Karsten Hopp 547f73
      int i, mi;
Karsten Hopp 547f73
  
Karsten Hopp 547f73
      randbyte_offset = update_offset = 0;
Karsten Hopp 547f73
!     vim_memset(ofb_buffer, 0, BF_OFB_LEN);
Karsten Hopp 547f73
      if (iv_len > 0)
Karsten Hopp 547f73
      {
Karsten Hopp 547f73
! 	mi = iv_len > BF_OFB_LEN ? iv_len : BF_OFB_LEN;
Karsten Hopp 547f73
  	for (i = 0; i < mi; i++)
Karsten Hopp 547f73
! 	    ofb_buffer[i % BF_OFB_LEN] ^= iv[i % iv_len];
Karsten Hopp 547f73
      }
Karsten Hopp 547f73
  }
Karsten Hopp 547f73
  
Karsten Hopp 547f73
! #define BF_OFB_UPDATE(c) { \
Karsten Hopp 547f73
!     ofb_buffer[update_offset] ^= (char_u)c; \
Karsten Hopp 547f73
!     if (++update_offset == BF_OFB_LEN) \
Karsten Hopp 547f73
  	update_offset = 0; \
Karsten Hopp 547f73
  }
Karsten Hopp 547f73
  
Karsten Hopp 547f73
  #define BF_RANBYTE(t) { \
Karsten Hopp 547f73
      if ((randbyte_offset & BF_BLOCK_MASK) == 0) \
Karsten Hopp 547f73
! 	bf_e_cblock(&ofb_buffer[randbyte_offset]); \
Karsten Hopp 547f73
!     t = ofb_buffer[randbyte_offset]; \
Karsten Hopp 547f73
!     if (++randbyte_offset == BF_OFB_LEN) \
Karsten Hopp 547f73
  	randbyte_offset = 0; \
Karsten Hopp 547f73
  }
Karsten Hopp 547f73
  
Karsten Hopp 547f73
--- 554,595 ----
Karsten Hopp 547f73
      return err > 0 ? FAIL : OK;
Karsten Hopp 547f73
  }
Karsten Hopp 547f73
  
Karsten Hopp 547f73
! /* Cipher feedback mode. */
Karsten Hopp 547f73
  static int randbyte_offset = 0;
Karsten Hopp 547f73
  static int update_offset = 0;
Karsten Hopp 547f73
! static char_u cfb_buffer[BF_CFB_LEN]; /* 64 bytes */
Karsten Hopp 547f73
  
Karsten Hopp 547f73
  /*
Karsten Hopp 547f73
   * Initialize with seed "iv[iv_len]".
Karsten Hopp 547f73
   */
Karsten Hopp 547f73
      void
Karsten Hopp 547f73
! bf_cfb_init(iv, iv_len)
Karsten Hopp 547f73
      char_u *iv;
Karsten Hopp 547f73
      int    iv_len;
Karsten Hopp 547f73
  {
Karsten Hopp 547f73
      int i, mi;
Karsten Hopp 547f73
  
Karsten Hopp 547f73
      randbyte_offset = update_offset = 0;
Karsten Hopp 547f73
!     vim_memset(cfb_buffer, 0, BF_CFB_LEN);
Karsten Hopp 547f73
      if (iv_len > 0)
Karsten Hopp 547f73
      {
Karsten Hopp 547f73
! 	mi = iv_len > BF_CFB_LEN ? iv_len : BF_CFB_LEN;
Karsten Hopp 547f73
  	for (i = 0; i < mi; i++)
Karsten Hopp 547f73
! 	    cfb_buffer[i % BF_CFB_LEN] ^= iv[i % iv_len];
Karsten Hopp 547f73
      }
Karsten Hopp 547f73
  }
Karsten Hopp 547f73
  
Karsten Hopp 547f73
! #define BF_CFB_UPDATE(c) { \
Karsten Hopp 547f73
!     cfb_buffer[update_offset] ^= (char_u)c; \
Karsten Hopp 547f73
!     if (++update_offset == BF_CFB_LEN) \
Karsten Hopp 547f73
  	update_offset = 0; \
Karsten Hopp 547f73
  }
Karsten Hopp 547f73
  
Karsten Hopp 547f73
  #define BF_RANBYTE(t) { \
Karsten Hopp 547f73
      if ((randbyte_offset & BF_BLOCK_MASK) == 0) \
Karsten Hopp 547f73
! 	bf_e_cblock(&cfb_buffer[randbyte_offset]); \
Karsten Hopp 547f73
!     t = cfb_buffer[randbyte_offset]; \
Karsten Hopp 547f73
!     if (++randbyte_offset == BF_CFB_LEN) \
Karsten Hopp 547f73
  	randbyte_offset = 0; \
Karsten Hopp 547f73
  }
Karsten Hopp 547f73
  
Karsten Hopp 547f73
***************
Karsten Hopp 547f73
*** 610,616 ****
Karsten Hopp 547f73
      {
Karsten Hopp 547f73
  	ztemp = from[i];
Karsten Hopp 547f73
  	BF_RANBYTE(t);
Karsten Hopp 547f73
! 	BF_OFB_UPDATE(ztemp);
Karsten Hopp 547f73
  	to[i] = t ^ ztemp;
Karsten Hopp 547f73
      }
Karsten Hopp 547f73
  }
Karsten Hopp 547f73
--- 610,616 ----
Karsten Hopp 547f73
      {
Karsten Hopp 547f73
  	ztemp = from[i];
Karsten Hopp 547f73
  	BF_RANBYTE(t);
Karsten Hopp 547f73
! 	BF_CFB_UPDATE(ztemp);
Karsten Hopp 547f73
  	to[i] = t ^ ztemp;
Karsten Hopp 547f73
      }
Karsten Hopp 547f73
  }
Karsten Hopp 547f73
***************
Karsten Hopp 547f73
*** 630,636 ****
Karsten Hopp 547f73
      {
Karsten Hopp 547f73
  	BF_RANBYTE(t);
Karsten Hopp 547f73
  	*p ^= t;
Karsten Hopp 547f73
! 	BF_OFB_UPDATE(*p);
Karsten Hopp 547f73
      }
Karsten Hopp 547f73
  }
Karsten Hopp 547f73
  
Karsten Hopp 547f73
--- 630,636 ----
Karsten Hopp 547f73
      {
Karsten Hopp 547f73
  	BF_RANBYTE(t);
Karsten Hopp 547f73
  	*p ^= t;
Karsten Hopp 547f73
! 	BF_CFB_UPDATE(*p);
Karsten Hopp 547f73
      }
Karsten Hopp 547f73
  }
Karsten Hopp 547f73
  
Karsten Hopp 547f73
***************
Karsten Hopp 547f73
*** 646,658 ****
Karsten Hopp 547f73
  
Karsten Hopp 547f73
      for (p = passwd; *p != NUL; ++p)
Karsten Hopp 547f73
      {
Karsten Hopp 547f73
! 	BF_OFB_UPDATE(*p);
Karsten Hopp 547f73
      }
Karsten Hopp 547f73
  }
Karsten Hopp 547f73
  
Karsten Hopp 547f73
  static int save_randbyte_offset;
Karsten Hopp 547f73
  static int save_update_offset;
Karsten Hopp 547f73
! static char_u save_ofb_buffer[BF_OFB_LEN];
Karsten Hopp 547f73
  static UINT32_T save_pax[18];
Karsten Hopp 547f73
  static UINT32_T save_sbx[4][256];
Karsten Hopp 547f73
  
Karsten Hopp 547f73
--- 646,658 ----
Karsten Hopp 547f73
  
Karsten Hopp 547f73
      for (p = passwd; *p != NUL; ++p)
Karsten Hopp 547f73
      {
Karsten Hopp 547f73
! 	BF_CFB_UPDATE(*p);
Karsten Hopp 547f73
      }
Karsten Hopp 547f73
  }
Karsten Hopp 547f73
  
Karsten Hopp 547f73
  static int save_randbyte_offset;
Karsten Hopp 547f73
  static int save_update_offset;
Karsten Hopp 547f73
! static char_u save_cfb_buffer[BF_CFB_LEN];
Karsten Hopp 547f73
  static UINT32_T save_pax[18];
Karsten Hopp 547f73
  static UINT32_T save_sbx[4][256];
Karsten Hopp 547f73
  
Karsten Hopp 547f73
***************
Karsten Hopp 547f73
*** 665,671 ****
Karsten Hopp 547f73
  {
Karsten Hopp 547f73
      save_randbyte_offset = randbyte_offset;
Karsten Hopp 547f73
      save_update_offset = update_offset;
Karsten Hopp 547f73
!     mch_memmove(save_ofb_buffer, ofb_buffer, BF_OFB_LEN);
Karsten Hopp 547f73
      mch_memmove(save_pax, pax, 4 * 18);
Karsten Hopp 547f73
      mch_memmove(save_sbx, sbx, 4 * 4 * 256);
Karsten Hopp 547f73
  }
Karsten Hopp 547f73
--- 665,671 ----
Karsten Hopp 547f73
  {
Karsten Hopp 547f73
      save_randbyte_offset = randbyte_offset;
Karsten Hopp 547f73
      save_update_offset = update_offset;
Karsten Hopp 547f73
!     mch_memmove(save_cfb_buffer, cfb_buffer, BF_CFB_LEN);
Karsten Hopp 547f73
      mch_memmove(save_pax, pax, 4 * 18);
Karsten Hopp 547f73
      mch_memmove(save_sbx, sbx, 4 * 4 * 256);
Karsten Hopp 547f73
  }
Karsten Hopp 547f73
***************
Karsten Hopp 547f73
*** 679,685 ****
Karsten Hopp 547f73
  {
Karsten Hopp 547f73
      randbyte_offset = save_randbyte_offset;
Karsten Hopp 547f73
      update_offset = save_update_offset;
Karsten Hopp 547f73
!     mch_memmove(ofb_buffer, save_ofb_buffer, BF_OFB_LEN);
Karsten Hopp 547f73
      mch_memmove(pax, save_pax, 4 * 18);
Karsten Hopp 547f73
      mch_memmove(sbx, save_sbx, 4 * 4 * 256);
Karsten Hopp 547f73
  }
Karsten Hopp 547f73
--- 679,685 ----
Karsten Hopp 547f73
  {
Karsten Hopp 547f73
      randbyte_offset = save_randbyte_offset;
Karsten Hopp 547f73
      update_offset = save_update_offset;
Karsten Hopp 547f73
!     mch_memmove(cfb_buffer, save_cfb_buffer, BF_CFB_LEN);
Karsten Hopp 547f73
      mch_memmove(pax, save_pax, 4 * 18);
Karsten Hopp 547f73
      mch_memmove(sbx, save_sbx, 4 * 4 * 256);
Karsten Hopp 547f73
  }
Karsten Hopp 547f73
*** ../vim-7.4.171/src/fileio.c	2013-11-28 18:53:47.000000000 +0100
Karsten Hopp 547f73
--- src/fileio.c	2014-02-11 15:16:57.546117649 +0100
Karsten Hopp 547f73
***************
Karsten Hopp 547f73
*** 2973,2979 ****
Karsten Hopp 547f73
  	    else
Karsten Hopp 547f73
  	    {
Karsten Hopp 547f73
  		bf_key_init(cryptkey, ptr + CRYPT_MAGIC_LEN, salt_len);
Karsten Hopp 547f73
! 		bf_ofb_init(ptr + CRYPT_MAGIC_LEN + salt_len, seed_len);
Karsten Hopp 547f73
  	    }
Karsten Hopp 547f73
  
Karsten Hopp 547f73
  	    /* Remove magic number from the text */
Karsten Hopp 547f73
--- 2973,2979 ----
Karsten Hopp 547f73
  	    else
Karsten Hopp 547f73
  	    {
Karsten Hopp 547f73
  		bf_key_init(cryptkey, ptr + CRYPT_MAGIC_LEN, salt_len);
Karsten Hopp 547f73
! 		bf_cfb_init(ptr + CRYPT_MAGIC_LEN + salt_len, seed_len);
Karsten Hopp 547f73
  	    }
Karsten Hopp 547f73
  
Karsten Hopp 547f73
  	    /* Remove magic number from the text */
Karsten Hopp 547f73
***************
Karsten Hopp 547f73
*** 3025,3031 ****
Karsten Hopp 547f73
  	if (fread(buffer, salt_len + seed_len, 1, fp) != 1)
Karsten Hopp 547f73
  	    return FAIL;
Karsten Hopp 547f73
  	bf_key_init(curbuf->b_p_key, buffer, salt_len);
Karsten Hopp 547f73
! 	bf_ofb_init(buffer + salt_len, seed_len);
Karsten Hopp 547f73
      }
Karsten Hopp 547f73
      return OK;
Karsten Hopp 547f73
  }
Karsten Hopp 547f73
--- 3025,3031 ----
Karsten Hopp 547f73
  	if (fread(buffer, salt_len + seed_len, 1, fp) != 1)
Karsten Hopp 547f73
  	    return FAIL;
Karsten Hopp 547f73
  	bf_key_init(curbuf->b_p_key, buffer, salt_len);
Karsten Hopp 547f73
! 	bf_cfb_init(buffer + salt_len, seed_len);
Karsten Hopp 547f73
      }
Karsten Hopp 547f73
      return OK;
Karsten Hopp 547f73
  }
Karsten Hopp 547f73
***************
Karsten Hopp 547f73
*** 3064,3070 ****
Karsten Hopp 547f73
  	    seed = salt + salt_len;
Karsten Hopp 547f73
  	    sha2_seed(salt, salt_len, seed, seed_len);
Karsten Hopp 547f73
  	    bf_key_init(buf->b_p_key, salt, salt_len);
Karsten Hopp 547f73
! 	    bf_ofb_init(seed, seed_len);
Karsten Hopp 547f73
  	}
Karsten Hopp 547f73
      }
Karsten Hopp 547f73
      *lenp = CRYPT_MAGIC_LEN + salt_len + seed_len;
Karsten Hopp 547f73
--- 3064,3070 ----
Karsten Hopp 547f73
  	    seed = salt + salt_len;
Karsten Hopp 547f73
  	    sha2_seed(salt, salt_len, seed, seed_len);
Karsten Hopp 547f73
  	    bf_key_init(buf->b_p_key, salt, salt_len);
Karsten Hopp 547f73
! 	    bf_cfb_init(seed, seed_len);
Karsten Hopp 547f73
  	}
Karsten Hopp 547f73
      }
Karsten Hopp 547f73
      *lenp = CRYPT_MAGIC_LEN + salt_len + seed_len;
Karsten Hopp 547f73
*** ../vim-7.4.171/src/proto/blowfish.pro	2013-08-10 13:37:06.000000000 +0200
Karsten Hopp 547f73
--- src/proto/blowfish.pro	2014-02-11 15:18:20.382118919 +0100
Karsten Hopp 547f73
***************
Karsten Hopp 547f73
*** 1,6 ****
Karsten Hopp 547f73
  /* blowfish.c */
Karsten Hopp 547f73
  void bf_key_init __ARGS((char_u *password, char_u *salt, int salt_len));
Karsten Hopp 547f73
! void bf_ofb_init __ARGS((char_u *iv, int iv_len));
Karsten Hopp 547f73
  void bf_crypt_encode __ARGS((char_u *from, size_t len, char_u *to));
Karsten Hopp 547f73
  void bf_crypt_decode __ARGS((char_u *ptr, long len));
Karsten Hopp 547f73
  void bf_crypt_init_keys __ARGS((char_u *passwd));
Karsten Hopp 547f73
--- 1,6 ----
Karsten Hopp 547f73
  /* blowfish.c */
Karsten Hopp 547f73
  void bf_key_init __ARGS((char_u *password, char_u *salt, int salt_len));
Karsten Hopp 547f73
! void bf_cfb_init __ARGS((char_u *iv, int iv_len));
Karsten Hopp 547f73
  void bf_crypt_encode __ARGS((char_u *from, size_t len, char_u *to));
Karsten Hopp 547f73
  void bf_crypt_decode __ARGS((char_u *ptr, long len));
Karsten Hopp 547f73
  void bf_crypt_init_keys __ARGS((char_u *passwd));
Karsten Hopp 547f73
*** ../vim-7.4.171/src/memline.c	2013-11-28 17:41:41.000000000 +0100
Karsten Hopp 547f73
--- src/memline.c	2014-02-11 15:17:02.190117720 +0100
Karsten Hopp 547f73
***************
Karsten Hopp 547f73
*** 4914,4920 ****
Karsten Hopp 547f73
  	 * block for the salt. */
Karsten Hopp 547f73
  	vim_snprintf((char *)salt, sizeof(salt), "%ld", (long)offset);
Karsten Hopp 547f73
  	bf_key_init(key, salt, (int)STRLEN(salt));
Karsten Hopp 547f73
! 	bf_ofb_init(seed, MF_SEED_LEN);
Karsten Hopp 547f73
      }
Karsten Hopp 547f73
  }
Karsten Hopp 547f73
  
Karsten Hopp 547f73
--- 4914,4920 ----
Karsten Hopp 547f73
  	 * block for the salt. */
Karsten Hopp 547f73
  	vim_snprintf((char *)salt, sizeof(salt), "%ld", (long)offset);
Karsten Hopp 547f73
  	bf_key_init(key, salt, (int)STRLEN(salt));
Karsten Hopp 547f73
! 	bf_cfb_init(seed, MF_SEED_LEN);
Karsten Hopp 547f73
      }
Karsten Hopp 547f73
  }
Karsten Hopp 547f73
  
Karsten Hopp 547f73
*** ../vim-7.4.171/src/version.c	2014-02-11 15:10:38.138111836 +0100
Karsten Hopp 547f73
--- src/version.c	2014-02-11 15:16:01.206116786 +0100
Karsten Hopp 547f73
***************
Karsten Hopp 547f73
*** 740,741 ****
Karsten Hopp 547f73
--- 740,743 ----
Karsten Hopp 547f73
  {   /* Add new patch number below this line */
Karsten Hopp 547f73
+ /**/
Karsten Hopp 547f73
+     172,
Karsten Hopp 547f73
  /**/
Karsten Hopp 547f73
Karsten Hopp 547f73
-- 
Karsten Hopp 547f73
GALAHAD: No look, really, this isn't nescess ...
Karsten Hopp 547f73
PIGLET:  We must examine you.
Karsten Hopp 547f73
GALAHAD: There's nothing wrong with ... that.
Karsten Hopp 547f73
                 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD
Karsten Hopp 547f73
Karsten Hopp 547f73
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp 547f73
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp 547f73
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
Karsten Hopp 547f73
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///