moved pseudo-random seed generation to generateKey

This commit is contained in:
Václav Šmejkal 2022-12-09 18:03:30 +01:00
parent 80dd838ca8
commit 90eef0bb21
No known key found for this signature in database
GPG Key ID: FD749A97DF2D5E19
2 changed files with 18 additions and 9 deletions

View File

@ -53,14 +53,7 @@ outputFlags encryptText(char *text, char *keyNew)
char *returningText;
char *textBuffer = malloc(1);
int *textKeyChain = malloc(sizeof(int) * strlen(text));
int numberBuffer;
FILE *fileBuffer;
//TRY TO MAKE RANDOM GENERATION REALLY "RANDOM"
fileBuffer = fopen("/dev/urandom", "r");
(void) (fread(&numberBuffer, sizeof(numberBuffer), 1, fileBuffer) + 1); //TODO: Try to create some function for processing exit value
numberBuffer = abs(numberBuffer); //MAKE numberBuffer POSITIVE
srand(numberBuffer);
int numberBuffer = 0;
if (keyNew != NULL)
{
@ -135,7 +128,6 @@ outputFlags encryptText(char *text, char *keyNew)
//DEALLOCATION
free(textKeyChain);
free(textBuffer);
fclose(fileBuffer);
return output;
}

View File

@ -31,6 +31,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <why2/flags.h>
boolean seedSet = 0; //DO NOT FUCKING TOUCH THIS!!!
double multiply_cb(int a, int b) { return a * b; }
double subtract_cb(int a, int b) { return a - b; }
double sum_cb(int a, int b) { return a + b; }
@ -392,6 +394,21 @@ void generateKey(char *key, int keyLength)
{
int numberBuffer;
if (!seedSet)
{
//TRY TO MAKE RANDOM GENERATION REALLY "RANDOM"
FILE *fileBuffer;
fileBuffer = fopen("/dev/urandom", "r");
(void) (fread(&numberBuffer, sizeof(numberBuffer), 1, fileBuffer) + 1); //TODO: Try to create some function for processing exit value
numberBuffer = abs(numberBuffer); //MAKE numberBuffer POSITIVE
srand(numberBuffer);
fclose(fileBuffer);
seedSet = 1;
}
for (int i = 0; i < keyLength; i++)
{
//SET numberBuffer TO RANDOM NUMBER BETWEEN 0 AND 52