summaryrefslogtreecommitdiff
path: root/lcrypt/lcrypt.c
diff options
context:
space:
mode:
authorNicolas "Pixel" Noble <pixel@nobis-crew.org>2013-08-10 08:14:28 +0200
committerNicolas "Pixel" Noble <pixel@nobis-crew.org>2013-08-10 08:14:28 +0200
commita702df0e6b2cf5d523a8db764d6523d868eba8df (patch)
treec7f618894aabb0879ea5ba748b875c1eee8ac6b1 /lcrypt/lcrypt.c
parent5ddf9b5b18431b7fe85bf555d9cfa7fe04aae5e1 (diff)
parent697f9e4655829013e464c9c4485c91b5a4e5f132 (diff)
Merge branch 'master' of /pub/repo.git/Balau
Diffstat (limited to 'lcrypt/lcrypt.c')
-rw-r--r--lcrypt/lcrypt.c47
1 files changed, 34 insertions, 13 deletions
diff --git a/lcrypt/lcrypt.c b/lcrypt/lcrypt.c
index 5ca67cf..779504e 100644
--- a/lcrypt/lcrypt.c
+++ b/lcrypt/lcrypt.c
@@ -45,7 +45,6 @@ static void* lcrypt_malloc(lua_State *L, size_t size)
#include "lcrypt_hashes.c"
//#include "lcrypt_math.c"
#include "lcrypt_bits.c"
-#include "lcrypt_rsa.c"
static int lcrypt_tohex(lua_State *L)
{
@@ -221,20 +220,42 @@ static int lcrypt_time(lua_State *L)
static int lcrypt_random(lua_State *L)
{
int len = luaL_checkint(L, 1);
- FILE *fp;
char *buffer = lcrypt_malloc(L, len);
- if(unlikely((fp = fopen("/dev/urandom", "rb")) == NULL))
- {
- lua_pushstring(L, "Unable to open /dev/urandom.");
- (void)lua_error(L);
- }
- if(unlikely(fread(buffer, len, 1, fp) != 1))
- {
+ #ifdef _WIN32
+ HMODULE hLib = LoadLibrary("ADVAPI32.DLL");
+ if (unlikely(!hLib))
+ {
+ lua_pushstring(L, "Unable to open ADVAPI32.DLL");
+ (void)lua_error(L);
+ }
+ BOOLEAN (APIENTRY *pfn)(void *, ULONG) =
+ (BOOLEAN (APIENTRY *)(void *, ULONG)) GetProcAddress(hLib, "SystemFunction036");
+ if (unlikely(!pfn))
+ {
+ lua_pushstring(L, "Unable to open ADVAPI32.DLL");
+ (void)lua_error(L);
+ }
+ ULONG ulCbBuff = len;
+ if (unlikely(!pfn(buffer, ulCbBuff)))
+ {
+ lua_pushstring(L, "Call to SystemFunction036 failed.");
+ (void)lua_error(L);
+ }
+ #else
+ FILE *fp;
+ if(unlikely((fp = fopen("/dev/urandom", "rb")) == NULL))
+ {
+ lua_pushstring(L, "Unable to open /dev/urandom.");
+ (void)lua_error(L);
+ }
+ if(unlikely(fread(buffer, len, 1, fp) != 1))
+ {
+ fclose(fp);
+ lua_pushstring(L, "Unable to read /dev/urandom.");
+ (void)lua_error(L);
+ }
fclose(fp);
- lua_pushstring(L, "Unable to read /dev/urandom.");
- (void)lua_error(L);
- }
- fclose(fp);
+ #endif
lua_pushlstring(L, buffer, len);
free(buffer);
return 1;