moved key's random number generation to why2_random fn
This commit is contained in:
parent
5b06ea5dc1
commit
f95608f52a
@ -23,6 +23,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
//MACROS
|
||||
#define WHY2_SUM_SEGMENT_SIZE 32 //SEGMENT SIZE FOR CALCULATING SUM
|
||||
#define WHY2_SUM_BASE_PRIME 31 //PRIME FOR SUM BASE
|
||||
@ -30,6 +32,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
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -20,6 +20,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/random.h>
|
||||
|
||||
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
|
||||
{
|
||||
@ -44,3 +46,8 @@ 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)
|
||||
{
|
||||
return getrandom(dest, size, GRND_NONBLOCK);
|
||||
}
|
@ -24,13 +24,13 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/random.h>
|
||||
#include <ftw.h>
|
||||
|
||||
#include <curl/curl.h>
|
||||
#include <json-c/json.h>
|
||||
#include <git2.h>
|
||||
|
||||
#include <why2/crypto.h>
|
||||
#include <why2/flags.h>
|
||||
#include <why2/memory.h>
|
||||
|
||||
@ -422,7 +422,7 @@ char *why2_generate_key(int key_length)
|
||||
for (int i = 0; i < key_length; i++)
|
||||
{
|
||||
//GET RANDOM NUMBER
|
||||
if (getrandom(&random_buffer, sizeof(unsigned int), GRND_NONBLOCK) == -1) why2_die("getrandom fn failed!");
|
||||
if (why2_random(&random_buffer, sizeof(unsigned int)) == -1) why2_die("getrandom fn failed!");
|
||||
|
||||
//SET numberBuffer TO RANDOM NUMBER BETWEEN 0 AND 52
|
||||
number_buffer = (random_buffer % 52) + 1;
|
||||
|
Loading…
x
Reference in New Issue
Block a user