Skip to content

Commit f573c6e

Browse files
chrisbrabrammool
authored andcommitted
patch 8.2.3022: available encryption methods are not strong enough
Problem: Available encryption methods are not strong enough. Solution: Add initial support for xchaha20. (Christian Brabandt, closes #8394)
1 parent 208f0b4 commit f573c6e

29 files changed

+820
-64
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ jobs:
7171
cscope \
7272
libgtk2.0-dev \
7373
desktop-file-utils \
74-
libtool-bin
74+
libtool-bin \
75+
libsodium-dev
7576
7677
- name: Install clang-11
7778
if: matrix.compiler == 'clang'

runtime/doc/eval.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11971,6 +11971,7 @@ scrollbind Compiled with 'scrollbind' support. (always true)
1197111971
showcmd Compiled with 'showcmd' support.
1197211972
signs Compiled with |:sign| support.
1197311973
smartindent Compiled with 'smartindent' support.
11974+
sodium Compiled with libsodium for better crypt support
1197411975
sound Compiled with sound support, e.g. `sound_playevent()`
1197511976
spell Compiled with spell checking support |spell|.
1197611977
startuptime Compiled with |--startuptime| support.

runtime/doc/options.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2384,6 +2384,23 @@ A jump table for the options with a short description can be found at |Q_op|.
23842384
you write the file the encrypted bytes will be
23852385
different. The whole undo file is encrypted, not just
23862386
the pieces of text.
2387+
*E1193* *E1194* *E1195* *E1196*
2388+
*E1197* *E1198* *E1199* *E1200* *E1201*
2389+
xchacha20 XChaCha20 Cipher with Poly1305 Message Authentication
2390+
Code. Medium strong till strong encryption.
2391+
Encryption is provided by the libsodium library, it
2392+
requires Vim to be built with |+sodium|
2393+
It adds a seed and a message authentication code (MAC)
2394+
to the file. This needs at least a Vim 8.2.3022 to
2395+
read the encrypted file.
2396+
Encryption of swap files is not supported, therefore
2397+
no swap file will be used when xchacha20 encryption is
2398+
enabled.
2399+
Encryption of undo files is not yet supported,
2400+
therefore no undo file will currently be written.
2401+
CURRENTLY EXPERIMENTAL: Files written with this method
2402+
might have to be read back with the same version of
2403+
Vim if the binary format changes later.
23872404

23882405
You should use "blowfish2", also to re-encrypt older files.
23892406

runtime/doc/various.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,7 @@ m *+ruby/dyn* Ruby interface |ruby-dynamic| |/dyn|
444444
T *+scrollbind* |'scrollbind'|
445445
B *+signs* |:sign|
446446
N *+smartindent* |'smartindent'|
447+
B *+sodium* compiled with libsodium for better encryption support
447448
B *+sound* |sound_playevent()|, |sound_playfile()| functions, etc.
448449
N *+spell* spell checking support, see |spell|
449450
N *+startuptime* |--startuptime| argument

src/INSTALLpc.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,9 @@ MSYS2 has its own git package, and you can also install it via pacman:
322322

323323
$ pacman -S git
324324

325+
For enabling libsodium support, you also need to install the package
326+
327+
$ pacman -S mingw-w64-x86_64-libsodium
325328

326329
2.3. Keep the build environment up-to-date
327330

src/Make_cyg_ming.mak

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ DEBUG=no
4141
# set to yes to measure code coverage
4242
COVERAGE=no
4343

44+
# better encryption support using libsodium
45+
#SODIUM=yes
46+
4447
# set to SIZE for size, SPEED for speed, MAXSPEED for maximum optimization
4548
OPTIMIZE=MAXSPEED
4649

@@ -517,6 +520,10 @@ CXXFLAGS = -std=gnu++11
517520
WINDRES_FLAGS =
518521
EXTRA_LIBS =
519522

523+
ifdef SODIUM
524+
DEFINES += -DHAVE_SODIUM
525+
endif
526+
520527
ifdef GETTEXT
521528
DEFINES += -DHAVE_GETTEXT -DHAVE_LOCALE_H
522529
GETTEXTINCLUDE = $(GETTEXT)/include
@@ -660,6 +667,10 @@ DEFINES += -DFEAT_DIRECTX_COLOR_EMOJI
660667
endif
661668
endif
662669

670+
ifeq ($(SODIUM),yes)
671+
SODIUMLIB = -lsodium
672+
endif
673+
663674
# Only allow XPM for a GUI build.
664675
ifeq (yes, $(GUI))
665676

@@ -1064,7 +1075,7 @@ $(EXEOBJC): | $(OUTDIR)
10641075

10651076
ifeq ($(VIMDLL),yes)
10661077
$(TARGET): $(OBJ)
1067-
$(LINK) $(CFLAGS) $(LFLAGS) -o $@ $(OBJ) $(LIB) -lole32 -luuid -lgdi32 $(LUA_LIB) $(MZSCHEME_LIBDIR) $(MZSCHEME_LIB) $(PYTHONLIB) $(PYTHON3LIB) $(RUBYLIB)
1078+
$(LINK) $(CFLAGS) $(LFLAGS) -o $@ $(OBJ) $(LIB) -lole32 -luuid -lgdi32 $(LUA_LIB) $(MZSCHEME_LIBDIR) $(MZSCHEME_LIB) $(PYTHONLIB) $(PYTHON3LIB) $(RUBYLIB) $(SODIUMLIB)
10681079

10691080
$(GVIMEXE): $(EXEOBJG) $(VIMDLLBASE).dll
10701081
$(CC) -L. $(EXELFLAGS) -mwindows -o $@ $(EXEOBJG) -l$(VIMDLLBASE)
@@ -1073,7 +1084,7 @@ $(VIMEXE): $(EXEOBJC) $(VIMDLLBASE).dll
10731084
$(CC) -L. $(EXELFLAGS) -o $@ $(EXEOBJC) -l$(VIMDLLBASE)
10741085
else
10751086
$(TARGET): $(OBJ)
1076-
$(LINK) $(CFLAGS) $(LFLAGS) -o $@ $(OBJ) $(LIB) -lole32 -luuid $(LUA_LIB) $(MZSCHEME_LIBDIR) $(MZSCHEME_LIB) $(PYTHONLIB) $(PYTHON3LIB) $(RUBYLIB)
1087+
$(LINK) $(CFLAGS) $(LFLAGS) -o $@ $(OBJ) $(LIB) -lole32 -luuid $(LUA_LIB) $(MZSCHEME_LIBDIR) $(MZSCHEME_LIB) $(PYTHONLIB) $(PYTHON3LIB) $(RUBYLIB) $(SODIUMLIB)
10771088
endif
10781089

10791090
upx: exes

src/Make_mvc.mak

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@
4141
#
4242
# Sound support: SOUND=yes (default is yes)
4343
#
44+
# Sodium support: SODIUM=[Path to Sodium directory]
45+
# You need to install the msvc package from https://download.libsodium.org/libsodium/releases/
46+
#
4447
# DLL support (EXPERIMENTAL): VIMDLL=yes (default is no)
4548
# Creates vim{32,64}.dll, and stub gvim.exe and vim.exe.
4649
# The shared codes between the GUI and the console are built into
@@ -372,6 +375,26 @@ SOUND = no
372375
! endif
373376
!endif
374377

378+
!ifndef SODIUM
379+
SODIUM = no
380+
!endif
381+
382+
!if "$(SODIUM)" != "no"
383+
! if "$(CPU)" == "AMD64"
384+
SOD_LIB = $(SODIUM)\x64\Release\v140\dynamic
385+
! elseif "$(CPU)" == "i386"
386+
SOD_LIB = $(SODIUM)\x86\Release\v140\dynamic
387+
! else
388+
SODIUM = no
389+
! endif
390+
!endif
391+
392+
!if "$(SODIUM)" != "no"
393+
SOD_INC = -I $(SODIUM)\include
394+
SOD_DEFS = -DFEAT_SODIUM
395+
SOD_LIB = $(SOD_LIB)\libsodium.lib
396+
!endif
397+
375398
!ifndef NETBEANS
376399
NETBEANS = $(GUI)
377400
!endif
@@ -491,7 +514,7 @@ CON_LIB = $(CON_LIB) /DELAYLOAD:comdlg32.dll /DELAYLOAD:ole32.dll DelayImp.lib
491514

492515
CFLAGS = -c /W3 /GF /nologo $(CVARS) -I. -Iproto -DHAVE_PATHDEF -DWIN32 \
493516
$(CSCOPE_DEFS) $(TERM_DEFS) $(SOUND_DEFS) $(NETBEANS_DEFS) $(CHANNEL_DEFS) \
494-
$(NBDEBUG_DEFS) $(XPM_DEFS) \
517+
$(NBDEBUG_DEFS) $(XPM_DEFS) $(SOD_DEFS) \
495518
$(DEFINES) -DWINVER=$(WINVER) -D_WIN32_WINNT=$(WINVER)
496519

497520
#>>>>> end of choices
@@ -703,7 +726,7 @@ CFLAGS = $(CFLAGS) $(CFLAGS_DEPR)
703726

704727
INCL = vim.h alloc.h ascii.h ex_cmds.h feature.h errors.h globals.h \
705728
keymap.h macros.h option.h os_dos.h os_win32.h proto.h regexp.h \
706-
spell.h structs.h term.h beval.h $(NBDEBUG_INCL)
729+
spell.h structs.h term.h beval.h $(NBDEBUG_INCL) $(SOD_INC)
707730

708731
OBJ = \
709732
$(OUTDIR)\arabic.obj \
@@ -1282,7 +1305,7 @@ conflags = $(conflags) /map /mapinfo:lines
12821305
LINKARGS1 = $(linkdebug) $(conflags)
12831306
LINKARGS2 = $(CON_LIB) $(GUI_LIB) $(NODEFAULTLIB) $(LIBC) $(OLE_LIB) user32.lib \
12841307
$(LUA_LIB) $(MZSCHEME_LIB) $(PERL_LIB) $(PYTHON_LIB) $(PYTHON3_LIB) $(RUBY_LIB) \
1285-
$(TCL_LIB) $(SOUND_LIB) $(NETBEANS_LIB) $(XPM_LIB) $(LINK_PDB)
1308+
$(TCL_LIB) $(SOUND_LIB) $(NETBEANS_LIB) $(XPM_LIB) $(SOD_LIB) $(LINK_PDB)
12861309

12871310
# Report link time code generation progress if used.
12881311
!ifdef NODEBUG

src/auto/configure

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,7 @@ with_motif_lib
839839
with_tlib
840840
enable_largefile
841841
enable_canberra
842+
enable_libsodium
842843
enable_acl
843844
enable_gpm
844845
enable_sysmouse
@@ -1513,6 +1514,7 @@ Optional Features:
15131514
--disable-desktop-database-update update disabled
15141515
--disable-largefile omit support for large files
15151516
--disable-canberra Do not use libcanberra.
1517+
--disable-libsodium Do not use libsodium.
15161518
--disable-acl No check for ACL support.
15171519
--disable-gpm Don't use gpm (Linux mouse daemon).
15181520
--disable-sysmouse Don't use sysmouse (mouse in *BSD console).
@@ -13005,6 +13007,70 @@ rm -f core conftest.err conftest.$ac_objext \
1300513007
conftest$ac_exeext conftest.$ac_ext
1300613008
fi
1300713009

13010+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking --enable-libsodium argument" >&5
13011+
$as_echo_n "checking --enable-libsodium argument... " >&6; }
13012+
# Check whether --enable-libsodium was given.
13013+
if test "${enable_libsodium+set}" = set; then :
13014+
enableval=$enable_libsodium;
13015+
else
13016+
enable_libsodium="maybe"
13017+
fi
13018+
13019+
13020+
if test "$enable_libsodium" = "maybe"; then
13021+
if test "$features" = "big" -o "$features" = "huge"; then
13022+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: Defaulting to yes" >&5
13023+
$as_echo "Defaulting to yes" >&6; }
13024+
enable_libsodium="yes"
13025+
else
13026+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: Defaulting to no" >&5
13027+
$as_echo "Defaulting to no" >&6; }
13028+
enable_libsodium="no"
13029+
fi
13030+
else
13031+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $enable_libsodium" >&5
13032+
$as_echo "$enable_libsodium" >&6; }
13033+
fi
13034+
if test "$enable_libsodium" = "yes"; then
13035+
if test "x$PKG_CONFIG" != "xno"; then
13036+
libsodium_lib=`$PKG_CONFIG --libs libsodium 2>/dev/null`
13037+
libsodium_cflags=`$PKG_CONFIG --cflags libsodium 2>/dev/null`
13038+
fi
13039+
if test "x$libsodium_lib" = "x"; then
13040+
libsodium_lib=-lsodium
13041+
libsodium_cflags=
13042+
fi
13043+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for libcanberra" >&5
13044+
$as_echo_n "checking for libcanberra... " >&6; }
13045+
ac_save_CFLAGS="$CFLAGS"
13046+
ac_save_LIBS="$LIBS"
13047+
CFLAGS="$CFLAGS $libsodium_cflags"
13048+
LIBS="$LIBS $libsodium_lib"
13049+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
13050+
/* end confdefs.h. */
13051+
13052+
# include <sodium.h>
13053+
13054+
int
13055+
main ()
13056+
{
13057+
13058+
printf("%d", sodium_init());
13059+
;
13060+
return 0;
13061+
}
13062+
_ACEOF
13063+
if ac_fn_c_try_link "$LINENO"; then :
13064+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
13065+
$as_echo "yes" >&6; }; $as_echo "#define HAVE_SODIUM 1" >>confdefs.h
13066+
13067+
else
13068+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no; try installing libsodium-dev" >&5
13069+
$as_echo "no; try installing libsodium-dev" >&6; }; CFLAGS="$ac_save_CFLAGS"; LIBS="$ac_save_LIBS"
13070+
fi
13071+
rm -f core conftest.err conftest.$ac_objext \
13072+
conftest$ac_exeext conftest.$ac_ext
13073+
fi
1300813074

