コード例 #1
0
ファイル: MD4.cpp プロジェクト: WeijieH/HashME
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;
}
コード例 #2
0
/*!
  Returns the final hash value.

  \sa QByteArray::toHex()
*/
QByteArray QCryptographicHash::result() const
{
    if (!d->result.isEmpty()) 
        return d->result;

    switch (d->method) {
    case Md4: {
        md4_context copy = d->md4Context;
        d->result.resize(MD4_RESULTLEN);
        md4_final(&copy, (unsigned char *)d->result.data());
        break;
    }
    case Md5: {
        MD5Context copy = d->md5Context;
        d->result.resize(16);
        MD5Final(&copy, (unsigned char *)d->result.data());
        break;
    }
    case Sha1: {
        Sha1State copy = d->sha1Context;
        d->result.resize(20);
        sha1FinalizeState(&copy);
        sha1ToHash(&copy, (unsigned char *)d->result.data());
    }
    }
    return d->result;
}
コード例 #3
0
/*!
  Returns the final hash value.

  \sa QByteArray::toHex()
*/
QByteArray QCryptographicHash::result() const
{
    if (!d->result.isEmpty())
        return d->result;

    switch (d->method) {
    case Sha1: {
        Sha1State copy = d->sha1Context;
        d->result.resize(20);
        sha1FinalizeState(&copy);
        sha1ToHash(&copy, (unsigned char *)d->result.data());
        break;
    }
#ifdef QT_CRYPTOGRAPHICHASH_ONLY_SHA1
    default:
        Q_ASSERT_X(false, "QCryptographicHash", "Method not compiled in");
        Q_UNREACHABLE();
        break;
#else
    case Md4: {
        md4_context copy = d->md4Context;
        d->result.resize(MD4_RESULTLEN);
        md4_final(&copy, (unsigned char *)d->result.data());
        break;
    }
    case Md5: {
        MD5Context copy = d->md5Context;
        d->result.resize(16);
        MD5Final(&copy, (unsigned char *)d->result.data());
        break;
    }
    case Sha224: {
        SHA224Context copy = d->sha224Context;
        d->result.resize(SHA224HashSize);
        SHA224Result(&copy, reinterpret_cast<unsigned char *>(d->result.data()));
        break;
    }
    case Sha256:{
        SHA256Context copy = d->sha256Context;
        d->result.resize(SHA256HashSize);
        SHA256Result(&copy, reinterpret_cast<unsigned char *>(d->result.data()));
        break;
    }
    case Sha384:{
        SHA384Context copy = d->sha384Context;
        d->result.resize(SHA384HashSize);
        SHA384Result(&copy, reinterpret_cast<unsigned char *>(d->result.data()));
        break;
    }
    case Sha512:{
        SHA512Context copy = d->sha512Context;
        d->result.resize(SHA512HashSize);
        SHA512Result(&copy, reinterpret_cast<unsigned char *>(d->result.data()));
        break;
    }
    case RealSha3_224: {
        d->sha3Finish(224, QCryptographicHashPrivate::Sha3Variant::Sha3);
        break;
    }
    case RealSha3_256: {
        d->sha3Finish(256, QCryptographicHashPrivate::Sha3Variant::Sha3);
        break;
    }
    case RealSha3_384: {
        d->sha3Finish(384, QCryptographicHashPrivate::Sha3Variant::Sha3);
        break;
    }
    case RealSha3_512: {
        d->sha3Finish(512, QCryptographicHashPrivate::Sha3Variant::Sha3);
        break;
    }
    case Keccak_224: {
        d->sha3Finish(224, QCryptographicHashPrivate::Sha3Variant::Keccak);
        break;
    }
    case Keccak_256: {
        d->sha3Finish(256, QCryptographicHashPrivate::Sha3Variant::Keccak);
        break;
    }
    case Keccak_384: {
        d->sha3Finish(384, QCryptographicHashPrivate::Sha3Variant::Keccak);
        break;
    }
    case Keccak_512: {
        d->sha3Finish(512, QCryptographicHashPrivate::Sha3Variant::Keccak);
        break;
    }
#endif
    }
    return d->result;
}