vim-patch:7.4.172

Problem:    The blowfish code mentions output feedback, but the code is
	        actually doing cipher feedback.
Solution:   Adjust names and comments.

https://code.google.com/p/vim/source/detail?r=391e10afccf6879dcfab8b28cb1587a13eb835c0
This commit is contained in:
oni-link 2014-04-03 13:09:07 +02:00 committed by Thiago de Arruda
parent 26206d4cfd
commit ade0c127e5
5 changed files with 38 additions and 34 deletions

View File

@ -6,7 +6,7 @@
* 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.
* 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.
*/
@ -22,7 +22,7 @@
#define BF_BLOCK 8
#define BF_BLOCK_MASK 7
#define BF_OFB_LEN (8 * (BF_BLOCK))
#define BF_CFB_LEN (8 * (BF_BLOCK))
typedef union {
uint32_t ul[2];
@ -493,42 +493,44 @@ static int bf_self_test(void)
return err > 0 ? FAIL : OK;
}
// Output feedback mode.
// Cipher feedback mode.
static int randbyte_offset = 0;
static int update_offset = 0;
static char_u ofb_buffer[BF_OFB_LEN]; // 64 bytes
static char_u cfb_buffer[BF_CFB_LEN]; // 64 bytes
// Initialize with seed "iv[iv_len]".
void bf_ofb_init(char_u *iv, int iv_len)
void bf_cfb_init(char_u *iv, int iv_len)
{
randbyte_offset = update_offset = 0;
memset(ofb_buffer, 0, BF_OFB_LEN);
memset(cfb_buffer, 0, BF_CFB_LEN);
if (iv_len > 0) {
int mi = iv_len > BF_OFB_LEN ? iv_len : BF_OFB_LEN;
int mi = iv_len > BF_CFB_LEN ? iv_len : BF_CFB_LEN;
int i;
for (i = 0; i < mi; i++) {
ofb_buffer[i % BF_OFB_LEN] ^= iv[i % iv_len];
cfb_buffer[i % BF_CFB_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_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(&ofb_buffer[randbyte_offset]); \
} \
t = ofb_buffer[randbyte_offset]; \
if (++randbyte_offset == BF_OFB_LEN) { \
randbyte_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; \
} \
}
// Encrypt "from[len]" into "to[len]".
// "from" and "to" can be equal to encrypt in place.
@ -539,7 +541,7 @@ void bf_crypt_encode(char_u *from, size_t len, char_u *to)
int ztemp = from[i];
int t;
BF_RANBYTE(t);
BF_OFB_UPDATE(ztemp);
BF_CFB_UPDATE(ztemp);
to[i] = t ^ ztemp;
}
}
@ -554,7 +556,7 @@ void bf_crypt_decode(char_u *ptr, long len)
int t;
BF_RANBYTE(t);
*p ^= t;
BF_OFB_UPDATE(*p);
BF_CFB_UPDATE(*p);
}
}
@ -567,13 +569,13 @@ void bf_crypt_init_keys(char_u *passwd)
{
char_u *p;
for (p = passwd; *p != NUL; p++) {
BF_OFB_UPDATE(*p);
BF_CFB_UPDATE(*p);
}
}
static int save_randbyte_offset;
static int save_update_offset;
static char_u save_ofb_buffer[BF_OFB_LEN];
static char_u save_cfb_buffer[BF_CFB_LEN];
static uint32_t save_pax[18];
static uint32_t save_sbx[4][256];
@ -585,7 +587,7 @@ void bf_crypt_save(void)
{
save_randbyte_offset = randbyte_offset;
save_update_offset = update_offset;
memmove(save_ofb_buffer, ofb_buffer, BF_OFB_LEN);
memmove(save_cfb_buffer, cfb_buffer, BF_CFB_LEN);
memmove(save_pax, pax, 4 * 18);
memmove(save_sbx, sbx, 4 * 4 * 256);
}
@ -598,7 +600,7 @@ void bf_crypt_restore(void)
{
randbyte_offset = save_randbyte_offset;
update_offset = save_update_offset;
memmove(ofb_buffer, save_ofb_buffer, BF_OFB_LEN);
memmove(cfb_buffer, save_cfb_buffer, BF_CFB_LEN);
memmove(pax, save_pax, 4 * 18);
memmove(sbx, save_sbx, 4 * 4 * 256);
}

View File

@ -2,7 +2,7 @@
#define NEOVIM_BLOWFISH_H
void bf_key_init(char_u *password, char_u *salt, int salt_len);
void bf_ofb_init(char_u *iv, int iv_len);
void bf_cfb_init(char_u *iv, int iv_len);
void bf_crypt_encode(char_u *from, size_t len, char_u *to);
void bf_crypt_decode(char_u *ptr, long len);
void bf_crypt_init_keys(char_u *passwd);

View File

@ -2324,7 +2324,7 @@ check_for_cryptkey (
crypt_init_keys(cryptkey);
else {
bf_key_init(cryptkey, ptr + CRYPT_MAGIC_LEN, salt_len);
bf_ofb_init(ptr + CRYPT_MAGIC_LEN + salt_len, seed_len);
bf_cfb_init(ptr + CRYPT_MAGIC_LEN + salt_len, seed_len);
}
/* Remove magic number from the text */
@ -2373,7 +2373,7 @@ int prepare_crypt_read(FILE *fp)
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);
bf_cfb_init(buffer + salt_len, seed_len);
}
return OK;
}
@ -2407,7 +2407,7 @@ char_u *prepare_crypt_write(buf_T *buf, int *lenp)
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);
bf_cfb_init(seed, seed_len);
}
}
*lenp = CRYPT_MAGIC_LEN + salt_len + seed_len;

View File

@ -4279,7 +4279,7 @@ static void ml_crypt_prepare(memfile_T *mfp, off_t offset, int reading)
* 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);
bf_cfb_init(seed, MF_SEED_LEN);
}
}

View File

@ -202,6 +202,8 @@ static char *(features[]) = {
static int included_patches[] = {
// Add new patch number below this line
172,
//171,
170,
169,
//168,