From 023e201ac73810225c41e2cdffbfe27c0ba30eb6 Mon Sep 17 00:00:00 2001 From: ENGO150 Date: Fri, 10 Jan 2025 17:56:34 +0100 Subject: [PATCH] implemented seeded-rand fns in padding code --- src/core/lib/decrypter.c | 4 ++-- src/core/lib/encrypter.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/core/lib/decrypter.c b/src/core/lib/decrypter.c index 3e8b3ad..c429a0b 100644 --- a/src/core/lib/decrypter.c +++ b/src/core/lib/decrypter.c @@ -189,13 +189,13 @@ why2_output_flags why2_decrypt_text(char *text, char *key) } //OBTAIN SEED FROM key_new - srand(why2_sum_segment(key_new)); + why2_seed_random(why2_sum_segment(key_new)); //GET RANDOM SEQUENCE USED IN ENCRYPTION why2_list_t random_sequence = WHY2_LIST_EMPTY; for (unsigned long i = 0; i < why2_get_flags().padding; i++) { - int rand_buffer = rand(); + int rand_buffer = why2_seeded_random(); why2_list_push(&random_sequence, &rand_buffer, sizeof(int)); //ADD } why2_list_reverse(&random_sequence, sizeof(int)); //REVERSE diff --git a/src/core/lib/encrypter.c b/src/core/lib/encrypter.c index 5719a65..5f9c82c 100644 --- a/src/core/lib/encrypter.c +++ b/src/core/lib/encrypter.c @@ -92,12 +92,12 @@ why2_output_flags why2_encrypt_text(char *text, char *key) } //OBTAIN SEED FROM key_new - srand(why2_sum_segment(key_new)); + why2_seed_random(why2_sum_segment(key_new)); //ADD PADDING TO split_text LIST for (unsigned long i = 0; i < why2_get_flags().padding; i++) { - unsigned long random_position = (unsigned long) (rand() % (why2_list_get_size(&split_text))); //GET RANDOM POSITION + unsigned long random_position = (unsigned long) (why2_seeded_random() % (why2_list_get_size(&split_text))); //GET RANDOM POSITION char random_char = 0; for (int j = 0; j < WHY2_PADDING_NONZERO_TRIES && random_char == 0 ; j++) //GET RANDOM (EXCLUDING 0)