des initial permutation done
This commit is contained in:
parent
de73b25502
commit
941fde0be7
6 changed files with 124 additions and 4 deletions
18
Makefile
18
Makefile
|
@ -21,6 +21,7 @@ SRC_DIR := $(ROOT)/src/
|
|||
MD5_DIR := $(SRC_DIR)/md5/
|
||||
SHA_DIR := $(SRC_DIR)/sha/
|
||||
B64_DIR := $(SRC_DIR)/base64/
|
||||
DES_DIR := $(SRC_DIR)/des/
|
||||
OBJ_DIR := $(ROOT)/obj/
|
||||
INC_DIR := $(ROOT)/inc/
|
||||
LIB_DIR := $(ROOT)/lib/
|
||||
|
@ -32,10 +33,12 @@ MD5_HEADER := $(INC_DIR)/ft_md5.h
|
|||
SHA_HEADER := $(INC_DIR)/ft_sha.h
|
||||
SSL_HEADER := $(INC_DIR)/ft_ssl.h
|
||||
B64_HEADER := $(INC_DIR)/ft_base64.h
|
||||
DES_HEADER := $(INC_DIR)/ft_des.h
|
||||
HEADERS := $(MD5_HEADER) \
|
||||
$(SHA_HEADER) \
|
||||
$(SSL_HEADER) \
|
||||
$(B64_HEADER)
|
||||
$(B64_HEADER) \
|
||||
$(DES_HEADER)
|
||||
# libraries
|
||||
|
||||
LIBFT_DIR := $(LIB_DIR)libft/
|
||||
|
@ -99,12 +102,15 @@ BASE64_SRC = ft_base64.c \
|
|||
ft_base64_decode_transform.c \
|
||||
ft_base64_decode_finish.c
|
||||
|
||||
DES_SRC = ft_des_initial_permutation.c
|
||||
|
||||
SRC = main.c \
|
||||
ft_ssl_usage.c
|
||||
|
||||
SRC += $(MD5_SRC) \
|
||||
$(SHA_SRC) \
|
||||
$(BASE64_SRC)
|
||||
$(BASE64_SRC) \
|
||||
$(DES_SRC)
|
||||
# project object files
|
||||
|
||||
OBJ = $(addprefix $(OBJ_DIR), $(SRC:.c=.o))
|
||||
|
@ -123,10 +129,14 @@ SHA_TESTS += $(SHA_SRC)
|
|||
BASE64_TESTS = base64_tests.c
|
||||
BASE64_TESTS += $(BASE64_SRC)
|
||||
|
||||
DES_TESTS = des_tests.c
|
||||
DES_TESTS += $(DES_SRC)
|
||||
|
||||
TEST_SRC = tests.c
|
||||
TEST_SRC += $(MD5_TESTS) \
|
||||
$(SHA_TESTS) \
|
||||
$(BASE64_TESTS)
|
||||
$(BASE64_TESTS) \
|
||||
$(DES_TESTS)
|
||||
|
||||
TEST_OBJ = $(addprefix $(OBJ_DIR), $(TEST_SRC:.c=.o))
|
||||
|
||||
|
@ -207,7 +217,6 @@ re: fclean all
|
|||
|
||||
multi:
|
||||
$(MAKE) $(LIBFT)
|
||||
$(MAKE) check
|
||||
$(MAKE) $(NAME)
|
||||
|
||||
# special stuff
|
||||
|
@ -216,6 +225,7 @@ vpath %.c $(SRC_DIR) \
|
|||
$(MD5_DIR) \
|
||||
$(SHA_DIR) \
|
||||
$(B64_DIR) \
|
||||
$(DES_DIR) \
|
||||
$(TST_DIR)
|
||||
|
||||
.PHONY: all check clean fclean re multi
|
||||
|
|
26
inc/ft_des.h
Normal file
26
inc/ft_des.h
Normal file
|
@ -0,0 +1,26 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_des.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/01/19 17:58:39 by gtertysh #+# #+# */
|
||||
/* Updated: 2019/01/19 17:59:19 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef FT_DES_H
|
||||
# define FT_DES_H
|
||||
|
||||
# define FT_DES_BIT_BLOCK_SIZE 64
|
||||
|
||||
typedef unsigned char t_byte1;
|
||||
|
||||
void ft_des_initial_permutation
|
||||
(
|
||||
t_byte1 message[FT_DES_BIT_BLOCK_SIZE],
|
||||
t_byte1 initial_permutation[FT_DES_BIT_BLOCK_SIZE]
|
||||
);
|
||||
|
||||
#endif
|
|
@ -16,5 +16,6 @@
|
|||
int md5_tests(void);
|
||||
int sha_tests(void);
|
||||
int base64_tests(void);
|
||||
int des_tests(void);
|
||||
|
||||
#endif
|
||||
|
|
28
src/des/ft_des_initial_permutation.c
Normal file
28
src/des/ft_des_initial_permutation.c
Normal file
|
@ -0,0 +1,28 @@
|
|||
#include "ft_des.h"
|
||||
|
||||
void ft_des_initial_permutation
|
||||
(
|
||||
t_byte1 message[FT_DES_BIT_BLOCK_SIZE],
|
||||
t_byte1 initial_permutation[FT_DES_BIT_BLOCK_SIZE]
|
||||
)
|
||||
{
|
||||
static t_byte1 table[FT_DES_BIT_BLOCK_SIZE] = {
|
||||
58, 50, 42, 34, 26, 18, 10, 2,
|
||||
60, 52, 44, 36, 28, 20, 12, 4,
|
||||
62, 54, 46, 38, 30, 22, 14, 6,
|
||||
64, 56, 48, 40, 32, 24, 16, 8,
|
||||
57, 49, 41, 33, 25, 17, 9, 1,
|
||||
59, 51, 43, 35, 27, 19, 11, 3,
|
||||
61, 53, 45, 37, 29, 21, 13, 5,
|
||||
63, 55, 47, 39, 31, 23, 15, 7,
|
||||
};
|
||||
t_byte1 i;
|
||||
|
||||
i = 0;
|
||||
while(i < FT_DES_BIT_BLOCK_SIZE)
|
||||
{
|
||||
initial_permutation[i] = message[table[i] - 1];
|
||||
i++;
|
||||
}
|
||||
|
||||
}
|
54
t/des_tests.c
Normal file
54
t/des_tests.c
Normal file
|
@ -0,0 +1,54 @@
|
|||
#include "t.h"
|
||||
#include "tests.h"
|
||||
#include "ft_des.h"
|
||||
#include "libft.h"
|
||||
|
||||
int perform_initial_permutation()
|
||||
{
|
||||
// all 64 bits:
|
||||
// 00000001 00100011 01000101 01100111 10001001 10101011 11001101 11101111
|
||||
// block contains message bits in big-endian order
|
||||
t_byte1 message[FT_DES_BIT_BLOCK_SIZE] = (t_byte1 [FT_DES_BIT_BLOCK_SIZE]) {
|
||||
0, 0, 0, 0, 0, 0, 0, 1,
|
||||
0, 0, 1, 0, 0, 0, 1, 1,
|
||||
0, 1, 0, 0, 0, 1, 0, 1,
|
||||
0, 1, 1, 0, 0, 1, 1, 1,
|
||||
1, 0, 0, 0, 1, 0, 0, 1,
|
||||
1, 0, 1, 0, 1, 0, 1, 1,
|
||||
1, 1, 0, 0, 1, 1, 0, 1,
|
||||
1, 1, 1, 0, 1, 1, 1, 1,
|
||||
};
|
||||
|
||||
// all 64 bits after initial permutation:
|
||||
// 11001100 00000000 11001100 11111111 11110000 10101010 11110000 10101010
|
||||
t_byte1 expect[FT_DES_BIT_BLOCK_SIZE] = (t_byte1 [FT_DES_BIT_BLOCK_SIZE]) {
|
||||
1, 1, 0, 0, 1, 1, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
1, 1, 0, 0, 1, 1, 0, 0,
|
||||
1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 0, 0, 0, 0,
|
||||
1, 0, 1, 0, 1, 0, 1, 0,
|
||||
1, 1, 1, 1, 0, 0, 0, 0,
|
||||
1, 0, 1, 0, 1, 0, 1, 0,
|
||||
};
|
||||
|
||||
t_byte1 initial_permutation[FT_DES_BIT_BLOCK_SIZE];
|
||||
|
||||
ft_bzero(initial_permutation, FT_DES_BIT_BLOCK_SIZE);
|
||||
|
||||
ft_des_initial_permutation(message, initial_permutation);
|
||||
|
||||
int i = 0;
|
||||
while(i < FT_DES_BIT_BLOCK_SIZE)
|
||||
{
|
||||
_is(initial_permutation[i] == expect[i]);
|
||||
i++;
|
||||
}
|
||||
_end("perform initial permutation");
|
||||
}
|
||||
|
||||
int des_tests()
|
||||
{
|
||||
_should(perform_initial_permutation);
|
||||
return 0;
|
||||
}
|
|
@ -18,6 +18,7 @@ int all_tests()
|
|||
_verify("md5:", md5_tests);
|
||||
_verify("sha:", sha_tests);
|
||||
_verify("base64:", base64_tests);
|
||||
_verify("des:", des_tests);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue