mirror of
https://github.com/vim/vim.git
synced 2025-09-24 03:44:06 -04:00
Made crypt/decrypt faster.
This commit is contained in:
@@ -1085,7 +1085,6 @@ Vim 7.3:
|
|||||||
- using NSIS 2.46: install on Windows 7 works, but no "Edit with Vim" menu.
|
- using NSIS 2.46: install on Windows 7 works, but no "Edit with Vim" menu.
|
||||||
Use register_shell_extension()? (George Reilly, 2010 May 26)
|
Use register_shell_extension()? (George Reilly, 2010 May 26)
|
||||||
Ron's version: http://dev.ronware.org/p/vim/finfo?name=gvim.nsi
|
Ron's version: http://dev.ronware.org/p/vim/finfo?name=gvim.nsi
|
||||||
- Undo code: use union to store long in place of pointers?
|
|
||||||
- Also crypt the swap file, each block separately. Change mf_write() and
|
- Also crypt the swap file, each block separately. Change mf_write() and
|
||||||
mf_read(). How to get b_p_key to these functions?
|
mf_read(). How to get b_p_key to these functions?
|
||||||
Generate seed for each block, store in pointer block. Block 1 is not
|
Generate seed for each block, store in pointer block. Block 1 is not
|
||||||
@@ -1095,8 +1094,11 @@ Vim 7.3:
|
|||||||
Verify recovery works.
|
Verify recovery works.
|
||||||
- Update for crypt code to use salt. (Mohsin May 30)
|
- Update for crypt code to use salt. (Mohsin May 30)
|
||||||
Make the strengthen_key value configurable and store it in the header.
|
Make the strengthen_key value configurable and store it in the header.
|
||||||
- Do profiling on sha256 code to find obvious bottlenecks.
|
|
||||||
- Do profiling on crypt code to find obvious bottlenecks.
|
- Do profiling on crypt code to find obvious bottlenecks.
|
||||||
|
bf_ranbyte() and bf_ofb_init() are called for each byte, can they be done
|
||||||
|
inline somehow?
|
||||||
|
-> Add a function in blowfish.c to process an array, called once from
|
||||||
|
crypt_decode() and crypt_encode().
|
||||||
Patches to include:
|
Patches to include:
|
||||||
- Include conceal patch?
|
- Include conceal patch?
|
||||||
http://vince.negri.googlepages.com/
|
http://vince.negri.googlepages.com/
|
||||||
|
@@ -18,6 +18,7 @@
|
|||||||
#define ARRAY_LENGTH(A) (sizeof(A)/sizeof(A[0]))
|
#define ARRAY_LENGTH(A) (sizeof(A)/sizeof(A[0]))
|
||||||
|
|
||||||
#define BF_BLOCK 8
|
#define BF_BLOCK 8
|
||||||
|
#define BF_BLOCK_MASK 7
|
||||||
#define BF_OFB_LEN (8*(BF_BLOCK))
|
#define BF_OFB_LEN (8*(BF_BLOCK))
|
||||||
|
|
||||||
typedef union {
|
typedef union {
|
||||||
@@ -563,14 +564,14 @@ bf_ofb_update(c)
|
|||||||
int
|
int
|
||||||
bf_ranbyte()
|
bf_ranbyte()
|
||||||
{
|
{
|
||||||
int current_byte = randbyte_offset++;
|
int b;
|
||||||
int current_block = (current_byte / BF_BLOCK) * BF_BLOCK;
|
|
||||||
|
|
||||||
if (randbyte_offset == BF_OFB_LEN)
|
if ((randbyte_offset & BF_BLOCK_MASK) == 0)
|
||||||
|
bf_e_cblock(&ofb_buffer[randbyte_offset]);
|
||||||
|
b = ofb_buffer[randbyte_offset];
|
||||||
|
if (++randbyte_offset == BF_OFB_LEN)
|
||||||
randbyte_offset = 0;
|
randbyte_offset = 0;
|
||||||
if ((current_byte % BF_BLOCK) == 0)
|
return b;
|
||||||
bf_e_cblock(&ofb_buffer[current_block]);
|
|
||||||
return ofb_buffer[current_byte];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
24
src/fileio.c
24
src/fileio.c
@@ -1426,8 +1426,7 @@ retry:
|
|||||||
* Decrypt the read bytes.
|
* Decrypt the read bytes.
|
||||||
*/
|
*/
|
||||||
if (cryptkey != NULL && size > 0)
|
if (cryptkey != NULL && size > 0)
|
||||||
for (p = ptr; p < ptr + size; ++p)
|
crypt_decode(ptr, size);
|
||||||
ZDECODE(*p);
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
skip_read = FALSE;
|
skip_read = FALSE;
|
||||||
@@ -3004,7 +3003,6 @@ fwrite_crypt(buf, ptr, len, fp)
|
|||||||
{
|
{
|
||||||
char_u *copy;
|
char_u *copy;
|
||||||
char_u small_buf[100];
|
char_u small_buf[100];
|
||||||
int ztemp, t;
|
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
if (*buf->b_p_key == NUL)
|
if (*buf->b_p_key == NUL)
|
||||||
@@ -3017,11 +3015,7 @@ fwrite_crypt(buf, ptr, len, fp)
|
|||||||
if (copy == NULL)
|
if (copy == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
for (i = 0; i < len; ++i)
|
crypt_encode(ptr, len, copy);
|
||||||
{
|
|
||||||
ztemp = ptr[i];
|
|
||||||
copy[i] = ZENCODE(ztemp, t);
|
|
||||||
}
|
|
||||||
i = fwrite(copy, len, (size_t)1, fp);
|
i = fwrite(copy, len, (size_t)1, fp);
|
||||||
if (copy != small_buf)
|
if (copy != small_buf)
|
||||||
vim_free(copy);
|
vim_free(copy);
|
||||||
@@ -3039,12 +3033,10 @@ read_string_decrypt(buf, fd, len)
|
|||||||
int len;
|
int len;
|
||||||
{
|
{
|
||||||
char_u *ptr;
|
char_u *ptr;
|
||||||
char_u *p;
|
|
||||||
|
|
||||||
ptr = read_string(fd, len);
|
ptr = read_string(fd, len);
|
||||||
if (ptr != NULL || *buf->b_p_key != NUL)
|
if (ptr != NULL || *buf->b_p_key != NUL)
|
||||||
for (p = ptr; p < ptr + len; ++p)
|
crypt_decode(ptr, len);
|
||||||
ZDECODE(*p);
|
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -5678,15 +5670,7 @@ buf_write_bytes(ip)
|
|||||||
|
|
||||||
#ifdef FEAT_CRYPT
|
#ifdef FEAT_CRYPT
|
||||||
if (flags & FIO_ENCRYPTED) /* encrypt the data */
|
if (flags & FIO_ENCRYPTED) /* encrypt the data */
|
||||||
{
|
crypt_encode(buf, len, buf);
|
||||||
int ztemp, t, i;
|
|
||||||
|
|
||||||
for (i = 0; i < len; i++)
|
|
||||||
{
|
|
||||||
ztemp = buf[i];
|
|
||||||
buf[i] = ZENCODE(ztemp, t);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Repeat the write(), it may be interrupted by a signal. */
|
/* Repeat the write(), it may be interrupted by a signal. */
|
||||||
|
15
src/macros.h
15
src/macros.h
@@ -227,21 +227,6 @@
|
|||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
|
||||||
* Encryption macros. Mohsin Ahmed, mosh@sasi.com 98-09-24
|
|
||||||
* Based on zip/crypt sources.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifdef FEAT_CRYPT
|
|
||||||
|
|
||||||
/* encode byte c, using temp t. Warning: c must not have side effects. */
|
|
||||||
# define ZENCODE(c, t) (t = decrypt_byte(), update_keys(c), t^(c))
|
|
||||||
|
|
||||||
/* decode byte c in place */
|
|
||||||
# define ZDECODE(c) update_keys(c ^= decrypt_byte())
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef STARTUPTIME
|
#ifdef STARTUPTIME
|
||||||
# define TIME_MSG(s) { if (time_fd != NULL) time_msg(s, NULL); }
|
# define TIME_MSG(s) { if (time_fd != NULL) time_msg(s, NULL); }
|
||||||
#else
|
#else
|
||||||
|
96
src/misc2.c
96
src/misc2.c
@@ -3724,39 +3724,81 @@ make_crc_tab()
|
|||||||
|
|
||||||
#define CRC32(c, b) (crc_32_tab[((int)(c) ^ (b)) & 0xff] ^ ((c) >> 8))
|
#define CRC32(c, b) (crc_32_tab[((int)(c) ^ (b)) & 0xff] ^ ((c) >> 8))
|
||||||
|
|
||||||
|
|
||||||
static ulg keys[3]; /* keys defining the pseudo-random sequence */
|
static ulg keys[3]; /* keys defining the pseudo-random sequence */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Return the next byte in the pseudo-random sequence
|
* Return the next byte in the pseudo-random sequence.
|
||||||
*/
|
*/
|
||||||
int
|
#define DECRYPT_BYTE_ZIP(t) { \
|
||||||
decrypt_byte()
|
ush temp; \
|
||||||
{
|
\
|
||||||
ush temp;
|
temp = (ush)keys[2] | 2; \
|
||||||
|
t = (int)(((unsigned)(temp * (temp ^ 1)) >> 8) & 0xff); \
|
||||||
if (use_crypt_method > 0)
|
|
||||||
return bf_ranbyte();
|
|
||||||
temp = (ush)keys[2] | 2;
|
|
||||||
return (int)(((unsigned)(temp * (temp ^ 1)) >> 8) & 0xff);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Update the encryption keys with the next byte of plain text
|
* Update the encryption keys with the next byte of plain text.
|
||||||
|
*/
|
||||||
|
#define UPDATE_KEYS_ZIP(c) { \
|
||||||
|
keys[0] = CRC32(keys[0], (c)); \
|
||||||
|
keys[1] += keys[0] & 0xff; \
|
||||||
|
keys[1] = keys[1] * 134775813L + 1; \
|
||||||
|
keys[2] = CRC32(keys[2], (int)(keys[1] >> 24)); \
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Encrypt "from[len]" into "to[len]".
|
||||||
|
* "from" and "to" can be equal to encrypt in place.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
update_keys(c)
|
crypt_encode(from, len, to)
|
||||||
int c; /* byte of plain text */
|
char_u *from;
|
||||||
|
size_t len;
|
||||||
|
char_u *to;
|
||||||
{
|
{
|
||||||
if (use_crypt_method > 0)
|
size_t i;
|
||||||
bf_ofb_update(c);
|
int ztemp, t;
|
||||||
|
|
||||||
|
if (use_crypt_method == 0)
|
||||||
|
for (i = 0; i < len; ++i)
|
||||||
|
{
|
||||||
|
ztemp = from[i];
|
||||||
|
DECRYPT_BYTE_ZIP(t);
|
||||||
|
UPDATE_KEYS_ZIP(ztemp);
|
||||||
|
to[i] = t ^ ztemp;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
for (i = 0; i < len; ++i)
|
||||||
keys[0] = CRC32(keys[0], c);
|
{
|
||||||
keys[1] += keys[0] & 0xff;
|
ztemp = from[i];
|
||||||
keys[1] = keys[1] * 134775813L + 1;
|
t = bf_ranbyte();
|
||||||
keys[2] = CRC32(keys[2], (int)(keys[1] >> 24));
|
bf_ofb_update(ztemp);
|
||||||
}
|
to[i] = t ^ ztemp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Decrypt "ptr[len]" in place.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
crypt_decode(ptr, len)
|
||||||
|
char_u *ptr;
|
||||||
|
long len;
|
||||||
|
{
|
||||||
|
char_u *p;
|
||||||
|
|
||||||
|
if (use_crypt_method == 0)
|
||||||
|
for (p = ptr; p < ptr + len; ++p)
|
||||||
|
{
|
||||||
|
ush temp;
|
||||||
|
|
||||||
|
temp = (ush)keys[2] | 2;
|
||||||
|
temp = (int)(((unsigned)(temp * (temp ^ 1)) >> 8) & 0xff);
|
||||||
|
UPDATE_KEYS_ZIP(*p ^= temp);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
for (p = ptr; p < ptr + len; ++p)
|
||||||
|
bf_ofb_update(*p ^= bf_ranbyte());
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -3774,8 +3816,14 @@ crypt_init_keys(passwd)
|
|||||||
keys[0] = 305419896L;
|
keys[0] = 305419896L;
|
||||||
keys[1] = 591751049L;
|
keys[1] = 591751049L;
|
||||||
keys[2] = 878082192L;
|
keys[2] = 878082192L;
|
||||||
while (*passwd != '\0')
|
if (use_crypt_method == 0)
|
||||||
update_keys((int)*passwd++);
|
while (*passwd != '\0')
|
||||||
|
{
|
||||||
|
UPDATE_KEYS_ZIP((int)*passwd++);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
while (*passwd != '\0')
|
||||||
|
bf_ofb_update((int)*passwd++);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -80,8 +80,8 @@ int illegal_slash __ARGS((char *name));
|
|||||||
char_u *parse_shape_opt __ARGS((int what));
|
char_u *parse_shape_opt __ARGS((int what));
|
||||||
int get_shape_idx __ARGS((int mouse));
|
int get_shape_idx __ARGS((int mouse));
|
||||||
void update_mouseshape __ARGS((int shape_idx));
|
void update_mouseshape __ARGS((int shape_idx));
|
||||||
int decrypt_byte __ARGS((void));
|
void crypt_encode __ARGS((char_u *from, size_t len, char_u *to));
|
||||||
void update_keys __ARGS((int c));
|
void crypt_decode __ARGS((char_u *ptr, long len));
|
||||||
void crypt_init_keys __ARGS((char_u *passwd));
|
void crypt_init_keys __ARGS((char_u *passwd));
|
||||||
void free_crypt_key __ARGS((char_u *key));
|
void free_crypt_key __ARGS((char_u *key));
|
||||||
char_u *get_crypt_key __ARGS((int store, int twice));
|
char_u *get_crypt_key __ARGS((int store, int twice));
|
||||||
|
Reference in New Issue
Block a user