Skip to content

Commit df9190e

Browse files
author
Louise P
committed
[Function]: Create the function PBKDF2
[Norme]: The function PBKDF2 is normed [Debug]: The salt is the same of OpenSSL
1 parent 783ba76 commit df9190e

22 files changed

Lines changed: 316 additions & 83 deletions

Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# By: cpieri <cpieri@student.42.fr> +#+ +:+ +#+ #
77
# +#+#+#+#+#+ +#+ #
88
# Created: 2018/03/15 11:20:25 by cpieri #+# #+# #
9-
# Updated: 2019/12/31 12:31:25 by cpieri ### ########.fr #
9+
# Updated: 2019/12/31 14:37:46 by cpieri ### ########.fr #
1010
# #
1111
# **************************************************************************** #
1212

@@ -38,6 +38,7 @@ DEPS = Makefile \
3838
includes/hash/sha1.h \
3939
includes/hash/hmac.h \
4040
includes/base64/base64.h \
41+
includes/pbkdf2/pbkdf.h \
4142
includes/symmetric/symmetric.h \
4243
includes/symmetric/des/des.h \
4344
libft/libft.a
@@ -70,8 +71,9 @@ SRC_NAME= main.c \
7071
base64/base64_parsing.c \
7172
base64/base64_help_parsing.c \
7273
base64/base64_display.c \
74+
pbkdf2/pbkdf2.c \
75+
pbkdf2/pbkdf2_utils.c \
7376
symmetric/sym_key.c \
74-
symmetric/pbkdf.c \
7577
symmetric/symmetric_usage.c \
7678
symmetric/symmetric_parsing.c \
7779
symmetric/symmetric_parsing_pt_f.c \

includes/functions.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: cpieri <cpieri@student.42.fr> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2019/04/11 12:44:05 by cpieri #+# #+# */
9-
/* Updated: 2019/05/20 10:38:53 by cpieri ### ########.fr */
9+
/* Updated: 2020/01/06 09:02:50 by cpieri ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -34,7 +34,7 @@ t_data *new_data(void);
3434
t_data *get_data(const int fd, const char *fd_name);
3535
t_data *get_file(const int fd, const char *fd_name);
3636
t_data *get_string(char *s);
37-
uint64_t get_random(void);
37+
void *get_random(void);
3838

3939
/*
4040
** Functions for Lst_opt

includes/hash/hmac.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: cpieri <cpieri@student.42.fr> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2019/12/31 08:17:41 by cpieri #+# #+# */
9-
/* Updated: 2019/12/31 12:24:18 by cpieri ### ########.fr */
9+
/* Updated: 2019/12/31 13:33:46 by cpieri ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -28,4 +28,4 @@ void *hmac_sha1(void *pwd, size_t pwd_len, void *key, size_t key_len);
2828
void *hmac_sha256(void *pwd, size_t pwd_len, void *key, size_t key_len);
2929
void *hmac_md5(void *pwd, size_t pwd_len, void *key, size_t key_len);
3030

31-
#endif
31+
#endif

includes/hash/sha1.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: cpieri <cpieri@student.42.fr> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2019/12/30 08:05:02 by cpieri #+# #+# */
9-
/* Updated: 2019/12/30 08:59:37 by cpieri ### ########.fr */
9+
/* Updated: 2019/12/31 13:33:56 by cpieri ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -50,4 +50,4 @@ t_sha1_utils func_sha1_i(uint32_t b, uint32_t c, uint32_t d);
5050
void *sha1(void *data, size_t len_data);
5151
t_hash *set_hash2sha1(t_sha1 *e);
5252

53-
#endif
53+
#endif
Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: cpieri <cpieri@student.42.fr> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2019/05/20 10:11:40 by cpieri #+# #+# */
9-
/* Updated: 2019/12/31 08:50:05 by cpieri ### ########.fr */
9+
/* Updated: 2020/01/06 10:33:25 by cpieri ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -29,27 +29,31 @@ typedef struct s_prf
2929
{
3030
enum e_prf prf;
3131
void *(*f)(void *, size_t, void *, size_t);
32+
size_t nb_word;
3233
} t_prf;
3334

3435
typedef struct s_pbkdf
3536
{
36-
uint8_t *pass;
37-
uint64_t salt;
38-
uint64_t key;
37+
void *pass;
38+
void *salt;
39+
void *key;
40+
size_t pass_len;
41+
size_t salt_len;
42+
size_t dk_len;
3943
uint64_t vect;
4044
} t_pbkdf;
4145

4246
/*
4347
** Functions for create and del struct symmetric key
4448
*/
4549
uint8_t *get_pass(const char *prompt);
46-
t_pbkdf *new_key(uint8_t *pass, uint64_t salt, uint64_t key,
47-
uint64_t vect);
50+
t_pbkdf *new_key(uint8_t *pass, void *salt, uint64_t key,
51+
uint64_t vect);
4852
void print_pbkdf(t_pbkdf *to_print);
4953
void free_pbkdf(t_pbkdf **to_free);
5054
void free_vpbkdf(void **to_free);
5155
uint64_t gen_key(uint8_t *pass, uint64_t salt);
52-
uint64_t ft_pbkdf2(uint8_t *pass, uint64_t salt);
56+
void *pbkdf2(t_pbkdf *k, uint32_t c, size_t dk_len, enum e_prf func);
5357
void regen_key(t_pbkdf **k);
5458

5559
#endif

