read and encode data with hardcoded key
This commit is contained in:
parent
f600a2d0c6
commit
9e9e697cdc
6 changed files with 41 additions and 10 deletions
3
Makefile
3
Makefile
|
@ -130,7 +130,8 @@ DES_SRC = ft_des_initial_permutation.c \
|
||||||
ft_des_init_ctx.c \
|
ft_des_init_ctx.c \
|
||||||
ft_des_print_error.c \
|
ft_des_print_error.c \
|
||||||
ft_des_arg_parsers.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 \
|
SRC = main.c \
|
||||||
ft_ssl_usage.c
|
ft_ssl_usage.c
|
||||||
|
|
|
@ -8,9 +8,26 @@ int ft_des_key_arg_parser
|
||||||
t_des_ctx *ctx
|
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;
|
(void)argv;
|
||||||
if (position + 1 >= argc)
|
if (position + 1 >= argc)
|
||||||
ft_des_print_error("there is no key after -k flag. type -h for help.");
|
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);
|
return (position + 2);
|
||||||
}
|
}
|
|
@ -49,6 +49,6 @@ void ft_des_ecb
|
||||||
|
|
||||||
ft_des_init_ctx(&ctx);
|
ft_des_init_ctx(&ctx);
|
||||||
parse_args(argc, argv, &ctx);
|
parse_args(argc, argv, &ctx);
|
||||||
// ft_des_ecb_process(&ctx);
|
ft_des_ecb_process(&ctx);
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
|
@ -6,11 +6,11 @@ void ft_des_ecb_process
|
||||||
t_des_ctx *ctx
|
t_des_ctx *ctx
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
// t_byte1 buffer[FT_DES_READ_SIZE];
|
t_byte1 buffer[FT_DES_READ_SIZE];
|
||||||
// t_byte8 readed;
|
t_byte8 readed;
|
||||||
|
|
||||||
ft_des_generate_encryption_round_keys(ctx->key, ctx->round_keys);
|
ft_des_generate_encryption_round_keys(ctx->key, ctx->round_keys);
|
||||||
// while((readed = read(ctx->input_fd, buffer, FT_DES_READ_SIZE)) > 0)
|
while((readed = read(ctx->input_fd, buffer, FT_DES_READ_SIZE)) > 0)
|
||||||
// ft_des_ecb_process_chunk(ctx, readed, buffer);
|
ft_des_ecb_process_chunk(ctx, readed, buffer);
|
||||||
// ft_des_ecb_finish_process(ctx);
|
// ft_des_ecb_finish_process(ctx);
|
||||||
}
|
}
|
|
@ -1,10 +1,22 @@
|
||||||
|
#include <unistd.h>
|
||||||
#include "ft_des.h"
|
#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
|
void ft_des_ecb_process_chunk
|
||||||
(
|
(
|
||||||
t_des_ctx *ctx,
|
t_des_ctx *ctx,
|
||||||
t_byte8 readed,
|
t_byte8 readed,
|
||||||
t_byte8 buffer[FT_DES_READ_SIZE]
|
t_byte1 buffer[FT_DES_READ_SIZE]
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
t_byte8 free_space_in_buffer;
|
t_byte8 free_space_in_buffer;
|
||||||
|
@ -17,11 +29,11 @@ void ft_des_ecb_process_chunk
|
||||||
if (readed >= free_space_in_buffer)
|
if (readed >= free_space_in_buffer)
|
||||||
{
|
{
|
||||||
ft_memcpy(&ctx->buffer[buffer_index], buffer, 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;
|
idx = free_space_in_buffer;
|
||||||
while(idx + FT_DES_BYTE_BLOCK_SIZE <= readed)
|
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;
|
idx += FT_DES_BYTE_BLOCK_SIZE;
|
||||||
}
|
}
|
||||||
buffer_index = 0;
|
buffer_index = 0;
|
||||||
|
|
1
t/cases/des_ecb_8_byte_text.txt
Normal file
1
t/cases/des_ecb_8_byte_text.txt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
foo bar
|
Loading…
Reference in a new issue