Permalink
Browse files

Make getRandomBytes work on Windows

  • Loading branch information...
1 parent f7d6643 commit 076031a1d5110ee9ab5cb981f506ee9051d04333 @bos committed Oct 2, 2012
Showing with 7 additions and 5 deletions.
  1. +5 −5 cbits/getRandomBytes.c
  2. +2 −0 hashable.cabal
View
@@ -4,19 +4,19 @@ int hashable_getRandomBytes(int nbytes, unsigned char *dest);
#if defined(mingw32_HOST_OS) || defined(__MINGW32__)
-#include "wincrypt.h"
+#include <windows.h>
+#include <wincrypt.h>
int hashable_getRandomBytes(int nbytes, unsigned char *dest)
{
HCRYPTPROV hCryptProv;
int ret;
- if (CryptAcquireContext(&hCryptProv, NULL, NULL, PROV_RSA_FULL,
- CRYPT_VERIFYCONTEXT))
+ if (!CryptAcquireContextA(&hCryptProv, NULL, NULL, PROV_RSA_FULL,
+ CRYPT_VERIFYCONTEXT))
return -1;
- if (!CryptGenRandom(hCryptProv, (DWOORD) nbytes, (BYTE *) dest))
- ret = -1;
+ ret = CryptGenRandom(hCryptProv, (DWORD) nbytes, (BYTE *) dest) ? nbytes : -1;
CryptReleaseContext(hCryptProv, 0);
View
@@ -44,6 +44,8 @@ Library
Ghc-options: -Wall
if impl(ghc >= 6.8)
Ghc-options: -fwarn-tabs
+ if os(windows)
+ extra-libraries: advapi32
Test-suite tests
Type: exitcode-stdio-1.0

0 comments on commit 076031a

Please sign in to comment.