includes/symmetric/symmetric.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
/* By: cpieri <cpieri@student.42.fr> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2019/05/06 10:11:43 by cpieri #+# #+# */
9-
/* Updated: 2019/05/20 10:33:53 by cpieri ### ########.fr */
9+
/* Updated: 2019/12/31 14:36:27 by cpieri ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

1313
#ifndef SYMMETRIC_H
1414
# define SYMMETRIC_H
1515

1616
# include "./des/des.h"
17-
# include "./pbkdf.h"
17+
# include "../pbkdf2/pbkdf.h"
1818

1919
enum e_sym_opt
2020
{

libft/Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# By: cpieri <cpieri@student.42.fr> +#+ +:+ +#+ #
77
# +#+#+#+#+#+ +#+ #
88
# Created: 2017/11/07 18:38:31 by tmilon #+# #+# #
9-
# Updated: 2019/12/30 09:39:19 by cpieri ### ########.fr #
9+
# Updated: 2020/01/06 12:49:31 by cpieri ### ########.fr #
1010
# #
1111
# **************************************************************************** #
1212

@@ -35,6 +35,7 @@ DEPS = Makefile \
3535
SRCS = ft_atoi.c \
3636
ft_bzero.c \
3737
ft_ishexa_color.c \
38+
ft_ishexa.c \
3839
ft_isspace.c \
3940
ft_isalnum.c \
4041
ft_isalpha.c \
@@ -64,7 +65,8 @@ SRCS = ft_atoi.c \
6465
ft_putnbr_fd.c \
6566
ft_putstr.c \
6667
ft_putstr_fd.c \
67-
ft_hex2char.c \
68+
ft_hex64_to_char.c \
69+
ft_hex32_to_char.c \
6870
ft_strcat.c \
6971
ft_strchr.c \
7072
ft_strclr.c \
@@ -126,6 +128,7 @@ SRCS = ft_atoi.c \
126128
ft_left_rotate.c \
127129
ft_right_rotate.c \
128130
ft_swap_uint32t.c \
131+
ft_swap_uint64t.c \
129132
ft_putbits.c
130133

131134
OBJS = $(SRCS:.c=.o)

libft/include/libft.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: cpieri <cpieri@student.42.fr> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2017/11/09 16:47:24 by cpieri #+# #+# */
9-
/* Updated: 2019/12/30 09:36:53 by cpieri ### ########.fr */
9+
/* Updated: 2020/01/06 12:53:34 by cpieri ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -28,7 +28,8 @@ typedef struct s_list
2828
/*
2929
** Functions for Strings
3030
*/
31-
char *ft_hex2char(uint32_t hex);
31+
char *ft_hex32_to_char(uint32_t hex);
32+
char *ft_hex64_to_char(uint64_t hex);
3233
char *ft_strcat(char *s1, const char *s2);
3334
char *ft_strchr(const char *s, int c);
3435
char *ft_strchr(const char *s, int c);
@@ -94,6 +95,7 @@ int ft_isdigit(int c);
9495
int ft_isprint(int c);
9596
int ft_isspace(char c);
9697
int ft_ishexa_color(char *s);
98+
int ft_ishexa(char *s);
9799

98100
/*
99101
** Functions for Linked List
@@ -155,5 +157,6 @@ uint32_t left_shift(uint32_t x, uint32_t nb);
155157
uint32_t left_rotate(uint32_t x, uint32_t nb);
156158
uint32_t right_rotate(uint32_t x, uint32_t nb);
157159
uint32_t swap_uint32t(uint32_t nb);
160+
uint64_t swap_uint64t(uint64_t nb);
158161

159162
#endif
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/* ************************************************************************** */
22
/* */
33
/* ::: :::::::: */
4-
/* ft_hex2char.c :+: :+: :+: */
4+
/* ft_hex32_to_char.c :+: :+: :+: */
55
/* +:+ +:+ +:+ */
66
/* By: cpieri <cpieri@student.42.fr> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2019/05/20 21:21:06 by cpieri #+# #+# */
9-
/* Updated: 2019/05/22 10:36:33 by cpieri ### ########.fr */
9+
/* Updated: 2020/01/06 09:14:04 by cpieri ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -38,7 +38,7 @@ static void conv_32hexa(char **s, long len_s, uint32_t hex)
3838
}
3939
}
4040

41-
char *ft_hex2char(uint32_t hex)
41+
char *ft_hex32_to_char(uint32_t hex)
4242
{
4343
char *s;
4444

libft/srcs/ft_hex64_to_char.c

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* ft_hex64_to_char.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: cpieri <cpieri@student.42.fr> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2019/05/20 21:21:06 by cpieri #+# #+# */
9+
/* Updated: 2020/01/06 09:14:27 by cpieri ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "libft.h"
14+
15+
static void conv_32hexa(char **s, long len_s, uint64_t hex)
16+
{
17+
uint32_t nb;
18+
long i;
19+
char tmp;
20+
21+
nb = 0;
22+
i = 0;
23+
while (i < len_s)
24+
{
25+
nb = hex % 16;
26+
if (nb < 10)
27+
(*s)[i] = (nb) % 10 + '0';
28+
else
29+
(*s)[i] = (nb) + 'a' - 10;
30+
if ((i % 2) != 0)
31+
{
32+
tmp = (*s)[i];
33+
(*s)[i] = (*s)[i - 1];
34+
(*s)[i - 1] = tmp;
35+
}
36+
hex /= 16;
37+
i++;
38+
}
39+
}
40+
41+
char *ft_hex64_to_char(uint64_t hex)
42+
{
43+
char *s;
44+
45+
if (!(s = (char*)ft_memalloc(sizeof(char) * (16 + 1))))
46+
return (NULL);
47+
if (hex < 16)
48+
s[0] = '0';
49+
conv_32hexa(&s, 16, hex);
50+
return (s);
51+
}

0 commit comments

Comments
 (0)