norme done
This commit is contained in:
parent
5ea4c064b1
commit
efd7701b78
46 changed files with 1120 additions and 579 deletions
122
inc/ft_md5.h
122
inc/ft_md5.h
|
@ -1,3 +1,15 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_md5.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2018/10/23 19:11:58 by gtertysh #+# #+# */
|
||||||
|
/* Updated: 2018/10/23 19:12:43 by gtertysh ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#ifndef FT_MD5_H
|
#ifndef FT_MD5_H
|
||||||
# define FT_MD5_H
|
# define FT_MD5_H
|
||||||
|
|
||||||
|
@ -26,77 +38,79 @@
|
||||||
# define S43 15
|
# define S43 15
|
||||||
# define S44 21
|
# define S44 21
|
||||||
|
|
||||||
/* F, G, H and I are basic MD5 functions.
|
|
||||||
*/
|
|
||||||
# define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
|
# define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
|
||||||
# define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
|
# define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
|
||||||
# define H(x, y, z) ((x) ^ (y) ^ (z))
|
# define H(x, y, z) ((x) ^ (y) ^ (z))
|
||||||
# define I(x, y, z) ((y) ^ ((x) | (~z)))
|
# define I(x, y, z) ((y) ^ ((x) | (~z)))
|
||||||
|
|
||||||
/* ROTATE_LEFT rotates x left n bits.
|
# define RL(x, n) (((x) << (n)) | ((x) >> (32 - (n))))
|
||||||
*/
|
|
||||||
# define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32 - (n))))
|
|
||||||
|
|
||||||
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
|
# define FF1(a, b, c, d, x, ac) (a) += F((b), (c), (d)) + (x) + (t_byte4)(ac)
|
||||||
Rotation is separate from addition to prevent recomputation.
|
# define FF2(a, s) (a) = RL((a), (s))
|
||||||
*/
|
# define FF3(a, b) (a) += (b)
|
||||||
# define FF(a, b, c, d, x, s, ac) \
|
|
||||||
{ \
|
|
||||||
(a) += F((b), (c), (d)) + (x) + (BYTE4)(ac); \
|
|
||||||
(a) = ROTATE_LEFT((a), (s)); \
|
|
||||||
(a) += (b); \
|
|
||||||
}
|
|
||||||
|
|
||||||
# define GG(a, b, c, d, x, s, ac) \
|
# define FF(a, b, c, d, x, s, ac) FF1(a, b, c, d, x, ac); FF2(a, s); FF3(a, b);
|
||||||
{ \
|
|
||||||
(a) += G((b), (c), (d)) + (x) + (BYTE4)(ac); \
|
|
||||||
(a) = ROTATE_LEFT((a), (s)); \
|
|
||||||
(a) += (b); \
|
|
||||||
}
|
|
||||||
|
|
||||||
# define HH(a, b, c, d, x, s, ac) \
|
# define GG1(a, b, c, d, x, ac) (a) += G((b), (c), (d)) + (x) + (t_byte4)(ac)
|
||||||
{ \
|
# define GG2(a, s) (a) = RL((a), (s))
|
||||||
(a) += H((b), (c), (d)) + (x) + (BYTE4)(ac); \
|
# define GG3(a, b) (a) += (b)
|
||||||
(a) = ROTATE_LEFT((a), (s)); \
|
|
||||||
(a) += (b); \
|
|
||||||
}
|
|
||||||
|
|
||||||
# define II(a, b, c, d, x, s, ac) \
|
# define GG(a, b, c, d, x, s, ac) GG1(a, b, c, d, x, ac); GG2(a, s); GG3(a, b);
|
||||||
{ \
|
|
||||||
(a) += I((b), (c), (d)) + (x) + (BYTE4)(ac); \
|
|
||||||
(a) = ROTATE_LEFT((a), (s)); \
|
|
||||||
(a) += (b); \
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef uint64_t BYTE8;
|
# define HH1(a, b, c, d, x, ac) (a) += H((b), (c), (d)) + (x) + (t_byte4)(ac)
|
||||||
typedef uint32_t BYTE4;
|
# define HH2(a, s) (a) = RL((a), (s))
|
||||||
typedef unsigned char BYTE1;
|
# define HH3(a, b) (a) += (b)
|
||||||
|
|
||||||
|
# define HH(a, b, c, d, x, s, ac) HH1(a, b, c, d, x, ac); HH2(a, s); HH3(a, b);
|
||||||
|
|
||||||
|
# define II1(a, b, c, d, x, ac) (a) += I((b), (c), (d)) + (x) + (t_byte4)(ac)
|
||||||
|
# define II2(a, s) (a) = RL((a), (s))
|
||||||
|
# define II3(a, b) (a) += (b)
|
||||||
|
|
||||||
|
# define II(a, b, c, d, x, s, ac) II1(a, b, c, d, x, ac); II2(a, s); II3(a, b);
|
||||||
|
|
||||||
|
typedef uint64_t t_byte8;
|
||||||
|
typedef uint32_t t_byte4;
|
||||||
|
typedef unsigned char t_byte1;
|
||||||
|
|
||||||
typedef struct s_md5_ctx
|
typedef struct s_md5_ctx
|
||||||
{
|
{
|
||||||
BYTE4 a;
|
t_byte4 a;
|
||||||
BYTE4 b;
|
t_byte4 b;
|
||||||
BYTE4 c;
|
t_byte4 c;
|
||||||
BYTE4 d;
|
t_byte4 d;
|
||||||
BYTE1 block[FT_MD5_BLOCK_SIZE];
|
t_byte1 block[FT_MD5_BLOCK_SIZE];
|
||||||
BYTE8 bit_len;
|
t_byte8 bit_len;
|
||||||
} t_md5_ctx;
|
} t_md5_ctx;
|
||||||
|
|
||||||
|
typedef struct s_md5_intr_registers
|
||||||
|
{
|
||||||
|
t_byte4 a;
|
||||||
|
t_byte4 b;
|
||||||
|
t_byte4 c;
|
||||||
|
t_byte4 d;
|
||||||
|
} t_md5_intr_registers;
|
||||||
|
|
||||||
void ft_md5_init(t_md5_ctx *ctx);
|
void ft_md5_init(t_md5_ctx *ctx);
|
||||||
void ft_md5_update(t_md5_ctx *ctx, BYTE1 *chunk, BYTE8 len);
|
void ft_md5_update(t_md5_ctx *ctx, t_byte1 *chunk,
|
||||||
void ft_md5_transform(t_md5_ctx *ctx, BYTE1 blck[FT_MD5_BLOCK_SIZE]);
|
t_byte8 len);
|
||||||
void ft_md5_final(BYTE1 digest[FT_MD5_DIGEST_LENGTH_BYTE],
|
void ft_md5_transform(t_md5_ctx *ctx,
|
||||||
|
t_byte1 blck[FT_MD5_BLOCK_SIZE]);
|
||||||
|
void ft_md5_final(t_byte1 digest[FT_MD5_DIGEST_LENGTH_BYTE],
|
||||||
t_md5_ctx *ctx);
|
t_md5_ctx *ctx);
|
||||||
void ft_md5_decode(BYTE4 w[FT_MD5_WORDS_COUNT],
|
void ft_md5_decode(t_byte4 w[FT_MD5_WORDS_COUNT],
|
||||||
BYTE1 b[FT_MD5_BLOCK_SIZE]);
|
t_byte1 b[FT_MD5_BLOCK_SIZE]);
|
||||||
void ft_md5_encode_len(BYTE1 bits[FT_MD5_MESSAGE_LENGTH_BYTE],
|
void ft_md5_encode_len(
|
||||||
BYTE8 bit_len);
|
t_byte1 bits[FT_MD5_MESSAGE_LENGTH_BYTE],
|
||||||
void ft_md5_encode_register(BYTE1 *digest_part, BYTE4 reg);
|
t_byte8 bit_len);
|
||||||
void ft_md5_padding(BYTE1 padding[FT_MD5_BLOCK_SIZE]);
|
void ft_md5_encode_register(t_byte1 *digest_part,
|
||||||
void ft_md5_digest_string(BYTE1 digest[FT_MD5_DIGEST_LENGTH_BYTE],
|
t_byte4 reg);
|
||||||
BYTE1 string[FT_MD5_STRING_SIZE_BYTE]);
|
void ft_md5_padding(t_byte1 padding[FT_MD5_BLOCK_SIZE]);
|
||||||
void ft_md5_string(BYTE1 *str);
|
void ft_md5_digest_string(
|
||||||
void ft_md5_file(BYTE1 *filename);
|
t_byte1 digest[FT_MD5_DIGEST_LENGTH_BYTE],
|
||||||
|
t_byte1 string[FT_MD5_STRING_SIZE_BYTE]);
|
||||||
|
void ft_md5_string(t_byte1 *str);
|
||||||
|
void ft_md5_file(t_byte1 *filename);
|
||||||
void ft_md5_filter(void);
|
void ft_md5_filter(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
113
inc/ft_sha.h
113
inc/ft_sha.h
|
@ -1,7 +1,19 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_sha.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2018/10/23 19:20:23 by gtertysh #+# #+# */
|
||||||
|
/* Updated: 2018/10/23 19:29:10 by gtertysh ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#ifndef FT_SHA_H
|
#ifndef FT_SHA_H
|
||||||
# define FT_SHA_H
|
# define FT_SHA_H
|
||||||
|
|
||||||
#include <stdint.h>
|
# include <stdint.h>
|
||||||
|
|
||||||
# define FT_SHA256_BLOCK_SIZE 64
|
# define FT_SHA256_BLOCK_SIZE 64
|
||||||
# define FT_SHA256_WORDS_COUNT 16
|
# define FT_SHA256_WORDS_COUNT 16
|
||||||
|
@ -13,75 +25,78 @@
|
||||||
# define FT_SHA224_DIGEST_LENGTH_BYTE 28
|
# define FT_SHA224_DIGEST_LENGTH_BYTE 28
|
||||||
# define FT_SHA224_STRING_SIZE_BYTE 57
|
# define FT_SHA224_STRING_SIZE_BYTE 57
|
||||||
|
|
||||||
/* Define the SHA shift, rotate left, and rotate right macros */
|
# define SHR(bits, word) ((word) >> (bits))
|
||||||
#define SHR(bits, word) ((word) >> (bits))
|
# define ROTL(bits, word) (((word) << (bits)) | ((word) >> (32 - (bits))))
|
||||||
#define ROTL(bits, word) (((word) << (bits)) | ((word) >> (32 - (bits))))
|
# define ROTR(bits, word) (((word) >> (bits)) | ((word) << (32 - (bits))))
|
||||||
#define ROTR(bits, word) (((word) >> (bits)) | ((word) << (32 - (bits))))
|
|
||||||
|
|
||||||
/* Define the SHA SIGMA and sigma macros */
|
# define SHA256_SIGMA0(w) (ROTR(2, w) ^ ROTR(13, w) ^ ROTR(22, w))
|
||||||
#define SHA256_SIGMA0(w) (ROTR(2, w) ^ ROTR(13, w) ^ ROTR(22, w))
|
# define SHA256_SIGMA1(word) (ROTR(6, word) ^ ROTR(11, word) ^ ROTR(25, word))
|
||||||
#define SHA256_SIGMA1(word) (ROTR(6, word) ^ ROTR(11, word) ^ ROTR(25, word))
|
# define SHA256_SIG0(word) (ROTR(7, word) ^ ROTR(18, word) ^ SHR(3, word))
|
||||||
#define SHA256_sigma0(word) (ROTR(7, word) ^ ROTR(18, word) ^ SHR(3, word))
|
# define SHA256_SIG1(word) (ROTR(17, word) ^ ROTR(19, word) ^ SHR(10, word))
|
||||||
#define SHA256_sigma1(word) (ROTR(17, word) ^ ROTR(19, word) ^ SHR(10, word))
|
|
||||||
|
|
||||||
#define SHA_Ch(x, y, z) (((x) & ((y) ^ (z))) ^ (z))
|
# define SHA_CH(x, y, z) (((x) & ((y) ^ (z))) ^ (z))
|
||||||
#define SHA_Maj(x, y, z) (((x) & ((y) | (z))) | ((y) & (z)))
|
# define SHA_MAJ(x, y, z) (((x) & ((y) | (z))) | ((y) & (z)))
|
||||||
|
|
||||||
typedef uint64_t BYTE8;
|
typedef uint64_t t_byte8;
|
||||||
typedef uint32_t BYTE4;
|
typedef uint32_t t_byte4;
|
||||||
typedef unsigned char BYTE1;
|
typedef unsigned char t_byte1;
|
||||||
|
|
||||||
typedef struct s_sha256_ctx
|
typedef struct s_sha256_ctx
|
||||||
{
|
{
|
||||||
BYTE4 a;
|
t_byte4 a;
|
||||||
BYTE4 b;
|
t_byte4 b;
|
||||||
BYTE4 c;
|
t_byte4 c;
|
||||||
BYTE4 d;
|
t_byte4 d;
|
||||||
BYTE4 e;
|
t_byte4 e;
|
||||||
BYTE4 f;
|
t_byte4 f;
|
||||||
BYTE4 g;
|
t_byte4 g;
|
||||||
BYTE4 h;
|
t_byte4 h;
|
||||||
BYTE1 block[FT_SHA256_BLOCK_SIZE];
|
t_byte1 block[FT_SHA256_BLOCK_SIZE];
|
||||||
BYTE8 bit_len;
|
t_byte8 bit_len;
|
||||||
} t_sha256_ctx;
|
} t_sha256_ctx;
|
||||||
|
|
||||||
typedef struct s_temp_registers
|
typedef struct s_temp_registers
|
||||||
{
|
{
|
||||||
BYTE4 a;
|
t_byte4 a;
|
||||||
BYTE4 b;
|
t_byte4 b;
|
||||||
BYTE4 c;
|
t_byte4 c;
|
||||||
BYTE4 d;
|
t_byte4 d;
|
||||||
BYTE4 e;
|
t_byte4 e;
|
||||||
BYTE4 f;
|
t_byte4 f;
|
||||||
BYTE4 g;
|
t_byte4 g;
|
||||||
BYTE4 h;
|
t_byte4 h;
|
||||||
} t_temp_registers;
|
} t_temp_registers;
|
||||||
|
|
||||||
void ft_sha256_init(t_sha256_ctx *ctx);
|
void ft_sha256_init(t_sha256_ctx *ctx);
|
||||||
void ft_sha224_init(t_sha256_ctx *ctx);
|
void ft_sha224_init(t_sha256_ctx *ctx);
|
||||||
void ft_sha256_update(t_sha256_ctx *ctx,
|
void ft_sha256_update(t_sha256_ctx *ctx,
|
||||||
BYTE1 *message, BYTE8 len);
|
t_byte1 *message, t_byte8 len);
|
||||||
void ft_sha224_update(t_sha256_ctx *ctx,
|
void ft_sha224_update(t_sha256_ctx *ctx,
|
||||||
BYTE1 *message, BYTE8 len);
|
t_byte1 *message, t_byte8 len);
|
||||||
void ft_sha256_final(BYTE1 digest[FT_SHA256_DIGEST_LENGTH_BYTE],
|
void ft_sha256_final(
|
||||||
|
t_byte1 digest[FT_SHA256_DIGEST_LENGTH_BYTE],
|
||||||
t_sha256_ctx *ctx);
|
t_sha256_ctx *ctx);
|
||||||
void ft_sha224_final(BYTE1 digest[FT_SHA256_DIGEST_LENGTH_BYTE],
|
void ft_sha224_final(
|
||||||
|
t_byte1 digest[FT_SHA256_DIGEST_LENGTH_BYTE],
|
||||||
t_sha256_ctx *ctx);
|
t_sha256_ctx *ctx);
|
||||||
void ft_sha256_transform(t_sha256_ctx *ctx,
|
void ft_sha256_transform(t_sha256_ctx *ctx,
|
||||||
BYTE1 block[FT_SHA256_BLOCK_SIZE]);
|
t_byte1 block[FT_SHA256_BLOCK_SIZE]);
|
||||||
void ft_sha256_decode(BYTE4 w[FT_SHA256_WORDS_COUNT],
|
void ft_sha256_decode(t_byte4 w[FT_SHA256_WORDS_COUNT],
|
||||||
BYTE1 b[FT_SHA256_BLOCK_SIZE]);
|
t_byte1 b[FT_SHA256_BLOCK_SIZE]);
|
||||||
void ft_sha256_encode_len(BYTE1 b[FT_SHA256_MESSAGE_LENGTH_BYTE],
|
void ft_sha256_encode_len(
|
||||||
BYTE8 len);
|
t_byte1 b[FT_SHA256_MESSAGE_LENGTH_BYTE],
|
||||||
|
t_byte8 len);
|
||||||
void ft_sha256_encode_register(
|
void ft_sha256_encode_register(
|
||||||
BYTE1 digest_part[FT_SHA256_REG_SIZE_BYTE], BYTE4 reg);
|
t_byte1 digest_part[FT_SHA256_REG_SIZE_BYTE],
|
||||||
void ft_sha256_padding(BYTE1 padding[FT_SHA256_BLOCK_SIZE]);
|
t_byte4 reg);
|
||||||
|
void ft_sha256_padding(
|
||||||
|
t_byte1 padding[FT_SHA256_BLOCK_SIZE]);
|
||||||
void ft_sha256_digest_string(
|
void ft_sha256_digest_string(
|
||||||
BYTE1 digest[FT_SHA256_DIGEST_LENGTH_BYTE],
|
t_byte1 digest[FT_SHA256_DIGEST_LENGTH_BYTE],
|
||||||
BYTE1 digst_string[FT_SHA256_STRING_SIZE_BYTE]);
|
t_byte1 digst_string[FT_SHA256_STRING_SIZE_BYTE]);
|
||||||
void ft_sha224_digest_string(
|
void ft_sha224_digest_string(
|
||||||
BYTE1 digest[FT_SHA224_DIGEST_LENGTH_BYTE],
|
t_byte1 digest[FT_SHA224_DIGEST_LENGTH_BYTE],
|
||||||
BYTE1 digst_string[FT_SHA224_STRING_SIZE_BYTE]);
|
t_byte1 digst_string[FT_SHA224_STRING_SIZE_BYTE]);
|
||||||
BYTE4 *ft_sha256_constants(void);
|
t_byte4 *ft_sha256_constants(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2018/10/22 20:07:36 by gtertysh #+# #+# */
|
/* Created: 2018/10/22 20:07:36 by gtertysh #+# #+# */
|
||||||
/* Updated: 2018/10/22 20:15:49 by gtertysh ### ########.fr */
|
/* Updated: 2018/10/23 19:36:23 by gtertysh ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
79
inc/tests.h
79
inc/tests.h
|
@ -1,31 +1,58 @@
|
||||||
#ifndef TESTS
|
/* ************************************************************************** */
|
||||||
# define TESTS
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* tests.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2018/10/23 19:36:58 by gtertysh #+# #+# */
|
||||||
|
/* Updated: 2018/10/23 19:40:12 by gtertysh ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#define MUNIT_ENABLE_ASSERT_ALIASES
|
#ifndef TESTS_H
|
||||||
#include "munit.h"
|
# define TESTS_H
|
||||||
#include "tests_macros.h"
|
|
||||||
|
|
||||||
// md5 tests
|
# define MUNIT_ENABLE_ASSERT_ALIASES
|
||||||
CASE(should_init_ctx);
|
# include "munit.h"
|
||||||
CASE(update_should_change_count);
|
|
||||||
CASE(decode_string_to_int);
|
|
||||||
CASE(encode_bits_to_string);
|
|
||||||
CASE(encode_register);
|
|
||||||
CASE(create_digest);
|
|
||||||
CASE(create_string);
|
|
||||||
|
|
||||||
// sha tests
|
MunitResult should_init_ctx(const MunitParameter test_params[],
|
||||||
CASE(should_init_ctx_sha256);
|
void *test_data);
|
||||||
CASE(decode_string_to_int_sha256);
|
MunitResult update_should_change_count(const MunitParameter test_params[],
|
||||||
CASE(encode_len_to_string_sha256);
|
void *test_data);
|
||||||
CASE(encode_register_to_string_sha256);
|
MunitResult decode_string_to_int(const MunitParameter test_params[],
|
||||||
CASE(update_bit_count_sha256);
|
void *test_data);
|
||||||
CASE(fill_buffer_sha256);
|
MunitResult encode_bits_to_string(const MunitParameter test_params[],
|
||||||
CASE(add_right_padding_sha256);
|
void *test_data);
|
||||||
CASE(compute_digest_sha256);
|
MunitResult encode_register(const MunitParameter test_params[],
|
||||||
CASE(create_digest_string_sha256);
|
void *test_data);
|
||||||
CASE(should_init_ctx_sha224);
|
MunitResult create_digest(const MunitParameter test_params[],
|
||||||
CASE(compute_digest_sha224);
|
void *test_data);
|
||||||
CASE(create_digest_string_sha224);
|
MunitResult create_string(const MunitParameter test_params[],
|
||||||
|
void *test_data);
|
||||||
|
MunitResult should_init_ctx_sha256(const MunitParameter test_params[],
|
||||||
|
void *test_data);
|
||||||
|
MunitResult decode_string_to_int_sha256(const MunitParameter test_params[],
|
||||||
|
void *test_data);
|
||||||
|
MunitResult encode_len_to_string_sha256(const MunitParameter test_params[],
|
||||||
|
void *test_data);
|
||||||
|
MunitResult encode_register_to_string_sha256(const MunitParameter test_params[],
|
||||||
|
void *test_data);
|
||||||
|
MunitResult update_bit_count_sha256(const MunitParameter test_params[],
|
||||||
|
void *test_data);
|
||||||
|
MunitResult fill_buffer_sha256(const MunitParameter test_params[],
|
||||||
|
void *test_data);
|
||||||
|
MunitResult add_right_padding_sha256(const MunitParameter test_params[],
|
||||||
|
void *test_data);
|
||||||
|
MunitResult compute_digest_sha256(const MunitParameter test_params[],
|
||||||
|
void *test_data);
|
||||||
|
MunitResult create_digest_string_sha256(const MunitParameter test_params[],
|
||||||
|
void *test_data);
|
||||||
|
MunitResult should_init_ctx_sha224(const MunitParameter test_params[],
|
||||||
|
void *test_data);
|
||||||
|
MunitResult compute_digest_sha224(const MunitParameter test_params[],
|
||||||
|
void *test_data);
|
||||||
|
MunitResult create_digest_string_sha224(const MunitParameter test_params[],
|
||||||
|
void *test_data);
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -1,22 +1,34 @@
|
||||||
#ifndef TESTS_MACROS
|
/* ************************************************************************** */
|
||||||
# define TESTS_MACROS
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* tests_macros.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2018/10/23 19:46:23 by gtertysh #+# #+# */
|
||||||
|
/* Updated: 2018/10/23 19:46:33 by gtertysh ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "munit.h"
|
#ifndef TESTS_MACROS_H
|
||||||
|
# define TESTS_MACROS_H
|
||||||
|
|
||||||
#define UNUSED(x) (void)(x)
|
# include "munit.h"
|
||||||
|
|
||||||
#define TEST_RESULT MunitResult
|
# define UNUSED(x) (void)(x)
|
||||||
#define TEST_PARAMS const MunitParameter test_params[]
|
|
||||||
#define TEST_DATA void *test_data
|
|
||||||
#define CASE(f) TEST_RESULT f(TEST_PARAMS, TEST_DATA)
|
|
||||||
|
|
||||||
#define N(name) (char *)name
|
# define TEST_RESULT MunitResult
|
||||||
#define T(test_function) test_function
|
# define TEST_PARAMS const MunitParameter test_params[]
|
||||||
#define S(setup_function) setup_function
|
# define TEST_DATA void *test_data
|
||||||
#define TD(tear_down_function) tear_down_function
|
# define CASE(f) TEST_RESULT f(TEST_PARAMS, TEST_DATA)
|
||||||
#define O(options) options
|
|
||||||
#define P(paramenters) paramenters
|
# define N(name) (char *)name
|
||||||
#define IT(n, t, s, td, o, p) { N(n), T(t), S(s), TD(td), O(o), P(p) }
|
# define T(test_function) test_function
|
||||||
#define END_IT IT(NULL, NULL, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL)
|
# define S(setup_function) setup_function
|
||||||
|
# define TD(tear_down_function) tear_down_function
|
||||||
|
# define O(options) options
|
||||||
|
# define P(paramenters) paramenters
|
||||||
|
# define IT(n, t, s, td, o, p) { N(n), T(t), S(s), TD(td), O(o), P(p) }
|
||||||
|
# define END_IT IT(NULL, NULL, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL)
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -1,29 +1,27 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_ssl_init.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2018/10/23 20:21:21 by gtertysh #+# #+# */
|
||||||
|
/* Updated: 2018/10/23 20:28:00 by gtertysh ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "ft_ssl.h"
|
#include "ft_ssl.h"
|
||||||
#include "libft.h"
|
#include "libft.h"
|
||||||
|
|
||||||
static t_algorithm *init_algorithms(void)
|
static t_algorithm *init_algorithms(void)
|
||||||
{
|
{
|
||||||
static t_algorithm algs[FT_SSL_ALGS_COUNT] = {
|
static t_algorithm algs[FT_SSL_ALGS_COUNT] = {
|
||||||
{
|
{"md5", ft_ssl_md5_stdin, ft_ssl_md5_file, ft_ssl_md5_string},
|
||||||
"md5",
|
{"sha256", ft_ssl_sha256_stdin, ft_ssl_sha256_file, ft_ssl_sha256_string},
|
||||||
ft_ssl_md5_stdin,
|
{"sha224", ft_ssl_sha224_stdin, ft_ssl_sha224_file, ft_ssl_sha224_string}
|
||||||
ft_ssl_md5_file,
|
|
||||||
ft_ssl_md5_string,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"sha256",
|
|
||||||
ft_ssl_sha256_stdin,
|
|
||||||
ft_ssl_sha256_file,
|
|
||||||
ft_ssl_sha256_string,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"sha224",
|
|
||||||
ft_ssl_sha224_stdin,
|
|
||||||
ft_ssl_sha224_file,
|
|
||||||
ft_ssl_sha224_string,
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
return algs;
|
|
||||||
|
return (algs);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void init_flags(t_ft_ssl *ft_ssl)
|
static void init_flags(t_ft_ssl *ft_ssl)
|
||||||
|
@ -49,7 +47,6 @@ void ft_ssl_init(char *alg_name, t_ft_ssl *ft_ssl)
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
alg = 0;
|
alg = 0;
|
||||||
|
|
||||||
init_flags(ft_ssl);
|
init_flags(ft_ssl);
|
||||||
alg_walker = init_algorithms();
|
alg_walker = init_algorithms();
|
||||||
while (i < FT_SSL_ALGS_COUNT)
|
while (i < FT_SSL_ALGS_COUNT)
|
||||||
|
@ -57,7 +54,7 @@ void ft_ssl_init(char *alg_name, t_ft_ssl *ft_ssl)
|
||||||
if (ft_strcmp(alg_name, alg_walker[i].name) == 0)
|
if (ft_strcmp(alg_name, alg_walker[i].name) == 0)
|
||||||
{
|
{
|
||||||
alg = &alg_walker[i];
|
alg = &alg_walker[i];
|
||||||
break;
|
break ;
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,20 +1,32 @@
|
||||||
#include "ft_ssl.h"
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_ssl_md5_file.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2018/10/23 20:30:28 by gtertysh #+# #+# */
|
||||||
|
/* Updated: 2018/10/23 20:30:30 by gtertysh ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "ft_md5.h"
|
#include "ft_md5.h"
|
||||||
#include "fcntl.h"
|
#include "fcntl.h"
|
||||||
#include "stdio.h"
|
#include "stdio.h"
|
||||||
#include "unistd.h"
|
#include "unistd.h"
|
||||||
#include "libft.h"
|
#include "libft.h"
|
||||||
|
#include "ft_ssl.h"
|
||||||
|
|
||||||
void ft_ssl_md5_file(const char *filename, t_ft_ssl *ft_ssl)
|
void ft_ssl_md5_file(const char *filename, t_ft_ssl *ft_ssl)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
int len;
|
int len;
|
||||||
BYTE1 digest[FT_MD5_DIGEST_LENGTH_BYTE];
|
t_byte1 digest[FT_MD5_DIGEST_LENGTH_BYTE];
|
||||||
t_md5_ctx ctx;
|
t_md5_ctx ctx;
|
||||||
BYTE1 buf[FT_SSL_BUFFER_SIZE];
|
t_byte1 buf[FT_SSL_BUFFER_SIZE];
|
||||||
|
|
||||||
(void)ft_ssl;
|
(void)ft_ssl;
|
||||||
if((fd = open(filename, O_RDONLY)) == -1)
|
if ((fd = open(filename, O_RDONLY)) == -1)
|
||||||
{
|
{
|
||||||
perror("Error: ");
|
perror("Error: ");
|
||||||
exit(1);
|
exit(1);
|
||||||
|
|
|
@ -1,3 +1,15 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_ssl_md5_print.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2018/10/23 20:28:46 by gtertysh #+# #+# */
|
||||||
|
/* Updated: 2018/10/23 20:28:58 by gtertysh ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "ft_md5.h"
|
#include "ft_md5.h"
|
||||||
#include "ft_ssl.h"
|
#include "ft_ssl.h"
|
||||||
#include "libft.h"
|
#include "libft.h"
|
||||||
|
@ -24,7 +36,7 @@ void ft_ssl_md5_print
|
||||||
t_ft_ssl *ft_ssl
|
t_ft_ssl *ft_ssl
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
BYTE1 digest_string[FT_MD5_STRING_SIZE_BYTE];
|
t_byte1 digest_string[FT_MD5_STRING_SIZE_BYTE];
|
||||||
|
|
||||||
ft_md5_digest_string(digest, digest_string);
|
ft_md5_digest_string(digest, digest_string);
|
||||||
if (target && !ft_ssl->flags.quiet && ft_ssl->flags.reverse)
|
if (target && !ft_ssl->flags.quiet && ft_ssl->flags.reverse)
|
||||||
|
|
|
@ -1,3 +1,15 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_ssl_md5_stdin.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2018/10/23 20:29:11 by gtertysh #+# #+# */
|
||||||
|
/* Updated: 2018/10/23 20:29:38 by gtertysh ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "ft_ssl.h"
|
#include "ft_ssl.h"
|
||||||
#include "ft_md5.h"
|
#include "ft_md5.h"
|
||||||
#include "fcntl.h"
|
#include "fcntl.h"
|
||||||
|
@ -7,9 +19,9 @@
|
||||||
void ft_ssl_md5_stdin(t_ft_ssl *ft_ssl)
|
void ft_ssl_md5_stdin(t_ft_ssl *ft_ssl)
|
||||||
{
|
{
|
||||||
int len;
|
int len;
|
||||||
BYTE1 digest[FT_MD5_DIGEST_LENGTH_BYTE];
|
t_byte1 digest[FT_MD5_DIGEST_LENGTH_BYTE];
|
||||||
t_md5_ctx ctx;
|
t_md5_ctx ctx;
|
||||||
BYTE1 buf[FT_SSL_BUFFER_SIZE];
|
t_byte1 buf[FT_SSL_BUFFER_SIZE];
|
||||||
|
|
||||||
(void)ft_ssl;
|
(void)ft_ssl;
|
||||||
ft_md5_init(&ctx);
|
ft_md5_init(&ctx);
|
||||||
|
|
|
@ -1,3 +1,15 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_ssl_md5_string.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2018/10/23 20:29:48 by gtertysh #+# #+# */
|
||||||
|
/* Updated: 2018/10/23 20:30:06 by gtertysh ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "ft_ssl.h"
|
#include "ft_ssl.h"
|
||||||
#include "ft_md5.h"
|
#include "ft_md5.h"
|
||||||
#include "fcntl.h"
|
#include "fcntl.h"
|
||||||
|
@ -7,7 +19,7 @@
|
||||||
|
|
||||||
void ft_ssl_md5_string(const char *str, t_ft_ssl *ft_ssl)
|
void ft_ssl_md5_string(const char *str, t_ft_ssl *ft_ssl)
|
||||||
{
|
{
|
||||||
BYTE1 digest[FT_MD5_DIGEST_LENGTH_BYTE];
|
t_byte1 digest[FT_MD5_DIGEST_LENGTH_BYTE];
|
||||||
t_md5_ctx ctx;
|
t_md5_ctx ctx;
|
||||||
|
|
||||||
ft_md5_init(&ctx);
|
ft_md5_init(&ctx);
|
||||||
|
|
|
@ -1,3 +1,15 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_ssl_sha224_file.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2018/10/23 20:30:48 by gtertysh #+# #+# */
|
||||||
|
/* Updated: 2018/10/23 20:31:18 by gtertysh ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "ft_ssl.h"
|
#include "ft_ssl.h"
|
||||||
#include "ft_sha.h"
|
#include "ft_sha.h"
|
||||||
#include "fcntl.h"
|
#include "fcntl.h"
|
||||||
|
@ -9,9 +21,9 @@ void ft_ssl_sha224_file(const char *filename, t_ft_ssl *ft_ssl)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
int len;
|
int len;
|
||||||
BYTE1 digest[FT_SHA224_DIGEST_LENGTH_BYTE];
|
t_byte1 digest[FT_SHA224_DIGEST_LENGTH_BYTE];
|
||||||
t_sha256_ctx ctx;
|
t_sha256_ctx ctx;
|
||||||
BYTE1 buf[FT_SSL_BUFFER_SIZE];
|
t_byte1 buf[FT_SSL_BUFFER_SIZE];
|
||||||
|
|
||||||
(void)ft_ssl;
|
(void)ft_ssl;
|
||||||
if ((fd = open(filename, O_RDONLY)) == -1)
|
if ((fd = open(filename, O_RDONLY)) == -1)
|
||||||
|
|
|
@ -1,3 +1,15 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_ssl_sha224_print.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2018/10/23 20:31:27 by gtertysh #+# #+# */
|
||||||
|
/* Updated: 2018/10/23 20:31:42 by gtertysh ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "ft_sha.h"
|
#include "ft_sha.h"
|
||||||
#include "ft_ssl.h"
|
#include "ft_ssl.h"
|
||||||
#include "libft.h"
|
#include "libft.h"
|
||||||
|
@ -24,7 +36,7 @@ void ft_ssl_sha224_print
|
||||||
t_ft_ssl *ft_ssl
|
t_ft_ssl *ft_ssl
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
BYTE1 digest_string[FT_SHA224_STRING_SIZE_BYTE];
|
t_byte1 digest_string[FT_SHA224_STRING_SIZE_BYTE];
|
||||||
|
|
||||||
ft_sha224_digest_string(digest, digest_string);
|
ft_sha224_digest_string(digest, digest_string);
|
||||||
if (target && !ft_ssl->flags.quiet && ft_ssl->flags.reverse)
|
if (target && !ft_ssl->flags.quiet && ft_ssl->flags.reverse)
|
||||||
|
|
|
@ -1,3 +1,15 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_ssl_sha224_stdin.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2018/10/23 20:31:54 by gtertysh #+# #+# */
|
||||||
|
/* Updated: 2018/10/23 20:32:14 by gtertysh ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "ft_ssl.h"
|
#include "ft_ssl.h"
|
||||||
#include "ft_sha.h"
|
#include "ft_sha.h"
|
||||||
#include "fcntl.h"
|
#include "fcntl.h"
|
||||||
|
@ -8,9 +20,9 @@
|
||||||
void ft_ssl_sha224_stdin(t_ft_ssl *ft_ssl)
|
void ft_ssl_sha224_stdin(t_ft_ssl *ft_ssl)
|
||||||
{
|
{
|
||||||
int len;
|
int len;
|
||||||
BYTE1 digest[FT_SHA224_DIGEST_LENGTH_BYTE];
|
t_byte1 digest[FT_SHA224_DIGEST_LENGTH_BYTE];
|
||||||
t_sha256_ctx ctx;
|
t_sha256_ctx ctx;
|
||||||
BYTE1 buf[FT_SSL_BUFFER_SIZE];
|
t_byte1 buf[FT_SSL_BUFFER_SIZE];
|
||||||
|
|
||||||
(void)ft_ssl;
|
(void)ft_ssl;
|
||||||
ft_sha224_init(&ctx);
|
ft_sha224_init(&ctx);
|
||||||
|
|
|
@ -1,3 +1,15 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_ssl_sha224_string.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2018/10/23 20:32:29 by gtertysh #+# #+# */
|
||||||
|
/* Updated: 2018/10/23 20:32:48 by gtertysh ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "ft_ssl.h"
|
#include "ft_ssl.h"
|
||||||
#include "ft_sha.h"
|
#include "ft_sha.h"
|
||||||
#include "fcntl.h"
|
#include "fcntl.h"
|
||||||
|
@ -7,7 +19,7 @@
|
||||||
|
|
||||||
void ft_ssl_sha224_string(const char *str, t_ft_ssl *ft_ssl)
|
void ft_ssl_sha224_string(const char *str, t_ft_ssl *ft_ssl)
|
||||||
{
|
{
|
||||||
BYTE1 digest[FT_SHA224_DIGEST_LENGTH_BYTE];
|
t_byte1 digest[FT_SHA224_DIGEST_LENGTH_BYTE];
|
||||||
t_sha256_ctx ctx;
|
t_sha256_ctx ctx;
|
||||||
|
|
||||||
(void)ft_ssl;
|
(void)ft_ssl;
|
||||||
|
|
|
@ -1,3 +1,15 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_ssl_sha256_file.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2018/10/23 20:33:03 by gtertysh #+# #+# */
|
||||||
|
/* Updated: 2018/10/23 20:33:23 by gtertysh ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "ft_ssl.h"
|
#include "ft_ssl.h"
|
||||||
#include "ft_sha.h"
|
#include "ft_sha.h"
|
||||||
#include "fcntl.h"
|
#include "fcntl.h"
|
||||||
|
@ -9,9 +21,9 @@ void ft_ssl_sha256_file(const char *filename, t_ft_ssl *ft_ssl)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
int len;
|
int len;
|
||||||
BYTE1 digest[FT_SHA256_DIGEST_LENGTH_BYTE];
|
t_byte1 digest[FT_SHA256_DIGEST_LENGTH_BYTE];
|
||||||
t_sha256_ctx ctx;
|
t_sha256_ctx ctx;
|
||||||
BYTE1 buf[FT_SSL_BUFFER_SIZE];
|
t_byte1 buf[FT_SSL_BUFFER_SIZE];
|
||||||
|
|
||||||
(void)ft_ssl;
|
(void)ft_ssl;
|
||||||
if ((fd = open(filename, O_RDONLY)) == -1)
|
if ((fd = open(filename, O_RDONLY)) == -1)
|
||||||
|
|
|
@ -1,3 +1,15 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_ssl_sha256_print.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2018/10/23 20:33:33 by gtertysh #+# #+# */
|
||||||
|
/* Updated: 2018/10/23 20:33:43 by gtertysh ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "ft_sha.h"
|
#include "ft_sha.h"
|
||||||
#include "ft_ssl.h"
|
#include "ft_ssl.h"
|
||||||
#include "libft.h"
|
#include "libft.h"
|
||||||
|
@ -24,7 +36,7 @@ void ft_ssl_sha256_print
|
||||||
t_ft_ssl *ft_ssl
|
t_ft_ssl *ft_ssl
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
BYTE1 digest_string[FT_SHA256_STRING_SIZE_BYTE];
|
t_byte1 digest_string[FT_SHA256_STRING_SIZE_BYTE];
|
||||||
|
|
||||||
ft_sha256_digest_string(digest, digest_string);
|
ft_sha256_digest_string(digest, digest_string);
|
||||||
if (target && !ft_ssl->flags.quiet && ft_ssl->flags.reverse)
|
if (target && !ft_ssl->flags.quiet && ft_ssl->flags.reverse)
|
||||||
|
|
|
@ -1,3 +1,15 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_ssl_sha256_stdin.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2018/10/23 20:34:09 by gtertysh #+# #+# */
|
||||||
|
/* Updated: 2018/10/23 20:34:32 by gtertysh ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "ft_ssl.h"
|
#include "ft_ssl.h"
|
||||||
#include "ft_sha.h"
|
#include "ft_sha.h"
|
||||||
#include "fcntl.h"
|
#include "fcntl.h"
|
||||||
|
@ -8,9 +20,9 @@
|
||||||
void ft_ssl_sha256_stdin(t_ft_ssl *ft_ssl)
|
void ft_ssl_sha256_stdin(t_ft_ssl *ft_ssl)
|
||||||
{
|
{
|
||||||
int len;
|
int len;
|
||||||
BYTE1 digest[FT_SHA256_DIGEST_LENGTH_BYTE];
|
t_byte1 digest[FT_SHA256_DIGEST_LENGTH_BYTE];
|
||||||
t_sha256_ctx ctx;
|
t_sha256_ctx ctx;
|
||||||
BYTE1 buf[FT_SSL_BUFFER_SIZE];
|
t_byte1 buf[FT_SSL_BUFFER_SIZE];
|
||||||
|
|
||||||
(void)ft_ssl;
|
(void)ft_ssl;
|
||||||
ft_sha256_init(&ctx);
|
ft_sha256_init(&ctx);
|
||||||
|
|
|
@ -1,3 +1,15 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_ssl_sha256_string.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2018/10/23 20:34:49 by gtertysh #+# #+# */
|
||||||
|
/* Updated: 2018/10/23 20:34:59 by gtertysh ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "ft_ssl.h"
|
#include "ft_ssl.h"
|
||||||
#include "ft_sha.h"
|
#include "ft_sha.h"
|
||||||
#include "fcntl.h"
|
#include "fcntl.h"
|
||||||
|
@ -7,7 +19,7 @@
|
||||||
|
|
||||||
void ft_ssl_sha256_string(const char *str, t_ft_ssl *ft_ssl)
|
void ft_ssl_sha256_string(const char *str, t_ft_ssl *ft_ssl)
|
||||||
{
|
{
|
||||||
BYTE1 digest[FT_SHA256_DIGEST_LENGTH_BYTE];
|
t_byte1 digest[FT_SHA256_DIGEST_LENGTH_BYTE];
|
||||||
t_sha256_ctx ctx;
|
t_sha256_ctx ctx;
|
||||||
|
|
||||||
(void)ft_ssl;
|
(void)ft_ssl;
|
||||||
|
|
|
@ -1,3 +1,15 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_ssl_usage.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2018/10/23 20:35:14 by gtertysh #+# #+# */
|
||||||
|
/* Updated: 2018/10/23 20:35:16 by gtertysh ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "ft_ssl.h"
|
#include "ft_ssl.h"
|
||||||
#include "libft.h"
|
#include "libft.h"
|
||||||
|
|
||||||
|
|
20
src/main.c
20
src/main.c
|
@ -1,9 +1,21 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* main.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2018/10/23 20:36:18 by gtertysh #+# #+# */
|
||||||
|
/* Updated: 2018/10/23 20:39:16 by gtertysh ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "ft_ssl.h"
|
#include "ft_ssl.h"
|
||||||
#include "libft.h"
|
#include "libft.h"
|
||||||
|
|
||||||
static int find_flag(const char *expected, char *real)
|
static int find_flag(const char *expected, char *real)
|
||||||
{
|
{
|
||||||
return ft_strcmp(real, expected) == 0;
|
return (ft_strcmp(real, expected) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int process_flags(int argc, char **argv, t_ft_ssl *ft_ssl)
|
static int process_flags(int argc, char **argv, t_ft_ssl *ft_ssl)
|
||||||
|
@ -20,11 +32,12 @@ static int process_flags(int argc, char **argv, t_ft_ssl *ft_ssl)
|
||||||
else if (find_flag("-p", argv[i]))
|
else if (find_flag("-p", argv[i]))
|
||||||
ft_ssl->flags.print_stdin = 1;
|
ft_ssl->flags.print_stdin = 1;
|
||||||
else
|
else
|
||||||
break;
|
break ;
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
return i;
|
return (i);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void process_strings_and_files
|
static void process_strings_and_files
|
||||||
(
|
(
|
||||||
int i,
|
int i,
|
||||||
|
@ -46,6 +59,7 @@ static void process_strings_and_files
|
||||||
ft_ssl->process_file(argv[i++], ft_ssl);
|
ft_ssl->process_file(argv[i++], ft_ssl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
t_ft_ssl ft_ssl;
|
t_ft_ssl ft_ssl;
|
||||||
|
|
|
@ -1,19 +1,34 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_md5_decode.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2018/10/23 19:48:18 by gtertysh #+# #+# */
|
||||||
|
/* Updated: 2018/10/23 19:49:27 by gtertysh ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "ft_md5.h"
|
#include "ft_md5.h"
|
||||||
|
|
||||||
void ft_md5_decode(BYTE4 w[FT_MD5_WORDS_COUNT], BYTE1 b[FT_MD5_BLOCK_SIZE])
|
void ft_md5_decode
|
||||||
|
(
|
||||||
|
t_byte4 w[FT_MD5_WORDS_COUNT],
|
||||||
|
t_byte1 b[FT_MD5_BLOCK_SIZE]
|
||||||
|
)
|
||||||
{
|
{
|
||||||
BYTE8 i;
|
t_byte8 i;
|
||||||
BYTE8 j;
|
t_byte8 j;
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
j = 0;
|
j = 0;
|
||||||
|
|
||||||
while (j < FT_MD5_BLOCK_SIZE)
|
while (j < FT_MD5_BLOCK_SIZE)
|
||||||
{
|
{
|
||||||
w[i] = ((BYTE4)b[j]) |
|
w[i] = ((t_byte4)b[j]) |
|
||||||
(((BYTE4)b[j + 1]) << 8) |
|
(((t_byte4)b[j + 1]) << 8) |
|
||||||
(((BYTE4)b[j + 2]) << 16) |
|
(((t_byte4)b[j + 2]) << 16) |
|
||||||
(((BYTE4)b[j + 3]) << 24);
|
(((t_byte4)b[j + 3]) << 24);
|
||||||
i++;
|
i++;
|
||||||
j += 4;
|
j += 4;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,19 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_md5_digest_string.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2018/10/23 19:51:35 by gtertysh #+# #+# */
|
||||||
|
/* Updated: 2018/10/23 19:52:07 by gtertysh ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "ft_md5.h"
|
#include "ft_md5.h"
|
||||||
#include "libft.h"
|
#include "libft.h"
|
||||||
|
|
||||||
static void init_chars(BYTE1 chars[16])
|
static void init_chars(t_byte1 chars[16])
|
||||||
{
|
{
|
||||||
chars[0] = '0';
|
chars[0] = '0';
|
||||||
chars[1] = '1';
|
chars[1] = '1';
|
||||||
|
@ -21,17 +33,19 @@ static void init_chars(BYTE1 chars[16])
|
||||||
chars[15] = 'f';
|
chars[15] = 'f';
|
||||||
}
|
}
|
||||||
|
|
||||||
void ft_md5_digest_string(BYTE1 digest[FT_MD5_DIGEST_LENGTH_BYTE],
|
void ft_md5_digest_string
|
||||||
BYTE1 string[FT_MD5_STRING_SIZE_BYTE])
|
(
|
||||||
|
t_byte1 digest[FT_MD5_DIGEST_LENGTH_BYTE],
|
||||||
|
t_byte1 string[FT_MD5_STRING_SIZE_BYTE])
|
||||||
{
|
{
|
||||||
BYTE8 i;
|
t_byte8 i;
|
||||||
BYTE8 j;
|
t_byte8 j;
|
||||||
BYTE1 chars[16];
|
t_byte1 chars[16];
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
j = 0;
|
j = 0;
|
||||||
init_chars(chars);
|
init_chars(chars);
|
||||||
while(i < FT_MD5_DIGEST_LENGTH_BYTE)
|
while (i < FT_MD5_DIGEST_LENGTH_BYTE)
|
||||||
{
|
{
|
||||||
string[j] = chars[digest[i] / 16];
|
string[j] = chars[digest[i] / 16];
|
||||||
string[j + 1] = chars[digest[i] % 16];
|
string[j + 1] = chars[digest[i] % 16];
|
||||||
|
|
|
@ -1,13 +1,25 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_md5_encode_len.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2018/10/23 19:49:45 by gtertysh #+# #+# */
|
||||||
|
/* Updated: 2018/10/23 19:49:58 by gtertysh ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "ft_md5.h"
|
#include "ft_md5.h"
|
||||||
|
|
||||||
void ft_md5_encode_len(BYTE1 bits[FT_MD5_MESSAGE_LENGTH_BYTE], BYTE8 len)
|
void ft_md5_encode_len(t_byte1 bits[FT_MD5_MESSAGE_LENGTH_BYTE], t_byte8 len)
|
||||||
{
|
{
|
||||||
bits[0] = (BYTE1)(len & 0xff);
|
bits[0] = (t_byte1)(len & 0xff);
|
||||||
bits[1] = (BYTE1)(len >> 8 & 0xff);
|
bits[1] = (t_byte1)(len >> 8 & 0xff);
|
||||||
bits[2] = (BYTE1)(len >> 16 & 0xff);
|
bits[2] = (t_byte1)(len >> 16 & 0xff);
|
||||||
bits[3] = (BYTE1)(len >> 24 & 0xff);
|
bits[3] = (t_byte1)(len >> 24 & 0xff);
|
||||||
bits[4] = (BYTE1)(len >> 32 & 0xff);
|
bits[4] = (t_byte1)(len >> 32 & 0xff);
|
||||||
bits[5] = (BYTE1)(len >> 40 & 0xff);
|
bits[5] = (t_byte1)(len >> 40 & 0xff);
|
||||||
bits[6] = (BYTE1)(len >> 48 & 0xff);
|
bits[6] = (t_byte1)(len >> 48 & 0xff);
|
||||||
bits[7] = (BYTE1)(len >> 56 & 0xff);
|
bits[7] = (t_byte1)(len >> 56 & 0xff);
|
||||||
}
|
}
|
|
@ -1,9 +1,21 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_md5_encode_register.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2018/10/23 19:52:22 by gtertysh #+# #+# */
|
||||||
|
/* Updated: 2018/10/23 19:52:32 by gtertysh ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "ft_md5.h"
|
#include "ft_md5.h"
|
||||||
|
|
||||||
void ft_md5_encode_register(BYTE1 *digest_part, BYTE4 reg)
|
void ft_md5_encode_register(t_byte1 *digest_part, t_byte4 reg)
|
||||||
{
|
{
|
||||||
digest_part[0] = (BYTE1)(reg & 0xff);
|
digest_part[0] = (t_byte1)(reg & 0xff);
|
||||||
digest_part[1] = (BYTE1)(reg >> 8 & 0xff);
|
digest_part[1] = (t_byte1)(reg >> 8 & 0xff);
|
||||||
digest_part[2] = (BYTE1)(reg >> 16 & 0xff);
|
digest_part[2] = (t_byte1)(reg >> 16 & 0xff);
|
||||||
digest_part[3] = (BYTE1)(reg >> 24 & 0xff);
|
digest_part[3] = (t_byte1)(reg >> 24 & 0xff);
|
||||||
}
|
}
|
|
@ -1,17 +1,28 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_md5_final.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2018/10/23 19:50:09 by gtertysh #+# #+# */
|
||||||
|
/* Updated: 2018/10/23 19:50:25 by gtertysh ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "ft_md5.h"
|
#include "ft_md5.h"
|
||||||
#include "libft.h"
|
#include "libft.h"
|
||||||
|
|
||||||
void ft_md5_final(BYTE1 digest[FT_MD5_DIGEST_LENGTH_BYTE], t_md5_ctx *ctx)
|
void ft_md5_final(t_byte1 digest[FT_MD5_DIGEST_LENGTH_BYTE], t_md5_ctx *ctx)
|
||||||
{
|
{
|
||||||
BYTE1 length_as_bytes[FT_MD5_MESSAGE_LENGTH_BYTE];
|
t_byte1 length_as_bytes[FT_MD5_MESSAGE_LENGTH_BYTE];
|
||||||
BYTE1 padding[FT_MD5_BLOCK_SIZE];
|
t_byte1 padding[FT_MD5_BLOCK_SIZE];
|
||||||
BYTE8 buff_index;
|
t_byte8 buff_index;
|
||||||
BYTE8 padding_len;
|
t_byte8 padding_len;
|
||||||
|
|
||||||
ft_md5_encode_len(length_as_bytes, ctx->bit_len);
|
ft_md5_encode_len(length_as_bytes, ctx->bit_len);
|
||||||
buff_index = (ctx->bit_len / 8) % 64;
|
buff_index = (ctx->bit_len / 8) % 64;
|
||||||
padding_len = (buff_index < 56) ? (56 - buff_index) : (120 - buff_index);
|
padding_len = (buff_index < 56) ? (56 - buff_index) : (120 - buff_index);
|
||||||
|
|
||||||
ft_md5_padding(padding);
|
ft_md5_padding(padding);
|
||||||
ft_md5_update(ctx, padding, padding_len);
|
ft_md5_update(ctx, padding, padding_len);
|
||||||
ft_md5_update(ctx, length_as_bytes, FT_MD5_MESSAGE_LENGTH_BYTE);
|
ft_md5_update(ctx, length_as_bytes, FT_MD5_MESSAGE_LENGTH_BYTE);
|
||||||
|
|
|
@ -1,3 +1,15 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_md5_init.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2018/10/23 19:52:44 by gtertysh #+# #+# */
|
||||||
|
/* Updated: 2018/10/23 19:52:54 by gtertysh ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "ft_md5.h"
|
#include "ft_md5.h"
|
||||||
#include "libft.h"
|
#include "libft.h"
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,19 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_md5_padding.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2018/10/23 19:50:37 by gtertysh #+# #+# */
|
||||||
|
/* Updated: 2018/10/23 19:50:42 by gtertysh ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "ft_md5.h"
|
#include "ft_md5.h"
|
||||||
#include "libft.h"
|
#include "libft.h"
|
||||||
|
|
||||||
void ft_md5_padding(BYTE1 padding[FT_MD5_BLOCK_SIZE])
|
void ft_md5_padding(t_byte1 padding[FT_MD5_BLOCK_SIZE])
|
||||||
{
|
{
|
||||||
padding[0] = 0x80;
|
padding[0] = 0x80;
|
||||||
ft_bzero(&padding[1], FT_MD5_BLOCK_SIZE - 1);
|
ft_bzero(&padding[1], FT_MD5_BLOCK_SIZE - 1);
|
||||||
|
|
|
@ -1,97 +1,115 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_md5_transform.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2018/10/23 20:08:38 by gtertysh #+# #+# */
|
||||||
|
/* Updated: 2018/10/23 20:10:00 by gtertysh ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "ft_md5.h"
|
#include "ft_md5.h"
|
||||||
#include "libft.h"
|
#include "libft.h"
|
||||||
|
|
||||||
void ft_md5_transform(t_md5_ctx *ctx, BYTE1 block[FT_MD5_BLOCK_SIZE])
|
static void round_1(t_md5_intr_registers *r, t_byte4 w[FT_MD5_WORDS_COUNT])
|
||||||
{
|
{
|
||||||
BYTE4 words[FT_MD5_WORDS_COUNT];
|
FF(r->a, r->b, r->c, r->d, w[0], S11, 0xd76aa478);
|
||||||
BYTE4 a;
|
FF(r->d, r->a, r->b, r->c, w[1], S12, 0xe8c7b756);
|
||||||
BYTE4 b;
|
FF(r->c, r->d, r->a, r->b, w[2], S13, 0x242070db);
|
||||||
BYTE4 c;
|
FF(r->b, r->c, r->d, r->a, w[3], S14, 0xc1bdceee);
|
||||||
BYTE4 d;
|
FF(r->a, r->b, r->c, r->d, w[4], S11, 0xf57c0faf);
|
||||||
|
FF(r->d, r->a, r->b, r->c, w[5], S12, 0x4787c62a);
|
||||||
|
FF(r->c, r->d, r->a, r->b, w[6], S13, 0xa8304613);
|
||||||
|
FF(r->b, r->c, r->d, r->a, w[7], S14, 0xfd469501);
|
||||||
|
FF(r->a, r->b, r->c, r->d, w[8], S11, 0x698098d8);
|
||||||
|
FF(r->d, r->a, r->b, r->c, w[9], S12, 0x8b44f7af);
|
||||||
|
FF(r->c, r->d, r->a, r->b, w[10], S13, 0xffff5bb1);
|
||||||
|
FF(r->b, r->c, r->d, r->a, w[11], S14, 0x895cd7be);
|
||||||
|
FF(r->a, r->b, r->c, r->d, w[12], S11, 0x6b901122);
|
||||||
|
FF(r->d, r->a, r->b, r->c, w[13], S12, 0xfd987193);
|
||||||
|
FF(r->c, r->d, r->a, r->b, w[14], S13, 0xa679438e);
|
||||||
|
FF(r->b, r->c, r->d, r->a, w[15], S14, 0x49b40821);
|
||||||
|
}
|
||||||
|
|
||||||
a = ctx->a;
|
static void round_2(t_md5_intr_registers *r, t_byte4 w[FT_MD5_WORDS_COUNT])
|
||||||
b = ctx->b;
|
{
|
||||||
c = ctx->c;
|
GG(r->a, r->b, r->c, r->d, w[1], S21, 0xf61e2562);
|
||||||
d = ctx->d;
|
GG(r->d, r->a, r->b, r->c, w[6], S22, 0xc040b340);
|
||||||
|
GG(r->c, r->d, r->a, r->b, w[11], S23, 0x265e5a51);
|
||||||
|
GG(r->b, r->c, r->d, r->a, w[0], S24, 0xe9b6c7aa);
|
||||||
|
GG(r->a, r->b, r->c, r->d, w[5], S21, 0xd62f105d);
|
||||||
|
GG(r->d, r->a, r->b, r->c, w[10], S22, 0x2441453);
|
||||||
|
GG(r->c, r->d, r->a, r->b, w[15], S23, 0xd8a1e681);
|
||||||
|
GG(r->b, r->c, r->d, r->a, w[4], S24, 0xe7d3fbc8);
|
||||||
|
GG(r->a, r->b, r->c, r->d, w[9], S21, 0x21e1cde6);
|
||||||
|
GG(r->d, r->a, r->b, r->c, w[14], S22, 0xc33707d6);
|
||||||
|
GG(r->c, r->d, r->a, r->b, w[3], S23, 0xf4d50d87);
|
||||||
|
GG(r->b, r->c, r->d, r->a, w[8], S24, 0x455a14ed);
|
||||||
|
GG(r->a, r->b, r->c, r->d, w[13], S21, 0xa9e3e905);
|
||||||
|
GG(r->d, r->a, r->b, r->c, w[2], S22, 0xfcefa3f8);
|
||||||
|
GG(r->c, r->d, r->a, r->b, w[7], S23, 0x676f02d9);
|
||||||
|
GG(r->b, r->c, r->d, r->a, w[12], S24, 0x8d2a4c8a);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void round_3(t_md5_intr_registers *r, t_byte4 w[FT_MD5_WORDS_COUNT])
|
||||||
|
{
|
||||||
|
HH(r->a, r->b, r->c, r->d, w[5], S31, 0xfffa3942);
|
||||||
|
HH(r->d, r->a, r->b, r->c, w[8], S32, 0x8771f681);
|
||||||
|
HH(r->c, r->d, r->a, r->b, w[11], S33, 0x6d9d6122);
|
||||||
|
HH(r->b, r->c, r->d, r->a, w[14], S34, 0xfde5380c);
|
||||||
|
HH(r->a, r->b, r->c, r->d, w[1], S31, 0xa4beea44);
|
||||||
|
HH(r->d, r->a, r->b, r->c, w[4], S32, 0x4bdecfa9);
|
||||||
|
HH(r->c, r->d, r->a, r->b, w[7], S33, 0xf6bb4b60);
|
||||||
|
HH(r->b, r->c, r->d, r->a, w[10], S34, 0xbebfbc70);
|
||||||
|
HH(r->a, r->b, r->c, r->d, w[13], S31, 0x289b7ec6);
|
||||||
|
HH(r->d, r->a, r->b, r->c, w[0], S32, 0xeaa127fa);
|
||||||
|
HH(r->c, r->d, r->a, r->b, w[3], S33, 0xd4ef3085);
|
||||||
|
HH(r->b, r->c, r->d, r->a, w[6], S34, 0x4881d05);
|
||||||
|
HH(r->a, r->b, r->c, r->d, w[9], S31, 0xd9d4d039);
|
||||||
|
HH(r->d, r->a, r->b, r->c, w[12], S32, 0xe6db99e5);
|
||||||
|
HH(r->c, r->d, r->a, r->b, w[15], S33, 0x1fa27cf8);
|
||||||
|
HH(r->b, r->c, r->d, r->a, w[2], S34, 0xc4ac5665);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void round_4(t_md5_intr_registers *r, t_byte4 w[FT_MD5_WORDS_COUNT])
|
||||||
|
{
|
||||||
|
II(r->a, r->b, r->c, r->d, w[0], S41, 0xf4292244);
|
||||||
|
II(r->d, r->a, r->b, r->c, w[7], S42, 0x432aff97);
|
||||||
|
II(r->c, r->d, r->a, r->b, w[14], S43, 0xab9423a7);
|
||||||
|
II(r->b, r->c, r->d, r->a, w[5], S44, 0xfc93a039);
|
||||||
|
II(r->a, r->b, r->c, r->d, w[12], S41, 0x655b59c3);
|
||||||
|
II(r->d, r->a, r->b, r->c, w[3], S42, 0x8f0ccc92);
|
||||||
|
II(r->c, r->d, r->a, r->b, w[10], S43, 0xffeff47d);
|
||||||
|
II(r->b, r->c, r->d, r->a, w[1], S44, 0x85845dd1);
|
||||||
|
II(r->a, r->b, r->c, r->d, w[8], S41, 0x6fa87e4f);
|
||||||
|
II(r->d, r->a, r->b, r->c, w[15], S42, 0xfe2ce6e0);
|
||||||
|
II(r->c, r->d, r->a, r->b, w[6], S43, 0xa3014314);
|
||||||
|
II(r->b, r->c, r->d, r->a, w[13], S44, 0x4e0811a1);
|
||||||
|
II(r->a, r->b, r->c, r->d, w[4], S41, 0xf7537e82);
|
||||||
|
II(r->d, r->a, r->b, r->c, w[11], S42, 0xbd3af235);
|
||||||
|
II(r->c, r->d, r->a, r->b, w[2], S43, 0x2ad7d2bb);
|
||||||
|
II(r->b, r->c, r->d, r->a, w[9], S44, 0xeb86d391);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ft_md5_transform(t_md5_ctx *ctx, t_byte1 block[FT_MD5_BLOCK_SIZE])
|
||||||
|
{
|
||||||
|
t_byte4 words[FT_MD5_WORDS_COUNT];
|
||||||
|
t_md5_intr_registers t;
|
||||||
|
|
||||||
ft_md5_decode(words, block);
|
ft_md5_decode(words, block);
|
||||||
|
t.a = ctx->a;
|
||||||
/* Round 1 */
|
t.b = ctx->b;
|
||||||
FF(a, b, c, d, words[0], S11, 0xd76aa478); /* 1 */
|
t.c = ctx->c;
|
||||||
FF(d, a, b, c, words[1], S12, 0xe8c7b756); /* 2 */
|
t.d = ctx->d;
|
||||||
FF(c, d, a, b, words[2], S13, 0x242070db); /* 3 */
|
round_1(&t, words);
|
||||||
FF(b, c, d, a, words[3], S14, 0xc1bdceee); /* 4 */
|
round_2(&t, words);
|
||||||
FF(a, b, c, d, words[4], S11, 0xf57c0faf); /* 5 */
|
round_3(&t, words);
|
||||||
FF(d, a, b, c, words[5], S12, 0x4787c62a); /* 6 */
|
round_4(&t, words);
|
||||||
FF(c, d, a, b, words[6], S13, 0xa8304613); /* 7 */
|
ctx->a += t.a;
|
||||||
FF(b, c, d, a, words[7], S14, 0xfd469501); /* 8 */
|
ctx->b += t.b;
|
||||||
FF(a, b, c, d, words[8], S11, 0x698098d8); /* 9 */
|
ctx->c += t.c;
|
||||||
FF(d, a, b, c, words[9], S12, 0x8b44f7af); /* 10 */
|
ctx->d += t.d;
|
||||||
FF(c, d, a, b, words[10], S13, 0xffff5bb1); /* 11 */
|
|
||||||
FF(b, c, d, a, words[11], S14, 0x895cd7be); /* 12 */
|
|
||||||
FF(a, b, c, d, words[12], S11, 0x6b901122); /* 13 */
|
|
||||||
FF(d, a, b, c, words[13], S12, 0xfd987193); /* 14 */
|
|
||||||
FF(c, d, a, b, words[14], S13, 0xa679438e); /* 15 */
|
|
||||||
FF(b, c, d, a, words[15], S14, 0x49b40821); /* 16 */
|
|
||||||
|
|
||||||
/* Round 2 */
|
|
||||||
GG(a, b, c, d, words[1], S21, 0xf61e2562); /* 17 */
|
|
||||||
GG(d, a, b, c, words[6], S22, 0xc040b340); /* 18 */
|
|
||||||
GG(c, d, a, b, words[11], S23, 0x265e5a51); /* 19 */
|
|
||||||
GG(b, c, d, a, words[0], S24, 0xe9b6c7aa); /* 20 */
|
|
||||||
GG(a, b, c, d, words[5], S21, 0xd62f105d); /* 21 */
|
|
||||||
GG(d, a, b, c, words[10], S22, 0x2441453); /* 22 */
|
|
||||||
GG(c, d, a, b, words[15], S23, 0xd8a1e681); /* 23 */
|
|
||||||
GG(b, c, d, a, words[4], S24, 0xe7d3fbc8); /* 24 */
|
|
||||||
GG(a, b, c, d, words[9], S21, 0x21e1cde6); /* 25 */
|
|
||||||
GG(d, a, b, c, words[14], S22, 0xc33707d6); /* 26 */
|
|
||||||
GG(c, d, a, b, words[3], S23, 0xf4d50d87); /* 27 */
|
|
||||||
GG(b, c, d, a, words[8], S24, 0x455a14ed); /* 28 */
|
|
||||||
GG(a, b, c, d, words[13], S21, 0xa9e3e905); /* 29 */
|
|
||||||
GG(d, a, b, c, words[2], S22, 0xfcefa3f8); /* 30 */
|
|
||||||
GG(c, d, a, b, words[7], S23, 0x676f02d9); /* 31 */
|
|
||||||
GG(b, c, d, a, words[12], S24, 0x8d2a4c8a); /* 32 */
|
|
||||||
|
|
||||||
/* Round 3 */
|
|
||||||
HH(a, b, c, d, words[5], S31, 0xfffa3942); /* 33 */
|
|
||||||
HH(d, a, b, c, words[8], S32, 0x8771f681); /* 34 */
|
|
||||||
HH(c, d, a, b, words[11], S33, 0x6d9d6122); /* 35 */
|
|
||||||
HH(b, c, d, a, words[14], S34, 0xfde5380c); /* 36 */
|
|
||||||
HH(a, b, c, d, words[1], S31, 0xa4beea44); /* 37 */
|
|
||||||
HH(d, a, b, c, words[4], S32, 0x4bdecfa9); /* 38 */
|
|
||||||
HH(c, d, a, b, words[7], S33, 0xf6bb4b60); /* 39 */
|
|
||||||
HH(b, c, d, a, words[10], S34, 0xbebfbc70); /* 40 */
|
|
||||||
HH(a, b, c, d, words[13], S31, 0x289b7ec6); /* 41 */
|
|
||||||
HH(d, a, b, c, words[0], S32, 0xeaa127fa); /* 42 */
|
|
||||||
HH(c, d, a, b, words[3], S33, 0xd4ef3085); /* 43 */
|
|
||||||
HH(b, c, d, a, words[6], S34, 0x4881d05); /* 44 */
|
|
||||||
HH(a, b, c, d, words[9], S31, 0xd9d4d039); /* 45 */
|
|
||||||
HH(d, a, b, c, words[12], S32, 0xe6db99e5); /* 46 */
|
|
||||||
HH(c, d, a, b, words[15], S33, 0x1fa27cf8); /* 47 */
|
|
||||||
HH(b, c, d, a, words[2], S34, 0xc4ac5665); /* 48 */
|
|
||||||
|
|
||||||
/* Round 4 */
|
|
||||||
II(a, b, c, d, words[0], S41, 0xf4292244); /* 49 */
|
|
||||||
II(d, a, b, c, words[7], S42, 0x432aff97); /* 50 */
|
|
||||||
II(c, d, a, b, words[14], S43, 0xab9423a7); /* 51 */
|
|
||||||
II(b, c, d, a, words[5], S44, 0xfc93a039); /* 52 */
|
|
||||||
II(a, b, c, d, words[12], S41, 0x655b59c3); /* 53 */
|
|
||||||
II(d, a, b, c, words[3], S42, 0x8f0ccc92); /* 54 */
|
|
||||||
II(c, d, a, b, words[10], S43, 0xffeff47d); /* 55 */
|
|
||||||
II(b, c, d, a, words[1], S44, 0x85845dd1); /* 56 */
|
|
||||||
II(a, b, c, d, words[8], S41, 0x6fa87e4f); /* 57 */
|
|
||||||
II(d, a, b, c, words[15], S42, 0xfe2ce6e0); /* 58 */
|
|
||||||
II(c, d, a, b, words[6], S43, 0xa3014314); /* 59 */
|
|
||||||
II(b, c, d, a, words[13], S44, 0x4e0811a1); /* 60 */
|
|
||||||
II(a, b, c, d, words[4], S41, 0xf7537e82); /* 61 */
|
|
||||||
II(d, a, b, c, words[11], S42, 0xbd3af235); /* 62 */
|
|
||||||
II(c, d, a, b, words[2], S43, 0x2ad7d2bb); /* 63 */
|
|
||||||
II(b, c, d, a, words[9], S44, 0xeb86d391); /* 64 */
|
|
||||||
|
|
||||||
ctx->a += a;
|
|
||||||
ctx->b += b;
|
|
||||||
ctx->c += c;
|
|
||||||
ctx->d += d;
|
|
||||||
/* Zeroize sensitive information.*/
|
|
||||||
ft_bzero(words, sizeof(words));
|
ft_bzero(words, sizeof(words));
|
||||||
}
|
}
|
|
@ -1,7 +1,19 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_md5_update.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2018/10/23 19:50:54 by gtertysh #+# #+# */
|
||||||
|
/* Updated: 2018/10/23 19:51:24 by gtertysh ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "ft_md5.h"
|
#include "ft_md5.h"
|
||||||
#include "libft.h"
|
#include "libft.h"
|
||||||
|
|
||||||
void ft_md5_update(t_md5_ctx *c, BYTE1 * message, BYTE8 message_len)
|
void ft_md5_update(t_md5_ctx *c, t_byte1 *message, t_byte8 message_len)
|
||||||
{
|
{
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
unsigned int part_block_len;
|
unsigned int part_block_len;
|
||||||
|
@ -15,7 +27,7 @@ void ft_md5_update(t_md5_ctx *c, BYTE1 * message, BYTE8 message_len)
|
||||||
ft_memcpy(&c->block[curent_block_index], message, part_block_len);
|
ft_memcpy(&c->block[curent_block_index], message, part_block_len);
|
||||||
ft_md5_transform(c, c->block);
|
ft_md5_transform(c, c->block);
|
||||||
i = part_block_len;
|
i = part_block_len;
|
||||||
while(i + 63 < message_len)
|
while (i + 63 < message_len)
|
||||||
{
|
{
|
||||||
ft_md5_transform(c, &message[i]);
|
ft_md5_transform(c, &message[i]);
|
||||||
i += FT_MD5_BLOCK_SIZE;
|
i += FT_MD5_BLOCK_SIZE;
|
||||||
|
|
|
@ -1,6 +1,18 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_sha224_digest_string.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2018/10/23 20:10:41 by gtertysh #+# #+# */
|
||||||
|
/* Updated: 2018/10/23 20:10:54 by gtertysh ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "ft_sha.h"
|
#include "ft_sha.h"
|
||||||
|
|
||||||
static void init_chars(BYTE1 chars[16])
|
static void init_chars(t_byte1 chars[16])
|
||||||
{
|
{
|
||||||
chars[0] = '0';
|
chars[0] = '0';
|
||||||
chars[1] = '1';
|
chars[1] = '1';
|
||||||
|
@ -22,12 +34,12 @@ static void init_chars(BYTE1 chars[16])
|
||||||
|
|
||||||
void ft_sha224_digest_string
|
void ft_sha224_digest_string
|
||||||
(
|
(
|
||||||
BYTE1 digest[FT_SHA224_DIGEST_LENGTH_BYTE],
|
t_byte1 digest[FT_SHA224_DIGEST_LENGTH_BYTE],
|
||||||
BYTE1 string[FT_SHA224_STRING_SIZE_BYTE])
|
t_byte1 string[FT_SHA224_STRING_SIZE_BYTE])
|
||||||
{
|
{
|
||||||
BYTE8 i;
|
t_byte8 i;
|
||||||
BYTE8 j;
|
t_byte8 j;
|
||||||
BYTE1 chars[16];
|
t_byte1 chars[16];
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
j = 0;
|
j = 0;
|
||||||
|
|
|
@ -1,8 +1,20 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_sha224_final.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2018/10/23 20:11:43 by gtertysh #+# #+# */
|
||||||
|
/* Updated: 2018/10/23 20:11:47 by gtertysh ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "ft_sha.h"
|
#include "ft_sha.h"
|
||||||
|
|
||||||
void ft_sha224_final
|
void ft_sha224_final
|
||||||
(
|
(
|
||||||
BYTE1 digest[FT_SHA256_DIGEST_LENGTH_BYTE],
|
t_byte1 digest[FT_SHA256_DIGEST_LENGTH_BYTE],
|
||||||
t_sha256_ctx *ctx
|
t_sha256_ctx *ctx
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,3 +1,15 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_sha224_init.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2018/10/23 20:12:17 by gtertysh #+# #+# */
|
||||||
|
/* Updated: 2018/10/23 20:12:31 by gtertysh ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "ft_sha.h"
|
#include "ft_sha.h"
|
||||||
#include "libft.h"
|
#include "libft.h"
|
||||||
|
|
||||||
|
@ -11,7 +23,6 @@ void ft_sha224_init(t_sha256_ctx *ctx)
|
||||||
ctx->f = 0x68581511;
|
ctx->f = 0x68581511;
|
||||||
ctx->g = 0x64f98fa7;
|
ctx->g = 0x64f98fa7;
|
||||||
ctx->h = 0xbefa4fa4;
|
ctx->h = 0xbefa4fa4;
|
||||||
|
|
||||||
ctx->bit_len = 0;
|
ctx->bit_len = 0;
|
||||||
ft_bzero(ctx->block, FT_SHA256_BLOCK_SIZE);
|
ft_bzero(ctx->block, FT_SHA256_BLOCK_SIZE);
|
||||||
}
|
}
|
|
@ -1,6 +1,18 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_sha224_update.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2018/10/23 20:12:58 by gtertysh #+# #+# */
|
||||||
|
/* Updated: 2018/10/23 20:13:00 by gtertysh ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "ft_sha.h"
|
#include "ft_sha.h"
|
||||||
|
|
||||||
void ft_sha224_update(t_sha256_ctx *ctx, BYTE1 *message, BYTE8 len)
|
void ft_sha224_update(t_sha256_ctx *ctx, t_byte1 *message, t_byte8 len)
|
||||||
{
|
{
|
||||||
ft_sha256_update(ctx, message, len);
|
ft_sha256_update(ctx, message, len);
|
||||||
}
|
}
|
|
@ -1,8 +1,20 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_sha256_constants.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2018/10/23 20:13:18 by gtertysh #+# #+# */
|
||||||
|
/* Updated: 2018/10/23 20:13:41 by gtertysh ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "ft_sha.h"
|
#include "ft_sha.h"
|
||||||
|
|
||||||
BYTE4 *ft_sha256_constants(void)
|
t_byte4 *ft_sha256_constants(void)
|
||||||
{
|
{
|
||||||
static BYTE4 k[FT_SHA256_BLOCK_SIZE] = {
|
static t_byte4 k[FT_SHA256_BLOCK_SIZE] = {
|
||||||
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b,
|
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b,
|
||||||
0x59f111f1, 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01,
|
0x59f111f1, 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01,
|
||||||
0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7,
|
0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7,
|
||||||
|
@ -17,5 +29,5 @@ BYTE4 *ft_sha256_constants(void)
|
||||||
0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
|
0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
|
||||||
0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2};
|
0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2};
|
||||||
|
|
||||||
return k;
|
return (k);
|
||||||
}
|
}
|
|
@ -1,23 +1,34 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_sha256_decode.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2018/10/23 20:13:59 by gtertysh #+# #+# */
|
||||||
|
/* Updated: 2018/10/23 20:14:28 by gtertysh ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "ft_sha.h"
|
#include "ft_sha.h"
|
||||||
|
|
||||||
void ft_sha256_decode
|
void ft_sha256_decode
|
||||||
(
|
(
|
||||||
BYTE4 w[FT_SHA256_WORDS_COUNT],
|
t_byte4 w[FT_SHA256_WORDS_COUNT],
|
||||||
BYTE1 b[FT_SHA256_BLOCK_SIZE]
|
t_byte1 b[FT_SHA256_BLOCK_SIZE]
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
BYTE8 i;
|
t_byte8 i;
|
||||||
BYTE8 j;
|
t_byte8 j;
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
j = 0;
|
j = 0;
|
||||||
|
|
||||||
while (i < FT_SHA256_WORDS_COUNT)
|
while (i < FT_SHA256_WORDS_COUNT)
|
||||||
{
|
{
|
||||||
w[i] = ((((BYTE4)b[j]) << 24) |
|
w[i] = ((((t_byte4)b[j]) << 24) |
|
||||||
(((BYTE4)b[j + 1]) << 16) |
|
(((t_byte4)b[j + 1]) << 16) |
|
||||||
(((BYTE4)b[j + 2]) << 8) |
|
(((t_byte4)b[j + 2]) << 8) |
|
||||||
((BYTE4)b[j + 3]));
|
((t_byte4)b[j + 3]));
|
||||||
i++;
|
i++;
|
||||||
j += 4;
|
j += 4;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,18 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_sha256_digest_string.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2018/10/23 20:14:41 by gtertysh #+# #+# */
|
||||||
|
/* Updated: 2018/10/23 20:14:53 by gtertysh ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "ft_sha.h"
|
#include "ft_sha.h"
|
||||||
|
|
||||||
static void init_chars(BYTE1 chars[16])
|
static void init_chars(t_byte1 chars[16])
|
||||||
{
|
{
|
||||||
chars[0] = '0';
|
chars[0] = '0';
|
||||||
chars[1] = '1';
|
chars[1] = '1';
|
||||||
|
@ -22,13 +34,13 @@ static void init_chars(BYTE1 chars[16])
|
||||||
|
|
||||||
void ft_sha256_digest_string
|
void ft_sha256_digest_string
|
||||||
(
|
(
|
||||||
BYTE1 digest[FT_SHA256_DIGEST_LENGTH_BYTE],
|
t_byte1 digest[FT_SHA256_DIGEST_LENGTH_BYTE],
|
||||||
BYTE1 string[FT_SHA256_STRING_SIZE_BYTE]
|
t_byte1 string[FT_SHA256_STRING_SIZE_BYTE]
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
BYTE8 i;
|
t_byte8 i;
|
||||||
BYTE8 j;
|
t_byte8 j;
|
||||||
BYTE1 chars[16];
|
t_byte1 chars[16];
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
j = 0;
|
j = 0;
|
||||||
|
|
|
@ -1,13 +1,29 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_sha256_encode_len.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2018/10/23 20:15:16 by gtertysh #+# #+# */
|
||||||
|
/* Updated: 2018/10/23 20:15:34 by gtertysh ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "ft_sha.h"
|
#include "ft_sha.h"
|
||||||
|
|
||||||
void ft_sha256_encode_len(BYTE1 b[FT_SHA256_MESSAGE_LENGTH_BYTE], BYTE8 len)
|
void ft_sha256_encode_len
|
||||||
|
(
|
||||||
|
t_byte1 b[FT_SHA256_MESSAGE_LENGTH_BYTE],
|
||||||
|
t_byte8 len
|
||||||
|
)
|
||||||
{
|
{
|
||||||
b[7] = (BYTE1)(len & 0xff);
|
b[7] = (t_byte1)(len & 0xff);
|
||||||
b[6] = (BYTE1)(len >> 8 & 0xff);
|
b[6] = (t_byte1)(len >> 8 & 0xff);
|
||||||
b[5] = (BYTE1)(len >> 16 & 0xff);
|
b[5] = (t_byte1)(len >> 16 & 0xff);
|
||||||
b[4] = (BYTE1)(len >> 24 & 0xff);
|
b[4] = (t_byte1)(len >> 24 & 0xff);
|
||||||
b[3] = (BYTE1)(len >> 32 & 0xff);
|
b[3] = (t_byte1)(len >> 32 & 0xff);
|
||||||
b[2] = (BYTE1)(len >> 40 & 0xff);
|
b[2] = (t_byte1)(len >> 40 & 0xff);
|
||||||
b[1] = (BYTE1)(len >> 48 & 0xff);
|
b[1] = (t_byte1)(len >> 48 & 0xff);
|
||||||
b[0] = (BYTE1)(len >> 56 & 0xff);
|
b[0] = (t_byte1)(len >> 56 & 0xff);
|
||||||
}
|
}
|
|
@ -1,9 +1,21 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_sha256_encode_register.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2018/10/23 20:15:49 by gtertysh #+# #+# */
|
||||||
|
/* Updated: 2018/10/23 20:15:52 by gtertysh ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "ft_sha.h"
|
#include "ft_sha.h"
|
||||||
|
|
||||||
void ft_sha256_encode_register
|
void ft_sha256_encode_register
|
||||||
(
|
(
|
||||||
BYTE1 digest_part[FT_SHA256_REG_SIZE_BYTE],
|
t_byte1 digest_part[FT_SHA256_REG_SIZE_BYTE],
|
||||||
BYTE4 reg
|
t_byte4 reg
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
digest_part[0] = reg >> 24 & 0xff;
|
digest_part[0] = reg >> 24 & 0xff;
|
||||||
|
|
|
@ -1,9 +1,21 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_sha256_final.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2018/10/23 20:16:08 by gtertysh #+# #+# */
|
||||||
|
/* Updated: 2018/10/23 20:16:26 by gtertysh ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "ft_sha.h"
|
#include "ft_sha.h"
|
||||||
#include "libft.h"
|
#include "libft.h"
|
||||||
|
|
||||||
static void fill_digest
|
static void fill_digest
|
||||||
(
|
(
|
||||||
BYTE1 digest[FT_SHA256_DIGEST_LENGTH_BYTE],
|
t_byte1 digest[FT_SHA256_DIGEST_LENGTH_BYTE],
|
||||||
t_sha256_ctx *ctx
|
t_sha256_ctx *ctx
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
@ -19,19 +31,18 @@ static void fill_digest
|
||||||
|
|
||||||
void ft_sha256_final
|
void ft_sha256_final
|
||||||
(
|
(
|
||||||
BYTE1 digest[FT_SHA256_DIGEST_LENGTH_BYTE],
|
t_byte1 digest[FT_SHA256_DIGEST_LENGTH_BYTE],
|
||||||
t_sha256_ctx *ctx
|
t_sha256_ctx *ctx
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
BYTE1 length_as_bytes[FT_SHA256_MESSAGE_LENGTH_BYTE];
|
t_byte1 length_as_bytes[FT_SHA256_MESSAGE_LENGTH_BYTE];
|
||||||
BYTE1 padding[FT_SHA256_BLOCK_SIZE];
|
t_byte1 padding[FT_SHA256_BLOCK_SIZE];
|
||||||
BYTE8 buff_index;
|
t_byte8 buff_index;
|
||||||
BYTE8 padding_len;
|
t_byte8 padding_len;
|
||||||
|
|
||||||
ft_sha256_encode_len(length_as_bytes, ctx->bit_len);
|
ft_sha256_encode_len(length_as_bytes, ctx->bit_len);
|
||||||
buff_index = (ctx->bit_len / 8) % 64;
|
buff_index = (ctx->bit_len / 8) % 64;
|
||||||
padding_len = (buff_index < 56) ? (56 - buff_index) : (120 - buff_index);
|
padding_len = (buff_index < 56) ? (56 - buff_index) : (120 - buff_index);
|
||||||
|
|
||||||
ft_sha256_padding(padding);
|
ft_sha256_padding(padding);
|
||||||
ft_sha256_update(ctx, padding, padding_len);
|
ft_sha256_update(ctx, padding, padding_len);
|
||||||
ft_sha256_update(ctx, length_as_bytes, FT_SHA256_MESSAGE_LENGTH_BYTE);
|
ft_sha256_update(ctx, length_as_bytes, FT_SHA256_MESSAGE_LENGTH_BYTE);
|
||||||
|
|
|
@ -1,3 +1,15 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_sha256_init.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2018/10/23 20:16:36 by gtertysh #+# #+# */
|
||||||
|
/* Updated: 2018/10/23 20:16:47 by gtertysh ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "ft_sha.h"
|
#include "ft_sha.h"
|
||||||
#include "libft.h"
|
#include "libft.h"
|
||||||
|
|
||||||
|
@ -11,7 +23,6 @@ void ft_sha256_init(t_sha256_ctx *ctx)
|
||||||
ctx->f = 0x9b05688c;
|
ctx->f = 0x9b05688c;
|
||||||
ctx->g = 0x1f83d9ab;
|
ctx->g = 0x1f83d9ab;
|
||||||
ctx->h = 0x5be0cd19;
|
ctx->h = 0x5be0cd19;
|
||||||
|
|
||||||
ctx->bit_len = 0;
|
ctx->bit_len = 0;
|
||||||
ft_bzero(ctx->block, FT_SHA256_BLOCK_SIZE);
|
ft_bzero(ctx->block, FT_SHA256_BLOCK_SIZE);
|
||||||
}
|
}
|
|
@ -1,7 +1,19 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_sha256_padding.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2018/10/23 20:16:55 by gtertysh #+# #+# */
|
||||||
|
/* Updated: 2018/10/23 20:17:00 by gtertysh ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "ft_sha.h"
|
#include "ft_sha.h"
|
||||||
#include "libft.h"
|
#include "libft.h"
|
||||||
|
|
||||||
void ft_sha256_padding(BYTE1 padding[FT_SHA256_BLOCK_SIZE])
|
void ft_sha256_padding(t_byte1 padding[FT_SHA256_BLOCK_SIZE])
|
||||||
{
|
{
|
||||||
padding[0] = 0x80;
|
padding[0] = 0x80;
|
||||||
ft_bzero(&padding[1], FT_SHA256_BLOCK_SIZE - 1);
|
ft_bzero(&padding[1], FT_SHA256_BLOCK_SIZE - 1);
|
||||||
|
|
|
@ -1,19 +1,38 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_sha256_transform.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2018/10/23 20:17:19 by gtertysh #+# #+# */
|
||||||
|
/* Updated: 2018/10/23 20:20:10 by gtertysh ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "ft_sha.h"
|
#include "ft_sha.h"
|
||||||
|
|
||||||
static void fill_up_words(BYTE4 w[FT_SHA256_BLOCK_SIZE])
|
static void fill_up_words
|
||||||
|
(
|
||||||
|
t_byte4 w[FT_SHA256_BLOCK_SIZE]
|
||||||
|
)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
i = 16;
|
i = 16;
|
||||||
while (i < FT_SHA256_BLOCK_SIZE)
|
while (i < FT_SHA256_BLOCK_SIZE)
|
||||||
{
|
{
|
||||||
w[i] = SHA256_sigma1(w[i - 2]) + w[i - 7] +
|
w[i] = SHA256_SIG1(w[i - 2]) + w[i - 7] +
|
||||||
SHA256_sigma0(w[i - 15]) + w[i - 16];
|
SHA256_SIG0(w[i - 15]) + w[i - 16];
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void copy_from_registers(t_sha256_ctx *from, t_temp_registers *to)
|
static void copy_from_registers
|
||||||
|
(
|
||||||
|
t_sha256_ctx *from,
|
||||||
|
t_temp_registers *to
|
||||||
|
)
|
||||||
{
|
{
|
||||||
to->a = from->a;
|
to->a = from->a;
|
||||||
to->b = from->b;
|
to->b = from->b;
|
||||||
|
@ -25,7 +44,11 @@ static void copy_from_registers(t_sha256_ctx *from, t_temp_registers *to)
|
||||||
to->h = from->h;
|
to->h = from->h;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void add_to_registers(t_temp_registers *from, t_sha256_ctx *to)
|
static void add_to_registers
|
||||||
|
(
|
||||||
|
t_temp_registers *from,
|
||||||
|
t_sha256_ctx *to
|
||||||
|
)
|
||||||
{
|
{
|
||||||
to->a += from->a;
|
to->a += from->a;
|
||||||
to->b += from->b;
|
to->b += from->b;
|
||||||
|
@ -40,20 +63,21 @@ static void add_to_registers(t_temp_registers *from, t_sha256_ctx *to)
|
||||||
static void main_transform_loop
|
static void main_transform_loop
|
||||||
(
|
(
|
||||||
t_temp_registers *tr,
|
t_temp_registers *tr,
|
||||||
BYTE4 w[FT_SHA256_BLOCK_SIZE]
|
t_byte4 w[FT_SHA256_BLOCK_SIZE]
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
BYTE4 temp1, temp2;
|
t_byte4 temp1;
|
||||||
BYTE4 *k;
|
t_byte4 temp2;
|
||||||
|
t_byte4 *k;
|
||||||
|
|
||||||
k = ft_sha256_constants();
|
k = ft_sha256_constants();
|
||||||
i = 0;
|
i = 0;
|
||||||
while (i < FT_SHA256_BLOCK_SIZE)
|
while (i < FT_SHA256_BLOCK_SIZE)
|
||||||
{
|
{
|
||||||
temp1 = tr->h + SHA256_SIGMA1(tr->e) +
|
temp1 = tr->h + SHA256_SIGMA1(tr->e) +
|
||||||
SHA_Ch(tr->e, tr->f, tr->g) + k[i] + w[i];
|
SHA_CH(tr->e, tr->f, tr->g) + k[i] + w[i];
|
||||||
temp2 = SHA256_SIGMA0(tr->a) + SHA_Maj(tr->a, tr->b, tr->c);
|
temp2 = SHA256_SIGMA0(tr->a) + SHA_MAJ(tr->a, tr->b, tr->c);
|
||||||
tr->h = tr->g;
|
tr->h = tr->g;
|
||||||
tr->g = tr->f;
|
tr->g = tr->f;
|
||||||
tr->f = tr->e;
|
tr->f = tr->e;
|
||||||
|
@ -66,9 +90,13 @@ static void main_transform_loop
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ft_sha256_transform(t_sha256_ctx *c, BYTE1 block[FT_SHA256_BLOCK_SIZE])
|
void ft_sha256_transform
|
||||||
|
(
|
||||||
|
t_sha256_ctx *c,
|
||||||
|
t_byte1 block[FT_SHA256_BLOCK_SIZE]
|
||||||
|
)
|
||||||
{
|
{
|
||||||
BYTE4 w[FT_SHA256_BLOCK_SIZE];
|
t_byte4 w[FT_SHA256_BLOCK_SIZE];
|
||||||
t_temp_registers tr;
|
t_temp_registers tr;
|
||||||
|
|
||||||
ft_sha256_decode(w, block);
|
ft_sha256_decode(w, block);
|
||||||
|
|
|
@ -1,7 +1,19 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_sha256_update.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2018/10/23 20:20:53 by gtertysh #+# #+# */
|
||||||
|
/* Updated: 2018/10/23 20:21:00 by gtertysh ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "ft_sha.h"
|
#include "ft_sha.h"
|
||||||
#include "libft.h"
|
#include "libft.h"
|
||||||
|
|
||||||
void ft_sha256_update(t_sha256_ctx *c, BYTE1 *message, BYTE8 message_len)
|
void ft_sha256_update(t_sha256_ctx *c, t_byte1 *message, t_byte8 message_len)
|
||||||
{
|
{
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
unsigned int part_block_len;
|
unsigned int part_block_len;
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#include "tests.h"
|
#include "tests.h"
|
||||||
|
#include "tests_macros.h"
|
||||||
#include "ft_md5.h"
|
#include "ft_md5.h"
|
||||||
#include "libft.h"
|
#include "libft.h"
|
||||||
|
|
||||||
|
@ -26,8 +27,8 @@ TEST_RESULT decode_string_to_int(TEST_PARAMS, TEST_DATA)
|
||||||
UNUSED(test_params);
|
UNUSED(test_params);
|
||||||
UNUSED(test_data);
|
UNUSED(test_data);
|
||||||
|
|
||||||
BYTE1 block[FT_MD5_BLOCK_SIZE];
|
t_byte1 block[FT_MD5_BLOCK_SIZE];
|
||||||
BYTE4 words[FT_MD5_WORDS_COUNT];
|
t_byte4 words[FT_MD5_WORDS_COUNT];
|
||||||
|
|
||||||
ft_bzero(block, FT_MD5_BLOCK_SIZE);
|
ft_bzero(block, FT_MD5_BLOCK_SIZE);
|
||||||
block[0] = 'a';
|
block[0] = 'a';
|
||||||
|
@ -49,10 +50,10 @@ TEST_RESULT update_should_change_count(TEST_PARAMS, TEST_DATA)
|
||||||
UNUSED(test_data);
|
UNUSED(test_data);
|
||||||
t_md5_ctx ctx;
|
t_md5_ctx ctx;
|
||||||
char message[] = "hello, World!";
|
char message[] = "hello, World!";
|
||||||
BYTE8 size = ft_strlen(message);
|
t_byte8 size = ft_strlen(message);
|
||||||
|
|
||||||
ft_md5_init(&ctx);
|
ft_md5_init(&ctx);
|
||||||
ft_md5_update(&ctx, (BYTE1 *)message, size);
|
ft_md5_update(&ctx, (t_byte1 *)message, size);
|
||||||
|
|
||||||
munit_assert_true(size * 8 == ctx.bit_len);
|
munit_assert_true(size * 8 == ctx.bit_len);
|
||||||
|
|
||||||
|
@ -64,8 +65,8 @@ TEST_RESULT encode_bits_to_string(TEST_PARAMS, TEST_DATA)
|
||||||
UNUSED(test_params);
|
UNUSED(test_params);
|
||||||
UNUSED(test_data);
|
UNUSED(test_data);
|
||||||
|
|
||||||
BYTE8 len;
|
t_byte8 len;
|
||||||
BYTE1 bits[FT_MD5_MESSAGE_LENGTH_BYTE];
|
t_byte1 bits[FT_MD5_MESSAGE_LENGTH_BYTE];
|
||||||
|
|
||||||
/*
|
/*
|
||||||
1111 0000 : 63 - 56
|
1111 0000 : 63 - 56
|
||||||
|
@ -81,9 +82,9 @@ TEST_RESULT encode_bits_to_string(TEST_PARAMS, TEST_DATA)
|
||||||
|
|
||||||
ft_md5_encode_len(bits, len);
|
ft_md5_encode_len(bits, len);
|
||||||
|
|
||||||
munit_assert_true(bits[7] == (BYTE1)((len >> 56) & 0xff));
|
munit_assert_true(bits[7] == (t_byte1)((len >> 56) & 0xff));
|
||||||
munit_assert_true(bits[0] == (BYTE1)(len & 0xff));
|
munit_assert_true(bits[0] == (t_byte1)(len & 0xff));
|
||||||
munit_assert_true(bits[1] == (BYTE1)((len >> 8) & 0xff));
|
munit_assert_true(bits[1] == (t_byte1)((len >> 8) & 0xff));
|
||||||
|
|
||||||
return MUNIT_OK;
|
return MUNIT_OK;
|
||||||
}
|
}
|
||||||
|
@ -93,8 +94,8 @@ TEST_RESULT encode_register(TEST_PARAMS, TEST_DATA)
|
||||||
UNUSED(test_params);
|
UNUSED(test_params);
|
||||||
UNUSED(test_data);
|
UNUSED(test_data);
|
||||||
|
|
||||||
BYTE1 digest_part[4];
|
t_byte1 digest_part[4];
|
||||||
BYTE4 reg;
|
t_byte4 reg;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
1000 0000 : 31 - 24
|
1000 0000 : 31 - 24
|
||||||
|
@ -106,10 +107,10 @@ TEST_RESULT encode_register(TEST_PARAMS, TEST_DATA)
|
||||||
|
|
||||||
ft_md5_encode_register(digest_part, reg);
|
ft_md5_encode_register(digest_part, reg);
|
||||||
|
|
||||||
munit_assert_true(digest_part[0] == (BYTE1)(reg & 0xff));
|
munit_assert_true(digest_part[0] == (t_byte1)(reg & 0xff));
|
||||||
munit_assert_true(digest_part[1] == (BYTE1)((reg >> 8) & 0xff));
|
munit_assert_true(digest_part[1] == (t_byte1)((reg >> 8) & 0xff));
|
||||||
munit_assert_true(digest_part[2] == (BYTE1)((reg >> 16) & 0xff));
|
munit_assert_true(digest_part[2] == (t_byte1)((reg >> 16) & 0xff));
|
||||||
munit_assert_true(digest_part[3] == (BYTE1)((reg >> 24) & 0xff));
|
munit_assert_true(digest_part[3] == (t_byte1)((reg >> 24) & 0xff));
|
||||||
|
|
||||||
return MUNIT_OK;
|
return MUNIT_OK;
|
||||||
}
|
}
|
||||||
|
@ -120,12 +121,12 @@ TEST_RESULT create_digest(TEST_PARAMS, TEST_DATA)
|
||||||
UNUSED(test_data);
|
UNUSED(test_data);
|
||||||
|
|
||||||
t_md5_ctx ctx;
|
t_md5_ctx ctx;
|
||||||
BYTE1 digest[FT_MD5_DIGEST_LENGTH_BYTE];
|
t_byte1 digest[FT_MD5_DIGEST_LENGTH_BYTE];
|
||||||
BYTE1 digest_string[FT_MD5_STRING_SIZE_BYTE];
|
t_byte1 digest_string[FT_MD5_STRING_SIZE_BYTE];
|
||||||
|
|
||||||
BYTE1 case1[] = "";
|
t_byte1 case1[] = "";
|
||||||
BYTE1 case2[] = "a";
|
t_byte1 case2[] = "a";
|
||||||
BYTE1 case7[] = "1234567890123456789012345678901234567\
|
t_byte1 case7[] = "1234567890123456789012345678901234567\
|
||||||
891234567890123456789012345678901234567890";
|
891234567890123456789012345678901234567890";
|
||||||
|
|
||||||
ft_md5_init(&ctx);
|
ft_md5_init(&ctx);
|
||||||
|
@ -160,12 +161,12 @@ TEST_RESULT create_string(TEST_PARAMS, TEST_DATA)
|
||||||
UNUSED(test_params);
|
UNUSED(test_params);
|
||||||
UNUSED(test_data);
|
UNUSED(test_data);
|
||||||
|
|
||||||
BYTE1 digest[FT_MD5_DIGEST_LENGTH_BYTE];
|
t_byte1 digest[FT_MD5_DIGEST_LENGTH_BYTE];
|
||||||
BYTE1 digest_string[FT_MD5_STRING_SIZE_BYTE];
|
t_byte1 digest_string[FT_MD5_STRING_SIZE_BYTE];
|
||||||
BYTE4 a;
|
t_byte4 a;
|
||||||
BYTE4 b;
|
t_byte4 b;
|
||||||
BYTE4 c;
|
t_byte4 c;
|
||||||
BYTE4 d;
|
t_byte4 d;
|
||||||
|
|
||||||
/* final registers values for empty input */
|
/* final registers values for empty input */
|
||||||
a = 3649838548;
|
a = 3649838548;
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#include "tests.h"
|
#include "tests.h"
|
||||||
|
#include "tests_macros.h"
|
||||||
#include "ft_sha.h"
|
#include "ft_sha.h"
|
||||||
#include "libft.h"
|
#include "libft.h"
|
||||||
|
|
||||||
|
@ -53,8 +54,8 @@ TEST_RESULT decode_string_to_int_sha256(TEST_PARAMS, TEST_DATA)
|
||||||
UNUSED(test_params);
|
UNUSED(test_params);
|
||||||
UNUSED(test_data);
|
UNUSED(test_data);
|
||||||
|
|
||||||
BYTE1 block[FT_SHA256_BLOCK_SIZE];
|
t_byte1 block[FT_SHA256_BLOCK_SIZE];
|
||||||
BYTE4 words[FT_SHA256_WORDS_COUNT];
|
t_byte4 words[FT_SHA256_WORDS_COUNT];
|
||||||
|
|
||||||
ft_bzero(block, FT_SHA256_BLOCK_SIZE);
|
ft_bzero(block, FT_SHA256_BLOCK_SIZE);
|
||||||
block[0] = 'a';
|
block[0] = 'a';
|
||||||
|
@ -73,8 +74,8 @@ TEST_RESULT encode_len_to_string_sha256(TEST_PARAMS, TEST_DATA)
|
||||||
UNUSED(test_params);
|
UNUSED(test_params);
|
||||||
UNUSED(test_data);
|
UNUSED(test_data);
|
||||||
|
|
||||||
BYTE8 len;
|
t_byte8 len;
|
||||||
BYTE1 bits[FT_SHA256_MESSAGE_LENGTH_BYTE];
|
t_byte1 bits[FT_SHA256_MESSAGE_LENGTH_BYTE];
|
||||||
|
|
||||||
/*
|
/*
|
||||||
1111 0000 : 63 - 56
|
1111 0000 : 63 - 56
|
||||||
|
@ -90,9 +91,9 @@ TEST_RESULT encode_len_to_string_sha256(TEST_PARAMS, TEST_DATA)
|
||||||
|
|
||||||
ft_sha256_encode_len(bits, len);
|
ft_sha256_encode_len(bits, len);
|
||||||
|
|
||||||
munit_assert_uchar(bits[0], ==, (BYTE1)((len >> 56) & 0xff));
|
munit_assert_uchar(bits[0], ==, (t_byte1)((len >> 56) & 0xff));
|
||||||
munit_assert_uchar(bits[7], ==, (BYTE1)(len & 0xff));
|
munit_assert_uchar(bits[7], ==, (t_byte1)(len & 0xff));
|
||||||
munit_assert_uchar(bits[6], ==, (BYTE1)((len >> 8) & 0xff));
|
munit_assert_uchar(bits[6], ==, (t_byte1)((len >> 8) & 0xff));
|
||||||
|
|
||||||
return MUNIT_OK;
|
return MUNIT_OK;
|
||||||
}
|
}
|
||||||
|
@ -102,8 +103,8 @@ TEST_RESULT encode_register_to_string_sha256(TEST_PARAMS, TEST_DATA)
|
||||||
UNUSED(test_params);
|
UNUSED(test_params);
|
||||||
UNUSED(test_data);
|
UNUSED(test_data);
|
||||||
|
|
||||||
BYTE1 digest_part[4];
|
t_byte1 digest_part[4];
|
||||||
BYTE4 reg;
|
t_byte4 reg;
|
||||||
|
|
||||||
reg = 0xba7816bf;
|
reg = 0xba7816bf;
|
||||||
|
|
||||||
|
@ -123,7 +124,7 @@ TEST_RESULT update_bit_count_sha256(TEST_PARAMS, TEST_DATA)
|
||||||
UNUSED(test_params);
|
UNUSED(test_params);
|
||||||
|
|
||||||
t_sha256_ctx ctx;
|
t_sha256_ctx ctx;
|
||||||
BYTE1 message[] = "abc";
|
t_byte1 message[] = "abc";
|
||||||
|
|
||||||
ft_sha256_init(&ctx);
|
ft_sha256_init(&ctx);
|
||||||
ft_sha256_update(&ctx, message, sizeof(message));
|
ft_sha256_update(&ctx, message, sizeof(message));
|
||||||
|
@ -139,7 +140,7 @@ TEST_RESULT fill_buffer_sha256(TEST_PARAMS, TEST_DATA)
|
||||||
UNUSED(test_params);
|
UNUSED(test_params);
|
||||||
|
|
||||||
t_sha256_ctx ctx;
|
t_sha256_ctx ctx;
|
||||||
BYTE1 message[] = "abc";
|
t_byte1 message[] = "abc";
|
||||||
|
|
||||||
ft_sha256_init(&ctx);
|
ft_sha256_init(&ctx);
|
||||||
ft_sha256_update(&ctx, message, sizeof(message));
|
ft_sha256_update(&ctx, message, sizeof(message));
|
||||||
|
@ -151,9 +152,9 @@ TEST_RESULT fill_buffer_sha256(TEST_PARAMS, TEST_DATA)
|
||||||
|
|
||||||
static void block_with_right_padding
|
static void block_with_right_padding
|
||||||
(
|
(
|
||||||
BYTE1 *message,
|
t_byte1 *message,
|
||||||
BYTE8 message_len,
|
t_byte8 message_len,
|
||||||
BYTE1 padding[FT_SHA256_BLOCK_SIZE]
|
t_byte1 padding[FT_SHA256_BLOCK_SIZE]
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
ft_bzero(padding, FT_SHA256_BLOCK_SIZE);
|
ft_bzero(padding, FT_SHA256_BLOCK_SIZE);
|
||||||
|
@ -167,11 +168,11 @@ TEST_RESULT add_right_padding_sha256(TEST_PARAMS, TEST_DATA)
|
||||||
UNUSED(test_params);
|
UNUSED(test_params);
|
||||||
|
|
||||||
t_sha256_ctx ctx;
|
t_sha256_ctx ctx;
|
||||||
BYTE1 message[] = "abc";
|
t_byte1 message[] = "abc";
|
||||||
BYTE8 buff_index;
|
t_byte8 buff_index;
|
||||||
BYTE8 padding_len;
|
t_byte8 padding_len;
|
||||||
BYTE1 padding[FT_SHA256_BLOCK_SIZE];
|
t_byte1 padding[FT_SHA256_BLOCK_SIZE];
|
||||||
BYTE1 block_with_message_and_pading[FT_SHA256_BLOCK_SIZE];
|
t_byte1 block_with_message_and_pading[FT_SHA256_BLOCK_SIZE];
|
||||||
|
|
||||||
ft_sha256_init(&ctx);
|
ft_sha256_init(&ctx);
|
||||||
ft_sha256_update(&ctx, message, sizeof(message));
|
ft_sha256_update(&ctx, message, sizeof(message));
|
||||||
|
@ -193,9 +194,9 @@ TEST_RESULT compute_digest_sha256(TEST_PARAMS, TEST_DATA)
|
||||||
UNUSED(test_data);
|
UNUSED(test_data);
|
||||||
UNUSED(test_params);
|
UNUSED(test_params);
|
||||||
|
|
||||||
BYTE1 message[] = "abc";
|
t_byte1 message[] = "abc";
|
||||||
t_sha256_ctx ctx;
|
t_sha256_ctx ctx;
|
||||||
BYTE1 digest[FT_SHA256_DIGEST_LENGTH_BYTE];
|
t_byte1 digest[FT_SHA256_DIGEST_LENGTH_BYTE];
|
||||||
|
|
||||||
ft_sha256_init(&ctx);
|
ft_sha256_init(&ctx);
|
||||||
ft_sha256_update(&ctx, message, ft_strlen((const char *)message));
|
ft_sha256_update(&ctx, message, ft_strlen((const char *)message));
|
||||||
|
@ -219,9 +220,9 @@ TEST_RESULT compute_digest_sha224(TEST_PARAMS, TEST_DATA)
|
||||||
UNUSED(test_data);
|
UNUSED(test_data);
|
||||||
UNUSED(test_params);
|
UNUSED(test_params);
|
||||||
|
|
||||||
BYTE1 message[] = "abc";
|
t_byte1 message[] = "abc";
|
||||||
t_sha256_ctx ctx;
|
t_sha256_ctx ctx;
|
||||||
BYTE1 digest[FT_SHA256_DIGEST_LENGTH_BYTE];
|
t_byte1 digest[FT_SHA256_DIGEST_LENGTH_BYTE];
|
||||||
|
|
||||||
ft_sha224_init(&ctx);
|
ft_sha224_init(&ctx);
|
||||||
ft_sha224_update(&ctx, message, ft_strlen((const char *)message));
|
ft_sha224_update(&ctx, message, ft_strlen((const char *)message));
|
||||||
|
@ -243,12 +244,12 @@ TEST_RESULT create_digest_string_sha256(TEST_PARAMS, TEST_DATA)
|
||||||
UNUSED(test_data);
|
UNUSED(test_data);
|
||||||
UNUSED(test_params);
|
UNUSED(test_params);
|
||||||
|
|
||||||
BYTE1 message[] = "abc";
|
t_byte1 message[] = "abc";
|
||||||
BYTE1 message_digest[] =
|
t_byte1 message_digest[] =
|
||||||
"ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad";
|
"ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad";
|
||||||
t_sha256_ctx ctx;
|
t_sha256_ctx ctx;
|
||||||
BYTE1 digest[FT_SHA256_DIGEST_LENGTH_BYTE];
|
t_byte1 digest[FT_SHA256_DIGEST_LENGTH_BYTE];
|
||||||
BYTE1 digest_string[FT_SHA256_STRING_SIZE_BYTE];
|
t_byte1 digest_string[FT_SHA256_STRING_SIZE_BYTE];
|
||||||
|
|
||||||
ft_sha256_init(&ctx);
|
ft_sha256_init(&ctx);
|
||||||
ft_sha256_update(&ctx, message, ft_strlen((const char *)message));
|
ft_sha256_update(&ctx, message, ft_strlen((const char *)message));
|
||||||
|
@ -266,12 +267,12 @@ TEST_RESULT create_digest_string_sha224(TEST_PARAMS, TEST_DATA)
|
||||||
UNUSED(test_data);
|
UNUSED(test_data);
|
||||||
UNUSED(test_params);
|
UNUSED(test_params);
|
||||||
|
|
||||||
BYTE1 message[] = "abc";
|
t_byte1 message[] = "abc";
|
||||||
BYTE1 message_digest[] =
|
t_byte1 message_digest[] =
|
||||||
"23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7";
|
"23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7";
|
||||||
t_sha256_ctx ctx;
|
t_sha256_ctx ctx;
|
||||||
BYTE1 digest[FT_SHA256_DIGEST_LENGTH_BYTE];
|
t_byte1 digest[FT_SHA256_DIGEST_LENGTH_BYTE];
|
||||||
BYTE1 digest_string[FT_SHA224_STRING_SIZE_BYTE];
|
t_byte1 digest_string[FT_SHA224_STRING_SIZE_BYTE];
|
||||||
|
|
||||||
ft_sha224_init(&ctx);
|
ft_sha224_init(&ctx);
|
||||||
ft_sha224_update(&ctx, message, ft_strlen((const char *)message));
|
ft_sha224_update(&ctx, message, ft_strlen((const char *)message));
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
#include "tests.h"
|
#include "tests.h"
|
||||||
|
#include "tests_macros.h"
|
||||||
|
|
||||||
|
|
||||||
MunitTest md5_tests[] = {
|
MunitTest md5_tests[] = {
|
||||||
IT("/init_ctx", should_init_ctx, NULL, NULL, 0, NULL),
|
IT("/init_ctx", should_init_ctx, NULL, NULL, 0, NULL),
|
||||||
|
|
Loading…
Reference in a new issue