Compare commits
10 Commits
7dcbd4fc80
...
c72eb44ab0
Author | SHA1 | Date | |
---|---|---|---|
c72eb44ab0 | |||
0aed96415c | |||
3a62ed36e7 | |||
222f55587f | |||
cf277b249f | |||
1027042edf | |||
812e31f429 | |||
6a3f005321 | |||
126565cf97 | |||
326f8f0768 |
1
.gitignore
vendored
1
.gitignore
vendored
@ -6,3 +6,4 @@ logs/
|
|||||||
vgcore.*
|
vgcore.*
|
||||||
target/
|
target/
|
||||||
Cargo.lock
|
Cargo.lock
|
||||||
|
.gdbinit
|
4
Makefile
4
Makefile
@ -23,8 +23,8 @@ CFLAGS=-Wall -Wextra -Werror -Wcomment -Wformat -Wformat-security -Wmain -Wnonnu
|
|||||||
|
|
||||||
# Output Files
|
# Output Files
|
||||||
PROJECT_NAME=why2
|
PROJECT_NAME=why2
|
||||||
OUTPUT=out
|
OUTPUT=./out
|
||||||
LOGS=logs
|
LOGS=./logs
|
||||||
|
|
||||||
OUTPUT_TEST_CORE=$(OUTPUT)/$(PROJECT_NAME)-core-test
|
OUTPUT_TEST_CORE=$(OUTPUT)/$(PROJECT_NAME)-core-test
|
||||||
OUTPUT_APP_CORE=$(OUTPUT)/$(PROJECT_NAME)-core-app
|
OUTPUT_APP_CORE=$(OUTPUT)/$(PROJECT_NAME)-core-app
|
||||||
|
@ -30,6 +30,9 @@ extern "C" {
|
|||||||
#define WHY2_SUM_BASE_PRIME 31 //PRIME FOR SUM BASE
|
#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_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
|
//FUNCTIONS
|
||||||
unsigned long long why2_sum_segment(char *input); //CALCULATE SUM++ FOR input; USED FOR PADDING SEED
|
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
|
ssize_t why2_random(void *dest, size_t size); //WRITE CRYPTO-SECURE RANDOM NUMBER INTO dest
|
||||||
|
@ -30,6 +30,7 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
//CORE
|
//CORE
|
||||||
|
#include <why2/crypto.h>
|
||||||
#include <why2/decrypter.h>
|
#include <why2/decrypter.h>
|
||||||
#include <why2/encrypter.h>
|
#include <why2/encrypter.h>
|
||||||
#include <why2/flags.h>
|
#include <why2/flags.h>
|
||||||
|
@ -23,7 +23,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
|
||||||
|
#include <why2/crypto.h>
|
||||||
#include <why2/flags.h>
|
#include <why2/flags.h>
|
||||||
|
#include <why2/llist.h>
|
||||||
#include <why2/memory.h>
|
#include <why2/memory.h>
|
||||||
#include <why2/misc.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];
|
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
|
//GET FINISH TIME
|
||||||
gettimeofday(&finish_time, NULL);
|
gettimeofday(&finish_time, NULL);
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ why2_output_flags why2_encrypt_text(char *text, char *key)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//PADDING
|
//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
|
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
|
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
|
why2_random(&random_char, sizeof(random_char)); //GENERATE COMPLETELY RANDOM CHARACTER
|
||||||
|
}
|
||||||
|
if (random_char == 0) random_char = 1;
|
||||||
|
|
||||||
//INSERT RANDOM VALUE
|
//INSERT RANDOM VALUE
|
||||||
why2_list_push_at(&split_text, random_position, &random_char, sizeof(random_char));
|
why2_list_push_at(&split_text, random_position, &random_char, sizeof(random_char));
|
||||||
|
@ -46,7 +46,7 @@ int main(void)
|
|||||||
0, //UPDATE
|
0, //UPDATE
|
||||||
WHY2_v4, //LATEST VERSION
|
WHY2_v4, //LATEST VERSION
|
||||||
WHY2_OUTPUT_TEXT, //READABLE TEXT OUTPUT
|
WHY2_OUTPUT_TEXT, //READABLE TEXT OUTPUT
|
||||||
255 //PADDING RATE
|
WHY2_RECOMMENDED_PADDING_RATE(strlen(WHY2_TEST_TEXT)) //PADDING RATE
|
||||||
};
|
};
|
||||||
|
|
||||||
//SET FLAGS
|
//SET FLAGS
|
||||||
|
@ -34,7 +34,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|||||||
#include <why2/flags.h>
|
#include <why2/flags.h>
|
||||||
#include <why2/memory.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 multiply_cb(int a, int b) { return a * b; }
|
||||||
int subtract_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; }
|
int sum_cb(int a, int b) { return a + b; }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user