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 #11667)
This commit is contained in:
		
							
								
								
									
										21
									
								
								src/crypt.c
									
									
									
									
									
								
							
							
						
						
									
										21
									
								
								src/crypt.c
									
									
									
									
									
								
							| @ -73,7 +73,7 @@ typedef struct { | |||||||
| 							char_u *p2, int last); | 							char_u *p2, int last); | ||||||
| } cryptmethod_T; | } 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 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_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); | static long crypt_sodium_buffer_encode(cryptstate_T *state, char_u *from, size_t len, char_u **buf_out, int last); | ||||||
|  |  | ||||||
| @ -145,7 +145,7 @@ static cryptmethod_T cryptmethods[CRYPT_M_COUNT] = { | |||||||
| #endif | #endif | ||||||
| 	FALSE, | 	FALSE, | ||||||
| 	NULL, | 	NULL, | ||||||
| 	crypt_sodium_init, | 	crypt_sodium_init_, | ||||||
| 	NULL, NULL, | 	NULL, NULL, | ||||||
| 	crypt_sodium_buffer_encode, crypt_sodium_buffer_decode, | 	crypt_sodium_buffer_encode, crypt_sodium_buffer_decode, | ||||||
| 	NULL, NULL, | 	NULL, NULL, | ||||||
| @ -198,6 +198,7 @@ typedef struct { | |||||||
|     dll_crypto_secretstream_xchacha20poly1305_pull |     dll_crypto_secretstream_xchacha20poly1305_pull | ||||||
| #  define crypto_pwhash	    dll_crypto_pwhash | #  define crypto_pwhash	    dll_crypto_pwhash | ||||||
| #  define randombytes_buf   dll_randombytes_buf | #  define randombytes_buf   dll_randombytes_buf | ||||||
|  | #  define randombytes_random dll_randombytes_random | ||||||
|  |  | ||||||
| static int (*dll_sodium_init)(void) = NULL; | static int (*dll_sodium_init)(void) = NULL; | ||||||
| static void (*dll_sodium_free)(void *) = NULL; | static void (*dll_sodium_free)(void *) = NULL; | ||||||
| @ -231,6 +232,7 @@ static int (*dll_crypto_pwhash)(unsigned char * const out, | |||||||
|     unsigned long long opslimit, size_t memlimit, int alg) |     unsigned long long opslimit, size_t memlimit, int alg) | ||||||
|     = NULL; |     = NULL; | ||||||
| static void (*dll_randombytes_buf)(void * const buf, const size_t size); | static void (*dll_randombytes_buf)(void * const buf, const size_t size); | ||||||
|  | static uint32_t (*dll_randombytes_random)(void); | ||||||
|  |  | ||||||
| static struct { | static struct { | ||||||
|     const char *name; |     const char *name; | ||||||
| @ -248,6 +250,7 @@ static struct { | |||||||
|     {"crypto_secretstream_xchacha20poly1305_pull", (SODIUM_PROC*)&dll_crypto_secretstream_xchacha20poly1305_pull}, |     {"crypto_secretstream_xchacha20poly1305_pull", (SODIUM_PROC*)&dll_crypto_secretstream_xchacha20poly1305_pull}, | ||||||
|     {"crypto_pwhash", (SODIUM_PROC*)&dll_crypto_pwhash}, |     {"crypto_pwhash", (SODIUM_PROC*)&dll_crypto_pwhash}, | ||||||
|     {"randombytes_buf", (SODIUM_PROC*)&dll_randombytes_buf}, |     {"randombytes_buf", (SODIUM_PROC*)&dll_randombytes_buf}, | ||||||
|  |     {"randombytes_random", (SODIUM_PROC*)&dll_randombytes_random}, | ||||||
|     {NULL, NULL} |     {NULL, NULL} | ||||||
| }; | }; | ||||||
|  |  | ||||||
| @ -855,7 +858,7 @@ crypt_append_msg( | |||||||
| } | } | ||||||
|  |  | ||||||
|     static int |     static int | ||||||
| crypt_sodium_init( | crypt_sodium_init_( | ||||||
|     cryptstate_T	*state UNUSED, |     cryptstate_T	*state UNUSED, | ||||||
|     char_u		*key UNUSED, |     char_u		*key UNUSED, | ||||||
|     char_u		*salt UNUSED, |     char_u		*salt UNUSED, | ||||||
| @ -1143,6 +1146,18 @@ crypt_sodium_randombytes_buf(void *const buf, const size_t size) | |||||||
| { | { | ||||||
|     randombytes_buf(buf, size); |     randombytes_buf(buf, size); | ||||||
| } | } | ||||||
|  |  | ||||||
|  |     int | ||||||
|  | crypt_sodium_init(void) | ||||||
|  | { | ||||||
|  |     return sodium_init(); | ||||||
|  | } | ||||||
|  |  | ||||||
|  |     uint32_t | ||||||
|  | crypt_sodium_randombytes_random(void) | ||||||
|  | { | ||||||
|  |     return randombytes_random(); | ||||||
|  | } | ||||||
| # endif | # endif | ||||||
|  |  | ||||||
| #endif // FEAT_CRYPT | #endif // FEAT_CRYPT | ||||||
|  | |||||||
| @ -8166,8 +8166,8 @@ init_srand(UINT32_T *x) | |||||||
| 	// - reltime() or time() | 	// - reltime() or time() | ||||||
| 	// - XOR with process ID | 	// - XOR with process ID | ||||||
| #if defined(FEAT_SODIUM) | #if defined(FEAT_SODIUM) | ||||||
| 	if (sodium_init() >= 0) | 	if (crypt_sodium_init() >= 0) | ||||||
| 	    *x = randombytes_random(); | 	    *x = crypt_sodium_randombytes_random(); | ||||||
| 	else | 	else | ||||||
| #endif | #endif | ||||||
| 	{ | 	{ | ||||||
|  | |||||||
| @ -26,4 +26,6 @@ char_u *crypt_get_key(int store, int twice); | |||||||
| void crypt_append_msg(buf_T *buf); | void crypt_append_msg(buf_T *buf); | ||||||
| int crypt_sodium_munlock(void *const addr, const size_t len); | int crypt_sodium_munlock(void *const addr, const size_t len); | ||||||
| void crypt_sodium_randombytes_buf(void *const buf, const size_t size); | 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: set ft=c : */ | ||||||
|  | |||||||
| @ -695,6 +695,8 @@ static char *(features[]) = | |||||||
|  |  | ||||||
| static int included_patches[] = | static int included_patches[] = | ||||||
| {   /* Add new patch number below this line */ | {   /* Add new patch number below this line */ | ||||||
|  | /**/ | ||||||
|  |     1023, | ||||||
| /**/ | /**/ | ||||||
|     1022, |     1022, | ||||||
| /**/ | /**/ | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user