blob: 085f8bb81396f989a4e8b96186df73d53e66001a [file] [log] [blame]
Bram Moolenaaredf3f972016-08-29 22:49:24 +02001/* vi:set ts=8 sts=4 sw=4 noet:
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02002 *
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.c: Generic 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, 1998-09-24
19 * Based on zip/crypt sources.
20 * Refactored by David Leadbeater, 2014.
21 *
22 * NOTE FOR USA: Since 2000 exporting this code from the USA is allowed to
23 * most countries. There are a few exceptions, but that still should not be a
24 * problem since this code was originally created in Europe and India.
25 *
26 * Blowfish addition originally made by Mohsin Ahmed,
27 * http://www.cs.albany.edu/~mosh 2010-03-14
28 * Based on blowfish by Bruce Schneier (http://www.schneier.com/blowfish.html)
29 * and sha256 by Christophe Devine.
30 */
31
32typedef struct {
33 char *name; /* encryption name as used in 'cryptmethod' */
34 char *magic; /* magic bytes stored in file header */
35 int salt_len; /* length of salt, or 0 when not using salt */
36 int seed_len; /* length of seed, or 0 when not using salt */
Bram Moolenaar987411d2019-01-18 22:48:34 +010037#ifdef CRYPT_NOT_INPLACE
Bram Moolenaar8f4ac012014-08-10 13:38:34 +020038 int works_inplace; /* encryption/decryption can be done in-place */
Bram Moolenaar987411d2019-01-18 22:48:34 +010039#endif
Bram Moolenaar8f4ac012014-08-10 13:38:34 +020040 int whole_undofile; /* whole undo file is encrypted */
41
42 /* Optional function pointer for a self-test. */
43 int (* self_test_fn)();
44
Bram Moolenaarad3ec762019-04-21 00:00:13 +020045 // Function pointer for initializing encryption/decryption.
Bram Moolenaar8f4ac012014-08-10 13:38:34 +020046 void (* init_fn)(cryptstate_T *state, char_u *key,
47 char_u *salt, int salt_len, char_u *seed, int seed_len);
48
49 /* Function pointers for encoding/decoding from one buffer into another.
50 * Optional, however, these or the _buffer ones should be configured. */
51 void (*encode_fn)(cryptstate_T *state, char_u *from, size_t len,
52 char_u *to);
53 void (*decode_fn)(cryptstate_T *state, char_u *from, size_t len,
54 char_u *to);
55
56 /* Function pointers for encoding and decoding, can buffer data if needed.
57 * Optional (however, these or the above should be configured). */
58 long (*encode_buffer_fn)(cryptstate_T *state, char_u *from, size_t len,
59 char_u **newptr);
60 long (*decode_buffer_fn)(cryptstate_T *state, char_u *from, size_t len,
61 char_u **newptr);
62
63 /* Function pointers for in-place encoding and decoding, used for
64 * crypt_*_inplace(). "from" and "to" arguments will be equal.
65 * These may be the same as decode_fn and encode_fn above, however an
66 * algorithm may implement them in a way that is not interchangeable with
67 * the crypt_(en|de)code() interface (for example because it wishes to add
68 * padding to files).
69 * This method is used for swap and undo files which have a rigid format.
70 */
71 void (*encode_inplace_fn)(cryptstate_T *state, char_u *p1, size_t len,
72 char_u *p2);
73 void (*decode_inplace_fn)(cryptstate_T *state, char_u *p1, size_t len,
74 char_u *p2);
75} cryptmethod_T;
76
77/* index is method_nr of cryptstate_T, CRYPT_M_* */
78static cryptmethod_T cryptmethods[CRYPT_M_COUNT] = {
79 /* PK_Zip; very weak */
80 {
81 "zip",
82 "VimCrypt~01!",
83 0,
84 0,
Bram Moolenaar987411d2019-01-18 22:48:34 +010085#ifdef CRYPT_NOT_INPLACE
Bram Moolenaar8f4ac012014-08-10 13:38:34 +020086 TRUE,
Bram Moolenaar987411d2019-01-18 22:48:34 +010087#endif
Bram Moolenaar8f4ac012014-08-10 13:38:34 +020088 FALSE,
89 NULL,
90 crypt_zip_init,
91 crypt_zip_encode, crypt_zip_decode,
92 NULL, NULL,
93 crypt_zip_encode, crypt_zip_decode,
94 },
95
96 /* Blowfish/CFB + SHA-256 custom key derivation; implementation issues. */
97 {
98 "blowfish",
99 "VimCrypt~02!",
100 8,
101 8,
Bram Moolenaar987411d2019-01-18 22:48:34 +0100102#ifdef CRYPT_NOT_INPLACE
Bram Moolenaar8f4ac012014-08-10 13:38:34 +0200103 TRUE,
Bram Moolenaar987411d2019-01-18 22:48:34 +0100104#endif
Bram Moolenaar8f4ac012014-08-10 13:38:34 +0200105 FALSE,
106 blowfish_self_test,
107 crypt_blowfish_init,
108 crypt_blowfish_encode, crypt_blowfish_decode,
109 NULL, NULL,
110 crypt_blowfish_encode, crypt_blowfish_decode,
111 },
112
113 /* Blowfish/CFB + SHA-256 custom key derivation; fixed. */
114 {
115 "blowfish2",
116 "VimCrypt~03!",
117 8,
118 8,
Bram Moolenaar987411d2019-01-18 22:48:34 +0100119#ifdef CRYPT_NOT_INPLACE
Bram Moolenaar8f4ac012014-08-10 13:38:34 +0200120 TRUE,
Bram Moolenaar987411d2019-01-18 22:48:34 +0100121#endif
Bram Moolenaar8f4ac012014-08-10 13:38:34 +0200122 TRUE,
123 blowfish_self_test,
124 crypt_blowfish_init,
125 crypt_blowfish_encode, crypt_blowfish_decode,
126 NULL, NULL,
127 crypt_blowfish_encode, crypt_blowfish_decode,
128 },
Bram Moolenaard23a8232018-02-10 18:45:26 +0100129
130 /* NOTE: when adding a new method, use some random bytes for the magic key,
131 * to avoid that a text file is recognized as encrypted. */
Bram Moolenaar8f4ac012014-08-10 13:38:34 +0200132};
133
134#define CRYPT_MAGIC_LEN 12 /* cannot change */
135static char crypt_magic_head[] = "VimCrypt~";
136
137/*
138 * Return int value for crypt method name.
139 * 0 for "zip", the old method. Also for any non-valid value.
140 * 1 for "blowfish".
141 * 2 for "blowfish2".
142 */
143 int
Bram Moolenaar7454a062016-01-30 15:14:10 +0100144crypt_method_nr_from_name(char_u *name)
Bram Moolenaar8f4ac012014-08-10 13:38:34 +0200145{
146 int i;
147
148 for (i = 0; i < CRYPT_M_COUNT; ++i)
149 if (STRCMP(name, cryptmethods[i].name) == 0)
150 return i;
151 return 0;
152}
153
154/*
155 * Get the crypt method used for a file from "ptr[len]", the magic text at the
156 * start of the file.
157 * Returns -1 when no encryption used.
158 */
159 int
Bram Moolenaar7454a062016-01-30 15:14:10 +0100160crypt_method_nr_from_magic(char *ptr, int len)
Bram Moolenaar8f4ac012014-08-10 13:38:34 +0200161{
162 int i;
163
164 if (len < CRYPT_MAGIC_LEN)
165 return -1;
166
167 for (i = 0; i < CRYPT_M_COUNT; i++)
168 if (memcmp(ptr, cryptmethods[i].magic, CRYPT_MAGIC_LEN) == 0)
169 return i;
170
171 i = (int)STRLEN(crypt_magic_head);
172 if (len >= i && memcmp(ptr, crypt_magic_head, i) == 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +0100173 emsg(_("E821: File is encrypted with unknown method"));
Bram Moolenaar8f4ac012014-08-10 13:38:34 +0200174
175 return -1;
176}
177
Bram Moolenaar987411d2019-01-18 22:48:34 +0100178#ifdef CRYPT_NOT_INPLACE
Bram Moolenaar8f4ac012014-08-10 13:38:34 +0200179/*
180 * Return TRUE if the crypt method for "method_nr" can be done in-place.
181 */
182 int
Bram Moolenaar7454a062016-01-30 15:14:10 +0100183crypt_works_inplace(cryptstate_T *state)
Bram Moolenaar8f4ac012014-08-10 13:38:34 +0200184{
185 return cryptmethods[state->method_nr].works_inplace;
186}
Bram Moolenaar987411d2019-01-18 22:48:34 +0100187#endif
Bram Moolenaar8f4ac012014-08-10 13:38:34 +0200188
189/*
190 * Get the crypt method for buffer "buf" as a number.
191 */
192 int
Bram Moolenaar7454a062016-01-30 15:14:10 +0100193crypt_get_method_nr(buf_T *buf)
Bram Moolenaar8f4ac012014-08-10 13:38:34 +0200194{
195 return crypt_method_nr_from_name(*buf->b_p_cm == NUL ? p_cm : buf->b_p_cm);
196}
197
198/*
199 * Return TRUE when the buffer uses an encryption method that encrypts the
200 * whole undo file, not only the text.
201 */
202 int
Bram Moolenaar7454a062016-01-30 15:14:10 +0100203crypt_whole_undofile(int method_nr)
Bram Moolenaar8f4ac012014-08-10 13:38:34 +0200204{
205 return cryptmethods[method_nr].whole_undofile;
206}
207
208/*
209 * Get crypt method specifc length of the file header in bytes.
210 */
211 int
Bram Moolenaar7454a062016-01-30 15:14:10 +0100212crypt_get_header_len(int method_nr)
Bram Moolenaar8f4ac012014-08-10 13:38:34 +0200213{
214 return CRYPT_MAGIC_LEN
215 + cryptmethods[method_nr].salt_len
216 + cryptmethods[method_nr].seed_len;
217}
218
219/*
220 * Set the crypt method for buffer "buf" to "method_nr" using the int value as
221 * returned by crypt_method_nr_from_name().
222 */
223 void
Bram Moolenaar7454a062016-01-30 15:14:10 +0100224crypt_set_cm_option(buf_T *buf, int method_nr)
Bram Moolenaar8f4ac012014-08-10 13:38:34 +0200225{
226 free_string_option(buf->b_p_cm);
227 buf->b_p_cm = vim_strsave((char_u *)cryptmethods[method_nr].name);
228}
229
230/*
231 * If the crypt method for the current buffer has a self-test, run it and
232 * return OK/FAIL.
233 */
234 int
Bram Moolenaar7454a062016-01-30 15:14:10 +0100235crypt_self_test(void)
Bram Moolenaar8f4ac012014-08-10 13:38:34 +0200236{
237 int method_nr = crypt_get_method_nr(curbuf);
238
239 if (cryptmethods[method_nr].self_test_fn == NULL)
240 return OK;
241 return cryptmethods[method_nr].self_test_fn();
242}
243
244/*
245 * Allocate a crypt state and initialize it.
246 */
247 cryptstate_T *
Bram Moolenaar7454a062016-01-30 15:14:10 +0100248crypt_create(
249 int method_nr,
250 char_u *key,
251 char_u *salt,
252 int salt_len,
253 char_u *seed,
254 int seed_len)
Bram Moolenaar8f4ac012014-08-10 13:38:34 +0200255{
256 cryptstate_T *state = (cryptstate_T *)alloc((int)sizeof(cryptstate_T));
257
258 state->method_nr = method_nr;
259 cryptmethods[method_nr].init_fn(state, key, salt, salt_len, seed, seed_len);
260 return state;
261}
262
263/*
264 * Allocate a crypt state from a file header and initialize it.
265 * Assumes that header contains at least the number of bytes that
266 * crypt_get_header_len() returns for "method_nr".
267 */
268 cryptstate_T *
Bram Moolenaar7454a062016-01-30 15:14:10 +0100269crypt_create_from_header(
270 int method_nr,
271 char_u *key,
272 char_u *header)
Bram Moolenaar8f4ac012014-08-10 13:38:34 +0200273{
274 char_u *salt = NULL;
275 char_u *seed = NULL;
276 int salt_len = cryptmethods[method_nr].salt_len;
277 int seed_len = cryptmethods[method_nr].seed_len;
278
279 if (salt_len > 0)
280 salt = header + CRYPT_MAGIC_LEN;
281 if (seed_len > 0)
282 seed = header + CRYPT_MAGIC_LEN + salt_len;
283
284 return crypt_create(method_nr, key, salt, salt_len, seed, seed_len);
285}
286
287/*
288 * Read the crypt method specific header data from "fp".
289 * Return an allocated cryptstate_T or NULL on error.
290 */
291 cryptstate_T *
Bram Moolenaar7454a062016-01-30 15:14:10 +0100292crypt_create_from_file(FILE *fp, char_u *key)
Bram Moolenaar8f4ac012014-08-10 13:38:34 +0200293{
294 int method_nr;
295 int header_len;
296 char magic_buffer[CRYPT_MAGIC_LEN];
297 char_u *buffer;
298 cryptstate_T *state;
299
300 if (fread(magic_buffer, CRYPT_MAGIC_LEN, 1, fp) != 1)
301 return NULL;
302 method_nr = crypt_method_nr_from_magic(magic_buffer, CRYPT_MAGIC_LEN);
303 if (method_nr < 0)
304 return NULL;
305
306 header_len = crypt_get_header_len(method_nr);
307 if ((buffer = alloc(header_len)) == NULL)
308 return NULL;
309 mch_memmove(buffer, magic_buffer, CRYPT_MAGIC_LEN);
310 if (header_len > CRYPT_MAGIC_LEN
311 && fread(buffer + CRYPT_MAGIC_LEN,
312 header_len - CRYPT_MAGIC_LEN, 1, fp) != 1)
313 {
314 vim_free(buffer);
315 return NULL;
316 }
317
318 state = crypt_create_from_header(method_nr, key, buffer);
319 vim_free(buffer);
320 return state;
321}
322
323/*
324 * Allocate a cryptstate_T for writing and initialize it with "key".
325 * Allocates and fills in the header and stores it in "header", setting
326 * "header_len". The header may include salt and seed, depending on
327 * cryptmethod. Caller must free header.
328 * Returns the state or NULL on failure.
329 */
330 cryptstate_T *
Bram Moolenaar7454a062016-01-30 15:14:10 +0100331crypt_create_for_writing(
332 int method_nr,
333 char_u *key,
334 char_u **header,
335 int *header_len)
Bram Moolenaar8f4ac012014-08-10 13:38:34 +0200336{
337 int len = crypt_get_header_len(method_nr);
338 char_u *salt = NULL;
339 char_u *seed = NULL;
340 int salt_len = cryptmethods[method_nr].salt_len;
341 int seed_len = cryptmethods[method_nr].seed_len;
342 cryptstate_T *state;
343
344 *header_len = len;
345 *header = alloc(len);
346 if (*header == NULL)
347 return NULL;
348
349 mch_memmove(*header, cryptmethods[method_nr].magic, CRYPT_MAGIC_LEN);
350 if (salt_len > 0 || seed_len > 0)
351 {
352 if (salt_len > 0)
353 salt = *header + CRYPT_MAGIC_LEN;
354 if (seed_len > 0)
355 seed = *header + CRYPT_MAGIC_LEN + salt_len;
356
357 /* TODO: Should this be crypt method specific? (Probably not worth
358 * it). sha2_seed is pretty bad for large amounts of entropy, so make
359 * that into something which is suitable for anything. */
360 sha2_seed(salt, salt_len, seed, seed_len);
361 }
362
363 state = crypt_create(method_nr, key, salt, salt_len, seed, seed_len);
364 if (state == NULL)
Bram Moolenaard23a8232018-02-10 18:45:26 +0100365 VIM_CLEAR(*header);
Bram Moolenaar8f4ac012014-08-10 13:38:34 +0200366 return state;
367}
368
369/*
370 * Free the crypt state.
371 */
372 void
Bram Moolenaar7454a062016-01-30 15:14:10 +0100373crypt_free_state(cryptstate_T *state)
Bram Moolenaar8f4ac012014-08-10 13:38:34 +0200374{
375 vim_free(state->method_state);
376 vim_free(state);
377}
378
Bram Moolenaar987411d2019-01-18 22:48:34 +0100379#ifdef CRYPT_NOT_INPLACE
Bram Moolenaar8f4ac012014-08-10 13:38:34 +0200380/*
381 * Encode "from[len]" and store the result in a newly allocated buffer, which
382 * is stored in "newptr".
383 * Return number of bytes in "newptr", 0 for need more or -1 on error.
384 */
385 long
Bram Moolenaar7454a062016-01-30 15:14:10 +0100386crypt_encode_alloc(
387 cryptstate_T *state,
388 char_u *from,
389 size_t len,
390 char_u **newptr)
Bram Moolenaar8f4ac012014-08-10 13:38:34 +0200391{
392 cryptmethod_T *method = &cryptmethods[state->method_nr];
393
394 if (method->encode_buffer_fn != NULL)
395 /* Has buffer function, pass through. */
396 return method->encode_buffer_fn(state, from, len, newptr);
397 if (len == 0)
398 /* Not buffering, just return EOF. */
Bram Moolenaar9b8f0212014-08-13 22:05:53 +0200399 return (long)len;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +0200400
Bram Moolenaar9b8f0212014-08-13 22:05:53 +0200401 *newptr = alloc((long)len);
Bram Moolenaar8f4ac012014-08-10 13:38:34 +0200402 if (*newptr == NULL)
403 return -1;
404 method->encode_fn(state, from, len, *newptr);
Bram Moolenaar9b8f0212014-08-13 22:05:53 +0200405 return (long)len;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +0200406}
407
408/*
409 * Decrypt "ptr[len]" and store the result in a newly allocated buffer, which
410 * is stored in "newptr".
411 * Return number of bytes in "newptr", 0 for need more or -1 on error.
412 */
413 long
Bram Moolenaar7454a062016-01-30 15:14:10 +0100414crypt_decode_alloc(
415 cryptstate_T *state,
416 char_u *ptr,
417 long len,
418 char_u **newptr)
Bram Moolenaar8f4ac012014-08-10 13:38:34 +0200419{
420 cryptmethod_T *method = &cryptmethods[state->method_nr];
421
422 if (method->decode_buffer_fn != NULL)
423 /* Has buffer function, pass through. */
424 return method->decode_buffer_fn(state, ptr, len, newptr);
425
426 if (len == 0)
427 /* Not buffering, just return EOF. */
428 return len;
429
430 *newptr = alloc(len);
431 if (*newptr == NULL)
432 return -1;
433 method->decode_fn(state, ptr, len, *newptr);
434 return len;
435}
Bram Moolenaar987411d2019-01-18 22:48:34 +0100436#endif
Bram Moolenaar8f4ac012014-08-10 13:38:34 +0200437
438/*
439 * Encrypting "from[len]" into "to[len]".
440 */
441 void
Bram Moolenaar7454a062016-01-30 15:14:10 +0100442crypt_encode(
443 cryptstate_T *state,
444 char_u *from,
445 size_t len,
446 char_u *to)
Bram Moolenaar8f4ac012014-08-10 13:38:34 +0200447{
448 cryptmethods[state->method_nr].encode_fn(state, from, len, to);
449}
450
Bram Moolenaar987411d2019-01-18 22:48:34 +0100451#if 0 // unused
Bram Moolenaar8f4ac012014-08-10 13:38:34 +0200452/*
453 * decrypting "from[len]" into "to[len]".
454 */
455 void
Bram Moolenaar7454a062016-01-30 15:14:10 +0100456crypt_decode(
457 cryptstate_T *state,
458 char_u *from,
459 size_t len,
460 char_u *to)
Bram Moolenaar8f4ac012014-08-10 13:38:34 +0200461{
462 cryptmethods[state->method_nr].decode_fn(state, from, len, to);
463}
Bram Moolenaar987411d2019-01-18 22:48:34 +0100464#endif
Bram Moolenaar8f4ac012014-08-10 13:38:34 +0200465
466/*
467 * Simple inplace encryption, modifies "buf[len]" in place.
468 */
469 void
Bram Moolenaar7454a062016-01-30 15:14:10 +0100470crypt_encode_inplace(
471 cryptstate_T *state,
472 char_u *buf,
473 size_t len)
Bram Moolenaar8f4ac012014-08-10 13:38:34 +0200474{
475 cryptmethods[state->method_nr].encode_inplace_fn(state, buf, len, buf);
476}
477
478/*
479 * Simple inplace decryption, modifies "buf[len]" in place.
480 */
481 void
Bram Moolenaar7454a062016-01-30 15:14:10 +0100482crypt_decode_inplace(
483 cryptstate_T *state,
484 char_u *buf,
485 size_t len)
Bram Moolenaar8f4ac012014-08-10 13:38:34 +0200486{
487 cryptmethods[state->method_nr].decode_inplace_fn(state, buf, len, buf);
488}
489
490/*
491 * Free an allocated crypt key. Clear the text to make sure it doesn't stay
492 * in memory anywhere.
493 */
494 void
Bram Moolenaar7454a062016-01-30 15:14:10 +0100495crypt_free_key(char_u *key)
Bram Moolenaar8f4ac012014-08-10 13:38:34 +0200496{
497 char_u *p;
498
499 if (key != NULL)
500 {
501 for (p = key; *p != NUL; ++p)
502 *p = 0;
503 vim_free(key);
504 }
505}
506
507/*
Bram Moolenaar3a0c9082014-11-12 15:15:42 +0100508 * Check the crypt method and give a warning if it's outdated.
509 */
510 void
Bram Moolenaar7454a062016-01-30 15:14:10 +0100511crypt_check_method(int method)
Bram Moolenaar3a0c9082014-11-12 15:15:42 +0100512{
513 if (method < CRYPT_M_BF2)
514 {
515 msg_scroll = TRUE;
Bram Moolenaar32526b32019-01-19 17:43:09 +0100516 msg(_("Warning: Using a weak encryption method; see :help 'cm'"));
Bram Moolenaar3a0c9082014-11-12 15:15:42 +0100517 }
518}
519
520 void
Bram Moolenaar7454a062016-01-30 15:14:10 +0100521crypt_check_current_method(void)
Bram Moolenaar3a0c9082014-11-12 15:15:42 +0100522{
523 crypt_check_method(crypt_get_method_nr(curbuf));
524}
525
526/*
Bram Moolenaar8f4ac012014-08-10 13:38:34 +0200527 * Ask the user for a crypt key.
528 * When "store" is TRUE, the new key is stored in the 'key' option, and the
529 * 'key' option value is returned: Don't free it.
530 * When "store" is FALSE, the typed key is returned in allocated memory.
531 * Returns NULL on failure.
532 */
533 char_u *
Bram Moolenaar7454a062016-01-30 15:14:10 +0100534crypt_get_key(
535 int store,
536 int twice) /* Ask for the key twice. */
Bram Moolenaar8f4ac012014-08-10 13:38:34 +0200537{
538 char_u *p1, *p2 = NULL;
539 int round;
540
541 for (round = 0; ; ++round)
542 {
543 cmdline_star = TRUE;
544 cmdline_row = msg_row;
545 p1 = getcmdline_prompt(NUL, round == 0
546 ? (char_u *)_("Enter encryption key: ")
547 : (char_u *)_("Enter same key again: "), 0, EXPAND_NOTHING,
548 NULL);
549 cmdline_star = FALSE;
550
551 if (p1 == NULL)
552 break;
553
554 if (round == twice)
555 {
556 if (p2 != NULL && STRCMP(p1, p2) != 0)
557 {
Bram Moolenaar32526b32019-01-19 17:43:09 +0100558 msg(_("Keys don't match!"));
Bram Moolenaar8f4ac012014-08-10 13:38:34 +0200559 crypt_free_key(p1);
560 crypt_free_key(p2);
561 p2 = NULL;
562 round = -1; /* do it again */
563 continue;
564 }
565
566 if (store)
567 {
568 set_option_value((char_u *)"key", 0L, p1, OPT_LOCAL);
569 crypt_free_key(p1);
570 p1 = curbuf->b_p_key;
571 }
572 break;
573 }
574 p2 = p1;
575 }
576
577 /* since the user typed this, no need to wait for return */
578 if (msg_didout)
579 msg_putchar('\n');
580 need_wait_return = FALSE;
581 msg_didout = FALSE;
582
583 crypt_free_key(p2);
584 return p1;
585}
586
587
588/*
589 * Append a message to IObuff for the encryption/decryption method being used.
590 */
591 void
Bram Moolenaar7454a062016-01-30 15:14:10 +0100592crypt_append_msg(
593 buf_T *buf)
Bram Moolenaar8f4ac012014-08-10 13:38:34 +0200594{
595 if (crypt_get_method_nr(buf) == 0)
596 STRCAT(IObuff, _("[crypted]"));
597 else
598 {
599 STRCAT(IObuff, "[");
600 STRCAT(IObuff, *buf->b_p_cm == NUL ? p_cm : buf->b_p_cm);
601 STRCAT(IObuff, "]");
602 }
603}
604
605#endif /* FEAT_CRYPT */