Skip to content

Commit aae5834

Browse files
chrisbrabrammool
authored andcommitted
patch 9.0.1481: decrypting with libsodium may fail if the library changes
Problem: Decrypting with libsodium may fail if the library changes. Solution: Add parameters used to the encrypted file header. (Christian Brabandt, closes vim#12279)
1 parent dcd40cf commit aae5834

16 files changed

+422
-121
lines changed

runtime/doc/editing.txt

+4-3
Original file line numberDiff line numberDiff line change
@@ -1533,9 +1533,10 @@ To disable the encryption, reset the 'key' option to an empty value: >
15331533
15341534
You can use the 'cryptmethod' option to select the type of encryption, use one
15351535
of these: >
1536-
:setlocal cm=zip " weak method, backwards compatible
1537-
:setlocal cm=blowfish " method with flaws
1538-
:setlocal cm=blowfish2 " medium strong method
1536+
:setlocal cm=zip " weak method, backwards compatible
1537+
:setlocal cm=blowfish " method with flaws, do not use
1538+
:setlocal cm=blowfish2 " medium strong method
1539+
:setlocal cm=xchacha20v2 " medium strong method using libsodium
15391540
15401541
Do this before writing the file. When reading an encrypted file it will be
15411542
set automatically to the method used when that file was written. You can

runtime/doc/options.txt

+14-2
Original file line numberDiff line numberDiff line change
@@ -2511,12 +2511,14 @@ A jump table for the options with a short description can be found at |Q_op|.
25112511
*pkzip*
25122512
zip PkZip compatible method. A weak kind of encryption.
25132513
Backwards compatible with Vim 7.2 and older.
2514+
Only use if you need to be backwards compatible.
25142515
*blowfish*
25152516
blowfish Blowfish method. Medium strong encryption but it has
25162517
an implementation flaw. Requires Vim 7.3 or later,
25172518
files can NOT be read by Vim 7.2 and older. This adds
25182519
a "seed" to the file, every time you write the file
25192520
the encrypted bytes will be different.
2521+
Obsolete, please do no longer use.
25202522
*blowfish2*
25212523
blowfish2 Blowfish method. Medium strong encryption. Requires
25222524
Vim 7.4.401 or later, files can NOT be read by Vim 7.3
@@ -2538,11 +2540,21 @@ A jump table for the options with a short description can be found at |Q_op|.
25382540
enabled.
25392541
Encryption of undo files is not yet supported,
25402542
therefore no undo file will currently be written.
2541-
CURRENTLY EXPERIMENTAL: Files written with this method
2543+
CAREFUL: Files written with this method might have to
2544+
be read back with the same version of Vim if the
2545+
binary format changes later.
2546+
Obsolete, please do no longer use.
2547+
xchacha20v2 Same algorithm as with "xchacha20" that correctly
2548+
stores the key derivation parameters together with the
2549+
encrypted file. Should work better in case the
2550+
parameters in the libsodium library ever change.
2551+
STILL EXPERIMENTAL: Files written with this method
25422552
might have to be read back with the same version of
25432553
Vim if the binary format changes later.
25442554

2545-
You should use "blowfish2", also to re-encrypt older files.
2555+
You should use "blowfish2", also to re-encrypt older files. The
2556+
"xchacha20" method provides better encryption, but it does not work
2557+
with all versions of Vim.
25462558

25472559
When reading an encrypted file 'cryptmethod' will be set automatically
25482560
to the detected method of the file being read. Thus if you write it

src/blowfish.c

+4-7
Original file line numberDiff line numberDiff line change
@@ -641,11 +641,8 @@ crypt_blowfish_decode(
641641
int
642642
crypt_blowfish_init(
643643
cryptstate_T *state,
644-
char_u* key,
645-
char_u* salt,
646-
int salt_len,
647-
char_u* seed,
648-
int seed_len)
644+
char_u *key,
645+
crypt_arg_T *arg)
649646
{
650647
bf_state_T *bfs = ALLOC_CLEAR_ONE(bf_state_T);
651648

@@ -660,8 +657,8 @@ crypt_blowfish_init(
660657
if (blowfish_self_test() == FAIL)
661658
return FAIL;
662659

663-
bf_key_init(bfs, key, salt, salt_len);
664-
bf_cfb_init(bfs, seed, seed_len);
660+
bf_key_init(bfs, key, arg->cat_salt, arg->cat_salt_len);
661+
bf_cfb_init(bfs, arg->cat_seed, arg->cat_seed_len);
665662

666663
return OK;
667664
}

src/buffer.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -2362,8 +2362,8 @@ free_buf_options(
23622362
#endif
23632363
#ifdef FEAT_CRYPT
23642364
# ifdef FEAT_SODIUM
2365-
if ((buf->b_p_key != NULL) && (*buf->b_p_key != NUL) &&
2366-
(crypt_get_method_nr(buf) == CRYPT_M_SOD))
2365+
if (buf->b_p_key != NULL && *buf->b_p_key != NUL
2366+
&& crypt_method_is_sodium(crypt_get_method_nr(buf)))
23672367
crypt_sodium_munlock(buf->b_p_key, STRLEN(buf->b_p_key));
23682368
# endif
23692369
clear_string_option(&buf->b_p_key);

0 commit comments

Comments
 (0)