/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* sl_sha_init.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: bchanot +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2018/09/27 00:59:20 by bchanot #+# #+# */ /* Updated: 2018/10/10 12:54:19 by bchanot ### ########.fr */ /* */ /* ************************************************************************** */ #include "ft_ssl.h" #include "sl_sha2.h" #include "sl_sha3_5.h" void sl_sha2_init(t_sha2 *ctx, t_uint8 sha) { if (sha == SHA256) { ctx->state[0] = 0x6a09e667; ctx->state[1] = 0xbb67ae85; ctx->state[2] = 0x3c6ef372; ctx->state[3] = 0xa54ff53a; ctx->state[4] = 0x510e527f; ctx->state[5] = 0x9b05688c; ctx->state[6] = 0x1f83d9ab; ctx->state[7] = 0x5be0cd19; } else if (sha == SHA224) { ctx->state[0] = 0xc1059ed8; ctx->state[1] = 0x367cd507; ctx->state[2] = 0x3070dd17; ctx->state[3] = 0xf70e5939; ctx->state[4] = 0xffc00b31; ctx->state[5] = 0x68581511; ctx->state[6] = 0x64f98fa7; ctx->state[7] = 0xbefa4fa4; } ft_bzero(ctx->count, sizeof(ctx->count)); ft_bzero(ctx->buff, sizeof(ctx->buff)); } void sl_sha2_process_init_add(t_sha2 *ctx, t_process_sha2 *t, t_bool init) { if (init) { t->a = ctx->state[0]; t->b = ctx->state[1]; t->c = ctx->state[2]; t->d = ctx->state[3]; t->e = ctx->state[4]; t->f = ctx->state[5]; t->g = ctx->state[6]; t->h = ctx->state[7]; } else { ctx->state[0] += t->a; ctx->state[1] += t->b; ctx->state[2] += t->c; ctx->state[3] += t->d; ctx->state[4] += t->e; ctx->state[5] += t->f; ctx->state[6] += t->g; ctx->state[7] += t->h; } } void sl_sha3_5_init(t_sha3_5 *ctx, t_uint8 sha) { if (sha == SHA512) { ctx->state[0] = 0x6a09e667f3bcc908; ctx->state[1] = 0xbb67ae8584caa73b; ctx->state[2] = 0x3c6ef372fe94f82b; ctx->state[3] = 0xa54ff53a5f1d36f1; ctx->state[4] = 0x510e527fade682d1; ctx->state[5] = 0x9b05688c2b3e6c1f; ctx->state[6] = 0x1f83d9abfb41bd6b; ctx->state[7] = 0x5be0cd19137e2179; } else if (sha == SHA384) { ctx->state[0] = 0xcbbb9d5dc1059ed8; ctx->state[1] = 0x629a292a367cd507; ctx->state[2] = 0x9159015a3070dd17; ctx->state[3] = 0x152fecd8f70e5939; ctx->state[4] = 0x67332667ffc00b31; ctx->state[5] = 0x8eb44a8768581511; ctx->state[6] = 0xdb0c2e0d64f98fa7; ctx->state[7] = 0x47b5481dbefa4fa4; } ft_bzero(ctx->count, sizeof(ctx->count)); ft_bzero(ctx->buff, sizeof(ctx->buff)); } void sl_sha3_5_process_init_add(t_sha3_5 *ctx, t_process_sha3_5 *t, t_bool init) { if (init) { t->a = ctx->state[0]; t->b = ctx->state[1]; t->c = ctx->state[2]; t->d = ctx->state[3]; t->e = ctx->state[4]; t->f = ctx->state[5]; t->g = ctx->state[6]; t->h = ctx->state[7]; } else { ctx->state[0] += t->a; ctx->state[1] += t->b; ctx->state[2] += t->c; ctx->state[3] += t->d; ctx->state[4] += t->e; ctx->state[5] += t->f; ctx->state[6] += t->g; ctx->state[7] += t->h; } }