Patch 9.0.1023
Problem:    MS-Windows: dynamic loading of libsodium doesn't work.
Solution:   Add "randombytes_random". (Ken Takata, closes #11667)
Files:      src/crypt.c, src/evalfunc.c, src/proto/crypt.pro


*** ../vim-9.0.1022/src/crypt.c 2022-06-29 12:54:48.064572066 +0100
--- src/crypt.c 2022-12-06 16:15:03.471760735 +0000
***************
*** 73,79 ****
                                                        char_u *p2, int last);
  } cryptmethod_T;
  
! static int crypt_sodium_init(cryptstate_T *state, char_u *key, char_u *salt, 
int salt_len, char_u *seed, int seed_len);
  static long crypt_sodium_buffer_decode(cryptstate_T *state, char_u *from, 
size_t len, char_u **buf_out, int last);
  static long crypt_sodium_buffer_encode(cryptstate_T *state, char_u *from, 
size_t len, char_u **buf_out, int last);
  
--- 73,79 ----
                                                        char_u *p2, int last);
  } cryptmethod_T;
  
! static int crypt_sodium_init_(cryptstate_T *state, char_u *key, char_u *salt, 
int salt_len, char_u *seed, int seed_len);
  static long crypt_sodium_buffer_decode(cryptstate_T *state, char_u *from, 
size_t len, char_u **buf_out, int last);
  static long crypt_sodium_buffer_encode(cryptstate_T *state, char_u *from, 
size_t len, char_u **buf_out, int last);
  
***************
*** 145,151 ****
  #endif
        FALSE,
        NULL,
!       crypt_sodium_init,
        NULL, NULL,
        crypt_sodium_buffer_encode, crypt_sodium_buffer_decode,
        NULL, NULL,
--- 145,151 ----
  #endif
        FALSE,
        NULL,
!       crypt_sodium_init_,
        NULL, NULL,
        crypt_sodium_buffer_encode, crypt_sodium_buffer_decode,
        NULL, NULL,
***************
*** 198,203 ****
--- 198,204 ----
      dll_crypto_secretstream_xchacha20poly1305_pull
  #  define crypto_pwhash           dll_crypto_pwhash
  #  define randombytes_buf   dll_randombytes_buf
+ #  define randombytes_random dll_randombytes_random
  
  static int (*dll_sodium_init)(void) = NULL;
  static void (*dll_sodium_free)(void *) = NULL;
***************
*** 231,236 ****
--- 232,238 ----
      unsigned long long opslimit, size_t memlimit, int alg)
      = NULL;
  static void (*dll_randombytes_buf)(void * const buf, const size_t size);
+ static uint32_t (*dll_randombytes_random)(void);
  
  static struct {
      const char *name;
***************
*** 248,253 ****
--- 250,256 ----
      {"crypto_secretstream_xchacha20poly1305_pull", 
(SODIUM_PROC*)&dll_crypto_secretstream_xchacha20poly1305_pull},
      {"crypto_pwhash", (SODIUM_PROC*)&dll_crypto_pwhash},
      {"randombytes_buf", (SODIUM_PROC*)&dll_randombytes_buf},
+     {"randombytes_random", (SODIUM_PROC*)&dll_randombytes_random},
      {NULL, NULL}
  };
  
***************
*** 855,861 ****
  }
  
      static int
! crypt_sodium_init(
      cryptstate_T      *state UNUSED,
      char_u            *key UNUSED,
      char_u            *salt UNUSED,
--- 858,864 ----
  }
  
      static int
! crypt_sodium_init_(
      cryptstate_T      *state UNUSED,
      char_u            *key UNUSED,
      char_u            *salt UNUSED,
***************
*** 1143,1148 ****
--- 1146,1163 ----
  {
      randombytes_buf(buf, size);
  }
+ 
+     int
+ crypt_sodium_init(void)
+ {
+     return sodium_init();
+ }
+ 
+     uint32_t
+ crypt_sodium_randombytes_random(void)
+ {
+     return randombytes_random();
+ }
  # endif
  
  #endif // FEAT_CRYPT
*** ../vim-9.0.1022/src/evalfunc.c      2022-12-05 21:55:49.183027029 +0000
--- src/evalfunc.c      2022-12-06 16:15:03.471760735 +0000
***************
*** 8166,8173 ****
        // - reltime() or time()
        // - XOR with process ID
  #if defined(FEAT_SODIUM)
!       if (sodium_init() >= 0)
!           *x = randombytes_random();
        else
  #endif
        {
--- 8166,8173 ----
        // - reltime() or time()
        // - XOR with process ID
  #if defined(FEAT_SODIUM)
!       if (crypt_sodium_init() >= 0)
!           *x = crypt_sodium_randombytes_random();
        else
  #endif
        {
*** ../vim-9.0.1022/src/proto/crypt.pro 2022-06-29 12:54:48.064572066 +0100
--- src/proto/crypt.pro 2022-12-06 16:15:03.471760735 +0000
***************
*** 26,29 ****
--- 26,31 ----
  void crypt_append_msg(buf_T *buf);
  int crypt_sodium_munlock(void *const addr, const size_t len);
  void crypt_sodium_randombytes_buf(void *const buf, const size_t size);
+ int crypt_sodium_init(void);
+ uint32_t crypt_sodium_randombytes_random(void);
  /* vim: set ft=c : */
*** ../vim-9.0.1022/src/version.c       2022-12-06 16:09:49.231668054 +0000
--- src/version.c       2022-12-06 16:15:29.079768860 +0000
***************
*** 697,698 ****
--- 697,700 ----
  {   /* Add new patch number below this line */
+ /**/
+     1023,
  /**/

-- 
Hear about the guy who played a blank tape at full blast?
The mime next door went nuts.

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///                                                                      \\\
\\\        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/20221206161734.787331C07A0%40moolenaar.net.

Raspunde prin e-mail lui