unsigned char* md4_MemBlock(const unsigned char* buf, size_t size, HASH_ctx* ctx) { md4_init(ctx); md4_update(ctx, buf, size); md4_final(ctx, buf, size); return ctx->MD4_result; }
EXPORT_SYM int md4_digest(const hash_state *hs, uint8_t digest[16]) { static uint8_t s[8]; uint32_t padlen; hash_state temp; unsigned i; uint64_t bitlen; static const uint8_t padding[64] = { 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; if (NULL==hs || NULL==digest) return ERR_NULL; temp = *hs; bitlen = temp.bitlen; /* Save current length */ padlen= (56<=hs->count) ? 56-hs->count+64: 56-hs->count; md4_update(&temp, padding, padlen); for (i=0; i<8; i++) s[i] = (uint8_t)(bitlen >> (i*8)); md4_update(&temp, s, 8); STORE_U32_LITTLE(&digest[0], temp.A); STORE_U32_LITTLE(&digest[4], temp.B); STORE_U32_LITTLE(&digest[8], temp.C); STORE_U32_LITTLE(&digest[12], temp.D); return 0; }
/*! Adds the first \a length chars of \a data to the cryptographic hash. */ void QCryptographicHash::addData(const char *data, int length) { switch (d->method) { case Sha1: sha1Update(&d->sha1Context, (const unsigned char *)data, length); break; #ifdef QT_CRYPTOGRAPHICHASH_ONLY_SHA1 default: Q_ASSERT_X(false, "QCryptographicHash", "Method not compiled in"); Q_UNREACHABLE(); break; #else case Md4: md4_update(&d->md4Context, (const unsigned char *)data, length); break; case Md5: MD5Update(&d->md5Context, (const unsigned char *)data, length); break; case Sha224: SHA224Input(&d->sha224Context, reinterpret_cast<const unsigned char *>(data), length); break; case Sha256: SHA256Input(&d->sha256Context, reinterpret_cast<const unsigned char *>(data), length); break; case Sha384: SHA384Input(&d->sha384Context, reinterpret_cast<const unsigned char *>(data), length); break; case Sha512: SHA512Input(&d->sha512Context, reinterpret_cast<const unsigned char *>(data), length); break; case RealSha3_224: case Keccak_224: sha3Update(&d->sha3Context, reinterpret_cast<const BitSequence *>(data), length*8); break; case RealSha3_256: case Keccak_256: sha3Update(&d->sha3Context, reinterpret_cast<const BitSequence *>(data), length*8); break; case RealSha3_384: case Keccak_384: sha3Update(&d->sha3Context, reinterpret_cast<const BitSequence *>(data), length*8); break; case RealSha3_512: case Keccak_512: sha3Update(&d->sha3Context, reinterpret_cast<const BitSequence *>(data), length*8); break; #endif } d->result.clear(); }
/*! Adds the first \a length chars of \a data to the cryptographic hash. */ void QCryptographicHash::addData(const char *data, int length) { switch (d->method) { case Md4: md4_update(&d->md4Context, (const unsigned char *)data, length); break; case Md5: MD5Update(&d->md5Context, (const unsigned char *)data, length); break; case Sha1: sha1Update(&d->sha1Context, (const unsigned char *)data, length); break; } d->result.clear(); }
void handle_md4(array_t *out, bio_t *in) { md4_ctx_t ctx; char hex[sizeof(ctx.hash) * 2]; size_t r; md4_init(&ctx); do { r = bio_feed(in); md4_update(&ctx, BIO_PEEK(in), r); BIO_SEEK(in, r); } while (r > 0); md4_finish(&ctx); array_append(out, hex, fmt_hex_pad(hex, ctx.hash, sizeof(ctx.hash))); array_append_null(out); }
static void md4_update_wrap( void *ctx, const unsigned char *input, size_t ilen ) { md4_update( (md4_context *) ctx, input, ilen ); }
int main() { md4_ctx_t ctx; char hex_str[33]; char digest[16]; int i; uint32_t vector[][4] = { { 0x31d6cfe0, 0xd16ae931, 0xb73c59d7, 0xe0c089c0 }, { 0xbde52cb3, 0x1de33e46, 0x245e05fb, 0xdbd6fb24 }, { 0xa448017a, 0xaf21d852, 0x5fc10ae8, 0x7aa6729d }, { 0xd9130a81, 0x64549fe8, 0x18874806, 0xe1c7014b }, { 0xd79e1c30, 0x8aa5bbcd, 0xeea8ed63, 0xdf412da9 }, { 0x043f8582, 0xf241db35, 0x1ce627e1, 0x53e7f0e4 }, { 0xe33b4ddc, 0x9c38f219, 0x9c3e7b16, 0x4fcc0536 }, { 0xe33b4ddc, 0x9c38f219, 0x9c3e7b16, 0x4fcc0536 } }; md4s(&ctx, ""); for (i = 0; i < 4; i++) { if (vector[0][i] != be32toh(ctx.hash[i])) return 1; } md4s(&ctx, "a"); for (i = 0; i < 4; i++) { if (vector[1][i] != be32toh(ctx.hash[i])) return 2; } md4s(&ctx, "abc"); for (i = 0; i < 4; i++) { if (vector[2][i] != be32toh(ctx.hash[i])) return 3; } md4s(&ctx, "message digest"); for (i = 0; i < 4; i++) { if (vector[3][i] != be32toh(ctx.hash[i])) return 4; } md4s(&ctx, "abcdefghijklmnopqrstuvwxyz"); for (i = 0; i < 4; i++) { if (vector[4][i] != be32toh(ctx.hash[i])) return 5; } md4s(&ctx, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"); for (i = 0; i < 4; i++) { if (vector[5][i] != be32toh(ctx.hash[i])) return 6; } md4s(&ctx, "12345678901234567890123456789012345678901234567890123456789012345678901234567890"); for (i = 0; i < 4; i++) { if (vector[6][i] != be32toh(ctx.hash[i])) return 7; } md4_init(&ctx); md4_update(&ctx, "1234567890", 10); md4_update(&ctx, "1234567890", 10); md4_update(&ctx, "1234567890", 10); md4_update(&ctx, "1234567890", 10); md4_update(&ctx, "1234567890", 10); md4_update(&ctx, "1234567890", 10); md4_update(&ctx, "1234567890", 10); md4_update(&ctx, "1234567890", 10); md4_finish(&ctx); for (i = 0; i < 4; i++) { if (vector[7][i] != be32toh(ctx.hash[i])) return 8; } return 0; }
void update(const char* data, int len) { LIBED2K_ASSERT(data != 0); LIBED2K_ASSERT(len > 0); md4_update(&m_context, reinterpret_cast<const unsigned char*>(data), len); }