summaryrefslogtreecommitdiff
path: root/source/kit/secure_random.c
diff options
context:
space:
mode:
Diffstat (limited to 'source/kit/secure_random.c')
-rw-r--r--source/kit/secure_random.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/source/kit/secure_random.c b/source/kit/secure_random.c
index 8f7a302..02b168b 100644
--- a/source/kit/secure_random.c
+++ b/source/kit/secure_random.c
@@ -14,12 +14,12 @@
# include <unistd.h>
#endif
-void kit_secure_random(i64 size, void *data) {
+kit_status_t kit_secure_random(i64 size, void *data) {
assert(size >= 0);
assert(data != NULL);
if (size <= 0 || data == NULL)
- return;
+ return KIT_ERROR_INVALID_ARGUMENT;
#if defined(_WIN32) && !defined(__CYGWIN__)
HCRYPTPROV prov = 0;
@@ -27,17 +27,19 @@ void kit_secure_random(i64 size, void *data) {
CRYPT_VERIFYCONTEXT | CRYPT_SILENT) ||
!CryptGenRandom(prov, (DWORD) size, (BYTE *) data) ||
!CryptReleaseContext(prov, 0))
- abort();
+ return KIT_ERROR_RESOURCE_UNAVAILABLE;
#else
FILE *f = fopen("/dev/urandom", "rb");
if (f == NULL)
- abort();
+ return KIT_ERROR_RESOURCE_UNAVAILABLE;
i64 n = (i64) fread(data, 1, size, f);
fclose(f);
if (n != size)
- abort();
+ return KIT_ERROR_RESOURCE_UNAVAILABLE;
#endif
+
+ return KIT_OK;
}