Mercurial > vim
annotate src/crypt_zip.c @ 14129:cb731d098241 v8.1.0082
patch 8.1.0082: in terminal window, typing : at more prompt, inserts ':'
commit https://github.com/vim/vim/commit/1d4754f96fa5bff1c349cdb71560c55675f50d03
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Jun 19 17:49:24 2018 +0200
patch 8.1.0082: in terminal window, typing : at more prompt, inserts ':'
Problem: In terminal window, typing : at more prompt, inserts ':' instead
of starting another Ex command.
Solution: Add skip_term_loop and set it when putting ':' in the typeahead
buffer.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Tue, 19 Jun 2018 18:00:07 +0200 |
parents | 4aead6a9b7a9 |
children | 27b9a84395b5 |
rev | line source |
---|---|
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
7817
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
6122 | 2 * |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * | |
5 * Do ":help uganda" in Vim to read copying and usage conditions. | |
6 * Do ":help credits" in Vim to see a list of people who contributed. | |
7 * See README.txt for an overview of the Vim source code. | |
8 */ | |
9 | |
10 /* | |
11 * crypt_zip.c: Zip encryption support. | |
12 */ | |
13 #include "vim.h" | |
14 | |
15 #if defined(FEAT_CRYPT) || defined(PROTO) | |
16 /* | |
17 * Optional encryption support. | |
18 * Mohsin Ahmed, mosh@sasi.com, 98-09-24 | |
19 * Based on zip/crypt sources. | |
20 * | |
21 * NOTE FOR USA: Since 2000 exporting this code from the USA is allowed to | |
22 * most countries. There are a few exceptions, but that still should not be a | |
23 * problem since this code was originally created in Europe and India. | |
24 */ | |
25 | |
26 /* Need a type that should be 32 bits. 64 also works but wastes space. */ | |
27 # if VIM_SIZEOF_INT >= 4 | |
28 typedef unsigned int u32_T; /* int is at least 32 bits */ | |
29 # else | |
30 typedef unsigned long u32_T; /* long should be 32 bits or more */ | |
31 # endif | |
32 | |
33 /* The state of encryption, referenced by cryptstate_T. */ | |
34 typedef struct { | |
35 u32_T keys[3]; | |
36 } zip_state_T; | |
37 | |
38 | |
7799
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
6122
diff
changeset
|
39 static void make_crc_tab(void); |
6122 | 40 |
41 static u32_T crc_32_table[256]; | |
42 | |
43 /* | |
44 * Fill the CRC table, if not done already. | |
45 */ | |
46 static void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
47 make_crc_tab(void) |
6122 | 48 { |
49 u32_T s, t, v; | |
50 static int done = FALSE; | |
51 | |
52 if (done) | |
53 return; | |
54 for (t = 0; t < 256; t++) | |
55 { | |
56 v = t; | |
57 for (s = 0; s < 8; s++) | |
58 v = (v >> 1) ^ ((v & 1) * (u32_T)0xedb88320L); | |
59 crc_32_table[t] = v; | |
60 } | |
61 done = TRUE; | |
62 } | |
63 | |
64 #define CRC32(c, b) (crc_32_table[((int)(c) ^ (b)) & 0xff] ^ ((c) >> 8)) | |
65 | |
66 /* | |
67 * Return the next byte in the pseudo-random sequence. | |
68 */ | |
69 #define DECRYPT_BYTE_ZIP(keys, t) { \ | |
70 short_u temp = (short_u)keys[2] | 2; \ | |
71 t = (int)(((unsigned)(temp * (temp ^ 1U)) >> 8) & 0xff); \ | |
72 } | |
73 | |
74 /* | |
75 * Update the encryption keys with the next byte of plain text. | |
76 */ | |
77 #define UPDATE_KEYS_ZIP(keys, c) { \ | |
78 keys[0] = CRC32(keys[0], (c)); \ | |
79 keys[1] += keys[0] & 0xff; \ | |
80 keys[1] = keys[1] * 134775813L + 1; \ | |
81 keys[2] = CRC32(keys[2], (int)(keys[1] >> 24)); \ | |
82 } | |
83 | |
84 /* | |
85 * Initialize for encryption/decryption. | |
86 */ | |
87 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
88 crypt_zip_init( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
89 cryptstate_T *state, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
90 char_u *key, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
91 char_u *salt UNUSED, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
92 int salt_len UNUSED, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
93 char_u *seed UNUSED, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
94 int seed_len UNUSED) |
6122 | 95 { |
96 char_u *p; | |
97 zip_state_T *zs; | |
98 | |
99 zs = (zip_state_T *)alloc(sizeof(zip_state_T)); | |
100 state->method_state = zs; | |
101 | |
102 make_crc_tab(); | |
103 zs->keys[0] = 305419896L; | |
104 zs->keys[1] = 591751049L; | |
105 zs->keys[2] = 878082192L; | |
106 for (p = key; *p != NUL; ++p) | |
107 { | |
108 UPDATE_KEYS_ZIP(zs->keys, (int)*p); | |
109 } | |
110 } | |
111 | |
112 /* | |
113 * Encrypt "from[len]" into "to[len]". | |
114 * "from" and "to" can be equal to encrypt in place. | |
115 */ | |
116 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
117 crypt_zip_encode( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
118 cryptstate_T *state, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
119 char_u *from, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
120 size_t len, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
121 char_u *to) |
6122 | 122 { |
123 zip_state_T *zs = state->method_state; | |
124 size_t i; | |
125 int ztemp, t; | |
126 | |
127 for (i = 0; i < len; ++i) | |
128 { | |
129 ztemp = from[i]; | |
130 DECRYPT_BYTE_ZIP(zs->keys, t); | |
131 UPDATE_KEYS_ZIP(zs->keys, ztemp); | |
132 to[i] = t ^ ztemp; | |
133 } | |
134 } | |
135 | |
136 /* | |
137 * Decrypt "from[len]" into "to[len]". | |
138 */ | |
139 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
140 crypt_zip_decode( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
141 cryptstate_T *state, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
142 char_u *from, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
143 size_t len, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
144 char_u *to) |
6122 | 145 { |
146 zip_state_T *zs = state->method_state; | |
147 size_t i; | |
148 short_u temp; | |
149 | |
150 for (i = 0; i < len; ++i) | |
151 { | |
152 temp = (short_u)zs->keys[2] | 2; | |
153 temp = (int)(((unsigned)(temp * (temp ^ 1U)) >> 8) & 0xff); | |
154 UPDATE_KEYS_ZIP(zs->keys, to[i] = from[i] ^ temp); | |
155 } | |
156 } | |
157 | |
158 #endif /* FEAT_CRYPT */ |