Compare commits

...

10 Commits

Author SHA1 Message Date
c72eb44ab0 corrected output path in make
Some checks failed
Build WHY2-chat / test-why2 (./out/why2-chat-client, configure.sh, ubuntu-latest, ./out/why2-chat-server) (push) Failing after 1m19s
Test WHY2-core / test-why2 (why2, configure.sh, ubuntu-latest, ./out/why2-core-test, valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s) (push) Failing after 59s
Test WHY2-logger / test-why2 (why2-logger, configure.sh, ubuntu-latest, ./out/why2-logger-test, valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s) (push) Failing after 59s
Test Project / test-project (configure.sh, ubuntu-latest, test) (push) Failing after 1m2s
Codacy Scan / Codacy Security Scan (push) Failing after 2m31s
2024-12-26 11:49:24 +00:00
0aed96415c
added todo to encrypter padding 2024-11-21 21:13:43 +01:00
3a62ed36e7
ignoring .gdbinit file 2024-11-21 21:08:47 +01:00
222f55587f
implemented WHY2_RECOMMENDED_PADDING_RATE in core-test input_flags 2024-11-21 21:05:28 +01:00
cf277b249f
created WHY2_RECOMMENDED_PADDING_RATE macro
basically padding every 3 chars
2024-11-21 21:04:52 +01:00
1027042edf
added core-crypto to why2 header 2024-11-21 21:03:52 +01:00
812e31f429
preventing modulating by 0 in tkch 2024-11-21 21:00:52 +01:00
6a3f005321
implemented padding in decrypter
FUCKKKKK remember how I mentioned that creating padding in encrypter was pain? This, compared to the encrypter is like getting stuck up your ass and getting it shaked by a fucking gorilla compared to stepping on a lego brick. FUCK.
2024-11-21 20:56:18 +01:00
126565cf97
preventing padding char from being 0 2024-11-21 20:53:06 +01:00
326f8f0768
created WHY2_PADDING_NONZERO_TRIES macro
when I try to generate random number, I need to prevent it from being zero, so I try this many times to be non-zero before I forcefully set it to 1

this should run few times but yk, theoretically the generated number can be the same for infinite time (or at least slow the performance :) )
2024-11-21 20:50:20 +01:00
8 changed files with 72 additions and 8 deletions

1
.gitignore vendored
View File

@ -6,3 +6,4 @@ logs/
vgcore.*
target/
Cargo.lock
.gdbinit

View File

@ -23,8 +23,8 @@ CFLAGS=-Wall -Wextra -Werror -Wcomment -Wformat -Wformat-security -Wmain -Wnonnu
# Output Files
PROJECT_NAME=why2
OUTPUT=out
LOGS=logs
OUTPUT=./out
LOGS=./logs
OUTPUT_TEST_CORE=$(OUTPUT)/$(PROJECT_NAME)-core-test
OUTPUT_APP_CORE=$(OUTPUT)/$(PROJECT_NAME)-core-app

View File

