Skip to content

Commit

Permalink
Make getRandomBytes work on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
bos committed Oct 2, 2012
1 parent f7d6643 commit 076031a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 5 additions & 5 deletions cbits/getRandomBytes.c
Expand Up @@ -4,19 +4,19 @@ int hashable_getRandomBytes(int nbytes, unsigned char *dest);


#if defined(mingw32_HOST_OS) || defined(__MINGW32__) #if defined(mingw32_HOST_OS) || defined(__MINGW32__)


#include "wincrypt.h" #include <windows.h>
#include <wincrypt.h>


int hashable_getRandomBytes(int nbytes, unsigned char *dest) int hashable_getRandomBytes(int nbytes, unsigned char *dest)
{ {
HCRYPTPROV hCryptProv; HCRYPTPROV hCryptProv;
int ret; int ret;


if (CryptAcquireContext(&hCryptProv, NULL, NULL, PROV_RSA_FULL, if (!CryptAcquireContextA(&hCryptProv, NULL, NULL, PROV_RSA_FULL,
CRYPT_VERIFYCONTEXT)) CRYPT_VERIFYCONTEXT))
return -1; return -1;


if (!CryptGenRandom(hCryptProv, (DWOORD) nbytes, (BYTE *) dest)) ret = CryptGenRandom(hCryptProv, (DWORD) nbytes, (BYTE *) dest) ? nbytes : -1;
ret = -1;


CryptReleaseContext(hCryptProv, 0); CryptReleaseContext(hCryptProv, 0);


Expand Down
2 changes: 2 additions & 0 deletions hashable.cabal
Expand Up @@ -44,6 +44,8 @@ Library
Ghc-options: -Wall Ghc-options: -Wall
if impl(ghc >= 6.8) if impl(ghc >= 6.8)
Ghc-options: -fwarn-tabs Ghc-options: -fwarn-tabs
if os(windows)
extra-libraries: advapi32


Test-suite tests Test-suite tests
Type: exitcode-stdio-1.0 Type: exitcode-stdio-1.0
Expand Down

0 comments on commit 076031a

Please sign in to comment.