1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_ssl.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/03 20:27:19 by cacharle #+# #+# */
/* Updated: 2020/08/03 12:46:26 by charles ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdio.h>
#ifndef FT_SSL_H
# define FT_SSL_H
# include <stdint.h>
# include <string.h>
# include <endian.h>
# if __BYTE_ORDER == __BIG_ENDIAN
# error "This implementation doesn't support big endian"
# endif
# include "libft.h"
typedef void *(*t_compression_func)(void *state, uint8_t *chunk);
typedef struct
{
t_compression_func compression_func;
const void *compression_state_init;
size_t compression_state_size;
size_t compression_state_stride;
size_t chunk_size;
bool big_endian;
} t_message_digest_param;
void *md5_compression_func(void *v_state, uint8_t *chunk);
void *sha1_compression_func(void *v_state, uint8_t *chunk);
void *sha256_compression_func(void *v_state, uint8_t *chunk);
char *message_digest(t_message_digest_param *param, uint8_t *message_origin, uint64_t size);
#define MD5_A_INIT 0x67452301
#define MD5_B_INIT 0xefcdab89
#define MD5_C_INIT 0x98badcfe
#define MD5_D_INIT 0x10325476
typedef struct
{
char *name;
t_message_digest_param param;
} t_compression_entry;
typedef enum
{
FLAG_QUIET = 1 << 0,
FLAG_REVERSE = 1 << 1,
FLAG_STRING = 1 << 2,
} t_flags;
typedef char *(*t_func_hash)(char *message);
/*
** error.c
*/
void error_command(char *command);
/*
** args.c
*/
int parse_args(int argc, char **argv, char *command, t_message_digest_param *md_param);
/*
** utils.c
*/
uint32_t rotate_left(uint32_t x, int s);
uint32_t rotate_right(uint32_t x, int s);
char *bytes_to_str(uint8_t *bytes, size_t size);
uint32_t reverse_bytes32(uint32_t x);
uint64_t reverse_bytes64(uint64_t x);
/*
** md5
*/
char *message_digest_md5(uint8_t *msg, size_t size);
#endif
|