diff --git a/include/crypto.h b/include/crypto.h index 6c7cd95..06c0ce1 100644 --- a/include/crypto.h +++ b/include/crypto.h @@ -25,6 +25,8 @@ extern "C" { #include +#include + //MACROS #define WHY2_SUM_SEGMENT_SIZE 32 //SEGMENT SIZE FOR CALCULATING SUM #define WHY2_SUM_BASE_PRIME 31 //PRIME FOR SUM BASE @@ -35,7 +37,7 @@ extern "C" { //FUNCTIONS unsigned long long why2_sum_segment(char *input); //CALCULATE SUM++ FOR input; USED FOR PADDING SEED -ssize_t why2_random(void *dest, size_t size); //WRITE CRYPTO-SECURE RANDOM NUMBER INTO dest +why2_bool why2_random(void *dest, size_t size); //WRITE CRYPTO-SECURE RANDOM NUMBER INTO dest void why2_seed_random(unsigned int seed); //SEED why2_seeded_random OUTPUT int why2_seeded_random(); //GENERATE RANDOM NUMBER BASED ON SEED PASSED IN why2_seed_random diff --git a/src/core/lib/utils/crypto.c b/src/core/lib/utils/crypto.c index 9e11d72..17fc95f 100644 --- a/src/core/lib/utils/crypto.c +++ b/src/core/lib/utils/crypto.c @@ -26,6 +26,8 @@ along with this program. If not, see . #include +#include + unsigned long long why2_sum_segment(char *input) //THE OUTPUT IS GOING TO GROW A LOT WITH LONG input, BUT IT SHOULDN'T BE A BIG PROBLEM. I TESTED FOR OVERFLOWS UP TO 4096-CHAR input AND ONLY GOT TO (14*10^(-7))% OF FULL ULL RANGE LMAO { unsigned long input_size = strlen(input); @@ -50,7 +52,7 @@ unsigned long long why2_sum_segment(char *input) //THE OUTPUT IS GOING TO GROW A return output; } -ssize_t why2_random(void *dest, size_t size) +why2_bool why2_random(void *dest, size_t size) { return RAND_bytes((unsigned char*) dest, size) == 1; } diff --git a/src/core/lib/utils/misc.c b/src/core/lib/utils/misc.c index b6d2cf0..7f0f0b7 100644 --- a/src/core/lib/utils/misc.c +++ b/src/core/lib/utils/misc.c @@ -438,7 +438,7 @@ char *why2_generate_key(int key_length) for (int i = 0; i < key_length; i++) { //GET RANDOM NUMBER - if (why2_random(&random_buffer, sizeof(unsigned int)) == -1) why2_die("getrandom fn failed!"); + if (!why2_random(&random_buffer, sizeof(unsigned int))) why2_die("getrandom fn failed!"); //SET numberBuffer TO RANDOM NUMBER BETWEEN 0 AND 52 number_buffer = (random_buffer % 52) + 1;