1300913075
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for st_blksize" >&5
1301013076
$as_echo_n "checking for st_blksize... " >&6; }

src/blowfish.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,8 @@ crypt_blowfish_encode(
596596
cryptstate_T *state,
597597
char_u *from,
598598
size_t len,
599-
char_u *to)
599+
char_u *to,
600+
int last UNUSED)
600601
{
601602
bf_state_T *bfs = state->method_state;
602603
size_t i;
@@ -619,7 +620,8 @@ crypt_blowfish_decode(
619620
cryptstate_T *state,
620621
char_u *from,
621622
size_t len,
622-
char_u *to)
623+
char_u *to,
624+
int last UNUSED)
623625
{
624626
bf_state_T *bfs = state->method_state;
625627
size_t i;
@@ -680,5 +682,4 @@ blowfish_self_test(void)
680682
}
681683
return OK;
682684
}
683-
684685
#endif // FEAT_CRYPT

src/bufwrite.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ struct bw_info
3030
int bw_flags; // FIO_ flags
3131
#ifdef FEAT_CRYPT
3232
buf_T *bw_buffer; // buffer being written
33+
int bw_finish; // finish encrypting
3334
#endif
3435
char_u bw_rest[CONV_RESTLEN]; // not converted bytes
3536
int bw_restlen; // nr of bytes in bw_rest[]
@@ -493,14 +494,14 @@ buf_write_bytes(struct bw_info *ip)
493494
if (crypt_works_inplace(ip->bw_buffer->b_cryptstate))
494495
{
495496
# endif
496-
crypt_encode_inplace(ip->bw_buffer->b_cryptstate, buf, len);
497+
crypt_encode_inplace(ip->bw_buffer->b_cryptstate, buf, len, ip->bw_finish);
497498
# ifdef CRYPT_NOT_INPLACE
498499
}
499500
else
500501
{
501502
char_u *outbuf;
502503

503-
len = crypt_encode_alloc(curbuf->b_cryptstate, buf, len, &outbuf);
504+
len = crypt_encode_alloc(curbuf->b_cryptstate, buf, len, &outbuf, ip->bw_finish);
504505
if (len == 0)
505506
return OK; // Crypt layer is buffering, will flush later.
506507
wlen = write_eintr(ip->bw_fd, outbuf, len);
@@ -724,6 +725,7 @@ buf_write(
724725
#endif
725726
#ifdef FEAT_CRYPT
726727
write_info.bw_buffer = buf;
728+
write_info.bw_finish = FALSE;
727729
#endif
728730

729731
// After writing a file changedtick changes but we don't want to display
@@ -2015,6 +2017,13 @@ buf_write(
20152017
++s;
20162018
if (++len != bufsize)
20172019
continue;
2020+
#ifdef FEAT_CRYPT
2021+
if (write_info.bw_fd > 0 && lnum == end
2022+
&& (write_info.bw_flags & FIO_ENCRYPTED)
2023+
&& *buf->b_p_key != NUL && !filtering
2024+
&& *ptr == NUL)
2025+
write_info.bw_finish = TRUE;
2026+
#endif
20182027
if (buf_write_bytes(&write_info) == FAIL)
20192028
{
20202029
end = 0; // write error: break loop
@@ -2118,6 +2127,12 @@ buf_write(
21182127
if (len > 0 && end > 0)
21192128
{
21202129
write_info.bw_len = len;
2130+
#ifdef FEAT_CRYPT
2131+
if (write_info.bw_fd > 0 && lnum >= end
2132+
&& (write_info.bw_flags & FIO_ENCRYPTED)
2133+
&& *buf->b_p_key != NUL && !filtering)
2134+
write_info.bw_finish = TRUE;
2135+
#endif
21212136
if (buf_write_bytes(&write_info) == FAIL)
21222137
end = 0; // write error
21232138
nchars += len;

0 commit comments

Comments
 (0)