diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2013-02-22 17:53:33 -0800 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-02-23 18:38:49 +0100 |
commit | 44cb71d6fdb0b7285d4ef74a1ef778323aa9e5ee (patch) | |
tree | 596c5177ea3e8a7eea3e3ceb8e777da1c30a7410 | |
parent | bc616641a1c3d2d79cf7c5ee9e80a59279edb756 (diff) |
Compile only the SHA-1 code into qdoc
There's no need to compile the other codecs if they never get
used. It's possible that a whole-program optimisation would remove the
dead code away, but it's not very likely.
Change-Id: I75d7618c174566beec2fab44f60a9f7120133775
Reviewed-by: Richard J. Moore <rich@kde.org>
-rw-r--r-- | src/corelib/tools/qcryptographichash.cpp | 60 | ||||
-rw-r--r-- | src/tools/qdoc/qdoc.pro | 3 |
2 files changed, 45 insertions, 18 deletions
diff --git a/src/corelib/tools/qcryptographichash.cpp b/src/corelib/tools/qcryptographichash.cpp index 6704f14eb1..fdf2d1a620 100644 --- a/src/corelib/tools/qcryptographichash.cpp +++ b/src/corelib/tools/qcryptographichash.cpp @@ -41,12 +41,16 @@ ****************************************************************************/ #include <qcryptographichash.h> +#include <qiodevice.h> + +#include "../../3rdparty/sha1/sha1.cpp" +#ifndef QT_CRYPTOGRAPHICHASH_ONLY_SHA1 +// qdoc only needs SHA-1 #include "../../3rdparty/md5/md5.h" #include "../../3rdparty/md5/md5.cpp" #include "../../3rdparty/md4/md4.h" #include "../../3rdparty/md4/md4.cpp" -#include "../../3rdparty/sha1/sha1.cpp" typedef unsigned char BitSequence; typedef unsigned long long DataLength; @@ -124,8 +128,6 @@ static int SHA384_512AddLength(SHA512Context *context, unsigned int length); #undef uint68_t #undef int_least16_t -#include <qiodevice.h> - static inline int SHA224_256AddLength(SHA256Context *context, unsigned int length) { QT_PREPEND_NAMESPACE(quint32) addTemp; @@ -136,6 +138,7 @@ static inline int SHA384_512AddLength(SHA512Context *context, unsigned int lengt QT_PREPEND_NAMESPACE(quint64) addTemp; return SHA384_512AddLengthM(context, length); } +#endif // QT_CRYPTOGRAPHICHASH_ONLY_SHA1 QT_BEGIN_NAMESPACE @@ -144,14 +147,16 @@ class QCryptographicHashPrivate public: QCryptographicHash::Algorithm method; union { + Sha1State sha1Context; +#ifndef QT_CRYPTOGRAPHICHASH_ONLY_SHA1 MD5Context md5Context; md4_context md4Context; - Sha1State sha1Context; SHA224Context sha224Context; SHA256Context sha256Context; SHA384Context sha384Context; SHA512Context sha512Context; SHA3Context sha3Context; +#endif }; QByteArray result; }; @@ -212,15 +217,21 @@ QCryptographicHash::~QCryptographicHash() void QCryptographicHash::reset() { switch (d->method) { + case Sha1: + sha1InitState(&d->sha1Context); + break; +#ifdef QT_CRYPTOGRAPHICHASH_ONLY_SHA1 + default: + Q_ASSERT_X(false, "QCryptographicHash", "Method not compiled in"); + Q_UNREACHABLE(); + break; +#else case Md4: md4_init(&d->md4Context); break; case Md5: MD5Init(&d->md5Context); break; - case Sha1: - sha1InitState(&d->sha1Context); - break; case Sha224: SHA224Reset(&d->sha224Context); break; @@ -245,6 +256,7 @@ void QCryptographicHash::reset() case Sha3_512: sha3Init(&d->sha3Context, 512); break; +#endif } d->result.clear(); } @@ -256,15 +268,21 @@ void QCryptographicHash::reset() 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 Sha1: - sha1Update(&d->sha1Context, (const unsigned char *)data, length); - break; case Sha224: SHA224Input(&d->sha224Context, reinterpret_cast<const unsigned char *>(data), length); break; @@ -289,6 +307,7 @@ void QCryptographicHash::addData(const char *data, int length) case Sha3_512: sha3Update(&d->sha3Context, reinterpret_cast<const BitSequence *>(data), length*8); break; +#endif } d->result.clear(); } @@ -335,6 +354,19 @@ QByteArray QCryptographicHash::result() const return d->result; switch (d->method) { + case Sha1: { + Sha1State copy = d->sha1Context; + d->result.resize(20); + sha1FinalizeState(©); + sha1ToHash(©, (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); @@ -347,13 +379,6 @@ QByteArray QCryptographicHash::result() const MD5Final(©, (unsigned char *)d->result.data()); break; } - case Sha1: { - Sha1State copy = d->sha1Context; - d->result.resize(20); - sha1FinalizeState(©); - sha1ToHash(©, (unsigned char *)d->result.data()); - break; - } case Sha224: { SHA224Context copy = d->sha224Context; d->result.resize(SHA224HashSize); @@ -402,6 +427,7 @@ QByteArray QCryptographicHash::result() const sha3Final(©, reinterpret_cast<BitSequence *>(d->result.data())); break; } +#endif } return d->result; } diff --git a/src/tools/qdoc/qdoc.pro b/src/tools/qdoc/qdoc.pro index 9df79ec718..cd792e73e8 100644 --- a/src/tools/qdoc/qdoc.pro +++ b/src/tools/qdoc/qdoc.pro @@ -1,6 +1,7 @@ option(host_build) -DEFINES += QDOC2_COMPAT +DEFINES += QDOC2_COMPAT \ + QT_CRYPTOGRAPHICHASH_ONLY_SHA1 INCLUDEPATH += $$QT_SOURCE_TREE/src/tools/qdoc \ $$QT_SOURCE_TREE/src/tools/qdoc/qmlparser |