diff options
| author | Eli Zaretskii | 2016-01-20 11:47:19 +0200 |
|---|---|---|
| committer | Eli Zaretskii | 2016-01-20 11:47:19 +0200 |
| commit | 64a568d6100e5eab5b86e8bd31846212654d1fcf (patch) | |
| tree | aa65670a1439ce2375b0023f4ae2bce71c0e9707 /src | |
| parent | b895c72059521fec064ff27b4cfcfa4104081c4e (diff) | |
| download | emacs-64a568d6100e5eab5b86e8bd31846212654d1fcf.tar.gz emacs-64a568d6100e5eab5b86e8bd31846212654d1fcf.zip | |
Fix MS-Windows build broken by a botched merge from emacs-25
* src/w32.c (w32_crypto_hprov): New static variable.
(globals_of_w32): Initialize w32_crypto_hprov.
(w32_init_crypt_random, w32_init_random): New functions.
Include wincrypt.h.
* src/w32.h (w32_init_random): Add prototype.
Diffstat (limited to 'src')
| -rw-r--r-- | src/w32.c | 32 | ||||
| -rw-r--r-- | src/w32.h | 3 |
2 files changed, 35 insertions, 0 deletions
| @@ -224,6 +224,8 @@ typedef struct _REPARSE_DATA_BUFFER { | |||
| 224 | 224 | ||
| 225 | #include <iphlpapi.h> /* should be after winsock2.h */ | 225 | #include <iphlpapi.h> /* should be after winsock2.h */ |
| 226 | 226 | ||
| 227 | #include <wincrypt.h> | ||
| 228 | |||
| 227 | #include <c-strcase.h> | 229 | #include <c-strcase.h> |
| 228 | 230 | ||
| 229 | #include "w32.h" | 231 | #include "w32.h" |
| @@ -2094,6 +2096,34 @@ init_user_info (void) | |||
| 2094 | CloseHandle (token); | 2096 | CloseHandle (token); |
| 2095 | } | 2097 | } |
| 2096 | 2098 | ||
| 2099 | static HCRYPTPROV w32_crypto_hprov; | ||
| 2100 | static int | ||
| 2101 | w32_init_crypt_random (void) | ||
| 2102 | { | ||
| 2103 | if (!CryptAcquireContext (&w32_crypto_hprov, NULL, NULL, PROV_RSA_FULL, | ||
| 2104 | CRYPT_VERIFYCONTEXT | CRYPT_SILENT)) | ||
| 2105 | { | ||
| 2106 | DebPrint (("CryptAcquireContext failed with error %x\n", | ||
| 2107 | GetLastError ())); | ||
| 2108 | w32_crypto_hprov = 0; | ||
| 2109 | return -1; | ||
| 2110 | } | ||
| 2111 | return 0; | ||
| 2112 | } | ||
| 2113 | |||
| 2114 | int | ||
| 2115 | w32_init_random (void *buf, ptrdiff_t buflen) | ||
| 2116 | { | ||
| 2117 | if (!w32_crypto_hprov) | ||
| 2118 | w32_init_crypt_random (); | ||
| 2119 | if (w32_crypto_hprov) | ||
| 2120 | { | ||
| 2121 | if (CryptGenRandom (w32_crypto_hprov, buflen, (BYTE *)buf)) | ||
| 2122 | return 0; | ||
| 2123 | } | ||
| 2124 | return -1; | ||
| 2125 | } | ||
| 2126 | |||
| 2097 | int | 2127 | int |
| 2098 | random (void) | 2128 | random (void) |
| 2099 | { | 2129 | { |
| @@ -9417,6 +9447,8 @@ globals_of_w32 (void) | |||
| 9417 | extern void dynlib_reset_last_error (void); | 9447 | extern void dynlib_reset_last_error (void); |
| 9418 | dynlib_reset_last_error (); | 9448 | dynlib_reset_last_error (); |
| 9419 | #endif | 9449 | #endif |
| 9450 | |||
| 9451 | w32_crypto_hprov = (HCRYPTPROV)0; | ||
| 9420 | } | 9452 | } |
| 9421 | 9453 | ||
| 9422 | /* For make-serial-process */ | 9454 | /* For make-serial-process */ |
| @@ -223,6 +223,9 @@ extern int w32_memory_info (unsigned long long *, unsigned long long *, | |||
| 223 | /* Compare 2 UTF-8 strings in locale-dependent fashion. */ | 223 | /* Compare 2 UTF-8 strings in locale-dependent fashion. */ |
| 224 | extern int w32_compare_strings (const char *, const char *, char *, int); | 224 | extern int w32_compare_strings (const char *, const char *, char *, int); |
| 225 | 225 | ||
| 226 | /* Return a cryptographically secure seed for PRNG. */ | ||
| 227 | extern int w32_init_random (void *, ptrdiff_t); | ||
| 228 | |||
| 226 | #ifdef HAVE_GNUTLS | 229 | #ifdef HAVE_GNUTLS |
| 227 | #include <gnutls/gnutls.h> | 230 | #include <gnutls/gnutls.h> |
| 228 | 231 | ||