inline void hash_init_digest(MD5_WORD_T * digest) { static const MD5_WORD_T hash_initial_digest[MD5_DIGEST_NWORDS] = { MD5_INITIAL_DIGEST }; //memcpy(digest, hash_initial_digest, sizeof(hash_initial_digest)); memcpy_fixedlen(digest, hash_initial_digest, sizeof(hash_initial_digest)); }
static SHA1_HASH_CTX *sha1_ctx_mgr_resubmit(SHA1_HASH_CTX_MGR * mgr, SHA1_HASH_CTX * ctx) { while (ctx) { if (ctx->status & HASH_CTX_STS_COMPLETE) { ctx->status = HASH_CTX_STS_COMPLETE; // Clear PROCESSING bit return ctx; } // If the extra blocks are empty, begin hashing what remains in the user's buffer. if (ctx->partial_block_buffer_length == 0 && ctx->incoming_buffer_length) { const void *buffer = ctx->incoming_buffer; uint32_t len = ctx->incoming_buffer_length; // Only entire blocks can be hashed. Copy remainder to extra blocks buffer. uint32_t copy_len = len & (SHA1_BLOCK_SIZE - 1); if (copy_len) { len -= copy_len; memcpy_fixedlen(ctx->partial_block_buffer, ((const char *)buffer + len), copy_len); ctx->partial_block_buffer_length = copy_len; } ctx->incoming_buffer_length = 0; // len should be a multiple of the block size now assert((len % SHA1_BLOCK_SIZE) == 0); // Set len to the number of blocks to be hashed in the user's buffer len >>= SHA1_LOG2_BLOCK_SIZE; if (len) { ctx->job.buffer = (uint8_t *) buffer; ctx->job.len = len; ctx = (SHA1_HASH_CTX *) sha1_mb_mgr_submit_avx512(&mgr->mgr, &ctx->job); continue; } } // If the extra blocks are not empty, then we are either on the last block(s) // or we need more user input before continuing. if (ctx->status & HASH_CTX_STS_LAST) { uint8_t *buf = ctx->partial_block_buffer; uint32_t n_extra_blocks = hash_pad(buf, ctx->total_length); ctx->status = (HASH_CTX_STS) (HASH_CTX_STS_PROCESSING | HASH_CTX_STS_COMPLETE); ctx->job.buffer = buf; ctx->job.len = (uint32_t) n_extra_blocks; ctx = (SHA1_HASH_CTX *) sha1_mb_mgr_submit_avx512(&mgr->mgr, &ctx->job); continue; } if (ctx) ctx->status = HASH_CTX_STS_IDLE; return ctx; } return NULL; }
static inline void hash_init_digest(SHA512_WORD_T * digest) { static const SHA512_WORD_T hash_initial_digest[SHA512_DIGEST_NWORDS] = { SHA512_INITIAL_DIGEST }; memcpy_fixedlen(digest, hash_initial_digest, sizeof(hash_initial_digest)); }