diff options
author | Mitya Selivanov <automainint@guattari.tech> | 2024-07-14 21:12:37 +0200 |
---|---|---|
committer | Mitya Selivanov <automainint@guattari.tech> | 2024-07-14 21:12:37 +0200 |
commit | 30740ca4131d1f574718262451b4410207dc8d4e (patch) | |
tree | fc88b16a216079397ad85b9c6b1a1c1c5712a814 /source/kit/secure_random.c | |
parent | 5e3c99bb1cf1d03ea006300121265571f5008fd2 (diff) | |
download | saw-30740ca4131d1f574718262451b4410207dc8d4e.zip |
Reworking the build system
Diffstat (limited to 'source/kit/secure_random.c')
-rw-r--r-- | source/kit/secure_random.c | 47 |
1 files changed, 0 insertions, 47 deletions
diff --git a/source/kit/secure_random.c b/source/kit/secure_random.c deleted file mode 100644 index 2f53866..0000000 --- a/source/kit/secure_random.c +++ /dev/null @@ -1,47 +0,0 @@ -#include "secure_random.h" - -#include "status.h" - -#include <assert.h> -#include <stdio.h> -#include <stdlib.h> - -#if defined(_WIN32) && !defined(__CYGWIN__) -# ifndef WIN32_LEAN_AND_MEAN -# define WIN32_LEAN_AND_MEAN 1 -# endif -# include <windows.h> -# include <wincrypt.h> -#else -# include <unistd.h> -#endif - -s32 kit_secure_random(i64 size, void *data) { - assert(size >= 0); - assert(data != NULL); - - if (size <= 0 || data == NULL) - return KIT_ERROR_INVALID_ARGUMENT; - -#if defined(_WIN32) && !defined(__CYGWIN__) - HCRYPTPROV prov = 0; - if (!CryptAcquireContextW(&prov, NULL, NULL, PROV_RSA_FULL, - CRYPT_VERIFYCONTEXT | CRYPT_SILENT) || - !CryptGenRandom(prov, (DWORD) size, (BYTE *) data) || - !CryptReleaseContext(prov, 0)) - return KIT_ERROR_RESOURCE_UNAVAILABLE; -#else - FILE *f = fopen("/dev/urandom", "rb"); - - if (f == NULL) - return KIT_ERROR_RESOURCE_UNAVAILABLE; - - i64 n = (i64) fread(data, 1, size, f); - fclose(f); - - if (n != size) - return KIT_ERROR_RESOURCE_UNAVAILABLE; -#endif - - return KIT_OK; -} |