diff --git a/include/tscore/HashMD5.h b/include/tscore/HashMD5.h deleted file mode 100644 index 09c7bd67c63..00000000000 --- a/include/tscore/HashMD5.h +++ /dev/null @@ -1,41 +0,0 @@ -/** @file - - @section license License - - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - */ - -#pragma once - -#include "tscore/Hash.h" -#include - -struct ATSHashMD5 : ATSHash { - ATSHashMD5(); - void update(const void *data, size_t len) override; - void final() override; - const void *get() const override; - size_t size() const override; - void clear() override; - ~ATSHashMD5() override; - -private: - EVP_MD_CTX *ctx; - unsigned char md_value[EVP_MAX_MD_SIZE]; - unsigned int md_len = 0; - bool finalized = false; -}; diff --git a/include/tscore/INK_MD5.h b/include/tscore/MD5.h similarity index 73% rename from include/tscore/INK_MD5.h rename to include/tscore/MD5.h index baed4c59204..3131197dfef 100644 --- a/include/tscore/INK_MD5.h +++ b/include/tscore/MD5.h @@ -23,21 +23,34 @@ #pragma once -#include "tscore/ink_code.h" #include "tscore/ink_defs.h" #include "tscore/CryptoHash.h" +#include class MD5Context : public ats::CryptoContextBase { protected: - MD5_CTX _ctx; + EVP_MD_CTX *_ctx; public: - MD5Context(); + MD5Context() + { + _ctx = EVP_MD_CTX_new(); + EVP_DigestInit_ex(_ctx, EVP_md5(), nullptr); + } + ~MD5Context() { EVP_MD_CTX_free(_ctx); } /// Update the hash with @a data of @a length bytes. - bool update(void const *data, int length) override; + bool + update(void const *data, int length) override + { + return EVP_DigestUpdate(_ctx, data, length); + } /// Finalize and extract the @a hash. - bool finalize(CryptoHash &hash) override; + bool + finalize(CryptoHash &hash) override + { + return EVP_DigestFinal_ex(_ctx, hash.u8, nullptr); + } }; typedef CryptoHash INK_MD5; diff --git a/include/tscore/MMH.h b/include/tscore/MMH.h index 4489a5a19c7..15d74b64254 100644 --- a/include/tscore/MMH.h +++ b/include/tscore/MMH.h @@ -23,7 +23,6 @@ #pragma once -#include "tscore/ink_code.h" #include "tscore/ink_defs.h" #include "tscore/CryptoHash.h" diff --git a/include/tscore/SHA256.h b/include/tscore/SHA256.h index cbe8a590371..9b3140a028c 100644 --- a/include/tscore/SHA256.h +++ b/include/tscore/SHA256.h @@ -23,7 +23,6 @@ #pragma once -#include "tscore/ink_code.h" #include "tscore/ink_defs.h" #include "tscore/CryptoHash.h" #include diff --git a/include/tscore/ink_code.h b/include/tscore/ink_code.h deleted file mode 100644 index 405d43668f9..00000000000 --- a/include/tscore/ink_code.h +++ /dev/null @@ -1,42 +0,0 @@ -/** @file - - A brief file description - - @section license License - - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - */ - -#pragma once - -#include "tscore/ink_apidefs.h" -#include "tscore/ink_defs.h" -#if TS_ENABLE_FIPS == 0 -#include - -/* INK_MD5 context. */ -typedef MD5_CTX INK_DIGEST_CTX; - -/* - Wrappers around the MD5 functions, all of this should be deprecated and just use the functions directly -*/ - -int ink_code_md5(unsigned const char *input, int input_length, unsigned char *sixteen_byte_hash_pointer); -int ink_code_incr_md5_init(INK_DIGEST_CTX *context); -int ink_code_incr_md5_update(INK_DIGEST_CTX *context, const char *input, int input_length); -int ink_code_incr_md5_final(char *sixteen_byte_hash_pointer, INK_DIGEST_CTX *context); -#endif diff --git a/mgmt/api/INKMgmtAPI.cc b/mgmt/api/INKMgmtAPI.cc index 0c4c376f53b..d8a3347ac72 100644 --- a/mgmt/api/INKMgmtAPI.cc +++ b/mgmt/api/INKMgmtAPI.cc @@ -30,7 +30,6 @@ * ***************************************************************************/ #include "tscore/ink_platform.h" -#include "tscore/ink_code.h" #include "tscore/ink_memory.h" #include "tscore/ParseRules.h" #include diff --git a/src/traffic_cache_tool/Makefile.inc b/src/traffic_cache_tool/Makefile.inc index 0f662170bb1..6af99fa4926 100644 --- a/src/traffic_cache_tool/Makefile.inc +++ b/src/traffic_cache_tool/Makefile.inc @@ -35,7 +35,6 @@ traffic_cache_tool_traffic_cache_tool_SOURCES = \ traffic_cache_tool_traffic_cache_tool_LDADD = \ $(top_builddir)/src/tscore/.libs/ArgParser.o \ $(top_builddir)/src/tscore/.libs/ink_assert.o \ - $(top_builddir)/src/tscore/.libs/ink_code.o \ $(top_builddir)/src/tscore/.libs/ink_error.o \ $(top_builddir)/src/tscore/.libs/ink_file.o \ $(top_builddir)/src/tscore/.libs/ink_memory.o \ diff --git a/src/tscore/CryptoHash.cc b/src/tscore/CryptoHash.cc index 8c947dd366e..07bf2b68702 100644 --- a/src/tscore/CryptoHash.cc +++ b/src/tscore/CryptoHash.cc @@ -26,18 +26,19 @@ #include #include "tscore/ink_assert.h" #include "tscore/ink_platform.h" -#include "tscore/ink_code.h" #include "tscore/CryptoHash.h" #include "tscore/SHA256.h" #if TS_ENABLE_FIPS == 1 CryptoContext::HashType CryptoContext::Setting = CryptoContext::SHA256; #else -#include "tscore/INK_MD5.h" +#include "tscore/MD5.h" #include "tscore/MMH.h" CryptoContext::HashType CryptoContext::Setting = CryptoContext::MD5; #endif +ats::CryptoHash const ats::CRYPTO_HASH_ZERO; // default constructed is correct. + CryptoContext::CryptoContext() { switch (Setting) { diff --git a/src/tscore/HashMD5.cc b/src/tscore/HashMD5.cc deleted file mode 100644 index f8b4ff5642e..00000000000 --- a/src/tscore/HashMD5.cc +++ /dev/null @@ -1,88 +0,0 @@ -/** @file - - @section license License - - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - */ - -#include "tscore/ink_assert.h" -#include "tscore/ink_config.h" -#include "tscore/HashMD5.h" - -ATSHashMD5::ATSHashMD5() -{ - ctx = EVP_MD_CTX_new(); - int ret = EVP_DigestInit_ex(ctx, EVP_md5(), nullptr); - ink_assert(ret == 1); -} - -void -ATSHashMD5::update(const void *data, size_t len) -{ - if (!finalized) { - int ret = EVP_DigestUpdate(ctx, data, len); - ink_assert(ret == 1); - } -} - -void -ATSHashMD5::final() -{ - if (!finalized) { - int ret = EVP_DigestFinal_ex(ctx, md_value, &md_len); - ink_assert(ret == 1); - finalized = true; - } -} - -const void * -ATSHashMD5::get() const -{ - if (finalized) { - return (void *)md_value; - } else { - return nullptr; - } -} - -size_t -ATSHashMD5::size() const -{ - return EVP_MD_CTX_size(ctx); -} - -void -ATSHashMD5::clear() -{ -#ifndef OPENSSL_IS_BORINGSSL - int ret = EVP_MD_CTX_reset(ctx); -#else - // OpenSSL's EVP_MD_CTX_reset always returns 1 - int ret = 1; - EVP_MD_CTX_reset(ctx); -#endif - ink_assert(ret == 1); - ret = EVP_DigestInit_ex(ctx, EVP_md5(), nullptr); - ink_assert(ret == 1); - md_len = 0; - finalized = false; -} - -ATSHashMD5::~ATSHashMD5() -{ - EVP_MD_CTX_free(ctx); -} diff --git a/src/tscore/Makefile.am b/src/tscore/Makefile.am index 8861b86afbd..8b02bc17192 100644 --- a/src/tscore/Makefile.am +++ b/src/tscore/Makefile.am @@ -67,7 +67,6 @@ libtscore_la_SOURCES = \ Extendible.cc \ Hash.cc \ HashFNV.cc \ - HashMD5.cc \ HashSip.cc \ HostLookup.cc \ hugepages.cc \ @@ -75,7 +74,6 @@ libtscore_la_SOURCES = \ ink_assert.cc \ ink_base64.cc \ ink_cap.cc \ - ink_code.cc \ ink_defs.cc \ InkErrno.cc \ ink_error.cc \ diff --git a/src/tscore/ink_code.cc b/src/tscore/ink_code.cc deleted file mode 100644 index 931a956f764..00000000000 --- a/src/tscore/ink_code.cc +++ /dev/null @@ -1,94 +0,0 @@ -/** @file - - A brief file description - - @section license License - - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - */ - -#include -#include -#include "tscore/ink_code.h" -#include "tscore/ink_assert.h" -#include "tscore/CryptoHash.h" - -ats::CryptoHash const ats::CRYPTO_HASH_ZERO; // default constructed is correct. -#if TS_ENABLE_FIPS == 0 -#include "tscore/INK_MD5.h" - -MD5Context::MD5Context() -{ - MD5_Init(&_ctx); -} - -bool -MD5Context::update(void const *data, int length) -{ - return 0 != MD5_Update(&_ctx, data, length); -} - -bool -MD5Context::finalize(CryptoHash &hash) -{ - return 0 != MD5_Final(hash.u8, &_ctx); -} - -/** - @brief Wrapper around MD5_Init -*/ -int -ink_code_incr_md5_init(INK_DIGEST_CTX *context) -{ - return MD5_Init(context); -} - -/** - @brief Wrapper around MD5_Update -*/ -int -ink_code_incr_md5_update(INK_DIGEST_CTX *context, const char *input, int input_length) -{ - return MD5_Update(context, input, input_length); -} - -/** - @brief Wrapper around MD5_Final -*/ -int -ink_code_incr_md5_final(char *sixteen_byte_hash_pointer, INK_DIGEST_CTX *context) -{ - return MD5_Final(reinterpret_cast(sixteen_byte_hash_pointer), context); -} - -/** - @brief Helper that will init, update, and create a final MD5 - - @return always returns 0, maybe some error checking should be done -*/ -int -ink_code_md5(unsigned const char *input, int input_length, unsigned char *sixteen_byte_hash_pointer) -{ - MD5_CTX context; - - MD5_Init(&context); - MD5_Update(&context, input, input_length); - MD5_Final(sixteen_byte_hash_pointer, &context); - - return (0); -} -#endif diff --git a/src/tscore/unit_tests/test_BufferWriterFormat.cc b/src/tscore/unit_tests/test_BufferWriterFormat.cc index 43ab882b798..66004f97db7 100644 --- a/src/tscore/unit_tests/test_BufferWriterFormat.cc +++ b/src/tscore/unit_tests/test_BufferWriterFormat.cc @@ -31,7 +31,7 @@ #include "tscpp/util/MemSpan.h" #include "tscore/ink_config.h" #if TS_ENABLE_FIPS == 0 -#include "tscore/INK_MD5.h" +#include "tscore/MD5.h" #endif #include "tscore/CryptoHash.h" diff --git a/tools/jtest/jtest.cc b/tools/jtest/jtest.cc index 70efc73e962..a33f502aa18 100644 --- a/tools/jtest/jtest.cc +++ b/tools/jtest/jtest.cc @@ -56,7 +56,7 @@ #include "tscore/ink_error.h" #include "tscore/ink_memory.h" #include "tscore/ink_assert.h" -#include "tscore/INK_MD5.h" +#include "tscore/MD5.h" #include "tscore/ParseRules.h" #include "tscore/ink_time.h" #include "tscore/ink_args.h"