diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2014-09-12 00:49:55 +0900 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2014-09-13 00:08:07 +0900 |
| commit | e18e8aeeaa2c24591b0ebb89984cbdc30a0f25a8 (patch) | |
| tree | 5c1f5ab7b164f8f1b0b4cbf18822af4490487bf7 /src | |
| parent | d91f7dc721dbbbffd1b0ab3b3cd889fdaa67cf86 (diff) | |
Support Adler32 checksum
Adler32 checksum is available for --checksum option and hash element
in Metalink files. Currently, we use Adler32 implementation in Zlib.
Diffstat (limited to 'src')
| -rw-r--r-- | src/Adler32MessageDigestImpl.cc | 76 | ||||
| -rw-r--r-- | src/Adler32MessageDigestImpl.h | 67 | ||||
| -rw-r--r-- | src/AppleMessageDigestImpl.cc | 3 | ||||
| -rw-r--r-- | src/InternalMessageDigestImpl.cc | 3 | ||||
| -rw-r--r-- | src/LibgcryptMessageDigestImpl.cc | 3 | ||||
| -rw-r--r-- | src/LibnettleMessageDigestImpl.cc | 3 | ||||
| -rw-r--r-- | src/LibsslMessageDigestImpl.cc | 3 | ||||
| -rw-r--r-- | src/Makefile.am | 3 | ||||
| -rw-r--r-- | src/MessageDigest.cc | 3 |
9 files changed, 162 insertions, 2 deletions
diff --git a/src/Adler32MessageDigestImpl.cc b/src/Adler32MessageDigestImpl.cc new file mode 100644 index 00000000..96ce07ca --- /dev/null +++ b/src/Adler32MessageDigestImpl.cc @@ -0,0 +1,76 @@ +/* <!-- copyright */ +/* + * aria2 - The high speed download utility + * + * Copyright (C) 2014 Tatsuhiro Tsujikawa + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the + * OpenSSL library under certain conditions as described in each + * individual source file, and distribute linked combinations + * including the two. + * You must obey the GNU General Public License in all respects + * for all of the code used other than OpenSSL. If you modify + * file(s) with this exception, you may extend this exception to your + * version of the file(s), but you are not obligated to do so. If you + * do not wish to do so, delete this exception statement from your + * version. If you delete this exception statement from all source + * files in the program, then also delete it here. + */ +/* copyright --> */ +#include "Adler32MessageDigestImpl.h" + +#include <cstring> + +#include <zlib.h> + +#include "a2netcompat.h" + +namespace aria2 { + +Adler32MessageDigestImpl::Adler32MessageDigestImpl() + : adler_(adler32(0, Z_NULL, 0)) +{} + +size_t Adler32MessageDigestImpl::getDigestLength() const +{ + return length(); +} + +void Adler32MessageDigestImpl::reset() +{ + adler_ = adler32(0, Z_NULL, 0); +} + +void Adler32MessageDigestImpl::update(const void* data, size_t length) +{ + adler_ = adler32(adler_, reinterpret_cast<const unsigned char*>(data), + length); +} + +void Adler32MessageDigestImpl::digest(unsigned char* md) +{ + auto adler = htonl(adler_); + memcpy(md, &adler, getDigestLength()); +} + +size_t Adler32MessageDigestImpl::length() +{ + return 4; +} + +} // namespace aria2 diff --git a/src/Adler32MessageDigestImpl.h b/src/Adler32MessageDigestImpl.h new file mode 100644 index 00000000..1fb91785 --- /dev/null +++ b/src/Adler32MessageDigestImpl.h @@ -0,0 +1,67 @@ +/* <!-- copyright */ +/* + * aria2 - The high speed download utility + * + * Copyright (C) 2014 Tatsuhiro Tsujikawa + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the + * OpenSSL library under certain conditions as described in each + * individual source file, and distribute linked combinations + * including the two. + * You must obey the GNU General Public License in all respects + * for all of the code used other than OpenSSL. If you modify + * file(s) with this exception, you may extend this exception to your + * version of the file(s), but you are not obligated to do so. If you + * do not wish to do so, delete this exception statement from your + * version. If you delete this exception statement from all source + * files in the program, then also delete it here. + */ +/* copyright --> */ +#ifndef D_ADLER32_MESSAGE_DIGEST_H +#define D_ADLER32_MESSAGE_DIGEST_H + +#include "MessageDigestImpl.h" + +namespace aria2 { + +#ifdef HAVE_ZLIB + +#define ADLER32_MESSAGE_DIGEST \ + { "adler32", make_hi<Adler32MessageDigestImpl>() }, + +class Adler32MessageDigestImpl : public MessageDigestImpl { +public: + Adler32MessageDigestImpl(); + virtual size_t getDigestLength() const CXX11_OVERRIDE; + virtual void reset() CXX11_OVERRIDE; + virtual void update(const void* data, size_t length) CXX11_OVERRIDE; + virtual void digest(unsigned char* md) CXX11_OVERRIDE; + static size_t length(); +private: + unsigned long adler_; +}; + +#else // !HAVE_ZLIB + +#define ADLER32_MESSAGE_DIGEST + +#endif // !HAVE_ZLIB + +} // namespace aria2 + +#endif // D_ADLER32_MESSAGE_DIGEST_H diff --git a/src/AppleMessageDigestImpl.cc b/src/AppleMessageDigestImpl.cc index 5a5d45e6..59e4c4dd 100644 --- a/src/AppleMessageDigestImpl.cc +++ b/src/AppleMessageDigestImpl.cc @@ -37,6 +37,8 @@ #include <CommonCrypto/CommonDigest.h> +#include "Adler32MessageDigestImpl.h" + namespace aria2 { namespace { @@ -126,6 +128,7 @@ MessageDigestImpl::hashes_t MessageDigestImpl::hashes = { { "sha-384", make_hi<MessageDigestSHA384>() }, { "sha-512", make_hi<MessageDigestSHA512>() }, { "md5", make_hi<MessageDigestMD5>() }, + ADLER32_MESSAGE_DIGEST }; } // namespace aria2 diff --git a/src/InternalMessageDigestImpl.cc b/src/InternalMessageDigestImpl.cc index c9ad99a7..f8dd70eb 100644 --- a/src/InternalMessageDigestImpl.cc +++ b/src/InternalMessageDigestImpl.cc @@ -37,6 +37,8 @@ #include "crypto_hash.h" +#include "Adler32MessageDigestImpl.h" + namespace { using namespace aria2; using namespace crypto; @@ -101,6 +103,7 @@ MessageDigestImpl::hashes_t MessageDigestImpl::hashes = { { "sha-384", make_hi<MessageDigestSHA384>() }, { "sha-512", make_hi<MessageDigestSHA512>() }, { "md5", make_hi<MessageDigestMD5>() }, + ADLER32_MESSAGE_DIGEST }; } // namespace aria2 diff --git a/src/LibgcryptMessageDigestImpl.cc b/src/LibgcryptMessageDigestImpl.cc index 508b96be..8d43a665 100644 --- a/src/LibgcryptMessageDigestImpl.cc +++ b/src/LibgcryptMessageDigestImpl.cc @@ -37,6 +37,8 @@ #include <gcrypt.h> +#include "Adler32MessageDigestImpl.h" + namespace aria2 { namespace { @@ -116,6 +118,7 @@ MessageDigestImpl::hashes_t MessageDigestImpl::hashes = { { "sha-384", make_hi<MessageDigestSHA384>() }, { "sha-512", make_hi<MessageDigestSHA512>() }, { "md5", make_hi<MessageDigestMD5>() }, + ADLER32_MESSAGE_DIGEST }; } // namespace aria2 diff --git a/src/LibnettleMessageDigestImpl.cc b/src/LibnettleMessageDigestImpl.cc index 1f03c2e6..f63a820c 100644 --- a/src/LibnettleMessageDigestImpl.cc +++ b/src/LibnettleMessageDigestImpl.cc @@ -37,6 +37,8 @@ #include <nettle/nettle-meta.h> +#include "Adler32MessageDigestImpl.h" + namespace aria2 { namespace { @@ -95,6 +97,7 @@ MessageDigestImpl::hashes_t MessageDigestImpl::hashes = { { "sha-384", make_hi<MessageDigestSHA384>() }, { "sha-512", make_hi<MessageDigestSHA512>() }, { "md5", make_hi<MessageDigestMD5>() }, + ADLER32_MESSAGE_DIGEST }; } // namespace aria2 diff --git a/src/LibsslMessageDigestImpl.cc b/src/LibsslMessageDigestImpl.cc index 037fc45f..1077e8e3 100644 --- a/src/LibsslMessageDigestImpl.cc +++ b/src/LibsslMessageDigestImpl.cc @@ -37,6 +37,8 @@ #include <openssl/evp.h> +#include "Adler32MessageDigestImpl.h" + namespace aria2 { template<const EVP_MD* (*init_fn)()> @@ -102,6 +104,7 @@ MessageDigestImpl::hashes_t MessageDigestImpl::hashes = { { "sha-512", make_hi<MessageDigestBase<EVP_sha512> >() }, #endif { "md5", make_hi<MessageDigestMD5>() }, + ADLER32_MESSAGE_DIGEST }; } // namespace aria2 diff --git a/src/Makefile.am b/src/Makefile.am index bcf25948..cd49f94f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -417,7 +417,8 @@ if HAVE_ZLIB SRCS += \ GZipDecodingStreamFilter.cc GZipDecodingStreamFilter.h\ GZipEncoder.cc GZipEncoder.h\ - GZipFile.cc GZipFile.h + GZipFile.cc GZipFile.h \ + Adler32MessageDigestImpl.cc Adler32MessageDigestImpl.h endif # HAVE_ZLIB if HAVE_SQLITE3 diff --git a/src/MessageDigest.cc b/src/MessageDigest.cc index 731a9420..77c43e31 100644 --- a/src/MessageDigest.cc +++ b/src/MessageDigest.cc @@ -59,7 +59,8 @@ HashTypeEntry hashTypes[] = { HashTypeEntry("sha-256", 3), HashTypeEntry("sha-384", 4), HashTypeEntry("sha-512", 5), - HashTypeEntry("md5", 0) + HashTypeEntry("md5", 0), + HashTypeEntry("adler32", 0), }; } // namespace aria2 |
