void getMd5CString(const char* pSrc, size_t length, std::vector<unsigned char>& res) { res.clear(); res.resize(16); md5_ctxt ctx; md5_init(&ctx); md5_loop(&ctx, (BYTE*)pSrc, length); md5_pad(&ctx); md5_result(&res[0], &ctx); }
void gf_rsync_strong_checksum (char *buf, int32_t len, uint8_t *sum) { md_context m; md5_begin (&m); md5_update (&m, (unsigned char *) buf, len); md5_result (&m, (unsigned char *) sum); return; }
void md5_hex(char *out, md5_ctx *ctx) { uint8_t digest[16]; md5_result(digest, ctx); sprintf(out, "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", digest[0], digest[1], digest[2], digest[3], digest[4], digest[5], digest[6], digest[7], digest[8], digest[9], digest[10], digest[11], digest[12], digest[13], digest[14], digest[15]); }
// compute TLSv1 PRF (pseudo random function using HMAC) void PRF(byte* digest, uint digLen, const byte* secret, uint secLen, const byte* label, uint labLen, const byte* seed, uint seedLen) { uint half = (secLen + 1) / 2; output_buffer md5_half(half); output_buffer sha_half(half); output_buffer labelSeed(labLen + seedLen); md5_half.write(secret, half); sha_half.write(secret + half - secLen % 2, half); labelSeed.write(label, labLen); labelSeed.write(seed, seedLen); output_buffer md5_result(digLen); output_buffer sha_result(digLen); p_hash(md5_result, md5_half, labelSeed, md5); p_hash(sha_result, sha_half, labelSeed, sha); md5_result.set_current(0); sha_result.set_current(0); get_xor(digest, digLen, md5_result, sha_result); }
void Md5::finish(uint8_t digest[], md5_digest_ctxt* context) { md5_pad(context); return md5_result(digest, context); }