diff options
| author | Brian Anderson <banderson@mozilla.com> | 2013-05-06 16:29:54 -0700 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2013-05-07 12:08:00 -0700 |
| commit | 4cd51c416b8cf1a9d89089c99b8a1e2ac2f7255a (patch) | |
| tree | 5d507d561b6d473ad0d9fa15435f05d1ac7538b0 /src/rt/rust_rng.cpp | |
| parent | 19d2ba33832d1fa1ba6485df7b481e9aa5e5bd02 (diff) | |
| download | rust-4cd51c416b8cf1a9d89089c99b8a1e2ac2f7255a.tar.gz rust-4cd51c416b8cf1a9d89089c99b8a1e2ac2f7255a.zip | |
rt: Move win32_require out of the rust_kernel type
This is only used on rust_rng, which I am trying to extricate from the kernel.
Diffstat (limited to 'src/rt/rust_rng.cpp')
| -rw-r--r-- | src/rt/rust_rng.cpp | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/src/rt/rust_rng.cpp b/src/rt/rust_rng.cpp index 2c11691bf86..d55f9b5f2bc 100644 --- a/src/rt/rust_rng.cpp +++ b/src/rt/rust_rng.cpp @@ -12,6 +12,26 @@ #include "rust_rng.h" #include "rust_util.h" + +#ifdef __WIN32__ +void +win32_require(LPCTSTR fn, BOOL ok) { + if (!ok) { + LPTSTR buf; + DWORD err = GetLastError(); + FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | + FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, err, + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + (LPTSTR) &buf, 0, NULL ); + fprintf(stderr, "%s failed with error %ld: %s", fn, err, buf); + LocalFree((HLOCAL)buf); + abort(); + } +} +#endif + size_t rng_seed_size() { randctx rctx; @@ -24,13 +44,13 @@ void rng_gen_seed(rust_kernel* kernel, uint8_t* dest, size_t size) { #ifdef __WIN32__ HCRYPTPROV hProv; - kernel->win32_require + win32_require (_T("CryptAcquireContext"), CryptAcquireContext(&hProv, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT|CRYPT_SILENT)); - kernel->win32_require + win32_require (_T("CryptGenRandom"), CryptGenRandom(hProv, size, (BYTE*) dest)); - kernel->win32_require + win32_require (_T("CryptReleaseContext"), CryptReleaseContext(hProv, 0)); #else int fd = open("/dev/urandom", O_RDONLY); |
