aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEli Zaretskii2016-01-20 11:47:19 +0200
committerEli Zaretskii2016-01-20 11:47:19 +0200
commit64a568d6100e5eab5b86e8bd31846212654d1fcf (patch)
treeaa65670a1439ce2375b0023f4ae2bce71c0e9707 /src
parentb895c72059521fec064ff27b4cfcfa4104081c4e (diff)
downloademacs-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.c32
-rw-r--r--src/w32.h3
2 files changed, 35 insertions, 0 deletions
diff --git a/src/w32.c b/src/w32.c
index 183a4e7e9d9..6f1d5fd1698 100644
--- a/src/w32.c
+++ b/src/w32.c
@@ -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
2099static HCRYPTPROV w32_crypto_hprov;
2100static int
2101w32_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
2114int
2115w32_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
2097int 2127int
2098random (void) 2128random (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 */
diff --git a/src/w32.h b/src/w32.h
index 097241b1b8f..fde3803c739 100644
--- a/src/w32.h
+++ b/src/w32.h
@@ -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. */
224extern int w32_compare_strings (const char *, const char *, char *, int); 224extern int w32_compare_strings (const char *, const char *, char *, int);
225 225
226/* Return a cryptographically secure seed for PRNG. */
227extern 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