Compare commits

..

No commits in common. "c72eb44ab06bee8920ff0df30491a7add95c563a" and "7dcbd4fc80fa13e5f9d0d4fe90a742c0f8dfab3d" have entirely different histories.

8 changed files with 8 additions and 72 deletions

1
.gitignore vendored
View File

@ -6,4 +6,3 @@ 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,9 +30,6 @@ 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,7 +30,6 @@ extern "C" {
#endif
//CORE
#include <why2/crypto.h>
#include <why2/decrypter.h>
#include <why2/encrypter.h>
#include <why2/flags.h>

View File

@ -23,9 +23,7 @@ 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>
@ -177,59 +175,6 @@ 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) //TODO! this breaks when used with long strings or byte input
if (why2_get_flags().padding > 0)
{
why2_list_t split_text = WHY2_LIST_EMPTY; //LIST OF text SPLIT INTO CHARS
@ -99,12 +99,8 @@ 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 = 0;
for (int j = 0; j < WHY2_PADDING_NONZERO_TRIES && random_char == 0 ; j++) //GET RANDOM (EXCLUDING 0)
{
char random_char;
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
WHY2_RECOMMENDED_PADDING_RATE(strlen(WHY2_TEST_TEXT)) //PADDING RATE
255 //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 == 0 ? 1 : b); }
int mod_cb(int a, int b) { return a % 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; }