Mercurial > vim
annotate src/crypt_zip.c @ 32080:fc1d95479511 v9.0.1371
patch 9.0.1371: ballooneval interferes with Insert completion
Commit: https://github.com/vim/vim/commit/440d4cb55b84fd4b188630abc4a1312598649af0
Author: zeertzjq <zeertzjq@outlook.com>
Date: Thu Mar 2 17:51:32 2023 +0000
patch 9.0.1371: ballooneval interferes with Insert completion
Problem: Ballooneval interferes with Insert completion.
Solution: Ignore mouse-move events when completing. (closes https://github.com/vim/vim/issues/12094,
closes #12092)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 02 Mar 2023 19:00:05 +0100 |
parents | 50555279168b |
children | 3d4e28569a6d |
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 | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
26 // Need a type that should be 32 bits. 64 also works but wastes space. |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
27 typedef unsigned int u32_T; // int is at least 32 bits |
6122 | 28 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
29 // The state of encryption, referenced by cryptstate_T. |
6122 | 30 typedef struct { |
31 u32_T keys[3]; | |
32 } zip_state_T; | |
33 | |
34 | |
35 static u32_T crc_32_table[256]; | |
36 | |
37 /* | |
38 * Fill the CRC table, if not done already. | |
39 */ | |
40 static void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
41 make_crc_tab(void) |
6122 | 42 { |
43 u32_T s, t, v; | |
44 static int done = FALSE; | |
45 | |
46 if (done) | |
47 return; | |
48 for (t = 0; t < 256; t++) | |
49 { | |
50 v = t; | |
51 for (s = 0; s < 8; s++) | |
52 v = (v >> 1) ^ ((v & 1) * (u32_T)0xedb88320L); | |
53 crc_32_table[t] = v; | |
54 } | |
55 done = TRUE; | |
56 } | |
57 | |
58 #define CRC32(c, b) (crc_32_table[((int)(c) ^ (b)) & 0xff] ^ ((c) >> 8)) | |
59 | |
60 /* | |
61 * Return the next byte in the pseudo-random sequence. | |
62 */ | |
31804
50555279168b
patch 9.0.1234: the code style has to be checked manually
Bram Moolenaar <Bram@vim.org>
parents:
24970
diff
changeset
|
63 #define DECRYPT_BYTE_ZIP(keys, t) \ |
50555279168b
patch 9.0.1234: the code style has to be checked manually
Bram Moolenaar <Bram@vim.org>
parents:
24970
diff
changeset
|
64 { \ |
6122 | 65 short_u temp = (short_u)keys[2] | 2; \ |
66 t = (int)(((unsigned)(temp * (temp ^ 1U)) >> 8) & 0xff); \ | |
67 } | |
68 | |
69 /* | |
70 * Update the encryption keys with the next byte of plain text. | |
71 */ | |
16162
cd5c83115ec6
patch 8.1.1086: too many curly braces
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
72 #define UPDATE_KEYS_ZIP(keys, c) do { \ |
6122 | 73 keys[0] = CRC32(keys[0], (c)); \ |
74 keys[1] += keys[0] & 0xff; \ | |
75 keys[1] = keys[1] * 134775813L + 1; \ | |
76 keys[2] = CRC32(keys[2], (int)(keys[1] >> 24)); \ | |
16162
cd5c83115ec6
patch 8.1.1086: too many curly braces
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
77 } while (0) |
6122 | 78 |
79 /* | |
80 * Initialize for encryption/decryption. | |
81 */ | |
16429
a1229400434a
patch 8.1.1219: not checking for NULL return from alloc()
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
82 int |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
83 crypt_zip_init( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
84 cryptstate_T *state, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
85 char_u *key, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
86 char_u *salt UNUSED, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
87 int salt_len UNUSED, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
88 char_u *seed UNUSED, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
89 int seed_len UNUSED) |
6122 | 90 { |
91 char_u *p; | |
92 zip_state_T *zs; | |
93 | |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16429
diff
changeset
|
94 zs = ALLOC_ONE(zip_state_T); |
16429
a1229400434a
patch 8.1.1219: not checking for NULL return from alloc()
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
95 if (zs == NULL) |
a1229400434a
patch 8.1.1219: not checking for NULL return from alloc()
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
96 return FAIL; |
6122 | 97 state->method_state = zs; |
98 | |
99 make_crc_tab(); | |
100 zs->keys[0] = 305419896L; | |
101 zs->keys[1] = 591751049L; | |
102 zs->keys[2] = 878082192L; | |
103 for (p = key; *p != NUL; ++p) | |
104 UPDATE_KEYS_ZIP(zs->keys, (int)*p); | |
16429
a1229400434a
patch 8.1.1219: not checking for NULL return from alloc()
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
105 |
a1229400434a
patch 8.1.1219: not checking for NULL return from alloc()
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
106 return OK; |
6122 | 107 } |
108 | |
109 /* | |
110 * Encrypt "from[len]" into "to[len]". | |
111 * "from" and "to" can be equal to encrypt in place. | |
112 */ | |
113 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
114 crypt_zip_encode( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
115 cryptstate_T *state, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
116 char_u *from, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
117 size_t len, |
24970
7e9e53a0368f
patch 8.2.3022: available encryption methods are not strong enough
Bram Moolenaar <Bram@vim.org>
parents:
18757
diff
changeset
|
118 char_u *to, |
7e9e53a0368f
patch 8.2.3022: available encryption methods are not strong enough
Bram Moolenaar <Bram@vim.org>
parents:
18757
diff
changeset
|
119 int last UNUSED) |
6122 | 120 { |
121 zip_state_T *zs = state->method_state; | |
122 size_t i; | |
123 int ztemp, t; | |
124 | |
125 for (i = 0; i < len; ++i) | |
126 { | |
127 ztemp = from[i]; | |
128 DECRYPT_BYTE_ZIP(zs->keys, t); | |
129 UPDATE_KEYS_ZIP(zs->keys, ztemp); | |
130 to[i] = t ^ ztemp; | |
131 } | |
132 } | |
133 | |
134 /* | |
135 * Decrypt "from[len]" into "to[len]". | |
136 */ | |
137 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
138 crypt_zip_decode( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
139 cryptstate_T *state, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
140 char_u *from, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
141 size_t len, |
24970
7e9e53a0368f
patch 8.2.3022: available encryption methods are not strong enough
Bram Moolenaar <Bram@vim.org>
parents:
18757
diff
changeset
|
142 char_u *to, |
7e9e53a0368f
patch 8.2.3022: available encryption methods are not strong enough
Bram Moolenaar <Bram@vim.org>
parents:
18757
diff
changeset
|
143 int last UNUSED) |
6122 | 144 { |
145 zip_state_T *zs = state->method_state; | |
146 size_t i; | |
147 short_u temp; | |
148 | |
149 for (i = 0; i < len; ++i) | |
150 { | |
151 temp = (short_u)zs->keys[2] | 2; | |
152 temp = (int)(((unsigned)(temp * (temp ^ 1U)) >> 8) & 0xff); | |
153 UPDATE_KEYS_ZIP(zs->keys, to[i] = from[i] ^ temp); | |
154 } | |
155 } | |
156 | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
157 #endif // FEAT_CRYPT |