From 1946b3341f3a2cb7e55829bc8af56ead2a5a4e6a Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Thu, 11 Nov 2010 03:23:08 +0000 Subject: [PATCH] 2010-11-11 Tatsuhiro Tsujikawa Added sha-224, sha-384, sha-512 hash function support. * m4/openssl.m4 * src/MessageDigest.cc * src/LibgcryptMessageDigestImpl.cc * src/LibsslMessageDigestImpl.cc --- ChangeLog | 8 +++++++ config.h.in | 9 ++++++++ configure | 36 +++++++++++++++++++++++++++++++ m4/openssl.m4 | 6 ++++++ src/LibgcryptMessageDigestImpl.cc | 3 +++ src/LibsslMessageDigestImpl.cc | 9 ++++++++ src/MessageDigest.cc | 8 ++++++- 7 files changed, 78 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index c746dc3d..fe12382d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2010-11-11 Tatsuhiro Tsujikawa + + Added sha-224, sha-384, sha-512 hash function support. + * m4/openssl.m4 + * src/MessageDigest.cc + * src/LibgcryptMessageDigestImpl.cc + * src/LibsslMessageDigestImpl.cc + 2010-11-11 Tatsuhiro Tsujikawa Replaced MessageDigestContext with MessageDigest. Cleaned up diff --git a/config.h.in b/config.h.in index 56c61ed4..6b693bd5 100644 --- a/config.h.in +++ b/config.h.in @@ -123,9 +123,18 @@ /* Define to 1 if you have the `EVP_DigestInit_ex' function. */ #undef HAVE_EVP_DIGESTINIT_EX +/* Define to 1 if you have the `EVP_sha224' function. */ +#undef HAVE_EVP_SHA224 + /* Define to 1 if you have the `EVP_sha256' function. */ #undef HAVE_EVP_SHA256 +/* Define to 1 if you have the `EVP_sha384' function. */ +#undef HAVE_EVP_SHA384 + +/* Define to 1 if you have the `EVP_sha512' function. */ +#undef HAVE_EVP_SHA512 + /* Define to 1 if you have the `fallocate' function. */ #undef HAVE_FALLOCATE diff --git a/configure b/configure index 7a7ff902..95deb6be 100755 --- a/configure +++ b/configure @@ -6940,6 +6940,18 @@ $as_echo "#define HAVE_OLD_LIBSSL 1" >>confdefs.h fi + # search for sha224 support + for ac_func in EVP_sha224 +do : + ac_fn_cxx_check_func "$LINENO" "EVP_sha224" "ac_cv_func_EVP_sha224" +if test "x$ac_cv_func_EVP_sha224" = x""yes; then : + cat >>confdefs.h <<_ACEOF +#define HAVE_EVP_SHA224 1 +_ACEOF + +fi +done + # search for sha256 support for ac_func in EVP_sha256 do : @@ -6949,6 +6961,30 @@ if test "x$ac_cv_func_EVP_sha256" = x""yes; then : #define HAVE_EVP_SHA256 1 _ACEOF +fi +done + + # search for sha384 support + for ac_func in EVP_sha384 +do : + ac_fn_cxx_check_func "$LINENO" "EVP_sha384" "ac_cv_func_EVP_sha384" +if test "x$ac_cv_func_EVP_sha384" = x""yes; then : + cat >>confdefs.h <<_ACEOF +#define HAVE_EVP_SHA384 1 +_ACEOF + +fi +done + + # search for sha512 support + for ac_func in EVP_sha512 +do : + ac_fn_cxx_check_func "$LINENO" "EVP_sha512" "ac_cv_func_EVP_sha512" +if test "x$ac_cv_func_EVP_sha512" = x""yes; then : + cat >>confdefs.h <<_ACEOF +#define HAVE_EVP_SHA512 1 +_ACEOF + fi done diff --git a/m4/openssl.m4 b/m4/openssl.m4 index e3ed9261..dd03d88c 100644 --- a/m4/openssl.m4 +++ b/m4/openssl.m4 @@ -57,8 +57,14 @@ if test "x$have_openssl" = "xyes"; then fi AC_SUBST(OPENSSL_LIBS) AC_SUBST(OPENSSL_CFLAGS) + # search for sha224 support + AC_CHECK_FUNCS([EVP_sha224]) # search for sha256 support AC_CHECK_FUNCS([EVP_sha256]) + # search for sha384 support + AC_CHECK_FUNCS([EVP_sha384]) + # search for sha512 support + AC_CHECK_FUNCS([EVP_sha512]) fi LIBS=$LIBS_save diff --git a/src/LibgcryptMessageDigestImpl.cc b/src/LibgcryptMessageDigestImpl.cc index 1794eb34..84c3f8bc 100644 --- a/src/LibgcryptMessageDigestImpl.cc +++ b/src/LibgcryptMessageDigestImpl.cc @@ -62,7 +62,10 @@ typedef FindHashFunc CFindHashFunc; namespace { CHashFuncEntry hashFuncs[] = { CHashFuncEntry("sha-1", GCRY_MD_SHA1), + CHashFuncEntry("sha-224", GCRY_MD_SHA224), CHashFuncEntry("sha-256", GCRY_MD_SHA256), + CHashFuncEntry("sha-384", GCRY_MD_SHA384), + CHashFuncEntry("sha-512", GCRY_MD_SHA512), CHashFuncEntry("md5", GCRY_MD_MD5) }; } // namespace diff --git a/src/LibsslMessageDigestImpl.cc b/src/LibsslMessageDigestImpl.cc index 8b4a6349..74c7afd7 100644 --- a/src/LibsslMessageDigestImpl.cc +++ b/src/LibsslMessageDigestImpl.cc @@ -64,9 +64,18 @@ typedef FindHashFunc CFindHashFunc; namespace { CHashFuncEntry hashFuncs[] = { CHashFuncEntry("sha-1", EVP_sha1()), +#ifdef HAVE_EVP_SHA224 + CHashFuncEntry("sha-224", EVP_sha224()), +#endif // HAVE_EVP_SHA224 #ifdef HAVE_EVP_SHA256 CHashFuncEntry("sha-256", EVP_sha256()), #endif // HAVE_EVP_SHA256 +#ifdef HAVE_EVP_SHA384 + CHashFuncEntry("sha-384", EVP_sha384()), +#endif // HAVE_EVP_SHA384 +#ifdef HAVE_EVP_SHA512 + CHashFuncEntry("sha-512", EVP_sha512()), +#endif // HAVE_EVP_SHA512 CHashFuncEntry("md5", EVP_md5()) }; } // namespace diff --git a/src/MessageDigest.cc b/src/MessageDigest.cc index f842bf89..4c2ea17e 100644 --- a/src/MessageDigest.cc +++ b/src/MessageDigest.cc @@ -51,7 +51,10 @@ struct HashTypeEntry { namespace { HashTypeEntry hashTypes[] = { HashTypeEntry("sha-1", 1), - HashTypeEntry("sha-256", 2), + HashTypeEntry("sha-224", 2), + HashTypeEntry("sha-256", 3), + HashTypeEntry("sha-384", 4), + HashTypeEntry("sha-512", 5), HashTypeEntry("md5", 0) }; } // namespace aria2 @@ -137,6 +140,9 @@ bool MessageDigest::isValidHash std::string MessageDigest::getCanonicalHashType(const std::string& hashType) { + // This is really backward compatibility for Metalink3. aria2 only + // supported sha-1, sha-256 and md5 at Metalink3 era. So we don't + // add alias for sha-224, sha-384 and sha-512. if("sha1" == hashType) { return "sha-1"; } else if("sha256" == hashType) {