diff options
author | Mitya Selivanov <automainint@guattari.tech> | 2024-01-12 18:40:07 +0100 |
---|---|---|
committer | Mitya Selivanov <automainint@guattari.tech> | 2024-01-12 18:40:07 +0100 |
commit | 9fe0da76faaecd05d39101adf0e333f5ea1a6729 (patch) | |
tree | 35252e7c970fce3afb64f05c5ee9cc69f426e4c9 /source/kit/secure_random.c | |
parent | 9417f59a071174424f88a206f7789c863d9eb718 (diff) | |
download | saw-9fe0da76faaecd05d39101adf0e333f5ea1a6729.zip |
Update kit
Diffstat (limited to 'source/kit/secure_random.c')
-rw-r--r-- | source/kit/secure_random.c | 12 |
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; } |