changed why2_generate_key type to char*

This commit is contained in:
Václav Šmejkal 2023-02-08 19:31:46 +01:00
parent d304b811da
commit 6e3599ca74
Signed by: ENGO150
GPG Key ID: 4A57E86482968843
2 changed files with 10 additions and 5 deletions

View File

@ -24,7 +24,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <why2/flags.h> #include <why2/flags.h>
void why2_generate_text_key_chain(char *key, int *textKeyChain, int textKeyChainSize); //GENERATES ARRAY FOR ENCRYPTION/DECRYPTION void why2_generate_text_key_chain(char *key, int *textKeyChain, int textKeyChainSize); //GENERATES ARRAY FOR ENCRYPTION/DECRYPTION
void why2_generate_key(char *key, int keyLength); //GENERATE ENCRYPTION KEY char *why2_generate_key(int key_length); //GENERATE ENCRYPTION KEY
void why2_deallocate_output(why2_output_flags flags); //DEALLOCATES flags void why2_deallocate_output(why2_output_flags flags); //DEALLOCATES flags
enum WHY2_EXIT_CODES why2_check_version(void); //THIS FUNCTION CHECKS IF LATEST WHY2_VERSION OF WHY2 IS USED enum WHY2_EXIT_CODES why2_check_version(void); //THIS FUNCTION CHECKS IF LATEST WHY2_VERSION OF WHY2 IS USED
enum WHY2_EXIT_CODES why2_check_key(char *key); //CHECKS IF KEY IS VALID enum WHY2_EXIT_CODES why2_check_key(char *key); //CHECKS IF KEY IS VALID

View File

@ -410,9 +410,10 @@ unsigned long why2_compare_time_micro(struct timeval startTime, struct timeval f
return (finishTime.tv_sec - startTime.tv_sec) * 1000000 + finishTime.tv_usec - startTime.tv_usec; return (finishTime.tv_sec - startTime.tv_sec) * 1000000 + finishTime.tv_usec - startTime.tv_usec;
} }
void why2_generate_key(char *key, int keyLength) char *why2_generate_key(int key_length)
{ {
int numberBuffer; int numberBuffer;
char *key;
if (!seedSet) if (!seedSet)
{ {
@ -428,7 +429,7 @@ void why2_generate_key(char *key, int keyLength)
if (!why2_get_flags().no_output) fprintf(stderr, "Reading file failed!\n"); if (!why2_get_flags().no_output) fprintf(stderr, "Reading file failed!\n");
why2_clean_memory("core_key_generation_random"); why2_clean_memory("core_key_generation_random");
return; return NULL;
} }
numberBuffer = abs(numberBuffer); //MAKE numberBuffer POSITIVE numberBuffer = abs(numberBuffer); //MAKE numberBuffer POSITIVE
@ -441,7 +442,9 @@ void why2_generate_key(char *key, int keyLength)
why2_reset_memory_identifier(); why2_reset_memory_identifier();
} }
for (int i = 0; i < keyLength; i++) key = why2_malloc(key_length + 1);
for (int i = 0; i < key_length; i++)
{ {
//SET numberBuffer TO RANDOM NUMBER BETWEEN 0 AND 52 //SET numberBuffer TO RANDOM NUMBER BETWEEN 0 AND 52
numberBuffer = (rand() % 52) + 1; numberBuffer = (rand() % 52) + 1;
@ -459,5 +462,7 @@ void why2_generate_key(char *key, int keyLength)
key[i] = (char) numberBuffer; key[i] = (char) numberBuffer;
} }
key[keyLength] = '\0'; key[key_length] = '\0';
return key;
} }