@ -30,6 +30,9 @@ extern "C" {
#define WHY2_SUM_BASE_PRIME 31 //PRIME FOR SUM BASE
#define WHY2_SUM_MOD_PRIME 4294967295UL //PRIME FOR SUM MODULUS; 2^32 - 1
#define WHY2_RECOMMENDED_PADDING_RATE(input_len) ((unsigned long) input_len / 3)
#define WHY2_PADDING_NONZERO_TRIES 1024 //HOW MANY RANDOM NUMBERS TO TRY TO GENERATE WHEN PREVENTING 0s
//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

View File

@ -30,6 +30,7 @@ extern "C" {
#endif
//CORE
#include <why2/crypto.h>
#include <why2/decrypter.h>
#include <why2/encrypter.h>
#include <why2/flags.h>

View File

@ -23,7 +23,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <stdlib.h>
#include <sys/time.h>
#include <why2/crypto.h>
#include <why2/flags.h>
#include <why2/llist.h>
#include <why2/memory.h>
#include <why2/misc.h>
@ -175,6 +177,59 @@ why2_output_flags why2_decrypt_text(char *text, char *key)
returning_text[i] = text_key_chain[i];
}
//REMOVE PADDING
if (why2_get_flags().padding > 0)
{
why2_list_t split_text = WHY2_LIST_EMPTY; //LIST OF returning_text SPLIT INTO CHARS
//ADD CHARS
for (unsigned long i = 0; i < strlen(returning_text); i++)
{
why2_list_push(&split_text, &(returning_text[i]), sizeof(returning_text[i])); //ADD
}
//OBTAIN SEED FROM key_new
srand(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();
why2_list_push(&random_sequence, &rand_buffer, sizeof(int)); //ADD
}
why2_list_reverse(&random_sequence, sizeof(int)); //REVERSE
//REMOVE PADDING FROM split_text LIST
for (unsigned long i = 0; i < why2_get_flags().padding; i++)
{
unsigned long random_position = (unsigned long) (*(int*) random_sequence.head -> value % (why2_list_get_size(&split_text) - 1)); //GET RANDOM POSITION
//REMOVE FROM THE LIST
why2_list_remove_at(&split_text, random_position);
//DEALLOCATION
why2_list_remove_at(&random_sequence, 0);
}
//PUT PADDED TEXT INTO text_new
returning_text = why2_recalloc(returning_text, why2_list_get_size(&split_text) + 1, sizeof(char));
why2_node_t *buffer = split_text.head;
why2_node_t *buffer_2;
unsigned long index_buffer = 0;
do
{
returning_text[index_buffer++] = *(char*) buffer -> value; //COPY VALUE
buffer_2 = buffer;
buffer = buffer -> next; //ITER
why2_deallocate(buffer_2 -> value); //DEALLOCATION
why2_deallocate(buffer_2); //DEALLOCATION
} while (buffer != NULL);
}
//GET FINISH TIME
gettimeofday(&finish_time, NULL);

View File

@ -81,7 +81,7 @@ why2_output_flags why2_encrypt_text(char *text, char *key)
}
//PADDING
if (why2_get_flags().padding > 0)
if (why2_get_flags().padding > 0) //TODO! this breaks when used with long strings or byte input
{
why2_list_t split_text = WHY2_LIST_EMPTY; //LIST OF text SPLIT INTO CHARS
@ -99,8 +99,12 @@ why2_output_flags why2_encrypt_text(char *text, char *key)
{
unsigned long random_position = (unsigned long) (rand() % (why2_list_get_size(&split_text))); //GET RANDOM POSITION
char random_char;
char random_char = 0;
for (int j = 0; j < WHY2_PADDING_NONZERO_TRIES && random_char == 0 ; j++) //GET RANDOM (EXCLUDING 0)
{
why2_random(&random_char, sizeof(random_char)); //GENERATE COMPLETELY RANDOM CHARACTER
}
if (random_char == 0) random_char = 1;
//INSERT RANDOM VALUE
why2_list_push_at(&split_text, random_position, &random_char, sizeof(random_char));

View File

@ -46,7 +46,7 @@ int main(void)
0, //UPDATE
WHY2_v4, //LATEST VERSION
WHY2_OUTPUT_TEXT, //READABLE TEXT OUTPUT
255 //PADDING RATE
WHY2_RECOMMENDED_PADDING_RATE(strlen(WHY2_TEST_TEXT)) //PADDING RATE
};
//SET FLAGS

View File

@ -34,7 +34,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <why2/flags.h>
#include <why2/memory.h>
int mod_cb(int a, int b) { return a % b; }
int mod_cb(int a, int b) { return a % (b == 0 ? 1 : b); }
int multiply_cb(int a, int b) { return a * b; }
int subtract_cb(int a, int b) { return a - b; }
int sum_cb(int a, int b) { return a + b; }