File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2306,6 +2306,10 @@ free_buf_options(
23062306 clear_string_option (& buf -> b_p_fex );
23072307#endif
23082308#ifdef FEAT_CRYPT
2309+ # ifdef FEAT_SODIUM
2310+ if (buf -> b_p_key != NULL && (crypt_get_method_nr (buf ) == CRYPT_M_SOD ))
2311+ sodium_munlock (buf -> b_p_key , STRLEN (buf -> b_p_key ));
2312+ # endif
23092313 clear_string_option (& buf -> b_p_key );
23102314#endif
23112315 clear_string_option (& buf -> b_p_kp );
Original file line number Diff line number Diff line change 1212 */
1313#include "vim.h"
1414
15- #ifdef FEAT_SODIUM
16- # include <sodium.h>
17- #endif
18-
1915#if defined(FEAT_CRYPT ) || defined(PROTO )
2016/*
2117 * Optional encryption support.
@@ -447,6 +443,8 @@ crypt_free_state(cryptstate_T *state)
447443#ifdef FEAT_SODIUM
448444 if (state -> method_nr == CRYPT_M_SOD )
449445 {
446+ sodium_munlock (((sodium_state_T * )state -> method_state )-> key ,
447+ crypto_box_SEEDBYTES );
450448 sodium_memzero (state -> method_state , sizeof (sodium_state_T ));
451449 sodium_free (state -> method_state );
452450 }
@@ -726,6 +724,7 @@ crypt_sodium_init(
726724 // crypto_box_SEEDBYTES == crypto_secretstream_xchacha20poly1305_KEYBYTES
727725 unsigned char dkey [crypto_box_SEEDBYTES ]; // 32
728726 sodium_state_T * sd_state ;
727+ int retval = 0 ;
729728
730729 if (sodium_init () < 0 )
731730 return FAIL ;
@@ -743,6 +742,16 @@ crypt_sodium_init(
743742 return FAIL ;
744743 }
745744 memcpy (sd_state -> key , dkey , crypto_box_SEEDBYTES );
745+
746+ retval += sodium_mlock (sd_state -> key , crypto_box_SEEDBYTES );
747+ retval += sodium_mlock (key , STRLEN (key ));
748+
749+ if (retval < 0 )
750+ {
751+ emsg (_ (e_encryption_sodium_mlock_failed ));
752+ sodium_free (sd_state );
753+ return FAIL ;
754+ }
746755 sd_state -> count = 0 ;
747756 state -> method_state = sd_state ;
748757
Original file line number Diff line number Diff line change @@ -641,3 +641,5 @@ EXTERN char e_list_or_dict_or_blob_required_for_argument_nr[]
641641 INIT (= N_ ("E1228: List or Dictionary or Blob required for argument %d" ));
642642EXTERN char e_expected_dictionary_for_using_key_str_but_got_str []
643643 INIT (= N_ ("E1229: Expected dictionary for using key \"%s\", but got %s" ));
644+ EXTERN char e_encryption_sodium_mlock_failed []
645+ INIT (= N_ ("E1230: encryption: sodium_mlock() failed" ));
Original file line number Diff line number Diff line change 1313
1414#include "vim.h"
1515
16- #ifdef FEAT_SODIUM
17- # include <sodium.h>
18- #endif
19-
2016#if defined(__TANDEM )
2117# include <limits.h> // for SSIZE_MAX
2218#endif
Original file line number Diff line number Diff line change 4848# include <time.h>
4949#endif
5050
51- // for randombytes_buf
52- #ifdef FEAT_SODIUM
53- # include <sodium.h>
54- #endif
55-
5651#if defined(SASC ) || defined(__amigaos4__ )
5752# include <proto/dos.h> // for Open() and Close()
5853#endif
Original file line number Diff line number Diff line change @@ -755,6 +755,8 @@ static char *(features[]) =
755755
756756static int included_patches [] =
757757{ /* Add new patch number below this line */
758+ /**/
759+ 3245 ,
758760/**/
759761 3244 ,
760762/**/
Original file line number Diff line number Diff line change @@ -486,6 +486,10 @@ typedef unsigned int u8char_T; // int is 32 bits or more
486486# endif
487487#endif
488488
489+ #ifdef HAVE_SODIUM
490+ # include <sodium.h>
491+ #endif
492+
489493// ================ end of the header file puzzle ===============
490494
491495/*
You can’t perform that action at this time.
0 commit comments