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