norm formatting done
This commit is contained in:
parent
203532eff0
commit
2c3bd2fa7a
83 changed files with 1439 additions and 669 deletions
1
Makefile
1
Makefile
|
@ -140,6 +140,7 @@ DES_SRC = ft_des_initial_permutation.c \
|
|||
ft_des_generate_decryption_round_keys.c \
|
||||
ft_des_parse_args.c \
|
||||
ft_des_arg_parsers.c \
|
||||
ft_des_more_arg_parsers.c \
|
||||
ft_des_usage.c \
|
||||
ft_des.c \
|
||||
ft_des_ecb.c \
|
||||
|
|
|
@ -1,3 +1,14 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_pbkdf2.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/10 15:56:11 by gtertysh #+# #+# */
|
||||
/* Updated: 2019/04/10 15:56:16 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef FT_PBKDF2_H
|
||||
# define FT_PBKDF2_H
|
||||
|
@ -65,5 +76,4 @@ void ft_pbkdf2_sha256
|
|||
t_pbkdf2_sha256_ctx *ctx
|
||||
);
|
||||
|
||||
|
||||
#endif
|
10
inc/t.h
10
inc/t.h
|
@ -15,10 +15,10 @@
|
|||
# include <stdio.h>
|
||||
|
||||
# define FAIL() printf("\nfail in %s() %s:%d\n\n", __func__, __FILE__, __LINE__)
|
||||
# define _is(t) do { if (!(t)) { FAIL(); return 1; } } while(0)
|
||||
# define _should(t) do { int r = t(); if(r) return r; } while(0)
|
||||
# define _p_start(m) do { printf("%s\n", m); } while(0)
|
||||
# define _verify(m, t) do { _p_start(m); int r = t(); if(r) return r; } while(0)
|
||||
# define _end(m) do { printf(" %s - OK\n", m); return 0; } while(0)
|
||||
# define _IS(t) do { if (!(t)) { FAIL(); return 1; } } while(0)
|
||||
# define _SHOULD(t) do { int r = t(); if(r) return r; } while(0)
|
||||
# define _P_START(m) do { printf("%s\n", m); } while(0)
|
||||
# define _VERIFY(m, t) do { _P_START(m); int r = t(); if(r) return r; } while(0)
|
||||
# define _END(m) do { printf(" %s - OK\n", m); return 0; } while(0)
|
||||
|
||||
#endif
|
||||
|
|
2
obj/.gitignore
vendored
2
obj/.gitignore
vendored
|
@ -1,2 +0,0 @@
|
|||
./*
|
||||
!.gitignore
|
|
@ -1,3 +1,15 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_base64.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/10 16:05:46 by gtertysh #+# #+# */
|
||||
/* Updated: 2019/04/10 16:07:56 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/stat.h>
|
||||
|
@ -28,24 +40,20 @@ static int open_input(char *filename)
|
|||
ft_putstr_fd("base64: input path is not a file", STDERR_FILENO);
|
||||
exit(1);
|
||||
}
|
||||
return fd;
|
||||
return (fd);
|
||||
}
|
||||
|
||||
static int open_output(char *filename)
|
||||
{
|
||||
int fd;
|
||||
|
||||
if ((fd = open((const char *)filename,
|
||||
O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR)) == -1)
|
||||
{
|
||||
perror("base64: output stream error");
|
||||
exit(1);
|
||||
}
|
||||
return fd;
|
||||
}
|
||||
|
||||
static void init_flags(t_base64_flags *flags)
|
||||
{
|
||||
flags->decode = 0;
|
||||
return (fd);
|
||||
}
|
||||
|
||||
static void read_args
|
||||
|
@ -86,7 +94,7 @@ void ft_base64(int argc, char **argv)
|
|||
t_base64_flags flags;
|
||||
t_base64_ctx ctx;
|
||||
|
||||
init_flags(&flags);
|
||||
flags.decode = 0;
|
||||
ft_base64_init(&ctx);
|
||||
read_args(argc, argv, &flags, &ctx);
|
||||
if (flags.decode)
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_base64_decode.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/10 16:08:40 by gtertysh #+# #+# */
|
||||
/* Updated: 2019/04/10 16:09:10 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <unistd.h>
|
||||
#include "ft_base64.h"
|
||||
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_base64_decode_chunk.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/10 16:09:28 by gtertysh #+# #+# */
|
||||
/* Updated: 2019/04/10 16:09:50 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <unistd.h>
|
||||
#include "libft.h"
|
||||
#include "ft_base64.h"
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_base64_decode_filter.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/10 16:09:58 by gtertysh #+# #+# */
|
||||
/* Updated: 2019/04/10 16:10:14 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_base64.h"
|
||||
#include "libft.h"
|
||||
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_base64_decode_finish.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/10 16:10:18 by gtertysh #+# #+# */
|
||||
/* Updated: 2019/04/10 16:10:31 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <fcntl.h>
|
||||
#include "ft_base64.h"
|
||||
#include "libft.h"
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_base64_decode_transform.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/10 16:10:34 by gtertysh #+# #+# */
|
||||
/* Updated: 2019/04/10 16:11:02 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_base64.h"
|
||||
#include "libft.h"
|
||||
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_base64_encode_chunk.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/10 16:11:15 by gtertysh #+# #+# */
|
||||
/* Updated: 2019/04/10 16:11:28 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_base64.h"
|
||||
#include "libft.h"
|
||||
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_base64_encode_finish.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/10 16:11:30 by gtertysh #+# #+# */
|
||||
/* Updated: 2019/04/10 16:11:42 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_base64.h"
|
||||
#include "libft.h"
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/02/02 18:26:32 by gtertysh #+# #+# */
|
||||
/* Updated: 2019/02/02 18:26:51 by gtertysh ### ########.fr */
|
||||
/* Updated: 2019/04/10 16:12:05 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
@ -29,10 +29,8 @@ void ft_base64_encode_transform
|
|||
second_char = ((data[0] << 4) & 0x30) | ((data[1] >> 4) & 0xf);
|
||||
third_char = ((data[1] << 2) & 0x3c) | ((data[2] >> 6) & 0x3);
|
||||
fourth_char = data[2] & 0x3F;
|
||||
|
||||
chars[0] = ctx->alphabet[first_char];
|
||||
chars[1] = ctx->alphabet[second_char];
|
||||
chars[2] = ctx->alphabet[third_char];
|
||||
chars[3] = ctx->alphabet[fourth_char];
|
||||
|
||||
}
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_base64_init_decode_buffer.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/10 16:12:17 by gtertysh #+# #+# */
|
||||
/* Updated: 2019/04/10 16:12:33 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_base64.h"
|
||||
#include "libft.h"
|
||||
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_base64_init_encode_buffer.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/10 16:12:46 by gtertysh #+# #+# */
|
||||
/* Updated: 2019/04/10 16:12:48 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_base64.h"
|
||||
#include "libft.h"
|
||||
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_base64_write.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/10 16:12:56 by gtertysh #+# #+# */
|
||||
/* Updated: 2019/04/10 16:13:12 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_base64.h"
|
||||
#include <unistd.h>
|
||||
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_des.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/10 16:18:03 by gtertysh #+# #+# */
|
||||
/* Updated: 2019/04/10 16:18:15 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "ft_des.h"
|
||||
|
||||
|
|
|
@ -1,8 +1,15 @@
|
|||
#include <stddef.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_des_arg_parsers.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/10 16:18:18 by gtertysh #+# #+# */
|
||||
/* Updated: 2019/04/10 16:20:51 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_des.h"
|
||||
|
||||
int ft_des_base64_arg_parser
|
||||
|
@ -19,7 +26,6 @@ int ft_des_base64_arg_parser
|
|||
return (++position);
|
||||
}
|
||||
|
||||
|
||||
int ft_des_key_arg_parser
|
||||
(
|
||||
int argc,
|
||||
|
@ -34,7 +40,6 @@ int ft_des_key_arg_parser
|
|||
return (position + 2);
|
||||
}
|
||||
|
||||
|
||||
int ft_des_iv_arg_parser
|
||||
(
|
||||
int argc,
|
||||
|
@ -77,89 +82,3 @@ int ft_des_encode_arg_parser
|
|||
ctx->decode = 0;
|
||||
return (++position);
|
||||
}
|
||||
|
||||
int ft_des_input_file_arg_parser
|
||||
(
|
||||
int argc,
|
||||
char **argv,
|
||||
int position,
|
||||
t_des_ctx *ctx
|
||||
)
|
||||
{
|
||||
struct stat stat_buff;
|
||||
|
||||
if (position + 1 >= argc)
|
||||
ft_des_print_error("there is no filaname after -i flag.");
|
||||
if ((ctx->input_fd = open(argv[position + 1], O_RDONLY, 0)) == -1)
|
||||
{
|
||||
perror("des");
|
||||
exit(1);
|
||||
}
|
||||
stat(argv[position + 1], &stat_buff);
|
||||
if (S_ISDIR(stat_buff.st_mode))
|
||||
ft_des_print_error("input path is not a file.");
|
||||
return (position + 2);
|
||||
}
|
||||
|
||||
int ft_des_output_file_arg_parser
|
||||
(
|
||||
int argc,
|
||||
char **argv,
|
||||
int position,
|
||||
t_des_ctx *ctx
|
||||
)
|
||||
{
|
||||
if (position + 1 >= argc)
|
||||
ft_des_print_error("there is no filaname after -o flag.");
|
||||
if ((ctx->output_fd = open(
|
||||
argv[position + 1], O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR)) == -1)
|
||||
{
|
||||
perror("des");
|
||||
exit(1);
|
||||
}
|
||||
return (position + 2);
|
||||
}
|
||||
|
||||
int ft_des_password_arg_parser
|
||||
(
|
||||
int argc,
|
||||
char **argv,
|
||||
int position,
|
||||
t_des_ctx *ctx
|
||||
)
|
||||
{
|
||||
if (position + 1 >= argc)
|
||||
ft_des_print_error("there is no password after -p flag.");
|
||||
ctx->raw_password = argv[position + 1];
|
||||
return (position + 2);
|
||||
}
|
||||
|
||||
int ft_des_salt_arg_parser
|
||||
(
|
||||
int argc,
|
||||
char **argv,
|
||||
int position,
|
||||
t_des_ctx *ctx
|
||||
)
|
||||
{
|
||||
if (position + 1 >= argc)
|
||||
ft_des_print_error("there is no password after -p flag.");
|
||||
ctx->raw_salt = argv[position + 1];
|
||||
return (position + 2);
|
||||
}
|
||||
|
||||
int ft_des_help_arg_parser
|
||||
(
|
||||
int argc,
|
||||
char **argv,
|
||||
int position,
|
||||
t_des_ctx *ctx
|
||||
)
|
||||
{
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
(void)position;
|
||||
(void)ctx;
|
||||
ft_des_usage();
|
||||
return (position);
|
||||
}
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_des_bits_to_bytes.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/10 16:20:55 by gtertysh #+# #+# */
|
||||
/* Updated: 2019/04/10 16:21:03 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_des.h"
|
||||
|
||||
void ft_des_bits_to_bytes
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_des_buffered_read.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/10 16:21:20 by gtertysh #+# #+# */
|
||||
/* Updated: 2019/04/10 16:21:49 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <unistd.h>
|
||||
#include "ft_des.h"
|
||||
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_des_byte_to_bits.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/10 16:21:52 by gtertysh #+# #+# */
|
||||
/* Updated: 2019/04/10 16:22:09 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_des.h"
|
||||
|
||||
void ft_des_byte_to_bits
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_des_cbc.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/10 16:22:17 by gtertysh #+# #+# */
|
||||
/* Updated: 2019/04/10 16:23:17 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_des.h"
|
||||
|
||||
static void xor
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_des_decrypt.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/10 16:23:37 by gtertysh #+# #+# */
|
||||
/* Updated: 2019/04/10 16:23:58 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <unistd.h>
|
||||
#include "ft_des.h"
|
||||
#include "libft.h"
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_des_decrypt_b64.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/10 16:24:25 by gtertysh #+# #+# */
|
||||
/* Updated: 2019/04/10 16:24:56 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_des_decryption_key_routine.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/10 16:26:30 by gtertysh #+# #+# */
|
||||
/* Updated: 2019/04/10 16:27:41 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include "ft_des.h"
|
||||
|
@ -30,6 +42,7 @@ void ft_des_decryption_key_routine
|
|||
{
|
||||
char salt[FT_DES_BYTE_BLOCK_SIZE];
|
||||
char pass[128];
|
||||
|
||||
if (ctx->raw_password || !ctx->raw_key)
|
||||
get_salt(ctx, salt);
|
||||
if (!ctx->raw_key && !ctx->raw_password)
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_des_derive_decryption_round_key.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/10 16:28:02 by gtertysh #+# #+# */
|
||||
/* Updated: 2019/04/10 16:28:06 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_des.h"
|
||||
|
||||
void ft_des_derive_decryption_round_key
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_des_derive_encryption_round_key.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/10 16:28:18 by gtertysh #+# #+# */
|
||||
/* Updated: 2019/04/10 16:28:20 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_des.h"
|
||||
|
||||
void ft_des_derive_encryption_round_key
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_des_derive_key.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/10 16:29:33 by gtertysh #+# #+# */
|
||||
/* Updated: 2019/04/10 16:29:40 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_des.h"
|
||||
#include "ft_pbkdf2.h"
|
||||
#include "libft.h"
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_des_ecb.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/10 16:30:08 by gtertysh #+# #+# */
|
||||
/* Updated: 2019/04/10 16:30:27 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_des.h"
|
||||
|
||||
static void encrypt
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
#include "ft_des.h"
|
||||
|
||||
void ft_des_ecb_finish_decrypt
|
||||
(
|
||||
t_des_ctx *ctx,
|
||||
t_des_decrypt_buffer *buff
|
||||
)
|
||||
{
|
||||
t_byte1 idx;
|
||||
|
||||
idx = 0;
|
||||
ctx->readed += buff->readed[buff->current_buffer];
|
||||
if (ctx->readed % FT_DES_BYTE_BLOCK_SIZE != 0)
|
||||
ft_des_print_error("wrong message size, maybe corrupted?");
|
||||
while (idx + FT_DES_BYTE_BLOCK_SIZE <=)
|
||||
}
|
|
@ -1,3 +1,15 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_des_encode_process_chunk.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/10 16:32:07 by gtertysh #+# #+# */
|
||||
/* Updated: 2019/04/10 16:32:37 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <unistd.h>
|
||||
#include "ft_des.h"
|
||||
#include "libft.h"
|
||||
|
@ -9,6 +21,7 @@ static void ft_des_ecb_write
|
|||
)
|
||||
{
|
||||
t_byte1 cyphertext[FT_DES_BYTE_BLOCK_SIZE];
|
||||
|
||||
ctx->encrypt(buffer, ctx->round_keys, ctx->iv, cyphertext);
|
||||
write(ctx->output_fd, cyphertext, FT_DES_BYTE_BLOCK_SIZE);
|
||||
}
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_des_encrypt.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/10 16:33:05 by gtertysh #+# #+# */
|
||||
/* Updated: 2019/04/10 16:33:11 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <unistd.h>
|
||||
#include "ft_des.h"
|
||||
#include "ft_base64.h"
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_des_encrypt_b64.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/10 16:33:39 by gtertysh #+# #+# */
|
||||
/* Updated: 2019/04/10 16:34:06 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_des_encryption_key_routine.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/10 16:34:23 by gtertysh #+# #+# */
|
||||
/* Updated: 2019/04/10 16:34:35 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include "ft_des.h"
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_des_expansion_box.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/10 16:34:49 by gtertysh #+# #+# */
|
||||
/* Updated: 2019/04/10 16:38:05 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_des.h"
|
||||
|
||||
void ft_des_expansion_box
|
||||
|
@ -7,14 +19,9 @@ void ft_des_expansion_box
|
|||
)
|
||||
{
|
||||
static t_byte1 permutation_table[FT_DES_EXPANDED_HALF_BLOCK_SIZE] = {
|
||||
32, 1, 2, 3, 4, 5,
|
||||
4, 5, 6, 7, 8, 9,
|
||||
8, 9, 10, 11, 12, 13,
|
||||
12, 13, 14, 15, 16, 17,
|
||||
16, 17, 18, 19, 20, 21,
|
||||
20, 21, 22, 23, 24, 25,
|
||||
24, 25, 26, 27, 28, 29,
|
||||
28, 29, 30, 31, 32, 1,
|
||||
32, 1, 2, 3, 4, 5, 4, 5, 6, 7, 8, 9, 8, 9, 10, 11, 12, 13, 12, 13, 14, 15,
|
||||
16, 17, 16, 17, 18, 19, 20, 21, 20, 21, 22, 23, 24, 25, 24, 25, 26, 27, 28,
|
||||
29, 28, 29, 30, 31, 32, 1,
|
||||
};
|
||||
int i;
|
||||
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_des_feistel_function.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/10 16:38:27 by gtertysh #+# #+# */
|
||||
/* Updated: 2019/04/10 16:38:53 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_des.h"
|
||||
|
||||
static void merge_key
|
||||
|
@ -7,7 +19,9 @@ static void merge_key
|
|||
t_byte1 output[FT_DES_EXPANDED_HALF_BLOCK_SIZE]
|
||||
)
|
||||
{
|
||||
int i = 0;
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (i < FT_DES_EXPANDED_HALF_BLOCK_SIZE)
|
||||
{
|
||||
output[i] = expanded_half[i] ^ key[i];
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_des_feistel_function_permutation.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/10 16:39:02 by gtertysh #+# #+# */
|
||||
/* Updated: 2019/04/10 16:40:48 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_des.h"
|
||||
|
||||
void ft_des_feistel_function_permutation
|
||||
|
@ -7,10 +19,8 @@ void ft_des_feistel_function_permutation
|
|||
)
|
||||
{
|
||||
static t_byte1 table[FT_DES_BIT_BLOCK_SIZE / 2] = {
|
||||
16, 7, 20, 21, 29, 12, 28, 17,
|
||||
1, 15, 23, 26, 5, 18, 31, 10,
|
||||
2, 8, 24, 14, 32, 27, 3, 9,
|
||||
19, 13, 30, 6, 22, 11, 4, 25,
|
||||
16, 7, 20, 21, 29, 12, 28, 17, 1, 15, 23, 26, 5, 18, 31, 10, 2, 8, 24, 14,
|
||||
32, 27, 3, 9, 19, 13, 30, 6, 22, 11, 4, 25,
|
||||
};
|
||||
int i;
|
||||
|
||||
|
@ -20,5 +30,4 @@ void ft_des_feistel_function_permutation
|
|||
output[i] = input[table[i] - 1];
|
||||
i++;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,3 +1,15 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_des_final_permutation.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/10 16:41:16 by gtertysh #+# #+# */
|
||||
/* Updated: 2019/04/10 16:43:25 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_des.h"
|
||||
|
||||
void ft_des_final_permutation
|
||||
|
@ -7,14 +19,10 @@ void ft_des_final_permutation
|
|||
)
|
||||
{
|
||||
static t_byte1 table[FT_DES_BIT_BLOCK_SIZE] = {
|
||||
40, 8, 48, 16, 56, 24, 64, 32,
|
||||
39, 7, 47, 15, 55, 23, 63, 31,
|
||||
38, 6, 46, 14, 54, 22, 62, 30,
|
||||
37, 5, 45, 13, 53, 21, 61, 29,
|
||||
36, 4, 44, 12, 52, 20, 60, 28,
|
||||
35, 3, 43, 11, 51, 19, 59, 27,
|
||||
34, 2, 42, 10, 50, 18, 58, 26,
|
||||
33, 1, 41, 9, 49, 17, 57, 25,
|
||||
40, 8, 48, 16, 56, 24, 64, 32, 39, 7, 47, 15, 55, 23, 63, 31, 38, 6, 46,
|
||||
14, 54, 22, 62, 30, 37, 5, 45, 13, 53, 21, 61, 29, 36, 4, 44, 12, 52,
|
||||
20, 60, 28, 35, 3, 43, 11, 51, 19, 59, 27, 34, 2, 42, 10, 50, 18, 58,
|
||||
26, 33, 1, 41, 9, 49, 17, 57, 25,
|
||||
};
|
||||
t_byte1 i;
|
||||
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_des_finish_encrypt.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/10 16:43:34 by gtertysh #+# #+# */
|
||||
/* Updated: 2019/04/10 16:43:55 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_des.h"
|
||||
#include <unistd.h>
|
||||
|
||||
|
@ -12,7 +24,6 @@ void ft_des_finish_encrypt
|
|||
|
||||
buffer_index = ctx->readed % FT_DES_BYTE_BLOCK_SIZE;
|
||||
padding_size = FT_DES_BYTE_BLOCK_SIZE - buffer_index;
|
||||
|
||||
while (buffer_index < FT_DES_BYTE_BLOCK_SIZE)
|
||||
{
|
||||
ctx->buffer[buffer_index] = padding_size;
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_des_generate_decryption_round_keys.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/10 16:44:14 by gtertysh #+# #+# */
|
||||
/* Updated: 2019/04/10 16:44:22 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_des.h"
|
||||
|
||||
void ft_des_generate_decryption_round_keys
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_des_generate_encryption_round_keys.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/10 16:44:32 by gtertysh #+# #+# */
|
||||
/* Updated: 2019/04/10 16:44:40 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_des.h"
|
||||
|
||||
void ft_des_generate_encryption_round_keys
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_des_get_password.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/10 16:44:55 by gtertysh #+# #+# */
|
||||
/* Updated: 2019/04/10 16:45:07 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_des.h"
|
||||
#include "libft.h"
|
||||
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_des_hex_to_bit.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/10 16:45:24 by gtertysh #+# #+# */
|
||||
/* Updated: 2019/04/10 16:45:33 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_des.h"
|
||||
#include "libft.h"
|
||||
|
||||
|
@ -10,6 +22,7 @@ const char *ft_des_hex_to_bit
|
|||
{
|
||||
t_byte1 bits4;
|
||||
t_byte8 i;
|
||||
|
||||
i = 0;
|
||||
while (*hex && i < bit_len)
|
||||
{
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_des_hex_to_byte.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/10 16:45:44 by gtertysh #+# #+# */
|
||||
/* Updated: 2019/04/10 16:45:51 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_des.h"
|
||||
#include "libft.h"
|
||||
|
||||
|
@ -29,6 +41,7 @@ const char *ft_des_hex_to_byte
|
|||
t_byte1 first_byte_half;
|
||||
t_byte1 second_byte_half;
|
||||
t_byte8 i;
|
||||
|
||||
i = 0;
|
||||
while (*hex && i < byte_len)
|
||||
{
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_des_init_ctx.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/10 16:46:08 by gtertysh #+# #+# */
|
||||
/* Updated: 2019/04/10 16:46:12 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <unistd.h>
|
||||
#include "ft_des.h"
|
||||
#include "libft.h"
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
#include "ft_des.h"
|
||||
|
||||
void ft_des_init_flags
|
||||
(
|
||||
t_des_flags *flags
|
||||
)
|
||||
{
|
||||
flags->decode = 0;
|
||||
flags->output_in_base64 = 0;
|
||||
}
|
|
@ -1,3 +1,15 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_des_initial_permutation.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/10 16:47:22 by gtertysh #+# #+# */
|
||||
/* Updated: 2019/04/10 16:48:36 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_des.h"
|
||||
|
||||
void ft_des_initial_permutation
|
||||
|
@ -7,14 +19,10 @@ void ft_des_initial_permutation
|
|||
)
|
||||
{
|
||||
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,
|
||||
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;
|
||||
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_des_key_permuted_choice_one.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/10 16:48:53 by gtertysh #+# #+# */
|
||||
/* Updated: 2019/04/10 16:50:03 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_des.h"
|
||||
|
||||
void ft_des_key_permuted_choice_one
|
||||
|
@ -7,13 +19,9 @@ void ft_des_key_permuted_choice_one
|
|||
)
|
||||
{
|
||||
static t_byte1 table[FT_DES_REDUCED_KEY_SIZE] = {
|
||||
57, 49, 41, 33, 25, 17, 9, 1,
|
||||
58, 50, 42, 34, 26, 18, 10, 2,
|
||||
59, 51, 43, 35, 27, 19, 11, 3,
|
||||
60, 52, 44, 36, 63, 55, 47, 39,
|
||||
31, 23, 15, 7, 62, 54, 46, 38,
|
||||
30, 22, 14, 6, 61, 53, 45, 37,
|
||||
29, 21, 13, 5, 28, 20, 12, 4,
|
||||
57, 49, 41, 33, 25, 17, 9, 1, 58, 50, 42, 34, 26, 18, 10, 2, 59, 51, 43,
|
||||
35, 27, 19, 11, 3, 60, 52, 44, 36, 63, 55, 47, 39, 31, 23, 15, 7, 62,
|
||||
54, 46, 38, 30, 22, 14, 6, 61, 53, 45, 37, 29, 21, 13, 5, 28, 20, 12, 4,
|
||||
};
|
||||
int i;
|
||||
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_des_key_permuted_choice_two.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/10 16:50:17 by gtertysh #+# #+# */
|
||||
/* Updated: 2019/04/10 16:51:15 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_des.h"
|
||||
|
||||
void ft_des_key_permuted_choice_two
|
||||
|
@ -7,12 +19,9 @@ void ft_des_key_permuted_choice_two
|
|||
)
|
||||
{
|
||||
static t_byte1 table[FT_DES_ROUND_KEY_SIZE] = {
|
||||
14, 17, 11, 24, 1, 5, 3, 28,
|
||||
15, 6, 21, 10, 23, 19, 12, 4,
|
||||
26, 8, 16, 7, 27, 20, 13, 2,
|
||||
41, 52, 31, 37, 47, 55, 30, 40,
|
||||
51, 45, 33, 48, 44, 49, 39, 56,
|
||||
34, 53, 46, 42, 50, 36, 29, 32,
|
||||
14, 17, 11, 24, 1, 5, 3, 28, 15, 6, 21, 10, 23, 19, 12, 4, 26, 8, 16,
|
||||
7, 27, 20, 13, 2, 41, 52, 31, 37, 47, 55, 30, 40, 51, 45, 33, 48, 44,
|
||||
49, 39, 56, 34, 53, 46, 42, 50, 36, 29, 32,
|
||||
};
|
||||
int i;
|
||||
|
||||
|
|
104
src/des/ft_des_more_arg_parsers.c
Normal file
104
src/des/ft_des_more_arg_parsers.c
Normal file
|
@ -0,0 +1,104 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_des_more_arg_parsers.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/10 17:17:08 by gtertysh #+# #+# */
|
||||
/* Updated: 2019/04/10 17:17:09 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stddef.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
#include "ft_des.h"
|
||||
|
||||
int ft_des_input_file_arg_parser
|
||||
(
|
||||
int argc,
|
||||
char **argv,
|
||||
int position,
|
||||
t_des_ctx *ctx
|
||||
)
|
||||
{
|
||||
struct stat stat_buff;
|
||||
|
||||
if (position + 1 >= argc)
|
||||
ft_des_print_error("there is no filaname after -i flag.");
|
||||
if ((ctx->input_fd = open(argv[position + 1], O_RDONLY, 0)) == -1)
|
||||
{
|
||||
perror("des");
|
||||
exit(1);
|
||||
}
|
||||
stat(argv[position + 1], &stat_buff);
|
||||
if (S_ISDIR(stat_buff.st_mode))
|
||||
ft_des_print_error("input path is not a file.");
|
||||
return (position + 2);
|
||||
}
|
||||
|
||||
int ft_des_output_file_arg_parser
|
||||
(
|
||||
int argc,
|
||||
char **argv,
|
||||
int position,
|
||||
t_des_ctx *ctx
|
||||
)
|
||||
{
|
||||
if (position + 1 >= argc)
|
||||
ft_des_print_error("there is no filaname after -o flag.");
|
||||
if ((ctx->output_fd = open(
|
||||
argv[position + 1], O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR)) == -1)
|
||||
{
|
||||
perror("des");
|
||||
exit(1);
|
||||
}
|
||||
return (position + 2);
|
||||
}
|
||||
|
||||
int ft_des_password_arg_parser
|
||||
(
|
||||
int argc,
|
||||
char **argv,
|
||||
int position,
|
||||
t_des_ctx *ctx
|
||||
)
|
||||
{
|
||||
if (position + 1 >= argc)
|
||||
ft_des_print_error("there is no password after -p flag.");
|
||||
ctx->raw_password = argv[position + 1];
|
||||
return (position + 2);
|
||||
}
|
||||
|
||||
int ft_des_salt_arg_parser
|
||||
(
|
||||
int argc,
|
||||
char **argv,
|
||||
int position,
|
||||
t_des_ctx *ctx
|
||||
)
|
||||
{
|
||||
if (position + 1 >= argc)
|
||||
ft_des_print_error("there is no password after -p flag.");
|
||||
ctx->raw_salt = argv[position + 1];
|
||||
return (position + 2);
|
||||
}
|
||||
|
||||
int ft_des_help_arg_parser
|
||||
(
|
||||
int argc,
|
||||
char **argv,
|
||||
int position,
|
||||
t_des_ctx *ctx
|
||||
)
|
||||
{
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
(void)position;
|
||||
(void)ctx;
|
||||
ft_des_usage();
|
||||
return (position);
|
||||
}
|
|
@ -1,3 +1,15 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_des_parse_args.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/10 16:52:24 by gtertysh #+# #+# */
|
||||
/* Updated: 2019/04/10 16:53:19 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stddef.h>
|
||||
#include "ft_des.h"
|
||||
#include "libft.h"
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_des_pcbc.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/10 16:53:37 by gtertysh #+# #+# */
|
||||
/* Updated: 2019/04/10 16:54:07 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_des.h"
|
||||
|
||||
static void xor
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_des_print_error.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/10 16:54:22 by gtertysh #+# #+# */
|
||||
/* Updated: 2019/04/10 16:54:25 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <unistd.h>
|
||||
#include "ft_des.h"
|
||||
#include "libft.h"
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_des_process_block.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/10 16:54:39 by gtertysh #+# #+# */
|
||||
/* Updated: 2019/04/10 16:55:29 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_des.h"
|
||||
|
||||
static void switch_halves
|
||||
|
@ -7,6 +19,7 @@ static void switch_halves
|
|||
{
|
||||
int i;
|
||||
int tmp;
|
||||
|
||||
i = 0;
|
||||
while (i < FT_DES_BIT_BLOCK_SIZE / 2)
|
||||
{
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_des_rotate_half_key_left.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/10 16:56:02 by gtertysh #+# #+# */
|
||||
/* Updated: 2019/04/10 16:56:11 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_des.h"
|
||||
|
||||
void ft_des_rotate_half_key_left
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_des_rotate_half_key_right.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/10 16:56:19 by gtertysh #+# #+# */
|
||||
/* Updated: 2019/04/10 16:56:25 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_des.h"
|
||||
|
||||
void ft_des_rotate_half_key_right
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_des_round.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/10 17:13:31 by gtertysh #+# #+# */
|
||||
/* Updated: 2019/04/10 17:13:43 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_des.h"
|
||||
|
||||
static void xor
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_des_s_box.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/10 16:56:47 by gtertysh #+# #+# */
|
||||
/* Updated: 2019/04/10 16:56:51 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_des.h"
|
||||
|
||||
void ft_des_s_box
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_des_s_box_1.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/10 16:57:05 by gtertysh #+# #+# */
|
||||
/* Updated: 2019/04/10 16:59:02 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_des.h"
|
||||
|
||||
void ft_des_s_box_1
|
||||
|
@ -12,5 +24,6 @@ void ft_des_s_box_1
|
|||
{ 4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0 },
|
||||
{ 15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13 }
|
||||
};
|
||||
|
||||
ft_des_s_box(input, output, tbl);
|
||||
}
|
|
@ -1,3 +1,15 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_des_s_box_2.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/10 16:59:10 by gtertysh #+# #+# */
|
||||
/* Updated: 2019/04/10 17:00:36 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_des.h"
|
||||
|
||||
void ft_des_s_box_2
|
||||
|
@ -12,5 +24,6 @@ void ft_des_s_box_2
|
|||
{ 0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15 },
|
||||
{ 13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9 },
|
||||
};
|
||||
|
||||
ft_des_s_box(input, output, tbl);
|
||||
}
|
|
@ -1,3 +1,15 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_des_s_box_3.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/10 17:03:07 by gtertysh #+# #+# */
|
||||
/* Updated: 2019/04/10 17:04:25 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_des.h"
|
||||
|
||||
void ft_des_s_box_3
|
||||
|
@ -12,5 +24,6 @@ void ft_des_s_box_3
|
|||
{ 13, 6, 4, 9, 8, 15, 3, 0, 11, 1, 2, 12, 5, 10, 14, 7 },
|
||||
{ 1, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12 },
|
||||
};
|
||||
|
||||
ft_des_s_box(input, output, tbl);
|
||||
}
|
|
@ -1,3 +1,15 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_des_s_box_4.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/10 17:05:47 by gtertysh #+# #+# */
|
||||
/* Updated: 2019/04/10 17:05:48 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_des.h"
|
||||
|
||||
void ft_des_s_box_4
|
||||
|
@ -12,5 +24,6 @@ void ft_des_s_box_4
|
|||
{ 10, 6, 9, 0, 12, 11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4 },
|
||||
{ 3, 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14 },
|
||||
};
|
||||
|
||||
ft_des_s_box(input, output, tbl);
|
||||
}
|
|
@ -1,3 +1,15 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_des_s_box_5.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/10 17:05:56 by gtertysh #+# #+# */
|
||||
/* Updated: 2019/04/10 17:07:19 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_des.h"
|
||||
|
||||
void ft_des_s_box_5
|
||||
|
@ -12,5 +24,6 @@ void ft_des_s_box_5
|
|||
{ 4, 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14 },
|
||||
{ 11, 8, 12, 7, 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3 },
|
||||
};
|
||||
|
||||
ft_des_s_box(input, output, tbl);
|
||||
}
|
|
@ -1,3 +1,15 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_des_s_box_6.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/10 17:07:23 by gtertysh #+# #+# */
|
||||
/* Updated: 2019/04/10 17:08:34 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_des.h"
|
||||
|
||||
void ft_des_s_box_6
|
||||
|
@ -12,5 +24,6 @@ void ft_des_s_box_6
|
|||
{ 9, 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6 },
|
||||
{ 4, 3, 2, 12, 9, 5, 15, 10, 11, 14, 1, 7, 6, 0, 8, 13 },
|
||||
};
|
||||
|
||||
ft_des_s_box(input, output, tbl);
|
||||
}
|
|
@ -1,3 +1,15 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_des_s_box_7.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/10 17:08:42 by gtertysh #+# #+# */
|
||||
/* Updated: 2019/04/10 17:10:08 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_des.h"
|
||||
|
||||
void ft_des_s_box_7
|
||||
|
@ -12,5 +24,6 @@ void ft_des_s_box_7
|
|||
{ 1, 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2 },
|
||||
{ 6, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12 },
|
||||
};
|
||||
|
||||
ft_des_s_box(input, output, tbl);
|
||||
}
|
|
@ -1,3 +1,15 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_des_s_box_8.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/10 17:10:15 by gtertysh #+# #+# */
|
||||
/* Updated: 2019/04/10 17:11:30 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_des.h"
|
||||
|
||||
void ft_des_s_box_8
|
||||
|
@ -9,8 +21,9 @@ void ft_des_s_box_8
|
|||
static t_byte1 tbl[FT_DES_S_BOX_TABLE_ROWS][FT_DES_S_BOX_TABLE_COLUMNS] = {
|
||||
{ 13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7 },
|
||||
{ 1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2 },
|
||||
{ 7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 03, 5, 8},
|
||||
{ 7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8 },
|
||||
{ 2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11 },
|
||||
};
|
||||
|
||||
ft_des_s_box(input, output, tbl);
|
||||
}
|
|
@ -1,3 +1,15 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_des_set_raw_iv.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/10 17:12:17 by gtertysh #+# #+# */
|
||||
/* Updated: 2019/04/10 17:12:19 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_des.h"
|
||||
|
||||
void ft_des_set_raw_iv
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_des_set_raw_key.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/10 17:12:01 by gtertysh #+# #+# */
|
||||
/* Updated: 2019/04/10 17:12:06 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_des.h"
|
||||
|
||||
void ft_des_set_raw_key
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_des_switch_message_halves.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/10 17:12:41 by gtertysh #+# #+# */
|
||||
/* Updated: 2019/04/10 17:12:47 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_des.h"
|
||||
|
||||
void ft_des_switch_message_halves
|
||||
|
@ -7,8 +19,8 @@ void ft_des_switch_message_halves
|
|||
{
|
||||
int i;
|
||||
int tmp;
|
||||
i = 0;
|
||||
|
||||
i = 0;
|
||||
while (i < FT_DES_BIT_BLOCK_SIZE / 2)
|
||||
{
|
||||
tmp = message[i];
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_des_usage.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/10 17:13:04 by gtertysh #+# #+# */
|
||||
/* Updated: 2019/04/10 17:13:05 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_des_usage
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_hmac_sha256.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/10 16:14:22 by gtertysh #+# #+# */
|
||||
/* Updated: 2019/04/10 16:15:06 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_pbkdf2.h"
|
||||
#include "libft.h"
|
||||
#include "ft_sha.h"
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_hmac_sha256_init_ctx.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/10 16:15:12 by gtertysh #+# #+# */
|
||||
/* Updated: 2019/04/10 16:15:33 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stddef.h>
|
||||
#include "ft_pbkdf2.h"
|
||||
#include "ft_sha.h"
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_pbkdf2_sha256.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/10 16:15:38 by gtertysh #+# #+# */
|
||||
/* Updated: 2019/04/10 16:17:16 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_pbkdf2.h"
|
||||
#include "ft_sha.h"
|
||||
#include "libft.h"
|
||||
|
@ -37,7 +49,7 @@ static int ceil
|
|||
unsigned int y
|
||||
)
|
||||
{
|
||||
return 1 + ((x - 1) / y);
|
||||
return (1 + ((x - 1) / y));
|
||||
}
|
||||
|
||||
static void block_function
|
||||
|
@ -47,7 +59,6 @@ static void block_function
|
|||
unsigned int iteration,
|
||||
unsigned char block[FT_SHA256_DIGEST_LENGTH_BYTE]
|
||||
)
|
||||
|
||||
{
|
||||
unsigned int i;
|
||||
unsigned char c[4];
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_pbkdf2_sha256_init_ctx.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/10 16:17:30 by gtertysh #+# #+# */
|
||||
/* Updated: 2019/04/10 16:17:37 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stddef.h>
|
||||
#include "ft_pbkdf2.h"
|
||||
|
||||
|
|
|
@ -12,12 +12,12 @@ abcdefghijklmnopqrstuvwxyz0123456789+/";
|
|||
|
||||
ft_base64_init(&ctx);
|
||||
|
||||
_is(ctx.input_fd == STDIN_FILENO);
|
||||
_is(ctx.output_fd == STDOUT_FILENO);
|
||||
_IS(ctx.input_fd == STDIN_FILENO);
|
||||
_IS(ctx.output_fd == STDOUT_FILENO);
|
||||
|
||||
_is(ft_strcmp(alphabet, (char *)ctx.alphabet) == 0);
|
||||
_IS(ft_strcmp(alphabet, (char *)ctx.alphabet) == 0);
|
||||
|
||||
_end("init ctx");
|
||||
_END("init ctx");
|
||||
}
|
||||
|
||||
static int transform_block()
|
||||
|
@ -28,17 +28,17 @@ static int transform_block()
|
|||
ft_base64_init(&ctx);
|
||||
|
||||
ft_base64_encode_transform(&ctx, (t_byte1 *)"Man", buff);
|
||||
_is(ft_strncmp((char *)buff, "TWFu", 4) == 0);
|
||||
_IS(ft_strncmp((char *)buff, "TWFu", 4) == 0);
|
||||
|
||||
ft_base64_encode_transform(&ctx, (t_byte1 *)"LOL", buff);
|
||||
_is(ft_strncmp((char *)buff, "TE9M", 4) == 0);
|
||||
_IS(ft_strncmp((char *)buff, "TE9M", 4) == 0);
|
||||
|
||||
_end("transform block");
|
||||
_END("transform block");
|
||||
}
|
||||
|
||||
int base64_tests(void)
|
||||
{
|
||||
_should(init_ctx);
|
||||
_should(transform_block);
|
||||
_SHOULD(init_ctx);
|
||||
_SHOULD(transform_block);
|
||||
return 0;
|
||||
}
|
188
t/des_tests.c
188
t/des_tests.c
|
@ -44,10 +44,10 @@ int perform_initial_permutation()
|
|||
int i = 0;
|
||||
while(i < FT_DES_BIT_BLOCK_SIZE)
|
||||
{
|
||||
_is(initial_permutation[i] == expect[i]);
|
||||
_IS(initial_permutation[i] == expect[i]);
|
||||
i++;
|
||||
}
|
||||
_end("perform initial permutation");
|
||||
_END("perform initial permutation");
|
||||
}
|
||||
|
||||
int perform_final_permutation()
|
||||
|
@ -89,13 +89,13 @@ int perform_final_permutation()
|
|||
int i = 0;
|
||||
while(i < FT_DES_BIT_BLOCK_SIZE)
|
||||
{
|
||||
_is(final_permutation[i] == expect[i]);
|
||||
_IS(final_permutation[i] == expect[i]);
|
||||
i++;
|
||||
}
|
||||
_end("perform final permutation");
|
||||
_END("perform final permutation");
|
||||
}
|
||||
|
||||
int final_permutation_is_reverse_of_initial()
|
||||
int final_permutation_IS_reverse_of_initial()
|
||||
{
|
||||
t_byte1 message[FT_DES_BIT_BLOCK_SIZE] = {
|
||||
1, 0, 1, 0, 1, 0, 1, 0,
|
||||
|
@ -119,10 +119,10 @@ int final_permutation_is_reverse_of_initial()
|
|||
int i = 0;
|
||||
while(i < FT_DES_BIT_BLOCK_SIZE)
|
||||
{
|
||||
_is(final_permutation[i] == message[i]);
|
||||
_IS(final_permutation[i] == message[i]);
|
||||
i++;
|
||||
}
|
||||
_end("final permutation is reverse of initial");
|
||||
_END("final permutation is reverse of initial");
|
||||
}
|
||||
|
||||
int perform_expansion_in_feistel_function()
|
||||
|
@ -156,10 +156,10 @@ int perform_expansion_in_feistel_function()
|
|||
int i = 0;
|
||||
while(i < FT_DES_EXPANDED_HALF_BLOCK_SIZE)
|
||||
{
|
||||
_is(expanded_half_actual[i] == expanded_half_expected[i]);
|
||||
_IS(expanded_half_actual[i] == expanded_half_expected[i]);
|
||||
i++;
|
||||
}
|
||||
_end("perform expansion in feistel function");
|
||||
_END("perform expansion in feistel function");
|
||||
}
|
||||
|
||||
static int s_box_check
|
||||
|
@ -201,7 +201,7 @@ int s_boxes_confuse()
|
|||
{0, 1, 1, 1},
|
||||
};
|
||||
|
||||
_is(s_box_check(s1_inputs, s1_expected, ft_des_s_box_1));
|
||||
_IS(s_box_check(s1_inputs, s1_expected, ft_des_s_box_1));
|
||||
|
||||
t_byte1 s2_inputs[S_BOX_CASES_NUMBER][FT_DES_S_BOX_INPUT_SIZE] = {
|
||||
{0, 0, 0, 0, 0, 0},
|
||||
|
@ -215,7 +215,7 @@ int s_boxes_confuse()
|
|||
{0, 1, 0, 1},
|
||||
};
|
||||
|
||||
_is(s_box_check(s2_inputs, s2_expected, ft_des_s_box_2));
|
||||
_IS(s_box_check(s2_inputs, s2_expected, ft_des_s_box_2));
|
||||
|
||||
t_byte1 s3_inputs[S_BOX_CASES_NUMBER][FT_DES_S_BOX_INPUT_SIZE] = {
|
||||
{0, 0, 0, 0, 0, 0},
|
||||
|
@ -229,7 +229,7 @@ int s_boxes_confuse()
|
|||
{1, 0, 1, 1},
|
||||
};
|
||||
|
||||
_is(s_box_check(s3_inputs, s3_expected, ft_des_s_box_3));
|
||||
_IS(s_box_check(s3_inputs, s3_expected, ft_des_s_box_3));
|
||||
|
||||
t_byte1 s4_inputs[S_BOX_CASES_NUMBER][FT_DES_S_BOX_INPUT_SIZE] = {
|
||||
{0, 0, 0, 0, 0, 0},
|
||||
|
@ -243,7 +243,7 @@ int s_boxes_confuse()
|
|||
{1, 1, 1, 1},
|
||||
};
|
||||
|
||||
_is(s_box_check(s4_inputs, s4_expected, ft_des_s_box_4));
|
||||
_IS(s_box_check(s4_inputs, s4_expected, ft_des_s_box_4));
|
||||
|
||||
t_byte1 s5_inputs[S_BOX_CASES_NUMBER][FT_DES_S_BOX_INPUT_SIZE] = {
|
||||
{0, 0, 0, 0, 0, 0},
|
||||
|
@ -257,7 +257,7 @@ int s_boxes_confuse()
|
|||
{0, 0, 1, 1},
|
||||
};
|
||||
|
||||
_is(s_box_check(s5_inputs, s5_expected, ft_des_s_box_5));
|
||||
_IS(s_box_check(s5_inputs, s5_expected, ft_des_s_box_5));
|
||||
|
||||
t_byte1 s6_inputs[S_BOX_CASES_NUMBER][FT_DES_S_BOX_INPUT_SIZE] = {
|
||||
{0, 0, 0, 0, 0, 0},
|
||||
|
@ -271,7 +271,7 @@ int s_boxes_confuse()
|
|||
{1, 1, 0, 1},
|
||||
};
|
||||
|
||||
_is(s_box_check(s6_inputs, s6_expected, ft_des_s_box_6));
|
||||
_IS(s_box_check(s6_inputs, s6_expected, ft_des_s_box_6));
|
||||
|
||||
t_byte1 s7_inputs[S_BOX_CASES_NUMBER][FT_DES_S_BOX_INPUT_SIZE] = {
|
||||
{0, 0, 0, 0, 0, 0},
|
||||
|
@ -285,7 +285,7 @@ int s_boxes_confuse()
|
|||
{1, 1, 0, 0},
|
||||
};
|
||||
|
||||
_is(s_box_check(s7_inputs, s7_expected, ft_des_s_box_7));
|
||||
_IS(s_box_check(s7_inputs, s7_expected, ft_des_s_box_7));
|
||||
|
||||
t_byte1 s8_inputs[S_BOX_CASES_NUMBER][FT_DES_S_BOX_INPUT_SIZE] = {
|
||||
{0, 0, 0, 0, 0, 0},
|
||||
|
@ -299,9 +299,9 @@ int s_boxes_confuse()
|
|||
{1, 0, 1, 1},
|
||||
};
|
||||
|
||||
_is(s_box_check(s8_inputs, s8_expected, ft_des_s_box_8));
|
||||
_IS(s_box_check(s8_inputs, s8_expected, ft_des_s_box_8));
|
||||
|
||||
_end("s boxes confuse");
|
||||
_END("s boxes confuse");
|
||||
}
|
||||
|
||||
int perform_premutation_in_feistel_function()
|
||||
|
@ -327,10 +327,10 @@ int perform_premutation_in_feistel_function()
|
|||
int i = 0;
|
||||
while(i < FT_DES_BIT_BLOCK_SIZE / 2)
|
||||
{
|
||||
_is(actual[i] == expected[i]);
|
||||
_IS(actual[i] == expected[i]);
|
||||
i++;
|
||||
}
|
||||
_end("should perform permutation in feistel function");
|
||||
_END("should perform permutation in feistel function");
|
||||
}
|
||||
|
||||
int perform_feistel_function()
|
||||
|
@ -373,10 +373,10 @@ int perform_feistel_function()
|
|||
int i = 0;
|
||||
while(i < FT_DES_BIT_BLOCK_SIZE / 2)
|
||||
{
|
||||
_is(output[i] == expected[i]);
|
||||
_IS(output[i] == expected[i]);
|
||||
i++;
|
||||
}
|
||||
_end("feistel function should encode half of a block");
|
||||
_END("feistel function should encode half of a block");
|
||||
}
|
||||
|
||||
int reduce_key_to_56_bits()
|
||||
|
@ -409,11 +409,11 @@ int reduce_key_to_56_bits()
|
|||
int i = 0;
|
||||
while(i < FT_DES_REDUCED_KEY_SIZE)
|
||||
{
|
||||
_is(actual_reduced[i] == expected_reduced_key[i]);
|
||||
_IS(actual_reduced[i] == expected_reduced_key[i]);
|
||||
i++;
|
||||
}
|
||||
|
||||
_end("should reduce key size to 56 bits");
|
||||
_END("should reduce key size to 56 bits");
|
||||
}
|
||||
|
||||
int rotate_half_key()
|
||||
|
@ -442,10 +442,10 @@ int rotate_half_key()
|
|||
|
||||
while(i < FT_DES_REDUCED_KEY_SIZE / 2)
|
||||
{
|
||||
_is(half_key[i] == expected[i]);
|
||||
_IS(half_key[i] == expected[i]);
|
||||
i++;
|
||||
}
|
||||
_end("should rotate half of reduced key");
|
||||
_END("should rotate half of reduced key");
|
||||
}
|
||||
|
||||
int derive_round_key()
|
||||
|
@ -492,17 +492,17 @@ int derive_round_key()
|
|||
i = 0;
|
||||
while(i < FT_DES_REDUCED_KEY_SIZE)
|
||||
{
|
||||
_is(shifted_reduced_key[i] == reduced_key[i]);
|
||||
_IS(shifted_reduced_key[i] == reduced_key[i]);
|
||||
i++;
|
||||
}
|
||||
|
||||
i = 0;
|
||||
while(i < FT_DES_ROUND_KEY_SIZE)
|
||||
{
|
||||
_is(round_key[i] == expected_round_key[i]);
|
||||
_IS(round_key[i] == expected_round_key[i]);
|
||||
i++;
|
||||
}
|
||||
_end("should derive round key");
|
||||
_END("should derive round key");
|
||||
}
|
||||
|
||||
int perform_encryption_round()
|
||||
|
@ -550,10 +550,10 @@ int perform_encryption_round()
|
|||
int i = 0;
|
||||
while(i < FT_DES_BIT_BLOCK_SIZE)
|
||||
{
|
||||
_is(initial_permuatation[i] == expected_message[i]);
|
||||
_IS(initial_permuatation[i] == expected_message[i]);
|
||||
i++;
|
||||
}
|
||||
_end("should perform encryption round");
|
||||
_END("should perform encryption round");
|
||||
}
|
||||
|
||||
int encrypt_block()
|
||||
|
@ -583,10 +583,10 @@ int encrypt_block()
|
|||
int i = 0;
|
||||
while(i < FT_DES_BYTE_BLOCK_SIZE)
|
||||
{
|
||||
_is(cyphertext[i] == expected_cypertext[i]);
|
||||
_IS(cyphertext[i] == expected_cypertext[i]);
|
||||
i++;
|
||||
}
|
||||
_end("should encrypt block");
|
||||
_END("should encrypt block");
|
||||
}
|
||||
|
||||
int decrypt_block()
|
||||
|
@ -616,10 +616,10 @@ int decrypt_block()
|
|||
int i = 0;
|
||||
while(i < FT_DES_BYTE_BLOCK_SIZE)
|
||||
{
|
||||
_is(plaintext[i] == expected_plaintext[i]);
|
||||
_IS(plaintext[i] == expected_plaintext[i]);
|
||||
i++;
|
||||
}
|
||||
_end("should decrypt block");
|
||||
_END("should decrypt block");
|
||||
}
|
||||
|
||||
int init_ctx()
|
||||
|
@ -632,7 +632,7 @@ int init_ctx()
|
|||
i = 0;
|
||||
while(i < FT_DES_BIT_BLOCK_SIZE)
|
||||
{
|
||||
_is(ctx.key[i] == 0);
|
||||
_IS(ctx.key[i] == 0);
|
||||
i++;
|
||||
}
|
||||
|
||||
|
@ -642,7 +642,7 @@ int init_ctx()
|
|||
j = 0;
|
||||
while(j < FT_DES_ROUND_KEY_SIZE)
|
||||
{
|
||||
_is(ctx.round_keys[i][j] == 0);
|
||||
_IS(ctx.round_keys[i][j] == 0);
|
||||
j++;
|
||||
}
|
||||
i++;
|
||||
|
@ -650,27 +650,27 @@ int init_ctx()
|
|||
i = 0;
|
||||
while(i < FT_DES_BYTE_BLOCK_SIZE)
|
||||
{
|
||||
_is(ctx.buffer[i] == 0);
|
||||
_IS(ctx.buffer[i] == 0);
|
||||
i++;
|
||||
}
|
||||
i = 0;
|
||||
while(i < FT_DES_BIT_BLOCK_SIZE)
|
||||
{
|
||||
_is(ctx.iv[i] == 0);
|
||||
_IS(ctx.iv[i] == 0);
|
||||
i++;
|
||||
}
|
||||
_is(ctx.readed == 0);
|
||||
_is(ctx.input_fd == STDIN_FILENO);
|
||||
_is(ctx.output_fd == STDOUT_FILENO);
|
||||
_is(ctx.decode == 0);
|
||||
_is(ctx.b64 == 0);
|
||||
_is(ctx.raw_password == NULL);
|
||||
_is(ctx.raw_key == NULL);
|
||||
_is(ctx.raw_salt == NULL);
|
||||
_is(ctx.raw_iv == NULL);
|
||||
_is(ctx.encrypt == NULL);
|
||||
_is(ctx.decrypt == NULL);
|
||||
_end("shoud init ctx");
|
||||
_IS(ctx.readed == 0);
|
||||
_IS(ctx.input_fd == STDIN_FILENO);
|
||||
_IS(ctx.output_fd == STDOUT_FILENO);
|
||||
_IS(ctx.decode == 0);
|
||||
_IS(ctx.b64 == 0);
|
||||
_IS(ctx.raw_password == NULL);
|
||||
_IS(ctx.raw_key == NULL);
|
||||
_IS(ctx.raw_salt == NULL);
|
||||
_IS(ctx.raw_iv == NULL);
|
||||
_IS(ctx.encrypt == NULL);
|
||||
_IS(ctx.decrypt == NULL);
|
||||
_END("shoud init ctx");
|
||||
}
|
||||
|
||||
int convert_hex_string_to_bits()
|
||||
|
@ -691,26 +691,26 @@ int convert_hex_string_to_bits()
|
|||
|
||||
wrong_key_char = ft_des_hex_to_bit("FFFFFFFFFFFFFFFF", actual_key,
|
||||
FT_DES_INITIAL_KEY_SIZE);
|
||||
_is(wrong_key_char == NULL);
|
||||
_IS(wrong_key_char == NULL);
|
||||
|
||||
i = 0;
|
||||
while(i < FT_DES_INITIAL_KEY_SIZE)
|
||||
{
|
||||
_is(expected_key[i] == actual_key[i]);
|
||||
_IS(expected_key[i] == actual_key[i]);
|
||||
i++;
|
||||
}
|
||||
|
||||
wrong_key_char = ft_des_hex_to_bit("ffffffffffffffff", actual_key,
|
||||
FT_DES_INITIAL_KEY_SIZE);
|
||||
_is(wrong_key_char == NULL);
|
||||
_IS(wrong_key_char == NULL);
|
||||
|
||||
i = 0;
|
||||
while(i < FT_DES_INITIAL_KEY_SIZE)
|
||||
{
|
||||
_is(expected_key[i] == actual_key[i]);
|
||||
_IS(expected_key[i] == actual_key[i]);
|
||||
i++;
|
||||
}
|
||||
_end("should convert hex string to 64 bit key");
|
||||
_END("should convert hex string to 64 bit key");
|
||||
}
|
||||
|
||||
int convert_short_hex_string_to_bits()
|
||||
|
@ -731,15 +731,15 @@ int convert_short_hex_string_to_bits()
|
|||
ft_bzero(actual_key, FT_DES_INITIAL_KEY_SIZE);
|
||||
wrong_key_char = ft_des_hex_to_bit("FF12CD", actual_key,
|
||||
FT_DES_INITIAL_KEY_SIZE);
|
||||
_is(wrong_key_char == NULL);
|
||||
_IS(wrong_key_char == NULL);
|
||||
|
||||
i = 0;
|
||||
while(i < FT_DES_INITIAL_KEY_SIZE)
|
||||
{
|
||||
_is(expected_key[i] == actual_key[i]);
|
||||
_IS(expected_key[i] == actual_key[i]);
|
||||
i++;
|
||||
}
|
||||
_end("should convert shorter hex string to 64 bit key");
|
||||
_END("should convert shorter hex string to 64 bit key");
|
||||
}
|
||||
|
||||
int convert_longer_hex_string_to_bits()
|
||||
|
@ -761,15 +761,15 @@ int convert_longer_hex_string_to_bits()
|
|||
ft_bzero(actual_key, FT_DES_INITIAL_KEY_SIZE);
|
||||
wrong_key_char = ft_des_hex_to_bit("FF12CDFF12CDFF12CD", actual_key,
|
||||
FT_DES_INITIAL_KEY_SIZE);
|
||||
_is(wrong_key_char == NULL);
|
||||
_IS(wrong_key_char == NULL);
|
||||
|
||||
i = 0;
|
||||
while(i < FT_DES_INITIAL_KEY_SIZE)
|
||||
{
|
||||
_is(expected_key[i] == actual_key[i]);
|
||||
_IS(expected_key[i] == actual_key[i]);
|
||||
i++;
|
||||
}
|
||||
_end("should convert longer hex string to 64 bit key");
|
||||
_END("should convert longer hex string to 64 bit key");
|
||||
}
|
||||
|
||||
int convert_hex_string_to_bytes()
|
||||
|
@ -784,15 +784,15 @@ int convert_hex_string_to_bytes()
|
|||
ft_bzero(actual, FT_DES_BYTE_BLOCK_SIZE);
|
||||
wrong_char = ft_des_hex_to_byte("FFFFFFFFFFFFFFFF", actual,
|
||||
FT_DES_BYTE_BLOCK_SIZE);
|
||||
_is(wrong_char == NULL);
|
||||
_IS(wrong_char == NULL);
|
||||
|
||||
i = 0;
|
||||
while(i < FT_DES_BYTE_BLOCK_SIZE)
|
||||
{
|
||||
_is(expected[i] == actual[i]);
|
||||
_IS(expected[i] == actual[i]);
|
||||
i++;
|
||||
}
|
||||
_end("should convert hex to 8 byte");
|
||||
_END("should convert hex to 8 byte");
|
||||
}
|
||||
|
||||
int convert_short_hex_string_to_bytes()
|
||||
|
@ -807,15 +807,15 @@ int convert_short_hex_string_to_bytes()
|
|||
ft_bzero(actual, FT_DES_BYTE_BLOCK_SIZE);
|
||||
wrong_char = ft_des_hex_to_byte("CC565", actual,
|
||||
FT_DES_BYTE_BLOCK_SIZE);
|
||||
_is(wrong_char == NULL);
|
||||
_IS(wrong_char == NULL);
|
||||
|
||||
i = 0;
|
||||
while(i < FT_DES_BYTE_BLOCK_SIZE)
|
||||
{
|
||||
_is(expected[i] == actual[i]);
|
||||
_IS(expected[i] == actual[i]);
|
||||
i++;
|
||||
}
|
||||
_end("should convert short hex string to 8 bytes");
|
||||
_END("should convert short hex string to 8 bytes");
|
||||
}
|
||||
|
||||
int convert_bytes_to_bits()
|
||||
|
@ -844,10 +844,10 @@ int convert_bytes_to_bits()
|
|||
i = 0;
|
||||
while(i < FT_DES_BIT_BLOCK_SIZE)
|
||||
{
|
||||
_is(expected[i] == actual[i]);
|
||||
_IS(expected[i] == actual[i]);
|
||||
i++;
|
||||
}
|
||||
_end("should convert 8 bytes to 64 bits");
|
||||
_END("should convert 8 bytes to 64 bits");
|
||||
}
|
||||
|
||||
int convert_bits_to_bytes()
|
||||
|
@ -875,7 +875,7 @@ int convert_bits_to_bytes()
|
|||
i = 0;
|
||||
while(i < FT_DES_BYTE_BLOCK_SIZE)
|
||||
{
|
||||
_is(expected[i] == actual[i]);
|
||||
_IS(expected[i] == actual[i]);
|
||||
i++;
|
||||
}
|
||||
t_byte1 bits1[FT_DES_BIT_BLOCK_SIZE] = {
|
||||
|
@ -896,34 +896,34 @@ int convert_bits_to_bytes()
|
|||
i = 0;
|
||||
while(i < FT_DES_BYTE_BLOCK_SIZE)
|
||||
{
|
||||
_is(expected1[i] == actual[i]);
|
||||
_IS(expected1[i] == actual[i]);
|
||||
i++;
|
||||
}
|
||||
_end("should convert 64 bits to 8 bytes");
|
||||
_END("should convert 64 bits to 8 bytes");
|
||||
}
|
||||
|
||||
int des_tests()
|
||||
{
|
||||
_should(perform_initial_permutation);
|
||||
_should(perform_final_permutation);
|
||||
_should(final_permutation_is_reverse_of_initial);
|
||||
_should(perform_expansion_in_feistel_function);
|
||||
_should(s_boxes_confuse);
|
||||
_should(perform_premutation_in_feistel_function);
|
||||
_should(perform_feistel_function);
|
||||
_should(reduce_key_to_56_bits);
|
||||
_should(rotate_half_key);
|
||||
_should(derive_round_key);
|
||||
_should(perform_encryption_round);
|
||||
_should(encrypt_block);
|
||||
_should(decrypt_block);
|
||||
_should(init_ctx);
|
||||
_should(convert_hex_string_to_bits);
|
||||
_should(convert_short_hex_string_to_bits);
|
||||
_should(convert_longer_hex_string_to_bits);
|
||||
_should(convert_hex_string_to_bytes);
|
||||
_should(convert_short_hex_string_to_bytes);
|
||||
_should(convert_bytes_to_bits);
|
||||
_should(convert_bits_to_bytes);
|
||||
_SHOULD(perform_initial_permutation);
|
||||
_SHOULD(perform_final_permutation);
|
||||
_SHOULD(final_permutation_IS_reverse_of_initial);
|
||||
_SHOULD(perform_expansion_in_feistel_function);
|
||||
_SHOULD(s_boxes_confuse);
|
||||
_SHOULD(perform_premutation_in_feistel_function);
|
||||
_SHOULD(perform_feistel_function);
|
||||
_SHOULD(reduce_key_to_56_bits);
|
||||
_SHOULD(rotate_half_key);
|
||||
_SHOULD(derive_round_key);
|
||||
_SHOULD(perform_encryption_round);
|
||||
_SHOULD(encrypt_block);
|
||||
_SHOULD(decrypt_block);
|
||||
_SHOULD(init_ctx);
|
||||
_SHOULD(convert_hex_string_to_bits);
|
||||
_SHOULD(convert_short_hex_string_to_bits);
|
||||
_SHOULD(convert_longer_hex_string_to_bits);
|
||||
_SHOULD(convert_hex_string_to_bytes);
|
||||
_SHOULD(convert_short_hex_string_to_bytes);
|
||||
_SHOULD(convert_bytes_to_bits);
|
||||
_SHOULD(convert_bits_to_bytes);
|
||||
return 0;
|
||||
}
|
|
@ -20,15 +20,15 @@ static int init_ctx()
|
|||
|
||||
ft_md5_init(&ctx);
|
||||
|
||||
_is(ctx.a == 0x67452301);
|
||||
_is(ctx.b == 0xefcdab89);
|
||||
_is(ctx.c == 0x98badcfe);
|
||||
_is(ctx.d == 0x10325476);
|
||||
_is(ctx.bit_len == 0);
|
||||
_IS(ctx.a == 0x67452301);
|
||||
_IS(ctx.b == 0xefcdab89);
|
||||
_IS(ctx.c == 0x98badcfe);
|
||||
_IS(ctx.d == 0x10325476);
|
||||
_IS(ctx.bit_len == 0);
|
||||
for (int i = 0; i < FT_MD5_BLOCK_SIZE; i++)
|
||||
_is(ctx.block[i] == 0);
|
||||
_IS(ctx.block[i] == 0);
|
||||
|
||||
_end("init ctx");
|
||||
_END("init ctx");
|
||||
}
|
||||
|
||||
static int decode_string_to_int()
|
||||
|
@ -43,11 +43,11 @@ static int decode_string_to_int()
|
|||
|
||||
ft_md5_decode(words, block);
|
||||
|
||||
_is((words[0] & 0xff) == 97);
|
||||
_is(((words[2] >> 8) & 0xff) == 98);
|
||||
_is(((words[15] >> 24) & 0xff) == 99);
|
||||
_IS((words[0] & 0xff) == 97);
|
||||
_IS(((words[2] >> 8) & 0xff) == 98);
|
||||
_IS(((words[15] >> 24) & 0xff) == 99);
|
||||
|
||||
_end("decode string to int");
|
||||
_END("decode string to int");
|
||||
}
|
||||
|
||||
static int update_change_count()
|
||||
|
@ -59,9 +59,9 @@ static int update_change_count()
|
|||
ft_md5_init(&ctx);
|
||||
ft_md5_update(&ctx, (t_byte1 *)message, size);
|
||||
|
||||
_is(size * 8 == ctx.bit_len);
|
||||
_IS(size * 8 == ctx.bit_len);
|
||||
|
||||
_end("update change count");
|
||||
_END("update change count");
|
||||
}
|
||||
|
||||
static int encode_bits_to_string()
|
||||
|
@ -83,11 +83,11 @@ static int encode_bits_to_string()
|
|||
|
||||
ft_md5_encode_len(bits, len);
|
||||
|
||||
_is(bits[7] == (t_byte1)((len >> 56) & 0xff));
|
||||
_is(bits[0] == (t_byte1)(len & 0xff));
|
||||
_is(bits[1] == (t_byte1)((len >> 8) & 0xff));
|
||||
_IS(bits[7] == (t_byte1)((len >> 56) & 0xff));
|
||||
_IS(bits[0] == (t_byte1)(len & 0xff));
|
||||
_IS(bits[1] == (t_byte1)((len >> 8) & 0xff));
|
||||
|
||||
_end("encode bits to string");
|
||||
_END("encode bits to string");
|
||||
}
|
||||
|
||||
static int encode_register()
|
||||
|
@ -105,12 +105,12 @@ static int encode_register()
|
|||
|
||||
ft_md5_encode_register(digest_part, reg);
|
||||
|
||||
_is(digest_part[0] == (t_byte1)(reg & 0xff));
|
||||
_is(digest_part[1] == (t_byte1)((reg >> 8) & 0xff));
|
||||
_is(digest_part[2] == (t_byte1)((reg >> 16) & 0xff));
|
||||
_is(digest_part[3] == (t_byte1)((reg >> 24) & 0xff));
|
||||
_IS(digest_part[0] == (t_byte1)(reg & 0xff));
|
||||
_IS(digest_part[1] == (t_byte1)((reg >> 8) & 0xff));
|
||||
_IS(digest_part[2] == (t_byte1)((reg >> 16) & 0xff));
|
||||
_IS(digest_part[3] == (t_byte1)((reg >> 24) & 0xff));
|
||||
|
||||
_end("encode register");
|
||||
_END("encode register");
|
||||
}
|
||||
|
||||
static int create_digest()
|
||||
|
@ -129,7 +129,7 @@ static int create_digest()
|
|||
ft_md5_final(digest, &ctx);
|
||||
ft_md5_digest_string(digest, digest_string);
|
||||
|
||||
_is(ft_strcmp((const char *)digest_string,
|
||||
_IS(ft_strcmp((const char *)digest_string,
|
||||
"d41d8cd98f00b204e9800998ecf8427e") == 0);
|
||||
|
||||
ft_md5_init(&ctx);
|
||||
|
@ -137,7 +137,7 @@ static int create_digest()
|
|||
ft_md5_final(digest, &ctx);
|
||||
ft_md5_digest_string(digest, digest_string);
|
||||
|
||||
_is(ft_strcmp((const char *)digest_string,
|
||||
_IS(ft_strcmp((const char *)digest_string,
|
||||
"0cc175b9c0f1b6a831c399e269772661") == 0);
|
||||
|
||||
ft_md5_init(&ctx);
|
||||
|
@ -145,10 +145,10 @@ static int create_digest()
|
|||
ft_md5_final(digest, &ctx);
|
||||
ft_md5_digest_string(digest, digest_string);
|
||||
|
||||
_is(ft_strcmp((const char *)digest_string,
|
||||
_IS(ft_strcmp((const char *)digest_string,
|
||||
"2580a0aff7ef5e80f6b5432666530926") == 0);
|
||||
|
||||
_end("create digest");
|
||||
_END("create digest");
|
||||
}
|
||||
|
||||
static int create_digest_string()
|
||||
|
@ -173,20 +173,20 @@ static int create_digest_string()
|
|||
|
||||
ft_md5_digest_string(digest, digest_string);
|
||||
|
||||
_is(ft_strcmp((const char *)digest_string,
|
||||
_IS(ft_strcmp((const char *)digest_string,
|
||||
"d41d8cd98f00b204e9800998ecf8427e") == 0);
|
||||
|
||||
_end("create digest string");
|
||||
_END("create digest string");
|
||||
}
|
||||
|
||||
int md5_tests()
|
||||
{
|
||||
_should(init_ctx);
|
||||
_should(decode_string_to_int);
|
||||
_should(update_change_count);
|
||||
_should(encode_bits_to_string);
|
||||
_should(encode_register);
|
||||
_should(create_digest);
|
||||
_should(create_digest_string);
|
||||
_SHOULD(init_ctx);
|
||||
_SHOULD(decode_string_to_int);
|
||||
_SHOULD(update_change_count);
|
||||
_SHOULD(encode_bits_to_string);
|
||||
_SHOULD(encode_register);
|
||||
_SHOULD(create_digest);
|
||||
_SHOULD(create_digest_string);
|
||||
return 0;
|
||||
}
|
|
@ -10,18 +10,18 @@ static int init_hmac_sha256_ctx()
|
|||
t_hmac_sha256_ctx ctx;
|
||||
|
||||
ft_hmac_sha256_init_ctx(&ctx);
|
||||
_is(ctx.key == NULL);
|
||||
_is(ctx.msg == NULL);
|
||||
_is(ctx.key_size == 0);
|
||||
_is(ctx.msg_size == 0);
|
||||
_IS(ctx.key == NULL);
|
||||
_IS(ctx.msg == NULL);
|
||||
_IS(ctx.key_size == 0);
|
||||
_IS(ctx.msg_size == 0);
|
||||
int i = 0;
|
||||
while(i < FT_SHA256_BLOCK_SIZE)
|
||||
{
|
||||
_is(ctx.opad[i] == 0);
|
||||
_is(ctx.ipad[i] == 0);
|
||||
_IS(ctx.opad[i] == 0);
|
||||
_IS(ctx.ipad[i] == 0);
|
||||
i++;
|
||||
}
|
||||
_end("init hmac sha256 ctx");
|
||||
_END("init hmac sha256 ctx");
|
||||
}
|
||||
|
||||
static int perform_hmac_256_computation_short_key()
|
||||
|
@ -53,10 +53,10 @@ static int perform_hmac_256_computation_short_key()
|
|||
int i = 0;
|
||||
while(i < FT_SHA256_DIGEST_LENGTH_BYTE)
|
||||
{
|
||||
_is(out[i] == expected_result[i]);
|
||||
_IS(out[i] == expected_result[i]);
|
||||
i++;
|
||||
}
|
||||
_end("perform hamc sha256 computation with short key");
|
||||
_END("perform hamc sha256 computation with short key");
|
||||
}
|
||||
|
||||
static int perform_hmac_256_computation_long_key()
|
||||
|
@ -120,10 +120,10 @@ static int perform_hmac_256_computation_long_key()
|
|||
int i = 0;
|
||||
while(i < FT_SHA256_DIGEST_LENGTH_BYTE)
|
||||
{
|
||||
_is(out[i] == expected_result[i]);
|
||||
_IS(out[i] == expected_result[i]);
|
||||
i++;
|
||||
}
|
||||
_end("perform hamc sha256 computation with long key");
|
||||
_END("perform hamc sha256 computation with long key");
|
||||
}
|
||||
|
||||
int init_pbkdf2_sha256_ctx()
|
||||
|
@ -132,15 +132,15 @@ int init_pbkdf2_sha256_ctx()
|
|||
|
||||
ft_pbkdf2_sha256_init_ctx(&ctx);
|
||||
|
||||
_is(ctx.iterations == 0);
|
||||
_is(ctx.key_len == 0);
|
||||
_is(ctx.salt_len == 0);
|
||||
_is(ctx.pass_len == 0);
|
||||
_is(ctx.salt == NULL);
|
||||
_is(ctx.key == NULL);
|
||||
_is(ctx.pass == NULL);
|
||||
_IS(ctx.iterations == 0);
|
||||
_IS(ctx.key_len == 0);
|
||||
_IS(ctx.salt_len == 0);
|
||||
_IS(ctx.pass_len == 0);
|
||||
_IS(ctx.salt == NULL);
|
||||
_IS(ctx.key == NULL);
|
||||
_IS(ctx.pass == NULL);
|
||||
|
||||
_end("init pbkdf2 sha256 ctx");
|
||||
_END("init pbkdf2 sha256 ctx");
|
||||
}
|
||||
|
||||
int perform_pbkdf2_sha256()
|
||||
|
@ -171,7 +171,7 @@ int perform_pbkdf2_sha256()
|
|||
i = 0;
|
||||
while(i < 32)
|
||||
{
|
||||
_is(ctx.key[i] == expected1[i]);
|
||||
_IS(ctx.key[i] == expected1[i]);
|
||||
i++;
|
||||
}
|
||||
|
||||
|
@ -195,7 +195,7 @@ int perform_pbkdf2_sha256()
|
|||
i = 0;
|
||||
while(i < 32)
|
||||
{
|
||||
_is(ctx.key[i] == expected2[i]);
|
||||
_IS(ctx.key[i] == expected2[i]);
|
||||
i++;
|
||||
}
|
||||
|
||||
|
@ -219,7 +219,7 @@ int perform_pbkdf2_sha256()
|
|||
i = 0;
|
||||
while(i < 32)
|
||||
{
|
||||
_is(ctx.key[i] == expected3[i]);
|
||||
_IS(ctx.key[i] == expected3[i]);
|
||||
i++;
|
||||
}
|
||||
|
||||
|
@ -247,10 +247,10 @@ int perform_pbkdf2_sha256()
|
|||
i = 0;
|
||||
while(i < 40)
|
||||
{
|
||||
_is(ctx.key[i] == expected4[i]);
|
||||
_IS(ctx.key[i] == expected4[i]);
|
||||
i++;
|
||||
}
|
||||
_end("perform pbkdf2 sha256");
|
||||
_END("perform pbkdf2 sha256");
|
||||
}
|
||||
|
||||
int copy_openssl_pbkdf2()
|
||||
|
@ -290,19 +290,19 @@ int copy_openssl_pbkdf2()
|
|||
i = 0;
|
||||
while(i < 8)
|
||||
{
|
||||
_is(my_key[i] == orig_key[i]);
|
||||
_IS(my_key[i] == orig_key[i]);
|
||||
i++;
|
||||
}
|
||||
_end("copy openssl pbkdf2");
|
||||
_END("copy openssl pbkdf2");
|
||||
}
|
||||
|
||||
int pbkdf2_tests()
|
||||
{
|
||||
_should(init_hmac_sha256_ctx);
|
||||
_should(perform_hmac_256_computation_short_key);
|
||||
_should(perform_hmac_256_computation_long_key);
|
||||
_should(init_pbkdf2_sha256_ctx);
|
||||
_should(perform_pbkdf2_sha256);
|
||||
_should(copy_openssl_pbkdf2);
|
||||
_SHOULD(init_hmac_sha256_ctx);
|
||||
_SHOULD(perform_hmac_256_computation_short_key);
|
||||
_SHOULD(perform_hmac_256_computation_long_key);
|
||||
_SHOULD(init_pbkdf2_sha256_ctx);
|
||||
_SHOULD(perform_pbkdf2_sha256);
|
||||
_SHOULD(copy_openssl_pbkdf2);
|
||||
return 0;
|
||||
}
|
144
t/sha_tests.c
144
t/sha_tests.c
|
@ -20,19 +20,19 @@ static int init_sha256_ctx()
|
|||
|
||||
ft_sha256_init(&ctx);
|
||||
|
||||
_is(ctx.a == 0x6a09e667);
|
||||
_is(ctx.b == 0xbb67ae85);
|
||||
_is(ctx.c == 0x3c6ef372);
|
||||
_is(ctx.d == 0xa54ff53a);
|
||||
_is(ctx.e == 0x510e527f);
|
||||
_is(ctx.f == 0x9b05688c);
|
||||
_is(ctx.g == 0x1f83d9ab);
|
||||
_is(ctx.h == 0x5be0cd19);
|
||||
_is(ctx.bit_len == 0);
|
||||
_IS(ctx.a == 0x6a09e667);
|
||||
_IS(ctx.b == 0xbb67ae85);
|
||||
_IS(ctx.c == 0x3c6ef372);
|
||||
_IS(ctx.d == 0xa54ff53a);
|
||||
_IS(ctx.e == 0x510e527f);
|
||||
_IS(ctx.f == 0x9b05688c);
|
||||
_IS(ctx.g == 0x1f83d9ab);
|
||||
_IS(ctx.h == 0x5be0cd19);
|
||||
_IS(ctx.bit_len == 0);
|
||||
for (int i = 0; i < 64; i++)
|
||||
_is(ctx.block[i] == 0);
|
||||
_IS(ctx.block[i] == 0);
|
||||
|
||||
_end("init sha256 ctx");
|
||||
_END("init sha256 ctx");
|
||||
}
|
||||
|
||||
static int init_sha224_ctx()
|
||||
|
@ -41,19 +41,19 @@ static int init_sha224_ctx()
|
|||
|
||||
ft_sha224_init(&ctx);
|
||||
|
||||
_is(ctx.a == 0xc1059ed8);
|
||||
_is(ctx.b == 0x367cd507);
|
||||
_is(ctx.c == 0x3070dd17);
|
||||
_is(ctx.d == 0xf70e5939);
|
||||
_is(ctx.e == 0xffc00b31);
|
||||
_is(ctx.f == 0x68581511);
|
||||
_is(ctx.g == 0x64f98fa7);
|
||||
_is(ctx.h == 0xbefa4fa4);
|
||||
_is(ctx.bit_len == 0);
|
||||
_IS(ctx.a == 0xc1059ed8);
|
||||
_IS(ctx.b == 0x367cd507);
|
||||
_IS(ctx.c == 0x3070dd17);
|
||||
_IS(ctx.d == 0xf70e5939);
|
||||
_IS(ctx.e == 0xffc00b31);
|
||||
_IS(ctx.f == 0x68581511);
|
||||
_IS(ctx.g == 0x64f98fa7);
|
||||
_IS(ctx.h == 0xbefa4fa4);
|
||||
_IS(ctx.bit_len == 0);
|
||||
for (int i = 0; i < 64; i++)
|
||||
_is(ctx.block[i] == 0);
|
||||
_IS(ctx.block[i] == 0);
|
||||
|
||||
_end("init sha224 ctx");
|
||||
_END("init sha224 ctx");
|
||||
}
|
||||
|
||||
static int decode_string_to_int_sha256()
|
||||
|
@ -68,9 +68,9 @@ static int decode_string_to_int_sha256()
|
|||
|
||||
ft_sha256_decode(words, block);
|
||||
|
||||
_is(words[0] == 0x61626300);
|
||||
_IS(words[0] == 0x61626300);
|
||||
|
||||
_end("decode string to int sha256");
|
||||
_END("decode string to int sha256");
|
||||
}
|
||||
|
||||
static int encode_len_to_string_sha256()
|
||||
|
@ -92,11 +92,11 @@ static int encode_len_to_string_sha256()
|
|||
|
||||
ft_sha256_encode_len(bits, len);
|
||||
|
||||
_is(bits[0] == (t_byte1)((len >> 56) & 0xff));
|
||||
_is(bits[7] == (t_byte1)(len & 0xff));
|
||||
_is(bits[6] == (t_byte1)((len >> 8) & 0xff));
|
||||
_IS(bits[0] == (t_byte1)((len >> 56) & 0xff));
|
||||
_IS(bits[7] == (t_byte1)(len & 0xff));
|
||||
_IS(bits[6] == (t_byte1)((len >> 8) & 0xff));
|
||||
|
||||
_end("encode len to string sha256");
|
||||
_END("encode len to string sha256");
|
||||
}
|
||||
|
||||
static int encode_register_to_string_sha256()
|
||||
|
@ -108,12 +108,12 @@ static int encode_register_to_string_sha256()
|
|||
|
||||
ft_sha256_encode_register(digest_part, reg);
|
||||
|
||||
_is(digest_part[0] == 0xba);
|
||||
_is(digest_part[1] == 0x78);
|
||||
_is(digest_part[2] == 0x16);
|
||||
_is(digest_part[3] == 0xbf);
|
||||
_IS(digest_part[0] == 0xba);
|
||||
_IS(digest_part[1] == 0x78);
|
||||
_IS(digest_part[2] == 0x16);
|
||||
_IS(digest_part[3] == 0xbf);
|
||||
|
||||
_end("encode register to string sha256");
|
||||
_END("encode register to string sha256");
|
||||
}
|
||||
|
||||
static int update_bit_count_sha256()
|
||||
|
@ -124,9 +124,9 @@ static int update_bit_count_sha256()
|
|||
ft_sha256_init(&ctx);
|
||||
ft_sha256_update(&ctx, message, sizeof(message));
|
||||
|
||||
_is(ctx.bit_len == sizeof(message) * 8);
|
||||
_IS(ctx.bit_len == sizeof(message) * 8);
|
||||
|
||||
_end("update bit count sha256");
|
||||
_END("update bit count sha256");
|
||||
}
|
||||
|
||||
static int fill_buffer_sha256()
|
||||
|
@ -137,9 +137,9 @@ static int fill_buffer_sha256()
|
|||
ft_sha256_init(&ctx);
|
||||
ft_sha256_update(&ctx, message, sizeof(message));
|
||||
|
||||
_is(ft_strcmp((const char *)message, (const char *)ctx.block) == 0);
|
||||
_IS(ft_strcmp((const char *)message, (const char *)ctx.block) == 0);
|
||||
|
||||
_end("fill buffer sha256");
|
||||
_END("fill buffer sha256");
|
||||
}
|
||||
|
||||
static void block_with_right_padding
|
||||
|
@ -176,10 +176,10 @@ static int add_right_padding_sha256()
|
|||
|
||||
i = 0;
|
||||
|
||||
_is(ft_memcmp(ctx.block, block_with_message_and_pading,
|
||||
_IS(ft_memcmp(ctx.block, block_with_message_and_pading,
|
||||
FT_SHA256_BLOCK_SIZE) == 0);
|
||||
|
||||
_end("add right padding sha256");
|
||||
_END("add right padding sha256");
|
||||
}
|
||||
|
||||
static int compute_digest_sha256()
|
||||
|
@ -192,16 +192,16 @@ static int compute_digest_sha256()
|
|||
ft_sha256_update(&ctx, message, ft_strlen((const char *)message));
|
||||
ft_sha256_final(digest, &ctx);
|
||||
|
||||
_is(ctx.a == 0xba7816bf);
|
||||
_is(ctx.b == 0x8f01cfea);
|
||||
_is(ctx.c == 0x414140de);
|
||||
_is(ctx.d == 0x5dae2223);
|
||||
_is(ctx.e == 0xb00361a3);
|
||||
_is(ctx.f == 0x96177a9c);
|
||||
_is(ctx.g == 0xb410ff61);
|
||||
_is(ctx.h == 0xf20015ad);
|
||||
_IS(ctx.a == 0xba7816bf);
|
||||
_IS(ctx.b == 0x8f01cfea);
|
||||
_IS(ctx.c == 0x414140de);
|
||||
_IS(ctx.d == 0x5dae2223);
|
||||
_IS(ctx.e == 0xb00361a3);
|
||||
_IS(ctx.f == 0x96177a9c);
|
||||
_IS(ctx.g == 0xb410ff61);
|
||||
_IS(ctx.h == 0xf20015ad);
|
||||
|
||||
_end("compute digest sha256");
|
||||
_END("compute digest sha256");
|
||||
}
|
||||
|
||||
static int compute_digest_sha224()
|
||||
|
@ -214,15 +214,15 @@ static int compute_digest_sha224()
|
|||
ft_sha224_update(&ctx, message, ft_strlen((const char *)message));
|
||||
ft_sha224_final(digest, &ctx);
|
||||
|
||||
_is(ctx.a == 0x23097d22);
|
||||
_is(ctx.b == 0x3405d822);
|
||||
_is(ctx.c == 0x8642a477);
|
||||
_is(ctx.d == 0xbda255b3);
|
||||
_is(ctx.e == 0x2aadbce4);
|
||||
_is(ctx.f == 0xbda0b3f7);
|
||||
_is(ctx.g == 0xe36c9da7);
|
||||
_IS(ctx.a == 0x23097d22);
|
||||
_IS(ctx.b == 0x3405d822);
|
||||
_IS(ctx.c == 0x8642a477);
|
||||
_IS(ctx.d == 0xbda255b3);
|
||||
_IS(ctx.e == 0x2aadbce4);
|
||||
_IS(ctx.f == 0xbda0b3f7);
|
||||
_IS(ctx.g == 0xe36c9da7);
|
||||
|
||||
_end("computee digst sha224");
|
||||
_END("computee digst sha224");
|
||||
}
|
||||
|
||||
static int create_digest_string_sha256()
|
||||
|
@ -239,10 +239,10 @@ static int create_digest_string_sha256()
|
|||
ft_sha256_final(digest, &ctx);
|
||||
ft_sha256_digest_string(digest, digest_string);
|
||||
|
||||
_is(ft_strcmp((const char *)message_digest,
|
||||
_IS(ft_strcmp((const char *)message_digest,
|
||||
(const char *)digest_string) == 0);
|
||||
|
||||
_end("create digest string sha256");
|
||||
_END("create digest string sha256");
|
||||
}
|
||||
|
||||
static int create_digest_string_sha224()
|
||||
|
@ -259,26 +259,26 @@ static int create_digest_string_sha224()
|
|||
ft_sha224_final(digest, &ctx);
|
||||
ft_sha224_digest_string(digest, digest_string);
|
||||
|
||||
_is(ft_strcmp((const char *)message_digest,
|
||||
_IS(ft_strcmp((const char *)message_digest,
|
||||
(const char *)digest_string) == 0);
|
||||
|
||||
_end("create digest strinf sha224");
|
||||
_END("create digest strinf sha224");
|
||||
}
|
||||
|
||||
int sha_tests()
|
||||
{
|
||||
_should(init_sha256_ctx);
|
||||
_should(init_sha224_ctx);
|
||||
_should(decode_string_to_int_sha256);
|
||||
_should(encode_len_to_string_sha256);
|
||||
_should(encode_register_to_string_sha256);
|
||||
_should(update_bit_count_sha256);
|
||||
_should(fill_buffer_sha256);
|
||||
_should(add_right_padding_sha256);
|
||||
_should(compute_digest_sha256);
|
||||
_should(compute_digest_sha224);
|
||||
_should(create_digest_string_sha256);
|
||||
_should(create_digest_string_sha224);
|
||||
_SHOULD(init_sha256_ctx);
|
||||
_SHOULD(init_sha224_ctx);
|
||||
_SHOULD(decode_string_to_int_sha256);
|
||||
_SHOULD(encode_len_to_string_sha256);
|
||||
_SHOULD(encode_register_to_string_sha256);
|
||||
_SHOULD(update_bit_count_sha256);
|
||||
_SHOULD(fill_buffer_sha256);
|
||||
_SHOULD(add_right_padding_sha256);
|
||||
_SHOULD(compute_digest_sha256);
|
||||
_SHOULD(compute_digest_sha224);
|
||||
_SHOULD(create_digest_string_sha256);
|
||||
_SHOULD(create_digest_string_sha224);
|
||||
|
||||
return 0;
|
||||
}
|
10
t/tests.c
10
t/tests.c
|
@ -15,11 +15,11 @@
|
|||
|
||||
int all_tests()
|
||||
{
|
||||
_verify("md5:", md5_tests);
|
||||
_verify("sha:", sha_tests);
|
||||
_verify("base64:", base64_tests);
|
||||
_verify("des:", des_tests);
|
||||
_verify("pbkdf2:", pbkdf2_tests);
|
||||
_VERIFY("md5:", md5_tests);
|
||||
_VERIFY("sha:", sha_tests);
|
||||
_VERIFY("base64:", base64_tests);
|
||||
_VERIFY("des:", des_tests);
|
||||
_VERIFY("pbkdf2:", pbkdf2_tests);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue