void process_block(sha1_ctx *ctx) { pad_block(ctx); sha1_core(ctx); if (ctx->overflow) { memmove(ctx->block, ctx->block + SHA_BLOCK_SIZE, SHA_BLOCK_SIZE); ctx->overflow = 0; sha1_core(ctx); } }
static void run(struct EngineThread *eng) { SHA1_CTX *ctx = eng->priv; result160_sort(ctx->res); while (eng->active) { sha1_core(ctx); stack_turn(&ctx->stk[0], set_char_fast); stack_turn(&ctx->stk[1], set_char_fast); stack_turn(&ctx->stk[2], set_char_fast); stack_turn(&ctx->stk[3], set_char_fast); } }
static void proc_block160(uint32_t *hash, const byte_t *input) { uint32_t a, b, c, d, e; uint32_t wt[80]; expand_w160(wt, input); a = hash[0]; b = hash[1]; c = hash[2]; d = hash[3]; e = hash[4]; sha1_core(a, b, c, d, e, k160[0], wt, Ch<uint32_t>()); sha1_core(a, b, c, d, e, k160[1], wt + 20, Parity()); sha1_core(a, b, c, d, e, k160[2], wt + 40, Maj<uint32_t>()); sha1_core(a, b, c, d, e, k160[3], wt + 60, Parity()); hash[0] += a; hash[1] += b; hash[2] += c; hash[3] += d; hash[4] += e; }
void sha1_update(sha1_ctx_t *ctx, const octet_t *msg, int octets_in_msg) { int i; octet_t *buf = (octet_t *)ctx->M; /* update message bit-count */ ctx->num_bits_in_msg += octets_in_msg * 8; /* loop over 16-word blocks of M */ while (octets_in_msg > 0) { if (octets_in_msg + ctx->octets_in_buffer >= 64) { /* * copy words of M into msg buffer until that buffer is full, * converting them into host byte order as needed */ octets_in_msg -= (64 - ctx->octets_in_buffer); for (i=ctx->octets_in_buffer; i < 64; i++) buf[i] = *msg++; ctx->octets_in_buffer = 0; /* process a whole block */ debug_print(mod_sha1, "(update) running sha1_core()", NULL); sha1_core(ctx->M, ctx->H); } else { debug_print(mod_sha1, "(update) not running sha1_core()", NULL); for (i=ctx->octets_in_buffer; i < (ctx->octets_in_buffer + octets_in_msg); i++) buf[i] = *msg++; ctx->octets_in_buffer += octets_in_msg; octets_in_msg = 0; } } }