comparison src/crypt.c @ 31379:540e85ac14c9 v9.0.1023

patch 9.0.1023: MS-Windows: dynamic loading of libsodium doesn't work Commit: https://github.com/vim/vim/commit/a8cdb4eef83bce8614991f1191f8c8879fda4dc1 Author: K.Takata <kentkt@csc.jp> Date: Tue Dec 6 16:17:01 2022 +0000 patch 9.0.1023: MS-Windows: dynamic loading of libsodium doesn't work Problem: MS-Windows: dynamic loading of libsodium doesn't work. Solution: Add "randombytes_random". (Ken Takata, closes https://github.com/vim/vim/issues/11667)
author Bram Moolenaar <Bram@vim.org>
date Tue, 06 Dec 2022 17:30:04 +0100
parents a74398c432a4
children 4545f58c8490
comparison
equal deleted inserted replaced
31378:c6c4336ac00d 31379:540e85ac14c9
71 char_u *p2, int last); 71 char_u *p2, int last);
72 void (*decode_inplace_fn)(cryptstate_T *state, char_u *p1, size_t len, 72 void (*decode_inplace_fn)(cryptstate_T *state, char_u *p1, size_t len,
73 char_u *p2, int last); 73 char_u *p2, int last);
74 } cryptmethod_T; 74 } cryptmethod_T;
75 75
76 static int crypt_sodium_init(cryptstate_T *state, char_u *key, char_u *salt, int salt_len, char_u *seed, int seed_len); 76 static int crypt_sodium_init_(cryptstate_T *state, char_u *key, char_u *salt, int salt_len, char_u *seed, int seed_len);
77 static long crypt_sodium_buffer_decode(cryptstate_T *state, char_u *from, size_t len, char_u **buf_out, int last); 77 static long crypt_sodium_buffer_decode(cryptstate_T *state, char_u *from, size_t len, char_u **buf_out, int last);
78 static long crypt_sodium_buffer_encode(cryptstate_T *state, char_u *from, size_t len, char_u **buf_out, int last); 78 static long crypt_sodium_buffer_encode(cryptstate_T *state, char_u *from, size_t len, char_u **buf_out, int last);
79 79
80 // index is method_nr of cryptstate_T, CRYPT_M_* 80 // index is method_nr of cryptstate_T, CRYPT_M_*
81 static cryptmethod_T cryptmethods[CRYPT_M_COUNT] = { 81 static cryptmethod_T cryptmethods[CRYPT_M_COUNT] = {
143 #ifdef CRYPT_NOT_INPLACE 143 #ifdef CRYPT_NOT_INPLACE
144 FALSE, 144 FALSE,
145 #endif 145 #endif
146 FALSE, 146 FALSE,
147 NULL, 147 NULL,
148 crypt_sodium_init, 148 crypt_sodium_init_,
149 NULL, NULL, 149 NULL, NULL,
150 crypt_sodium_buffer_encode, crypt_sodium_buffer_decode, 150 crypt_sodium_buffer_encode, crypt_sodium_buffer_decode,
151 NULL, NULL, 151 NULL, NULL,
152 }, 152 },
153 153
196 dll_crypto_secretstream_xchacha20poly1305_init_pull 196 dll_crypto_secretstream_xchacha20poly1305_init_pull
197 # define crypto_secretstream_xchacha20poly1305_pull \ 197 # define crypto_secretstream_xchacha20poly1305_pull \
198 dll_crypto_secretstream_xchacha20poly1305_pull 198 dll_crypto_secretstream_xchacha20poly1305_pull
199 # define crypto_pwhash dll_crypto_pwhash 199 # define crypto_pwhash dll_crypto_pwhash
200 # define randombytes_buf dll_randombytes_buf 200 # define randombytes_buf dll_randombytes_buf
201 # define randombytes_random dll_randombytes_random
201 202
202 static int (*dll_sodium_init)(void) = NULL; 203 static int (*dll_sodium_init)(void) = NULL;
203 static void (*dll_sodium_free)(void *) = NULL; 204 static void (*dll_sodium_free)(void *) = NULL;
204 static void *(*dll_sodium_malloc)(const size_t) = NULL; 205 static void *(*dll_sodium_malloc)(const size_t) = NULL;
205 static void (*dll_sodium_memzero)(void * const, const size_t) = NULL; 206 static void (*dll_sodium_memzero)(void * const, const size_t) = NULL;
229 const char * const passwd, unsigned long long passwdlen, 230 const char * const passwd, unsigned long long passwdlen,
230 const unsigned char * const salt, 231 const unsigned char * const salt,
231 unsigned long long opslimit, size_t memlimit, int alg) 232 unsigned long long opslimit, size_t memlimit, int alg)
232 = NULL; 233 = NULL;
233 static void (*dll_randombytes_buf)(void * const buf, const size_t size); 234 static void (*dll_randombytes_buf)(void * const buf, const size_t size);
235 static uint32_t (*dll_randombytes_random)(void);
234 236
235 static struct { 237 static struct {
236 const char *name; 238 const char *name;
237 SODIUM_PROC *ptr; 239 SODIUM_PROC *ptr;
238 } sodium_funcname_table[] = { 240 } sodium_funcname_table[] = {
246 {"crypto_secretstream_xchacha20poly1305_push", (SODIUM_PROC*)&dll_crypto_secretstream_xchacha20poly1305_push}, 248 {"crypto_secretstream_xchacha20poly1305_push", (SODIUM_PROC*)&dll_crypto_secretstream_xchacha20poly1305_push},
247 {"crypto_secretstream_xchacha20poly1305_init_pull", (SODIUM_PROC*)&dll_crypto_secretstream_xchacha20poly1305_init_pull}, 249 {"crypto_secretstream_xchacha20poly1305_init_pull", (SODIUM_PROC*)&dll_crypto_secretstream_xchacha20poly1305_init_pull},
248 {"crypto_secretstream_xchacha20poly1305_pull", (SODIUM_PROC*)&dll_crypto_secretstream_xchacha20poly1305_pull}, 250 {"crypto_secretstream_xchacha20poly1305_pull", (SODIUM_PROC*)&dll_crypto_secretstream_xchacha20poly1305_pull},
249 {"crypto_pwhash", (SODIUM_PROC*)&dll_crypto_pwhash}, 251 {"crypto_pwhash", (SODIUM_PROC*)&dll_crypto_pwhash},
250 {"randombytes_buf", (SODIUM_PROC*)&dll_randombytes_buf}, 252 {"randombytes_buf", (SODIUM_PROC*)&dll_randombytes_buf},
253 {"randombytes_random", (SODIUM_PROC*)&dll_randombytes_random},
251 {NULL, NULL} 254 {NULL, NULL}
252 }; 255 };
253 256
254 static int 257 static int
255 sodium_runtime_link_init(int verbose) 258 sodium_runtime_link_init(int verbose)
853 STRCAT(IObuff, "]"); 856 STRCAT(IObuff, "]");
854 } 857 }
855 } 858 }
856 859
857 static int 860 static int
858 crypt_sodium_init( 861 crypt_sodium_init_(
859 cryptstate_T *state UNUSED, 862 cryptstate_T *state UNUSED,
860 char_u *key UNUSED, 863 char_u *key UNUSED,
861 char_u *salt UNUSED, 864 char_u *salt UNUSED,
862 int salt_len UNUSED, 865 int salt_len UNUSED,
863 char_u *seed UNUSED, 866 char_u *seed UNUSED,
1141 void 1144 void
1142 crypt_sodium_randombytes_buf(void *const buf, const size_t size) 1145 crypt_sodium_randombytes_buf(void *const buf, const size_t size)
1143 { 1146 {
1144 randombytes_buf(buf, size); 1147 randombytes_buf(buf, size);
1145 } 1148 }
1149
1150 int
1151 crypt_sodium_init(void)
1152 {
1153 return sodium_init();
1154 }
1155
1156 uint32_t
1157 crypt_sodium_randombytes_random(void)
1158 {
1159 return randombytes_random();
1160 }
1146 # endif 1161 # endif
1147 1162
1148 #endif // FEAT_CRYPT 1163 #endif // FEAT_CRYPT