diff --git a/Makefile b/Makefile index 1eb29e6a..65bc9e03 100644 --- a/Makefile +++ b/Makefile @@ -130,7 +130,8 @@ DES_SRC = ft_des_initial_permutation.c \ ft_des_init_ctx.c \ ft_des_print_error.c \ ft_des_arg_parsers.c \ - ft_des_ecb_process.c + ft_des_ecb_process.c \ + ft_des_ecb_process_chunk.c SRC = main.c \ ft_ssl_usage.c diff --git a/src/des/ft_des_arg_parsers.c b/src/des/ft_des_arg_parsers.c index aee1afb4..3d42f628 100644 --- a/src/des/ft_des_arg_parsers.c +++ b/src/des/ft_des_arg_parsers.c @@ -8,9 +8,26 @@ int ft_des_key_arg_parser t_des_ctx *ctx ) { - (void)ctx; + t_byte1 key[FT_DES_INITIAL_KEY_SIZE] = { + 0, 1, 1, 0, 0, 0, 0, 1, + 0, 1, 1, 0, 0, 0, 1, 0, + 0, 1, 1, 0, 0, 0, 1, 1, + 0, 1, 1, 0, 0, 1, 0, 0, + 0, 1, 1, 0, 0, 0, 0, 1, + 0, 1, 1, 0, 0, 0, 1, 0, + 0, 1, 1, 0, 0, 0, 1, 1, + 0, 1, 1, 0, 0, 1, 0, 0, + }; + int i; (void)argv; if (position + 1 >= argc) ft_des_print_error("there is no key after -k flag. type -h for help."); + + i = 0; + while (i < FT_DES_INITIAL_KEY_SIZE) + { + ctx->key[i] = key[i]; + i++; + } return (position + 2); } \ No newline at end of file diff --git a/src/des/ft_des_ecb.c b/src/des/ft_des_ecb.c index 36ef0648..88a37262 100644 --- a/src/des/ft_des_ecb.c +++ b/src/des/ft_des_ecb.c @@ -49,6 +49,6 @@ void ft_des_ecb ft_des_init_ctx(&ctx); parse_args(argc, argv, &ctx); - // ft_des_ecb_process(&ctx); + ft_des_ecb_process(&ctx); exit(0); } \ No newline at end of file diff --git a/src/des/ft_des_ecb_process.c b/src/des/ft_des_ecb_process.c index afc4e8fa..325dc81c 100644 --- a/src/des/ft_des_ecb_process.c +++ b/src/des/ft_des_ecb_process.c @@ -6,11 +6,11 @@ void ft_des_ecb_process t_des_ctx *ctx ) { - // t_byte1 buffer[FT_DES_READ_SIZE]; - // t_byte8 readed; + t_byte1 buffer[FT_DES_READ_SIZE]; + t_byte8 readed; ft_des_generate_encryption_round_keys(ctx->key, ctx->round_keys); - // while((readed = read(ctx->input_fd, buffer, FT_DES_READ_SIZE)) > 0) - // ft_des_ecb_process_chunk(ctx, readed, buffer); + while((readed = read(ctx->input_fd, buffer, FT_DES_READ_SIZE)) > 0) + ft_des_ecb_process_chunk(ctx, readed, buffer); // ft_des_ecb_finish_process(ctx); } \ No newline at end of file diff --git a/src/des/ft_des_ecb_process_chunk.c b/src/des/ft_des_ecb_process_chunk.c index 9b470f34..c87eac93 100644 --- a/src/des/ft_des_ecb_process_chunk.c +++ b/src/des/ft_des_ecb_process_chunk.c @@ -1,10 +1,22 @@ +#include #include "ft_des.h" +#include "libft.h" + +static void ft_des_ecb_write +( + t_des_ctx *ctx +) +{ + t_byte1 cyphertext[FT_DES_BYTE_BLOCK_SIZE]; + ft_des_process_block(ctx->buffer, ctx->round_keys, cyphertext); + write(ctx->output_fd, cyphertext, FT_DES_BYTE_BLOCK_SIZE); +} void ft_des_ecb_process_chunk ( t_des_ctx *ctx, t_byte8 readed, - t_byte8 buffer[FT_DES_READ_SIZE] + t_byte1 buffer[FT_DES_READ_SIZE] ) { t_byte8 free_space_in_buffer; @@ -17,11 +29,11 @@ void ft_des_ecb_process_chunk if (readed >= free_space_in_buffer) { ft_memcpy(&ctx->buffer[buffer_index], buffer, free_space_in_buffer); - ft_base64_encode_write(ctx, ctx->buffer); + ft_des_ecb_write(ctx); idx = free_space_in_buffer; while(idx + FT_DES_BYTE_BLOCK_SIZE <= readed) { - ft_base64_encode_write(ctx, &buffer[idx]); + ft_des_ecb_write(ctx); idx += FT_DES_BYTE_BLOCK_SIZE; } buffer_index = 0; diff --git a/t/cases/des_ecb_8_byte_text.txt b/t/cases/des_ecb_8_byte_text.txt new file mode 100644 index 00000000..d675fa44 --- /dev/null +++ b/t/cases/des_ecb_8_byte_text.txt @@ -0,0 +1 @@ +foo bar