diff --git a/AGENTS.md b/AGENTS.md index 545d9f624b..b0cc147841 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -12,7 +12,7 @@ score/ # C++ AND Rust libraries side by side (concurrency, containers, # Most components have a docs/ subfolder with requirements, architecture, detailed design, and safety analysis. src/ # Deprecated Bazel alias stubs. No real sources here. examples/ # Integration and usage examples (C++ and Rust) -third_party/ # External dependency BUILD files (acl, openssl, libcap2, etc.) +third_party/ # External dependency BUILD files (acl, libcap2, etc.) docs/ # Feature-level and module-level Sphinx docs. .github/ # CI workflows, CODEOWNERS, tools ``` diff --git a/MODULE.bazel b/MODULE.bazel index 1525f35e11..2f95ca2dbe 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -83,8 +83,6 @@ bazel_dep(name = "googletest", version = "1.17.0.bcr.2") bazel_dep(name = "google_benchmark", version = "1.9.5") bazel_dep(name = "download_utils", version = "1.2.2") bazel_dep(name = "rules_cc", version = "0.2.17") -bazel_dep(name = "openssl", version = "3.5.5.bcr.4") - ## Configure the Rust toolchain bazel_dep(name = "rules_rust", version = "0.68.2-score") diff --git a/MODULE.bazel.lock b/MODULE.bazel.lock index f4ed980a57..8634f77ca2 100644 --- a/MODULE.bazel.lock +++ b/MODULE.bazel.lock @@ -225,8 +225,6 @@ "https://bcr.bazel.build/modules/opencensus-cpp/0.0.0-20230502-50eb5de/source.json": "f50efc07822f5425bd1d3e40e977484f9c0142463052717d40ec85cd6744243e", "https://bcr.bazel.build/modules/opencensus-proto/0.4.1/MODULE.bazel": "4a2e8b4d0b544002502474d611a5a183aa282251e14f6a01afe841c0c1b10372", "https://bcr.bazel.build/modules/opencensus-proto/0.4.1/source.json": "a7d956700a85b833c43fc61455c0e111ab75bab40768ed17a206ee18a2bbe38f", - "https://bcr.bazel.build/modules/openssl/3.5.5.bcr.4/MODULE.bazel": "b3f35b53c6c73bd3a7c8efbf9b7e79e92566d189e64d313aede69f608ac6dd77", - "https://bcr.bazel.build/modules/openssl/3.5.5.bcr.4/source.json": "662d68be9227e60ef65fed83c6820564bda4af0efe6a40dc62dd9aee288fe9cf", "https://bcr.bazel.build/modules/opentelemetry-cpp/1.14.2/MODULE.bazel": "089a5613c2a159c7dfde098dabfc61e966889c7d6a81a98422a84c51535ed17d", "https://bcr.bazel.build/modules/opentelemetry-cpp/1.16.0/MODULE.bazel": "b7379a140f538cea3f749179a2d481ed81942cc6f7b05a6113723eb34ac3b3e7", "https://bcr.bazel.build/modules/opentelemetry-cpp/1.16.0/source.json": "da0cf667713b1e48d7f8912b100b4e0a8284c8a95717af5eb8c830d699e61cf5", @@ -400,8 +398,6 @@ "https://bcr.bazel.build/modules/rules_nodejs/6.5.2/MODULE.bazel": "7f9ea68a0ce6d82905ce9f74e76ab8a8b4531ed4c747018c9d76424ad0b3370d", "https://bcr.bazel.build/modules/rules_nodejs/6.7.3/MODULE.bazel": "c22a48b2a0dbf05a9dc5f83837bbc24c226c1f6e618de3c3a610044c9f336056", "https://bcr.bazel.build/modules/rules_nodejs/6.7.3/source.json": "a3f966f4415a8a6545e560ee5449eac95cc633f96429d08e87c87775c72f5e09", - "https://bcr.bazel.build/modules/rules_perl/1.1.0/MODULE.bazel": "22138e75bb8f1ee6c21f609b90d2c24b0c9b796ccf55cc04c1c9190b699f7e9d", - "https://bcr.bazel.build/modules/rules_perl/1.1.0/source.json": "896fe7707a38c5b229c6f5fa77134209874c4d57fecda5f756c1f23e4d25aae2", "https://bcr.bazel.build/modules/rules_pkg/0.7.0/MODULE.bazel": "df99f03fc7934a4737122518bb87e667e62d780b610910f0447665a7e2be62dc", "https://bcr.bazel.build/modules/rules_pkg/1.0.1/MODULE.bazel": "5b1df97dbc29623bccdf2b0dcd0f5cb08e2f2c9050aab1092fd39a41e82686ff", "https://bcr.bazel.build/modules/rules_pkg/1.1.0/MODULE.bazel": "9db8031e71b6ef32d1846106e10dd0ee2deac042bd9a2de22b4761b0c3036453", @@ -683,7 +679,6 @@ "https://raw.githubusercontent.com/eclipse-score/bazel_registry/main/modules/nlohmann_json/3.6.1/MODULE.bazel": "not found", "https://raw.githubusercontent.com/eclipse-score/bazel_registry/main/modules/opencensus-cpp/0.0.0-20230502-50eb5de/MODULE.bazel": "not found", "https://raw.githubusercontent.com/eclipse-score/bazel_registry/main/modules/opencensus-proto/0.4.1/MODULE.bazel": "not found", - "https://raw.githubusercontent.com/eclipse-score/bazel_registry/main/modules/openssl/3.5.5.bcr.4/MODULE.bazel": "not found", "https://raw.githubusercontent.com/eclipse-score/bazel_registry/main/modules/opentelemetry-cpp/1.14.2/MODULE.bazel": "not found", "https://raw.githubusercontent.com/eclipse-score/bazel_registry/main/modules/opentelemetry-cpp/1.16.0/MODULE.bazel": "not found", "https://raw.githubusercontent.com/eclipse-score/bazel_registry/main/modules/opentelemetry-proto/1.1.0/MODULE.bazel": "not found", @@ -833,7 +828,6 @@ "https://raw.githubusercontent.com/eclipse-score/bazel_registry/main/modules/rules_nodejs/6.3.3/MODULE.bazel": "not found", "https://raw.githubusercontent.com/eclipse-score/bazel_registry/main/modules/rules_nodejs/6.5.2/MODULE.bazel": "not found", "https://raw.githubusercontent.com/eclipse-score/bazel_registry/main/modules/rules_nodejs/6.7.3/MODULE.bazel": "not found", - "https://raw.githubusercontent.com/eclipse-score/bazel_registry/main/modules/rules_perl/1.1.0/MODULE.bazel": "not found", "https://raw.githubusercontent.com/eclipse-score/bazel_registry/main/modules/rules_pkg/0.7.0/MODULE.bazel": "not found", "https://raw.githubusercontent.com/eclipse-score/bazel_registry/main/modules/rules_pkg/1.0.1/MODULE.bazel": "not found", "https://raw.githubusercontent.com/eclipse-score/bazel_registry/main/modules/rules_pkg/1.1.0/MODULE.bazel": "not found", diff --git a/docs/baselibs/components/index.rst b/docs/baselibs/components/index.rst index 75aac0dcd8..a5d365c26f 100644 --- a/docs/baselibs/components/index.rst +++ b/docs/baselibs/components/index.rst @@ -36,8 +36,8 @@ Overview - :need:`doc__flatbuffers`: FlatBuffers-Library with serialization, read access, and structural verification of FlatBuffers data, plus code generation via ``flatc`` for C++, Rust, and Python. - :need:`doc__filesystem`: Filesystem manipulation library similar to ``std::filesystem``. -- :need:`doc__hash`: Hash calculation library supporting cryptographic (SHA-256, SHA-512) and - checksum (CRC-32) algorithms via a pluggable interface. +- :need:`doc__hash`: Checksum library supporting CRC-32 and a transitional native SHA-256 implementation for + existing safety-integrity consumers. Cryptographic hash operations are provided by the Security Crypto feature. - :need:`doc__futurecpp`: Extends the C++17 Standard Library with features from newer C++ standards up to C++26, as well as selected proposals for the C++ Standard Library. - :need:`doc__safecpp`: A collection of utilities that helps developers write safer C++ code, including diff --git a/examples/integration/MODULE.bazel.lock b/examples/integration/MODULE.bazel.lock index 840f011352..a38da424e5 100644 --- a/examples/integration/MODULE.bazel.lock +++ b/examples/integration/MODULE.bazel.lock @@ -215,8 +215,6 @@ "https://bcr.bazel.build/modules/opencensus-cpp/0.0.0-20230502-50eb5de/source.json": "f50efc07822f5425bd1d3e40e977484f9c0142463052717d40ec85cd6744243e", "https://bcr.bazel.build/modules/opencensus-proto/0.4.1/MODULE.bazel": "4a2e8b4d0b544002502474d611a5a183aa282251e14f6a01afe841c0c1b10372", "https://bcr.bazel.build/modules/opencensus-proto/0.4.1/source.json": "a7d956700a85b833c43fc61455c0e111ab75bab40768ed17a206ee18a2bbe38f", - "https://bcr.bazel.build/modules/openssl/3.5.5.bcr.4/MODULE.bazel": "b3f35b53c6c73bd3a7c8efbf9b7e79e92566d189e64d313aede69f608ac6dd77", - "https://bcr.bazel.build/modules/openssl/3.5.5.bcr.4/source.json": "662d68be9227e60ef65fed83c6820564bda4af0efe6a40dc62dd9aee288fe9cf", "https://bcr.bazel.build/modules/opentelemetry-cpp/1.14.2/MODULE.bazel": "089a5613c2a159c7dfde098dabfc61e966889c7d6a81a98422a84c51535ed17d", "https://bcr.bazel.build/modules/opentelemetry-cpp/1.16.0/MODULE.bazel": "b7379a140f538cea3f749179a2d481ed81942cc6f7b05a6113723eb34ac3b3e7", "https://bcr.bazel.build/modules/opentelemetry-cpp/1.16.0/source.json": "da0cf667713b1e48d7f8912b100b4e0a8284c8a95717af5eb8c830d699e61cf5", @@ -388,8 +386,6 @@ "https://bcr.bazel.build/modules/rules_nodejs/6.3.3/MODULE.bazel": "b66eadebd10f1f1b25f52f95ab5213a57e82c37c3f656fcd9a57ad04d2264ce7", "https://bcr.bazel.build/modules/rules_nodejs/6.5.2/MODULE.bazel": "7f9ea68a0ce6d82905ce9f74e76ab8a8b4531ed4c747018c9d76424ad0b3370d", "https://bcr.bazel.build/modules/rules_nodejs/6.5.2/source.json": "6a6ca0940914d55c550d1417cad13a56c9900e23f651a762d8ccc5a64adcf661", - "https://bcr.bazel.build/modules/rules_perl/1.1.0/MODULE.bazel": "22138e75bb8f1ee6c21f609b90d2c24b0c9b796ccf55cc04c1c9190b699f7e9d", - "https://bcr.bazel.build/modules/rules_perl/1.1.0/source.json": "896fe7707a38c5b229c6f5fa77134209874c4d57fecda5f756c1f23e4d25aae2", "https://bcr.bazel.build/modules/rules_pkg/0.7.0/MODULE.bazel": "df99f03fc7934a4737122518bb87e667e62d780b610910f0447665a7e2be62dc", "https://bcr.bazel.build/modules/rules_pkg/1.0.1/MODULE.bazel": "5b1df97dbc29623bccdf2b0dcd0f5cb08e2f2c9050aab1092fd39a41e82686ff", "https://bcr.bazel.build/modules/rules_pkg/1.1.0/MODULE.bazel": "9db8031e71b6ef32d1846106e10dd0ee2deac042bd9a2de22b4761b0c3036453", @@ -660,7 +656,6 @@ "https://raw.githubusercontent.com/eclipse-score/bazel_registry/main/modules/nlohmann_json/3.6.1/MODULE.bazel": "not found", "https://raw.githubusercontent.com/eclipse-score/bazel_registry/main/modules/opencensus-cpp/0.0.0-20230502-50eb5de/MODULE.bazel": "not found", "https://raw.githubusercontent.com/eclipse-score/bazel_registry/main/modules/opencensus-proto/0.4.1/MODULE.bazel": "not found", - "https://raw.githubusercontent.com/eclipse-score/bazel_registry/main/modules/openssl/3.5.5.bcr.4/MODULE.bazel": "not found", "https://raw.githubusercontent.com/eclipse-score/bazel_registry/main/modules/opentelemetry-cpp/1.14.2/MODULE.bazel": "not found", "https://raw.githubusercontent.com/eclipse-score/bazel_registry/main/modules/opentelemetry-cpp/1.16.0/MODULE.bazel": "not found", "https://raw.githubusercontent.com/eclipse-score/bazel_registry/main/modules/opentelemetry-proto/1.1.0/MODULE.bazel": "not found", @@ -807,7 +802,6 @@ "https://raw.githubusercontent.com/eclipse-score/bazel_registry/main/modules/rules_nodejs/6.3.0/MODULE.bazel": "not found", "https://raw.githubusercontent.com/eclipse-score/bazel_registry/main/modules/rules_nodejs/6.3.3/MODULE.bazel": "not found", "https://raw.githubusercontent.com/eclipse-score/bazel_registry/main/modules/rules_nodejs/6.5.2/MODULE.bazel": "not found", - "https://raw.githubusercontent.com/eclipse-score/bazel_registry/main/modules/rules_perl/1.1.0/MODULE.bazel": "not found", "https://raw.githubusercontent.com/eclipse-score/bazel_registry/main/modules/rules_pkg/0.7.0/MODULE.bazel": "not found", "https://raw.githubusercontent.com/eclipse-score/bazel_registry/main/modules/rules_pkg/1.0.1/MODULE.bazel": "not found", "https://raw.githubusercontent.com/eclipse-score/bazel_registry/main/modules/rules_pkg/1.1.0/MODULE.bazel": "not found", diff --git a/score/hash/code/common/algorithms.cpp b/score/hash/code/common/algorithms.cpp index 5a661ffd09..6b67427eae 100644 --- a/score/hash/code/common/algorithms.cpp +++ b/score/hash/code/common/algorithms.cpp @@ -30,18 +30,9 @@ score::cpp::optional HashSizeInBytes(const HashAlgorithm algorithm case HashAlgorithm::kCrc32Autosar: hashSizeInBytes = kCrc32AutosarSize; break; - case HashAlgorithm::kSha1: - hashSizeInBytes = kSha1Size; - break; case HashAlgorithm::kSha256: hashSizeInBytes = kSha256Size; break; - case HashAlgorithm::kSha384: - hashSizeInBytes = kSha384Size; - break; - case HashAlgorithm::kSha512: - hashSizeInBytes = kSha512Size; - break; case HashAlgorithm::kNone: case HashAlgorithm::kLast: default: @@ -74,18 +65,9 @@ HashAlgorithm IdentifyHash(std::string_view hash_string) noexcept // there's no way to distinguish between kCrc32 and kCrc32Autosar based on the bytes alone identifiedHash = HashAlgorithm::kCrc32; break; - case kSha1Size * 2U: - identifiedHash = HashAlgorithm::kSha1; - break; case kSha256Size * 2U: identifiedHash = HashAlgorithm::kSha256; break; - case kSha384Size * 2U: - identifiedHash = HashAlgorithm::kSha384; - break; - case kSha512Size * 2U: - identifiedHash = HashAlgorithm::kSha512; - break; default: break; } @@ -103,18 +85,9 @@ HashAlgorithm IdentifyHash(std::size_t hash_size_in_bytes) noexcept // there's no way to distinguish between kCrc32 and kCrc32Autosar based on the bytes alone identifiedHash = HashAlgorithm::kCrc32; break; - case kSha1Size: - identifiedHash = HashAlgorithm::kSha1; - break; case kSha256Size: identifiedHash = HashAlgorithm::kSha256; break; - case kSha384Size: - identifiedHash = HashAlgorithm::kSha384; - break; - case kSha512Size: - identifiedHash = HashAlgorithm::kSha512; - break; default: break; } diff --git a/score/hash/code/common/algorithms.h b/score/hash/code/common/algorithms.h index 69d57f289d..e25ddeaca6 100644 --- a/score/hash/code/common/algorithms.h +++ b/score/hash/code/common/algorithms.h @@ -25,26 +25,22 @@ namespace score namespace hash { +// Retain the existing capacity to avoid changing the layout of public hash types during the algorithm migration. constexpr std::size_t kMaxDigestSize{64U}; -constexpr std::uint8_t kSha1Size{20U}; constexpr std::uint8_t kSha256Size{32U}; -constexpr std::uint8_t kSha384Size{48U}; -constexpr std::uint8_t kSha512Size{64U}; constexpr std::uint8_t kCrc32Size{4U}; constexpr std::uint8_t kCrc32AutosarSize{4U}; -/// Cryptographic hash algorithm +/// Hash and checksum algorithms retained for safety-integrity use cases. enum class HashAlgorithm : std::uint8_t { kNone = 0, - kSha1, - kSha256, - kSha384, - kSha512, - kCrc32, - kCrc32Autosar, - kLast + // Values 1, 3, and 4 are reserved for the removed SHA-1, SHA-384, and SHA-512 identifiers. + kSha256 = 2, + kCrc32 = 5, + kCrc32Autosar = 6, + kLast = 7 }; // Suppress "UNUSED C++14 A13-2-2" rule finding: "A binary arithmetic operator and a bitwise operator shall return @@ -64,18 +60,9 @@ inline score::mw::log::LogStream& operator<<(score::mw::log::LogStream& stream, case HashAlgorithm::kCrc32Autosar: modifiedStream << "Crc32Autosar"; break; - case HashAlgorithm::kSha1: - modifiedStream << "Sha1"; - break; case HashAlgorithm::kSha256: modifiedStream << "Sha256"; break; - case HashAlgorithm::kSha384: - modifiedStream << "Sha384"; - break; - case HashAlgorithm::kSha512: - modifiedStream << "Sha512"; - break; case HashAlgorithm::kNone: modifiedStream << "None"; break; @@ -93,18 +80,17 @@ inline score::mw::log::LogStream& operator<<(score::mw::log::LogStream& stream, score::cpp::optional HashSizeInBytes(const HashAlgorithm algorithm) noexcept; score::cpp::optional HashSizeInCharacters(const HashAlgorithm algorithm) noexcept; -/// @brief identify the hash algorithm from the \p hash_string -/// @example if input is sha1sum as string "526eac4f80dd6e6e73c7a501dff1abc83f0b7ccc" the return will be -/// HashAlgorithm::kSha1 +/// @brief Identifies the hash algorithm from the length of \p hash_string. +/// @example A 64-character hexadecimal digest is identified as HashAlgorithm::kSha256. /// /// @param[in] hash_string - the hash as a string /// @return HashAlgorithm - the \p hash_string algorithm type HashAlgorithm IdentifyHash(std::string_view hash_string) noexcept; -/// @brief identify hash algorithm from \p hash_size_in_bytes, for example vector.size() +/// @brief Identifies the hash algorithm from \p hash_size_in_bytes, for example vector.size(). /// -/// @param[in] hash_vector - hash size in bytes -/// @return HashAlgorithm -the \p hash_size_in_bytes algorithm type +/// @param[in] hash_size_in_bytes - hash size in bytes +/// @return HashAlgorithm - the \p hash_size_in_bytes algorithm type HashAlgorithm IdentifyHash(std::size_t hash_size_in_bytes) noexcept; } // namespace hash diff --git a/score/hash/code/common/algorithms_test.cpp b/score/hash/code/common/algorithms_test.cpp index 7ef916084f..a5cf70d1e2 100644 --- a/score/hash/code/common/algorithms_test.cpp +++ b/score/hash/code/common/algorithms_test.cpp @@ -55,19 +55,10 @@ class AlgorithmLoggerFixture : public ::testing::Test TEST(HashIdentify, CorrectlyIdentifyHashFromString) { const std::string crc32{"4342711f"}; - const std::string sha1{"526eac4f80dd6e6e73c7a501dff1abc83f0b7ccc"}; const std::string sha256{"78e599a1555f8dec1d91833c01523e14ea8373cb92345600b24a3cbe987ba400"}; - const std::string sha384{ - "ca796ef303046f9773b9ca35b092be4a86b22d72f0ed91a0e49208d8defadf9f4de3bf63320c32d6890e80b7159afcdf"}; - const std::string sha512{ - "85b7400acc3064a0009ffbd99e2ace4b0d97ac0395f001d0e3ef8fe7f84fe91dfcb25366c6195684fab5e92c44218ed6bcfa50d7eea349" - "2d39f5800a06c47e91"}; EXPECT_EQ(IdentifyHash(crc32), HashAlgorithm::kCrc32); - EXPECT_EQ(IdentifyHash(sha1), HashAlgorithm::kSha1); EXPECT_EQ(IdentifyHash(sha256), HashAlgorithm::kSha256); - EXPECT_EQ(IdentifyHash(sha384), HashAlgorithm::kSha384); - EXPECT_EQ(IdentifyHash(sha512), HashAlgorithm::kSha512); } TEST(HashIdentify, CanNotIdentifyBadHashesFromString) @@ -75,37 +66,27 @@ TEST(HashIdentify, CanNotIdentifyBadHashesFromString) const std::string bad_hash_0{""}; const std::string bad_hash_1{"a"}; const std::string bad_hash_41{"526eac4f80dd6e6e73c7a501dff1abc83f0b7ccca"}; + const std::string removed_sha1_digest(40U, 'a'); + const std::string removed_sha384_digest(96U, 'a'); + const std::string removed_sha512_digest(128U, 'a'); EXPECT_EQ(IdentifyHash(bad_hash_0), HashAlgorithm::kNone); EXPECT_EQ(IdentifyHash(bad_hash_1), HashAlgorithm::kNone); EXPECT_EQ(IdentifyHash(bad_hash_41), HashAlgorithm::kNone); + EXPECT_EQ(IdentifyHash(removed_sha1_digest), HashAlgorithm::kNone); + EXPECT_EQ(IdentifyHash(removed_sha384_digest), HashAlgorithm::kNone); + EXPECT_EQ(IdentifyHash(removed_sha512_digest), HashAlgorithm::kNone); } TEST(HashIdentify, CorrectlyIdentifyHashFromSize) { const std::vector crc32{0x43, 0x42, 0x71, 0x1f}; - const std::vector sha1{0x52, 0x6e, 0xac, 0x4f, 0x80, 0xdd, 0x6e, 0x6e, 0x73, 0xc7, - 0xa5, 0x01, 0xdf, 0xf1, 0xab, 0xc8, 0x3f, 0x0b, 0x7c, 0xcc}; const std::vector sha256{0x78, 0xe5, 0x99, 0xa1, 0x55, 0x5f, 0x8d, 0xec, 0x1d, 0x91, 0x83, 0x3c, 0x01, 0x52, 0x3e, 0x14, 0xea, 0x83, 0x73, 0xcb, 0x92, 0x34, 0x56, 0x00, 0xb2, 0x4a, 0x3c, 0xbe, 0x98, 0x7b, 0xa4, 0x00}; - const std::vector sha384{0xca, 0x79, 0x6e, 0xf3, 0x03, 0x04, 0x6f, 0x97, 0x73, 0xb9, 0xca, 0x35, - 0xb0, 0x92, 0xbe, 0x4a, 0x86, 0xb2, 0x2d, 0x72, 0xf0, 0xed, 0x91, 0xa0, - 0xe4, 0x92, 0x08, 0xd8, 0xde, 0xfa, 0xdf, 0x9f, 0x4d, 0xe3, 0xbf, 0x63, - 0x32, 0x0c, 0x32, 0xd6, 0x89, 0x0e, 0x80, 0xb7, 0x15, 0x9a, 0xfc, 0xdf}; - const std::vector sha512{0x85, 0xb7, 0x40, 0x0a, 0xcc, 0x30, 0x64, 0xa0, 0x00, 0x9f, 0xfb, 0xd9, 0x9e, - 0x2a, 0xce, 0x4b, 0x0d, 0x97, 0xac, 0x03, 0x95, 0xf0, 0x01, 0xd0, 0xe3, 0xef, - 0x8f, 0xe7, 0xf8, 0x4f, 0xe9, 0x1d, 0xfc, 0xb2, 0x53, 0x66, 0xc6, 0x19, 0x56, - 0x84, 0xfa, 0xb5, 0xe9, 0x2c, 0x44, 0x21, 0x8e, 0xd6, 0xbc, 0xfa, 0x50, 0xd7, - 0xee, 0xa3, 0x49, 0x2d, 0x39, 0xf5, 0x80, 0x0a, 0x06, 0xc4, 0x7e, 0x91 - - }; EXPECT_EQ(IdentifyHash(crc32.size()), HashAlgorithm::kCrc32); - EXPECT_EQ(IdentifyHash(sha1.size()), HashAlgorithm::kSha1); EXPECT_EQ(IdentifyHash(sha256.size()), HashAlgorithm::kSha256); - EXPECT_EQ(IdentifyHash(sha384.size()), HashAlgorithm::kSha384); - EXPECT_EQ(IdentifyHash(sha512.size()), HashAlgorithm::kSha512); } TEST(HashIdentify, CanNotIdentifyBadHashesFromSize) @@ -118,6 +99,9 @@ TEST(HashIdentify, CanNotIdentifyBadHashesFromSize) EXPECT_EQ(IdentifyHash(bad_hash_0.size()), HashAlgorithm::kNone); EXPECT_EQ(IdentifyHash(bad_hash_1.size()), HashAlgorithm::kNone); EXPECT_EQ(IdentifyHash(bad_hash_41.size()), HashAlgorithm::kNone); + EXPECT_EQ(IdentifyHash(20U), HashAlgorithm::kNone); + EXPECT_EQ(IdentifyHash(48U), HashAlgorithm::kNone); + EXPECT_EQ(IdentifyHash(64U), HashAlgorithm::kNone); } TEST(HashIdentify, CorrectSizes) @@ -125,10 +109,7 @@ TEST(HashIdentify, CorrectSizes) const auto expected_sizes_bytes = std::map{ {HashAlgorithm::kCrc32, 4}, {HashAlgorithm::kCrc32Autosar, 4}, - {HashAlgorithm::kSha1, 20}, {HashAlgorithm::kSha256, 32}, - {HashAlgorithm::kSha384, 48}, - {HashAlgorithm::kSha512, 64}, }; for (const auto [key, expected_size] : expected_sizes_bytes) @@ -146,6 +127,13 @@ TEST(HashIdentify, CorrectSizes) EXPECT_FALSE(score::hash::HashSizeInBytes(HashAlgorithm::kLast).has_value()); EXPECT_FALSE(score::hash::HashSizeInCharacters(HashAlgorithm::kNone).has_value()); EXPECT_FALSE(score::hash::HashSizeInCharacters(HashAlgorithm::kLast).has_value()); + + for (const auto removed_algorithm_value : {1U, 3U, 4U}) + { + const auto removed_algorithm = static_cast(removed_algorithm_value); + EXPECT_FALSE(score::hash::HashSizeInBytes(removed_algorithm).has_value()); + EXPECT_FALSE(score::hash::HashSizeInCharacters(removed_algorithm).has_value()); + } } TEST_F(AlgorithmLoggerFixture, CanLogAlgorithms) @@ -157,18 +145,9 @@ TEST_F(AlgorithmLoggerFixture, CanLogAlgorithms) EXPECT_CALL(recorder_, LogStringView(_, {"CRC32 AUTOSAR:"})); EXPECT_CALL(recorder_, LogStringView(_, {"Crc32Autosar"})); - EXPECT_CALL(recorder_, LogStringView(_, {"SHA-1:"})); - EXPECT_CALL(recorder_, LogStringView(_, {"Sha1"})); - EXPECT_CALL(recorder_, LogStringView(_, {"SHA-256:"})); EXPECT_CALL(recorder_, LogStringView(_, {"Sha256"})); - EXPECT_CALL(recorder_, LogStringView(_, {"SHA-384:"})); - EXPECT_CALL(recorder_, LogStringView(_, {"Sha384"})); - - EXPECT_CALL(recorder_, LogStringView(_, {"SHA-512:"})); - EXPECT_CALL(recorder_, LogStringView(_, {"Sha512"})); - EXPECT_CALL(recorder_, LogStringView(_, {"None:"})); EXPECT_CALL(recorder_, LogStringView(_, {"None"})); @@ -182,10 +161,7 @@ TEST_F(AlgorithmLoggerFixture, CanLogAlgorithms) mw::log::LogInfo() << "CRC32:" << HashAlgorithm::kCrc32; mw::log::LogInfo() << "CRC32 AUTOSAR:" << HashAlgorithm::kCrc32Autosar; - mw::log::LogInfo() << "SHA-1:" << HashAlgorithm::kSha1; mw::log::LogInfo() << "SHA-256:" << HashAlgorithm::kSha256; - mw::log::LogInfo() << "SHA-384:" << HashAlgorithm::kSha384; - mw::log::LogInfo() << "SHA-512:" << HashAlgorithm::kSha512; mw::log::LogInfo() << "None:" << HashAlgorithm::kNone; mw::log::LogInfo() << "Last:" << HashAlgorithm::kLast; mw::log::LogInfo() << "Invalid:" << HashAlgorithm{42}; diff --git a/score/hash/code/core/factory/impl/BUILD b/score/hash/code/core/factory/impl/BUILD index d3d331c15b..d89848ae46 100644 --- a/score/hash/code/core/factory/impl/BUILD +++ b/score/hash/code/core/factory/impl/BUILD @@ -45,7 +45,6 @@ cc_library( deps = [ "@score_baselibs//score/hash/code/core/factory", "@score_baselibs//score/hash/code/crc:crc_ieee", - "@score_baselibs//score/hash/code/openssl:openssl_cal", "@score_baselibs//score/hash/code/sha256digest", ], ) @@ -103,7 +102,6 @@ cc_test( ":hash_impl_ieee", ":safe_hash_impl_ieee", "@googletest//:gtest_main", - "@score_baselibs//score/hash/code/openssl/openssl_wrapper:openssl_lib_mock", "@score_baselibs//score/mw/log:backend_stub_testutil", ], ) diff --git a/score/hash/code/core/factory/impl/hash_calculator_factory.h b/score/hash/code/core/factory/impl/hash_calculator_factory.h index 7c0eef2c67..9df7aea8bd 100644 --- a/score/hash/code/core/factory/impl/hash_calculator_factory.h +++ b/score/hash/code/core/factory/impl/hash_calculator_factory.h @@ -15,7 +15,6 @@ #define SCORE_LIB_HASH_CODE_CORE_FACTORY_IMPL_HASHCALCULATOR_FATCORY_H #include "score/hash/code/core/factory/i_hash_calculator_factory.h" -#include "score/hash/code/openssl/openssl_hash_calculator.h" namespace score { @@ -26,14 +25,8 @@ namespace hash class HashCalculatorFactory final : public IHashCalculatorFactory { public: - explicit HashCalculatorFactory( - score::cpp::optional> openssl_lib = {}) noexcept; - Result> CreateHashCalculator( const HashAlgorithm algorithm) const noexcept override; - - private: - score::cpp::optional> openssl_lib_; }; } // namespace hash diff --git a/score/hash/code/core/factory/impl/hash_calculator_factory_ieee.cpp b/score/hash/code/core/factory/impl/hash_calculator_factory_ieee.cpp index 57973d7c35..495def9048 100644 --- a/score/hash/code/core/factory/impl/hash_calculator_factory_ieee.cpp +++ b/score/hash/code/core/factory/impl/hash_calculator_factory_ieee.cpp @@ -23,12 +23,6 @@ namespace score namespace hash { -HashCalculatorFactory::HashCalculatorFactory( - score::cpp::optional> openssl_lib) noexcept - : IHashCalculatorFactory(), openssl_lib_{openssl_lib} -{ -} - Result> HashCalculatorFactory::CreateHashCalculator( const HashAlgorithm algorithm) const noexcept { @@ -45,22 +39,6 @@ Result> HashCalculatorFactory::CreateHashCalcul case HashAlgorithm::kSha256: result = static_cast>(std::make_unique()); break; - case HashAlgorithm::kSha1: - case HashAlgorithm::kSha384: - case HashAlgorithm::kSha512: - { - auto digest = openssl_lib_.has_value() ? OpensslHashCalculator::Create(algorithm, openssl_lib_->get()) - : OpensslHashCalculator::Create(algorithm); - if (!digest.has_value()) - { - mw::log::LogError() << "HashCalculatorFactory::Could not create OpenSSL based digest"; - return MakeUnexpected>(digest.error()); - } - - result = static_cast>( - std::make_unique(std::move(*digest))); - break; - } case HashAlgorithm::kCrc32Autosar: case HashAlgorithm::kNone: case HashAlgorithm::kLast: diff --git a/score/hash/code/core/factory/impl/hash_calculator_factory_ieee_test.cpp b/score/hash/code/core/factory/impl/hash_calculator_factory_ieee_test.cpp index 24f128b0e6..4a81f2fcb4 100644 --- a/score/hash/code/core/factory/impl/hash_calculator_factory_ieee_test.cpp +++ b/score/hash/code/core/factory/impl/hash_calculator_factory_ieee_test.cpp @@ -11,10 +11,8 @@ * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ #include "score/hash/code/common/algorithms.h" -#include "score/hash/code/common/error.h" #include "score/hash/code/core/factory/impl/hash_calculator_factory.h" #include "score/hash/code/core/factory/impl/safe_hash_calculator_factory.h" -#include "score/hash/code/openssl/openssl_wrapper/openssl_lib_mock.h" #include #include @@ -115,11 +113,23 @@ TYPED_TEST_P(HashCalculatorFactoryCreationTest, Crc32AutosarNotSupportedInIeeeVa EXPECT_FALSE(result.has_value()); } +TYPED_TEST_P(HashCalculatorFactoryCreationTest, RemovedCryptographicAlgorithmsAreNotSupported) +{ + TypeParam unit{}; + + for (const auto removed_algorithm_value : {1U, 3U, 4U}) + { + const auto removed_algorithm = static_cast(removed_algorithm_value); + EXPECT_FALSE(unit.CreateHashCalculator(removed_algorithm).has_value()); + } +} + REGISTER_TYPED_TEST_SUITE_P(HashCalculatorFactoryCreationTest, HashCalculatorFactorySuccessTest, CalculateSha256, CalculateCrc32, - Crc32AutosarNotSupportedInIeeeVariant); + Crc32AutosarNotSupportedInIeeeVariant, + RemovedCryptographicAlgorithmsAreNotSupported); using Factories = ::testing::Types; INSTANTIATE_TYPED_TEST_SUITE_P(WorkingDigests, HashCalculatorFactoryCreationTest, Factories, ); @@ -223,38 +233,10 @@ TEST(HashCalculatorFactory, HashCalculatorStreamInputWithMaxRead) EXPECT_EQ(hash_result_sha256.value(), (Hash{HashAlgorithm::kSha256, expected_sha256})); } -TEST(HashCalculatorFactory, InstantiateWithFailingOpenSslLib) -{ - openssl::OpensslLibMock open_ssl_lib_mock{}; - EXPECT_CALL(open_ssl_lib_mock, DigestAlgoSha1()).WillOnce(::testing::Return(nullptr)); - HashCalculatorFactory unit{std::cref(open_ssl_lib_mock)}; - const auto create_result{unit.CreateHashCalculator(HashAlgorithm::kSha1)}; - ASSERT_FALSE(create_result.has_value()); - EXPECT_EQ(create_result.error(), ErrorCode::kCouldNotCreateDigest); -} - -TEST(HashCalculatorFactory, InstantiateWithSuccess) -{ - openssl::OpensslLibMock open_ssl_lib_mock{}; - { - openssl::StructDigestCtx* digest_context{reinterpret_cast(0xC0DEBEEF)}; - const openssl::StructDigest* digest{reinterpret_cast(0xDEADBEEF)}; - - ::testing::InSequence seq{}; - EXPECT_CALL(open_ssl_lib_mock, DigestAlgoSha1()).WillOnce(::testing::Return(digest)); - EXPECT_CALL(open_ssl_lib_mock, CreateDigestCtx()).WillOnce(::testing::Return(digest_context)); - EXPECT_CALL(open_ssl_lib_mock, InitDigestCtx(digest_context, digest, nullptr)).WillOnce(::testing::Return(37)); - } - - HashCalculatorFactory unit{std::cref(open_ssl_lib_mock)}; - const auto create_result{unit.CreateHashCalculator(HashAlgorithm::kSha1)}; - EXPECT_TRUE(create_result.has_value()); -} - TEST(SafeHashCalculatorFactory, TryToInstantiateNonexistentHash) { SafeHashCalculatorFactory unit{}; - EXPECT_FALSE(unit.CreateHashCalculator(HashAlgorithm::kSha1).has_value()); + EXPECT_FALSE(unit.CreateHashCalculator(HashAlgorithm::kNone).has_value()); } } // namespace diff --git a/score/hash/code/core/factory/impl/safe_hash_calculator_factory_ieee.cpp b/score/hash/code/core/factory/impl/safe_hash_calculator_factory_ieee.cpp index 932dce5bf1..f191e34313 100644 --- a/score/hash/code/core/factory/impl/safe_hash_calculator_factory_ieee.cpp +++ b/score/hash/code/core/factory/impl/safe_hash_calculator_factory_ieee.cpp @@ -39,9 +39,6 @@ Result> SafeHashCalculatorFactory::CreateHashCa result = static_cast>(std::make_unique()); break; case HashAlgorithm::kCrc32Autosar: - case HashAlgorithm::kSha1: - case HashAlgorithm::kSha384: - case HashAlgorithm::kSha512: case HashAlgorithm::kNone: case HashAlgorithm::kLast: default: diff --git a/score/hash/code/core/hash_test.cpp b/score/hash/code/core/hash_test.cpp index 40d0b2b009..6f89387107 100644 --- a/score/hash/code/core/hash_test.cpp +++ b/score/hash/code/core/hash_test.cpp @@ -35,7 +35,7 @@ TEST_F(HashFixture, CanCompareEqual) TEST_F(HashFixture, DoesNotCoompareEqualOnDifferentAlgorithm) { - EXPECT_FALSE(unit_ == (Hash{HashAlgorithm::kSha1, {0x01}})); + EXPECT_FALSE(unit_ == (Hash{HashAlgorithm::kCrc32, {0x01}})); } TEST_F(HashFixture, DoesNotCoompareEqualOnDifferentContent) @@ -53,19 +53,18 @@ TEST_F(HashFixture, GetBytesAsSpan) TEST(HashTest, CanCreateFromValidString) { - const score::cpp::pmr::string sha1{"89fdde0b28373dc4f361cfb810b35342cc2c3232"}; - Hash::ByteVector expected_bytes = {0x89, 0xFD, 0xDE, 0x0B, 0x28, 0x37, 0x3D, 0xC4, 0xF3, 0x61, - 0xCF, 0xB8, 0x10, 0xB3, 0x53, 0x42, 0xCC, 0x2C, 0x32, 0x32}; + const score::cpp::pmr::string crc32{"39a34f41"}; + Hash::ByteVector expected_bytes{0x39, 0xA3, 0x4F, 0x41}; - Result sha1_hash_result = Hash::FromString(HashAlgorithm::kSha1, sha1); - ASSERT_TRUE(sha1_hash_result.has_value()); + Result crc32_hash_result = Hash::FromString(HashAlgorithm::kCrc32, crc32); + ASSERT_TRUE(crc32_hash_result.has_value()); - Hash sha1_hash = sha1_hash_result.value(); - auto result = sha1_hash.GetBytes(); + Hash crc32_hash = crc32_hash_result.value(); + auto result = crc32_hash.GetBytes(); EXPECT_TRUE(std::equal(result.begin(), result.end(), expected_bytes.begin(), expected_bytes.end())); - score::cpp::pmr::string result_str = sha1_hash.ToString(); - EXPECT_EQ(result_str, sha1); + score::cpp::pmr::string result_str = crc32_hash.ToString(); + EXPECT_EQ(result_str, crc32); } TEST(HashTest, ToStringEmptyValueTest) @@ -82,31 +81,11 @@ TEST(HashTest, CanCreateFromValidStringCompleteSetOfAlgorithms) static TestData complete_suite[]{ std::make_tuple(HashAlgorithm::kCrc32, "39a34f41", Hash::ByteVector{0x39, 0xa3, 0x4f, 0x41}), - std::make_tuple(HashAlgorithm::kSha1, - "89fdde0b28373dc4f361cfb810b35342cc2c3232", - Hash::ByteVector{0x89, 0xFD, 0xDE, 0x0B, 0x28, 0x37, 0x3D, 0xC4, 0xF3, 0x61, - 0xCF, 0xB8, 0x10, 0xB3, 0x53, 0x42, 0xCC, 0x2C, 0x32, 0x32}), std::make_tuple(HashAlgorithm::kSha256, "ff18256292f5f2ba5261b55940cdf1125ce30e97c22ace6afa54b7af3872c351", Hash::ByteVector{0xFF, 0x18, 0x25, 0x62, 0x92, 0xF5, 0xF2, 0xBA, 0x52, 0x61, 0xB5, 0x59, 0x40, 0xCD, 0xF1, 0x12, 0x5C, 0xE3, 0x0E, 0x97, 0xC2, 0x2A, 0xCE, 0x6A, 0xFA, 0x54, 0xB7, 0xAF, 0x38, 0x72, 0xC3, 0x51}), - std::make_tuple( - HashAlgorithm::kSha384, - "40f73e53971550af0189f05b090c96f8c0280e6cc15f6932ca0c143e301c98a6873f4394a24dc62d4df619d1890b5879", - Hash::ByteVector{0x40, 0xF7, 0x3E, 0x53, 0x97, 0x15, 0x50, 0xAF, 0x01, 0x89, 0xF0, 0x5B, - 0x09, 0x0C, 0x96, 0xF8, 0xC0, 0x28, 0x0E, 0x6C, 0xC1, 0x5F, 0x69, 0x32, - 0xCA, 0x0C, 0x14, 0x3E, 0x30, 0x1C, 0x98, 0xA6, 0x87, 0x3F, 0x43, 0x94, - 0xA2, 0x4D, 0xC6, 0x2D, 0x4D, 0xF6, 0x19, 0xD1, 0x89, 0x0B, 0x58, 0x79}), - std::make_tuple( - HashAlgorithm::kSha512, - "53f09563ec1e30bd40808202e14bff32968015397026532c0f9f7eb81fc2f099e7ba505eb1e8e69392a7afae6e8d95f286652b6dfa" - "2ab183e42ebd8dc54dd2aa", - Hash::ByteVector{0x53, 0xF0, 0x95, 0x63, 0xEC, 0x1E, 0x30, 0xBD, 0x40, 0x80, 0x82, 0x02, 0xE1, - 0x4B, 0xFF, 0x32, 0x96, 0x80, 0x15, 0x39, 0x70, 0x26, 0x53, 0x2C, 0x0F, 0x9F, - 0x7E, 0xB8, 0x1F, 0xC2, 0xF0, 0x99, 0xE7, 0xBA, 0x50, 0x5E, 0xB1, 0xE8, 0xE6, - 0x93, 0x92, 0xA7, 0xAF, 0xAE, 0x6E, 0x8D, 0x95, 0xF2, 0x86, 0x65, 0x2B, 0x6D, - 0xFA, 0x2A, 0xB1, 0x83, 0xE4, 0x2E, 0xBD, 0x8D, 0xC5, 0x4D, 0xD2, 0xAA}), }; for (auto test_tuple : complete_suite) @@ -132,30 +111,31 @@ TEST(HashTest, CanCreateFromValidStringCompleteSetOfAlgorithms) TEST(HashTest, ValidateAlgorithm) { - const score::cpp::pmr::string sha1 = "89fdde0b28373dc4f361cfb810b35342cc2c3232"; + const score::cpp::pmr::string sha256{"ff18256292f5f2ba5261b55940cdf1125ce30e97c22ace6afa54b7af3872c351"}; - Result sha1_hash_result = Hash::FromString(HashAlgorithm::kLast, sha1); - ASSERT_FALSE(sha1_hash_result.has_value()); + Result hash_result = Hash::FromString(HashAlgorithm::kLast, sha256); + ASSERT_FALSE(hash_result.has_value()); } TEST(HashTest, ValidateSize) { - const score::cpp::pmr::string short_sha1 = "89fdde0b28373dc4f361cfb810b35342cc2c323"; - const score::cpp::pmr::string long_sha1 = "89fdde0b28373dc4f361cfb810b35342cc2c3232A"; + const score::cpp::pmr::string short_sha256{"ff18256292f5f2ba5261b55940cdf1125ce30e97c22ace6afa54b7af3872c35"}; + const score::cpp::pmr::string long_sha256{"ff18256292f5f2ba5261b55940cdf1125ce30e97c22ace6afa54b7af3872c3510"}; - Result sha1_hash_result = Hash::FromString(HashAlgorithm::kSha1, short_sha1); - ASSERT_FALSE(sha1_hash_result.has_value()); + Result short_hash_result = Hash::FromString(HashAlgorithm::kSha256, short_sha256); + ASSERT_FALSE(short_hash_result.has_value()); - Result sha1_hash_result2 = Hash::FromString(HashAlgorithm::kSha1, long_sha1); - ASSERT_FALSE(sha1_hash_result2.has_value()); + Result long_hash_result = Hash::FromString(HashAlgorithm::kSha256, long_sha256); + ASSERT_FALSE(long_hash_result.has_value()); } TEST(HashTest, ValidateContents) { - const score::cpp::pmr::string invalid_sha1 = "89fdde0b28373dc4f361cfb810b35342cc2BOGUS"; + const score::cpp::pmr::string invalid_sha256{"ff18256292f5f2ba5261b55940cdf1125ce30e97c22ace6afa54b7af387BOGUS"}; + ASSERT_EQ(invalid_sha256.size(), 64U); - Result sha1_hash_result = Hash::FromString(HashAlgorithm::kSha1, invalid_sha1); - ASSERT_FALSE(sha1_hash_result.has_value()); + Result hash_result = Hash::FromString(HashAlgorithm::kSha256, invalid_sha256); + ASSERT_FALSE(hash_result.has_value()); } } // namespace diff --git a/score/hash/code/core/i_hash_calculator.h b/score/hash/code/core/i_hash_calculator.h index 466ff4e752..c8b8d28f09 100644 --- a/score/hash/code/core/i_hash_calculator.h +++ b/score/hash/code/core/i_hash_calculator.h @@ -27,7 +27,7 @@ namespace score namespace hash { -/// @brief This is an interface that calculates cryptographic hash over blocks of data. +/// @brief This is an interface that calculates a hash or checksum over blocks of data. /// /// Depending on the algorithm selected, the hash value is calculated. /// Example : Input data = 123abc sha256sum = DD130A849D7B29E5541B05D2F7F86A4ACD4F1EC598C1C9438783F56BC4F0FF80 diff --git a/score/hash/code/core/typed_hash_test.cpp b/score/hash/code/core/typed_hash_test.cpp index f050aaf903..7ea0f8a031 100644 --- a/score/hash/code/core/typed_hash_test.cpp +++ b/score/hash/code/core/typed_hash_test.cpp @@ -51,22 +51,21 @@ TEST_F(TypedHashFixture, GetBytesAsSpan) TEST(TypedHashTest, CanCreateFromValidString) { - const score::cpp::pmr::string sha1{"89fdde0b28373dc4f361cfb810b35342cc2c3232"}; - Hash::ByteVector expected_bytes = {0x89, 0xFD, 0xDE, 0x0B, 0x28, 0x37, 0x3D, 0xC4, 0xF3, 0x61, - 0xCF, 0xB8, 0x10, 0xB3, 0x53, 0x42, 0xCC, 0x2C, 0x32, 0x32}; + const score::cpp::pmr::string crc32{"39a34f41"}; + Hash::ByteVector expected_bytes{0x39, 0xA3, 0x4F, 0x41}; - Result> sha1_hash_result = TypedHash::FromString(sha1); - ASSERT_TRUE(sha1_hash_result.has_value()); + Result> crc32_hash_result = TypedHash::FromString(crc32); + ASSERT_TRUE(crc32_hash_result.has_value()); - TypedHash sha1_hash = sha1_hash_result.value(); - auto result = sha1_hash.GetBytes(); + TypedHash crc32_hash = crc32_hash_result.value(); + auto result = crc32_hash.GetBytes(); EXPECT_TRUE(std::equal(result.begin(), result.end(), expected_bytes.begin(), expected_bytes.end())); - score::cpp::pmr::string result_str = sha1_hash.ToString(); - EXPECT_EQ(result_str, sha1); + score::cpp::pmr::string result_str = crc32_hash.ToString(); + EXPECT_EQ(result_str, crc32); - Hash sha1_hash_nontyped{HashAlgorithm::kSha1, expected_bytes}; - EXPECT_EQ(sha1_hash_nontyped, sha1_hash.ToHash()); + Hash crc32_hash_nontyped{HashAlgorithm::kCrc32, expected_bytes}; + EXPECT_EQ(crc32_hash_nontyped, crc32_hash.ToHash()); } TEST(TypedHashTest, ToStringEmptyValueTest) diff --git a/score/hash/code/openssl/BUILD b/score/hash/code/openssl/BUILD deleted file mode 100644 index 38aecae522..0000000000 --- a/score/hash/code/openssl/BUILD +++ /dev/null @@ -1,56 +0,0 @@ -# ******************************************************************************* -# Copyright (c) 2026 Contributors to the Eclipse Foundation -# -# See the NOTICE file(s) distributed with this work for additional -# information regarding copyright ownership. -# -# This program and the accompanying materials are made available under the -# terms of the Apache License Version 2.0 which is available at -# https://www.apache.org/licenses/LICENSE-2.0 -# -# SPDX-License-Identifier: Apache-2.0 -# ******************************************************************************* - -load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test") - -COMPILER_WARNING_FEATURES = [ - "treat_warnings_as_errors", - "strict_warnings", - "additional_warnings", -] - -cc_library( - name = "openssl_cal", - srcs = [ - "openssl_hash_calculator.cpp", - ], - hdrs = [ - "openssl_hash_calculator.h", - ], - features = COMPILER_WARNING_FEATURES, - visibility = ["//visibility:public"], - deps = [ - "@score_baselibs//score/hash/code/common", - "@score_baselibs//score/hash/code/core", - "@score_baselibs//score/hash/code/openssl/openssl_wrapper:openssl_lib", - ], -) - -cc_test( - name = "unit_test", - srcs = [ - "openssl_hash_calculator_test.cpp", - ], - features = COMPILER_WARNING_FEATURES, - tags = ["unit"], - deps = [ - "@googletest//:gtest", - "@googletest//:gtest_main", - "@score_baselibs//score/hash/code/common:common_test", - "@score_baselibs//score/hash/code/openssl:openssl_cal", - "@score_baselibs//score/hash/code/openssl/openssl_wrapper:openssl_lib", - "@score_baselibs//score/hash/code/openssl/openssl_wrapper:openssl_lib_mock", - "@score_baselibs//score/language/futurecpp", - "@score_baselibs//score/mw/log:backend_stub_testutil", - ], -) diff --git a/score/hash/code/openssl/openssl_hash_calculator.cpp b/score/hash/code/openssl/openssl_hash_calculator.cpp deleted file mode 100644 index 57141f5fb7..0000000000 --- a/score/hash/code/openssl/openssl_hash_calculator.cpp +++ /dev/null @@ -1,140 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2026 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0 - * - * SPDX-License-Identifier: Apache-2.0 - ********************************************************************************/ - -#include "score/hash/code/openssl/openssl_hash_calculator.h" -#include "score/hash/code/common/error.h" -#include "score/hash/code/openssl/openssl_wrapper/openssl_lib_impl.h" - -#include -#include - -namespace score -{ -namespace hash -{ - -OpensslHashCalculator::OpensslHashCalculator(const HashAlgorithm algorithm, - openssl::StructDigestCtx* const message_digest_context, - const openssl::IOpensslLib& openssl) - : IHashCalculator(), - message_digest_context_{message_digest_context, - [openssl_lib{std::ref(openssl)}](openssl::StructDigestCtx* ptr) noexcept { - openssl_lib.get().ResetDigestCtx(ptr); - }}, - algorithm_{algorithm}, - openssl_{openssl} -{ -} - -Result OpensslHashCalculator::Create(const HashAlgorithm algorithm, - const openssl::IOpensslLib& openssl) noexcept -{ - const openssl::StructDigest* message_digest_type = nullptr; - - switch (algorithm) - { - case HashAlgorithm::kSha1: - message_digest_type = openssl.DigestAlgoSha1(); - break; - - case HashAlgorithm::kSha256: - message_digest_type = openssl.DigestAlgoSha256(); - break; - - case HashAlgorithm::kSha384: - message_digest_type = openssl.DigestAlgoSha384(); - break; - - case HashAlgorithm::kSha512: - message_digest_type = openssl.DigestAlgoSha512(); - break; - - case HashAlgorithm::kNone: - case HashAlgorithm::kCrc32: - case HashAlgorithm::kCrc32Autosar: - case HashAlgorithm::kLast: - default: - mw::log::LogError() << "OpensslHashCalculator::Unknown digest algorithm"; - break; - } - - if (nullptr == message_digest_type) - { - mw::log::LogError() << "OpensslHashCalculator::Digest algorithm not created"; - return MakeUnexpected(ErrorCode::kCouldNotCreateDigest); - } - - auto* const message_digest_context = openssl.CreateDigestCtx(); - - if (nullptr == message_digest_context) - { - mw::log::LogError() << "OpensslHashCalculator::Could not create message digest context."; - return MakeUnexpected(ErrorCode::kCouldNotCreateDigest); - } - - if (0 == openssl.InitDigestCtx(message_digest_context, message_digest_type, nullptr)) - { - mw::log::LogError() << "OpensslHashCalculator::Could not create message digest algorithm."; - return MakeUnexpected(ErrorCode::kCouldNotCreateDigest); - } - - return OpensslHashCalculator(algorithm, message_digest_context, openssl); -} - -Result OpensslHashCalculator::Update(const score::cpp::span data) noexcept -{ - if (nullptr == data.data()) - { - mw::log::LogError() << "OpensslHashCalculator::Invalid parameters"; - return MakeUnexpected(ErrorCode::kInvalidParameters); - } - - if (0 == openssl_.get().UpdateDigestCtx(message_digest_context_.get(), - static_cast(data.data()), - static_cast(data.size()))) - { - mw::log::LogError() << "OpensslHashCalculator::Unable to update the digest context." << __LINE__; - return MakeUnexpected(ErrorCode::kCouldNotUpdateDigest); - } - - return {}; -} - -Hash OpensslHashCalculator::Finalize() noexcept -{ - Hash result{HashAlgorithm::kNone, {}}; - std::uint32_t message_digest_size{0U}; - score::cpp::static_vector message_digest_value(kMaxDigestSize); - - if (0 == openssl_.get().FinalizeDigestValue( - message_digest_context_.get(), message_digest_value.data(), &message_digest_size)) - { - mw::log::LogError() << "OpensslHashCalculator::Could not finalize message digest algorithm"; - } - else - { - message_digest_value.resize(static_cast(message_digest_size)); - result = Hash{algorithm_, std::move(message_digest_value)}; - } - - return result; -} - -const openssl::IOpensslLib& OpensslHashCalculator::GetDefaultOpenSslImpl() -{ - static const openssl::OpensslLibImpl impl{}; - return impl; -} - -} // namespace hash -} // namespace score diff --git a/score/hash/code/openssl/openssl_hash_calculator.h b/score/hash/code/openssl/openssl_hash_calculator.h deleted file mode 100644 index 528172636b..0000000000 --- a/score/hash/code/openssl/openssl_hash_calculator.h +++ /dev/null @@ -1,74 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2026 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0 - * - * SPDX-License-Identifier: Apache-2.0 - ********************************************************************************/ - -#ifndef SCORE_LIB_HASH_CODE_OPENSSL_HASHCALCULATOR_IMPL_H -#define SCORE_LIB_HASH_CODE_OPENSSL_HASHCALCULATOR_IMPL_H - -#include "score/hash/code/common/algorithms.h" -#include "score/hash/code/core/i_hash_calculator.h" -#include "score/hash/code/openssl/openssl_wrapper/i_openssl_lib.h" - -#include "score/mw/log/logging.h" - -#include - -#include - -namespace score -{ -namespace hash -{ - -/// @brief OpenSSL-based implementation for hash calculation -class OpensslHashCalculator final : public IHashCalculator -{ - public: - OpensslHashCalculator(const OpensslHashCalculator&) noexcept = delete; - OpensslHashCalculator(OpensslHashCalculator&& other) noexcept = default; - OpensslHashCalculator& operator=(const OpensslHashCalculator&) & = delete; - OpensslHashCalculator& operator=(OpensslHashCalculator&& other) & noexcept = default; - - ~OpensslHashCalculator() noexcept override = default; - - /// @brief Create hash calculation to use the given algorithm - /// - /// @param[in] algorithm algorithm to use for hash calculation - /// @param[in] openssl reference to the OpenSSL library call wrapper - /// - /// @return OpensslHashCalculator upon successful initialization, error otherwise - static Result Create(const HashAlgorithm algorithm, - const openssl::IOpensslLib& openssl = GetDefaultOpenSslImpl()) noexcept; - - Result Update(const score::cpp::span data) noexcept override; - - Hash Finalize() noexcept override; - - private: - /// Returns the default implementation for the OpenSSL call wrapper which uses the real OpenSSL library calls. - static const openssl::IOpensslLib& GetDefaultOpenSslImpl(); - - OpensslHashCalculator(const HashAlgorithm algorithm, - openssl::StructDigestCtx* const message_digest_context, - const openssl::IOpensslLib& openssl); - - std::unique_ptr> - message_digest_context_; - HashAlgorithm algorithm_; - - std::reference_wrapper openssl_; -}; - -} // namespace hash -} // namespace score - -#endif // SCORE_LIB_HASH_CODE_OPENSSL_HASHCALCULATOR_IMPL_H diff --git a/score/hash/code/openssl/openssl_hash_calculator_test.cpp b/score/hash/code/openssl/openssl_hash_calculator_test.cpp deleted file mode 100644 index 5aa3960e53..0000000000 --- a/score/hash/code/openssl/openssl_hash_calculator_test.cpp +++ /dev/null @@ -1,341 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2026 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0 - * - * SPDX-License-Identifier: Apache-2.0 - ********************************************************************************/ - -#include "score/hash/code/openssl/openssl_hash_calculator.h" -#include "score/hash/code/common/error.h" -#include "score/hash/code/common/gtest_printers.h" -#include "score/hash/code/openssl/openssl_wrapper/openssl_lib_impl.h" -#include "score/hash/code/openssl/openssl_wrapper/openssl_lib_mock.h" - -#include -#include - -#include -#include -#include - -namespace score -{ -namespace hash -{ -namespace -{ - -using namespace ::testing; -using openssl::StructDigest; -using openssl::StructDigestCtx; -using ::testing::_; -using ::testing::InSequence; -using testing::Invoke; -using ::testing::NiceMock; -using ::testing::Return; - -class HashCalculatorTest : public ::testing::Test -{ - public: - void SetUp() override; - void TearDown() override; - void ExpectSha256Call(); - - protected: - score::hash::openssl::OpensslLibImpl openssl_lib_; - NiceMock openssl_lib_mock_; - const StructDigest* digest_type_sha256; - StructDigestCtx* digest_context_sha256; - std::int32_t hash_digest_sha256; -}; - -void HashCalculatorTest::SetUp() -{ - digest_type_sha256 = openssl_lib_.DigestAlgoSha256(); - digest_context_sha256 = openssl_lib_.CreateDigestCtx(); - hash_digest_sha256 = openssl_lib_.InitDigestCtx(digest_context_sha256, digest_type_sha256, nullptr); -} - -void HashCalculatorTest::TearDown() -{ - openssl_lib_.ResetDigestCtx(digest_context_sha256); - digest_context_sha256 = nullptr; -} - -void HashCalculatorTest::ExpectSha256Call() -{ - ON_CALL(openssl_lib_mock_, DigestAlgoSha256()).WillByDefault(Return(digest_type_sha256)); - ON_CALL(openssl_lib_mock_, CreateDigestCtx()).WillByDefault(Return(digest_context_sha256)); - ON_CALL(openssl_lib_mock_, InitDigestCtx(_, _, _)).WillByDefault(Return(hash_digest_sha256)); - EXPECT_CALL(openssl_lib_mock_, ResetDigestCtx(_)).Times(1); -} - -TEST_F(HashCalculatorTest, HashAlgorithmsSimpleSha1Test) -{ - const StructDigest* digest_type_sha1 = openssl_lib_.DigestAlgoSha1(); - StructDigestCtx* digest_context_sha1 = openssl_lib_.CreateDigestCtx(); - std::int32_t hash_digest_sha1 = openssl_lib_.InitDigestCtx(digest_context_sha1, digest_type_sha1, nullptr); - - EXPECT_CALL(openssl_lib_mock_, DigestAlgoSha1()).WillOnce(Return(digest_type_sha1)); - EXPECT_CALL(openssl_lib_mock_, CreateDigestCtx()).WillOnce(Return(digest_context_sha1)); - EXPECT_CALL(openssl_lib_mock_, InitDigestCtx(_, _, _)).WillOnce(Return(hash_digest_sha1)); - - auto digest = OpensslHashCalculator::Create(HashAlgorithm::kSha1, openssl_lib_mock_); - openssl_lib_.ResetDigestCtx(digest_context_sha1); - digest_context_sha1 = nullptr; - - ASSERT_TRUE(digest.has_value()); -} - -TEST_F(HashCalculatorTest, HashAlgorithmsSimpleSha256Test) -{ - ExpectSha256Call(); - - auto digest = OpensslHashCalculator::Create(HashAlgorithm::kSha256, openssl_lib_mock_); - - ASSERT_TRUE(digest.has_value()); -} - -TEST_F(HashCalculatorTest, HashAlgorithmsSimpleSha384Test) -{ - const StructDigest* digest_type_sha384 = openssl_lib_.DigestAlgoSha384(); - StructDigestCtx* digest_context_sha384 = openssl_lib_.CreateDigestCtx(); - std::int32_t hash_digest_sha384 = openssl_lib_.InitDigestCtx(digest_context_sha384, digest_type_sha384, nullptr); - - ON_CALL(openssl_lib_mock_, DigestAlgoSha384()).WillByDefault(Return(digest_type_sha384)); - ON_CALL(openssl_lib_mock_, CreateDigestCtx()).WillByDefault(Return(digest_context_sha384)); - ON_CALL(openssl_lib_mock_, InitDigestCtx(_, _, _)).WillByDefault(Return(hash_digest_sha384)); - - auto digest = OpensslHashCalculator::Create(HashAlgorithm::kSha384, openssl_lib_mock_); - openssl_lib_.ResetDigestCtx(digest_context_sha384); - digest_context_sha384 = nullptr; - - ASSERT_TRUE(digest.has_value()); -} - -TEST_F(HashCalculatorTest, HashAlgorithmsSimpleSha512Test) -{ - const StructDigest* digest_type_sha512 = openssl_lib_.DigestAlgoSha512(); - StructDigestCtx* digest_context_sha512 = openssl_lib_.CreateDigestCtx(); - std::int32_t hash_digest_sha512 = openssl_lib_.InitDigestCtx(digest_context_sha512, digest_type_sha512, nullptr); - - ON_CALL(openssl_lib_mock_, DigestAlgoSha512()).WillByDefault(Return(digest_type_sha512)); - ON_CALL(openssl_lib_mock_, CreateDigestCtx()).WillByDefault(Return(digest_context_sha512)); - ON_CALL(openssl_lib_mock_, InitDigestCtx(_, _, _)).WillByDefault(Return(hash_digest_sha512)); - EXPECT_CALL(openssl_lib_mock_, UpdateDigestCtx(_, _, _)).WillOnce(Return(1)); - - std::vector test_input{1, 2, 3, 4}; - score::cpp::span data(test_input.data(), test_input.size()); - - auto digest_1 = OpensslHashCalculator::Create(HashAlgorithm::kSha512, openssl_lib_mock_).value(); - auto digest_2 = OpensslHashCalculator::Create(HashAlgorithm::kSha512, openssl_lib_mock_).value(); - // Move assignement operator used for code coverage - digest_2 = std::move(digest_1); - auto update_result = digest_2.Update(data); - - openssl_lib_.ResetDigestCtx(digest_context_sha512); - digest_context_sha512 = nullptr; - - ASSERT_TRUE(update_result.has_value()); -} - -TEST_F(HashCalculatorTest, NullDigestTypeCreateAlgoTest) -{ - EXPECT_CALL(openssl_lib_mock_, DigestAlgoSha256()).WillOnce(Return(nullptr)); - auto digest = OpensslHashCalculator::Create(HashAlgorithm::kSha256, openssl_lib_mock_); - - EXPECT_EQ(digest.error(), ErrorCode::kCouldNotCreateDigest); -} - -TEST_F(HashCalculatorTest, InvalidDigestCtxCreateAlgoTest) -{ - ON_CALL(openssl_lib_mock_, DigestAlgoSha256()).WillByDefault(Return(digest_type_sha256)); - ON_CALL(openssl_lib_mock_, CreateDigestCtx()).WillByDefault(Return(nullptr)); - - auto digest = OpensslHashCalculator::Create(HashAlgorithm::kSha256, openssl_lib_mock_); - - EXPECT_EQ(digest.error(), ErrorCode::kCouldNotCreateDigest); -} - -TEST_F(HashCalculatorTest, InvalidDigestInitCreateAlgoTest) -{ - EXPECT_CALL(openssl_lib_mock_, DigestAlgoSha256()).WillOnce(Return(digest_type_sha256)); - EXPECT_CALL(openssl_lib_mock_, CreateDigestCtx()).WillOnce(Return(digest_context_sha256)); - EXPECT_CALL(openssl_lib_mock_, InitDigestCtx(_, _, _)).WillOnce(Return(0)); - - auto digest = OpensslHashCalculator::Create(HashAlgorithm::kSha256, openssl_lib_mock_); - - EXPECT_EQ(digest.error(), ErrorCode::kCouldNotCreateDigest); -} - -TEST_F(HashCalculatorTest, InvalidCreateAlgorthimTest) -{ - auto hash_calculator = OpensslHashCalculator::Create(HashAlgorithm::kNone, openssl_lib_mock_); - ASSERT_FALSE(hash_calculator.has_value()); - EXPECT_EQ(hash_calculator.error(), ErrorCode::kCouldNotCreateDigest); - - auto digest = OpensslHashCalculator::Create(HashAlgorithm::kLast, openssl_lib_mock_); - ASSERT_FALSE(digest.has_value()); - EXPECT_EQ(digest.error(), ErrorCode::kCouldNotCreateDigest); -} - -TEST_F(HashCalculatorTest, UpdateStreamTest) -{ - ExpectSha256Call(); - EXPECT_CALL(openssl_lib_mock_, UpdateDigestCtx(_, _, _)).WillOnce(Return(1)); - - std::vector test_input{1, 2, 3, 4}; - score::cpp::span data(test_input.data(), test_input.size()); - - auto digest = OpensslHashCalculator::Create(HashAlgorithm::kSha256, openssl_lib_mock_); - auto update_result = digest->Update(data); - - ASSERT_TRUE(update_result.has_value()); -} - -TEST_F(HashCalculatorTest, EmptyUpdateTest) -{ - ExpectSha256Call(); - score::cpp::span data; - - auto digest = OpensslHashCalculator::Create(HashAlgorithm::kSha256, openssl_lib_mock_); - auto update_result = digest->Update(data); - - ASSERT_FALSE(update_result.has_value()); - EXPECT_EQ(update_result.error(), ErrorCode::kInvalidParameters); -} - -TEST_F(HashCalculatorTest, InvalidDigestUpdateTest) -{ - ExpectSha256Call(); - EXPECT_CALL(openssl_lib_mock_, UpdateDigestCtx(_, _, _)).WillOnce(Return(0)); - - std::vector test_input{1, 2, 3, 4}; - score::cpp::span data(test_input.data(), test_input.size()); - - auto digest = OpensslHashCalculator::Create(HashAlgorithm::kSha256, openssl_lib_mock_); - auto update_result = digest->Update(data); - - ASSERT_FALSE(update_result.has_value()); - EXPECT_EQ(update_result.error(), ErrorCode::kCouldNotUpdateDigest); -} - -TEST_F(HashCalculatorTest, UpdateFromStreamTest) -{ - ExpectSha256Call(); - EXPECT_CALL(openssl_lib_mock_, UpdateDigestCtx(_, _, _)).WillOnce(Return(1)); - - std::vector test_input{1, 2, 3, 4}; - std::istringstream input_stream(std::string(test_input.begin(), test_input.end())); - - auto digest = OpensslHashCalculator::Create(HashAlgorithm::kSha256, openssl_lib_mock_); - auto update_result = digest->UpdateFromStream(input_stream); - - ASSERT_TRUE(update_result.has_value()); -} - -TEST_F(HashCalculatorTest, InvalidUpdateFromStreamTest) -{ - ExpectSha256Call(); - - EXPECT_CALL(openssl_lib_mock_, UpdateDigestCtx(_, _, _)).WillOnce(Return(0)); - - std::vector test_input{1, 2, 3, 4}; - std::istringstream input_stream(std::string(test_input.begin(), test_input.end())); - - auto digest = OpensslHashCalculator::Create(HashAlgorithm::kSha256, openssl_lib_mock_); - auto update_result = digest->UpdateFromStream(input_stream); - - ASSERT_FALSE(update_result.has_value()); - EXPECT_EQ(update_result.error(), ErrorCode::kCouldNotUpdateDigest); -} - -TEST_F(HashCalculatorTest, UpdateFromStreamGoesBadTest) -{ - ExpectSha256Call(); - - std::vector test_input{1, 2, 3, 4}; - std::istringstream input_stream(std::string(test_input.begin(), test_input.end())); - - auto callback = [&](StructDigestCtx*, const void*, std::size_t) -> std::int32_t { - input_stream.setstate(input_stream.badbit); - return 1; - }; - - EXPECT_CALL(openssl_lib_mock_, UpdateDigestCtx(_, _, _)).WillOnce(Invoke(callback)); - - auto digest = OpensslHashCalculator::Create(HashAlgorithm::kSha256, openssl_lib_mock_); - auto update_result = digest->UpdateFromStream(input_stream); - - ASSERT_FALSE(update_result.has_value()); - EXPECT_EQ(update_result.error(), ErrorCode::kCouldNotUpdateDigestFromStream); -} - -TEST_F(HashCalculatorTest, BadInputUpdateFromStreamTest) -{ - ExpectSha256Call(); - - std::stringstream input_stream; - input_stream.clear(input_stream.badbit); - - auto digest = OpensslHashCalculator::Create(HashAlgorithm::kSha256, openssl_lib_mock_); - auto update_result = digest->UpdateFromStream(input_stream); - - ASSERT_FALSE(update_result.has_value()); - EXPECT_EQ(update_result.error(), ErrorCode::kStreamError); -} - -TEST_F(HashCalculatorTest, EmptyInputUpdateFromStreamTest) -{ - std::vector test_input{}; - std::istringstream input_stream(std::string(test_input.begin(), test_input.end())); - const score::cpp::static_vector expected_sha256{ - 0xe3, 0xb0, 0xc4, 0x42, 0x98, 0xfc, 0x1c, 0x14, 0x9a, 0xfb, 0xf4, 0xc8, 0x99, 0x6f, 0xb9, 0x24, - 0x27, 0xae, 0x41, 0xe4, 0x64, 0x9b, 0x93, 0x4c, 0xa4, 0x95, 0x99, 0x1b, 0x78, 0x52, 0xb8, 0x55}; - - auto digest = OpensslHashCalculator::Create(HashAlgorithm::kSha256); - auto update_result = digest->UpdateFromStream(input_stream); - - ASSERT_TRUE(update_result.has_value()); - const auto hash_result_sha256 = digest->Finalize(); - - EXPECT_EQ(hash_result_sha256, (Hash{HashAlgorithm::kSha256, expected_sha256})); -} - -TEST_F(HashCalculatorTest, InvalidFinalizeTest) -{ - ExpectSha256Call(); - - EXPECT_CALL(openssl_lib_mock_, FinalizeDigestValue(_, _, _)).WillOnce(Return(0)); - - auto digest = OpensslHashCalculator::Create(HashAlgorithm::kSha256, openssl_lib_mock_); - auto update_result = digest->Finalize(); - - EXPECT_EQ(update_result, (Hash{HashAlgorithm::kNone, {}})); -} - -TEST(HashCalculatorSHATest, HashAlgorithmsSimpleTestSha256) -{ - constexpr std::uint8_t test_input[]{'1', '2', '3', 'a', 'b', 'c'}; - const score::cpp::static_vector expected_sha256{ - 221, 19, 10, 132, 157, 123, 41, 229, 84, 27, 5, 210, 247, 248, 106, 74, - 205, 79, 30, 197, 152, 193, 201, 67, 135, 131, 245, 107, 196, 240, 255, 128}; - - auto hash_calculator = OpensslHashCalculator::Create(HashAlgorithm::kSha256); - ASSERT_TRUE(hash_calculator.has_value()); - - EXPECT_TRUE(hash_calculator->Update(test_input).has_value()); - const auto hash_result_sha256 = hash_calculator->Finalize(); - - EXPECT_EQ(hash_result_sha256, (Hash{HashAlgorithm::kSha256, expected_sha256})); -} - -} // namespace -} // namespace hash -} // namespace score diff --git a/score/hash/code/openssl/openssl_wrapper/BUILD b/score/hash/code/openssl/openssl_wrapper/BUILD deleted file mode 100644 index 89aa8fe080..0000000000 --- a/score/hash/code/openssl/openssl_wrapper/BUILD +++ /dev/null @@ -1,68 +0,0 @@ -# ******************************************************************************* -# Copyright (c) 2026 Contributors to the Eclipse Foundation -# -# See the NOTICE file(s) distributed with this work for additional -# information regarding copyright ownership. -# -# This program and the accompanying materials are made available under the -# terms of the Apache License Version 2.0 which is available at -# https://www.apache.org/licenses/LICENSE-2.0 -# -# SPDX-License-Identifier: Apache-2.0 -# ******************************************************************************* - -load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test") - -COMPILER_WARNING_FEATURES = [ - "treat_warnings_as_errors", - "strict_warnings", - "additional_warnings", -] - -cc_library( - name = "openssl_lib", - srcs = [ - "i_openssl_lib.cpp", - "openssl_lib_impl.cpp", - ], - hdrs = [ - "i_openssl_lib.h", - "openssl_lib_impl.h", - ], - features = COMPILER_WARNING_FEATURES, - visibility = ["@score_baselibs//score/hash:__subpackages__"], - deps = [ - "@score_baselibs//score/language/futurecpp", - "@score_baselibs//score/result", - "@score_baselibs//third_party/openssl", - ], -) - -cc_library( - name = "openssl_lib_mock", - testonly = True, - hdrs = [ - "i_openssl_lib.h", - "openssl_lib_mock.h", - ], - features = COMPILER_WARNING_FEATURES, - visibility = ["//visibility:public"], - deps = [ - ":openssl_lib", - "@googletest//:gtest", - ], -) - -cc_test( - name = "unit_test", - srcs = [ - "openssl_lib_impl_test.cpp", - ], - features = COMPILER_WARNING_FEATURES, - tags = ["unit"], - deps = [ - ":openssl_lib", - ":openssl_lib_mock", - "@googletest//:gtest_main", - ], -) diff --git a/score/hash/code/openssl/openssl_wrapper/i_openssl_lib.cpp b/score/hash/code/openssl/openssl_wrapper/i_openssl_lib.cpp deleted file mode 100644 index 33eb7dacee..0000000000 --- a/score/hash/code/openssl/openssl_wrapper/i_openssl_lib.cpp +++ /dev/null @@ -1,14 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2026 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0 - * - * SPDX-License-Identifier: Apache-2.0 - ********************************************************************************/ - -#include "score/hash/code/openssl/openssl_wrapper/i_openssl_lib.h" diff --git a/score/hash/code/openssl/openssl_wrapper/i_openssl_lib.h b/score/hash/code/openssl/openssl_wrapper/i_openssl_lib.h deleted file mode 100644 index 707cee1ca4..0000000000 --- a/score/hash/code/openssl/openssl_wrapper/i_openssl_lib.h +++ /dev/null @@ -1,80 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2026 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0 - * - * SPDX-License-Identifier: Apache-2.0 - ********************************************************************************/ - -#ifndef SCORE_LIB_HASH_CODE_I_OPENSSL_LIB_H -#define SCORE_LIB_HASH_CODE_I_OPENSSL_LIB_H - -#include "score/expected.hpp" - -#include - -#include - -namespace score -{ -namespace hash -{ -namespace openssl -{ -/// @brief Type-alias for better readability -using StructDigest = ::EVP_MD; -using StructDigestCtx = ::EVP_MD_CTX; -using Engine = ::ENGINE; - -/// @brief IOpensslLib is an abstract class that defines the interface to the openssl library as it is used to -/// calculate hash values. Its purpose is to allow the interface to be mocked for testing. -class IOpensslLib -{ - public: - IOpensslLib() noexcept = default; - virtual ~IOpensslLib() noexcept = default; - IOpensslLib(const IOpensslLib&) = delete; - IOpensslLib(IOpensslLib&&) noexcept = delete; - IOpensslLib& operator=(const IOpensslLib&) = delete; - IOpensslLib& operator=(IOpensslLib&&) noexcept = delete; - - /// @brief Calculates the hash value with SHA1 algorithm. - virtual const StructDigest* DigestAlgoSha1() const noexcept = 0; - - /// @brief Calculates the hash value with SHA256 algorithm. - virtual const StructDigest* DigestAlgoSha256() const noexcept = 0; - - /// @brief Calculates the hash value with SHA384 algorithm. - virtual const StructDigest* DigestAlgoSha384() const noexcept = 0; - - /// @brief Calculates the hash value with SHA512 algorithm. - virtual const StructDigest* DigestAlgoSha512() const noexcept = 0; - - /// @brief Allocates and returns a digest context - virtual StructDigestCtx* CreateDigestCtx() const noexcept = 0; - - /// @brief Sets up digest context ctx to use a digest type from ENGINE impl - virtual std::int32_t InitDigestCtx(StructDigestCtx* ctx, const StructDigest* type, Engine* impl) const noexcept = 0; - - /// @brief Hashes count bytes of data at into the digest context ctx. - virtual std::int32_t UpdateDigestCtx(StructDigestCtx* ctx, const void* data, std::size_t count) const noexcept = 0; - - /// @brief Retrieves the digest value from ctx and places it in digest_value and stores the length of digest in - /// digest_size - virtual std::int32_t FinalizeDigestValue(StructDigestCtx* ctx, - unsigned char* digest_value, - unsigned int* digest_size) const noexcept = 0; - - /// @brief Cleans up digest context ctx and frees up the space allocated to it. - virtual void ResetDigestCtx(StructDigestCtx* ctx) const noexcept = 0; -}; - -} // namespace openssl -} // namespace hash -} // namespace score -#endif // SCORE_LIB_HASH_CODE_I_OPENSSL_LIB_H diff --git a/score/hash/code/openssl/openssl_wrapper/openssl_lib_impl.cpp b/score/hash/code/openssl/openssl_wrapper/openssl_lib_impl.cpp deleted file mode 100644 index 2cb3944064..0000000000 --- a/score/hash/code/openssl/openssl_wrapper/openssl_lib_impl.cpp +++ /dev/null @@ -1,73 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2026 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0 - * - * SPDX-License-Identifier: Apache-2.0 - ********************************************************************************/ - -#include "score/hash/code/openssl/openssl_wrapper/openssl_lib_impl.h" - -#include - -namespace score -{ -namespace hash -{ -namespace openssl -{ - -const StructDigest* OpensslLibImpl::DigestAlgoSha1() const noexcept -{ - return ::EVP_sha1(); -} - -const StructDigest* OpensslLibImpl::DigestAlgoSha256() const noexcept -{ - return ::EVP_sha256(); -} - -const StructDigest* OpensslLibImpl::DigestAlgoSha384() const noexcept -{ - return ::EVP_sha384(); -} - -const StructDigest* OpensslLibImpl::DigestAlgoSha512() const noexcept -{ - return ::EVP_sha512(); -} - -StructDigestCtx* OpensslLibImpl::CreateDigestCtx() const noexcept -{ - return ::EVP_MD_CTX_new(); -} - -std::int32_t OpensslLibImpl::InitDigestCtx(StructDigestCtx* ctx, const StructDigest* type, Engine* impl) const noexcept -{ - return ::EVP_DigestInit_ex(ctx, type, impl); -} - -std::int32_t OpensslLibImpl::UpdateDigestCtx(StructDigestCtx* ctx, const void* data, std::size_t count) const noexcept -{ - return ::EVP_DigestUpdate(ctx, data, count); -} - -std::int32_t OpensslLibImpl::FinalizeDigestValue(StructDigestCtx* ctx, - unsigned char* digest_value, - unsigned int* digest_size) const noexcept -{ - return ::EVP_DigestFinal_ex(ctx, digest_value, digest_size); -} - -void OpensslLibImpl::ResetDigestCtx(StructDigestCtx* ctx) const noexcept -{ - ::EVP_MD_CTX_free(ctx); -} -} // namespace openssl -} // namespace hash -} // namespace score diff --git a/score/hash/code/openssl/openssl_wrapper/openssl_lib_impl.h b/score/hash/code/openssl/openssl_wrapper/openssl_lib_impl.h deleted file mode 100644 index 7bc557ef67..0000000000 --- a/score/hash/code/openssl/openssl_wrapper/openssl_lib_impl.h +++ /dev/null @@ -1,55 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2026 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0 - * - * SPDX-License-Identifier: Apache-2.0 - ********************************************************************************/ - -#ifndef SCORE_LIB_HASH_CODE_OPENSSL_LIB_IMPL_H -#define SCORE_LIB_HASH_CODE_OPENSSL_LIB_IMPL_H - -#include "score/hash/code/openssl/openssl_wrapper/i_openssl_lib.h" - -#include - -namespace score -{ -namespace hash -{ -namespace openssl -{ - -class OpensslLibImpl final : public IOpensslLib -{ - public: - constexpr OpensslLibImpl() noexcept = default; - ~OpensslLibImpl() noexcept override = default; - - OpensslLibImpl(const OpensslLibImpl&) = delete; - OpensslLibImpl(OpensslLibImpl&&) noexcept = delete; - OpensslLibImpl& operator=(const OpensslLibImpl&) = delete; - OpensslLibImpl& operator=(OpensslLibImpl&&) noexcept = delete; - - const StructDigest* DigestAlgoSha1() const noexcept override; - const StructDigest* DigestAlgoSha256() const noexcept override; - const StructDigest* DigestAlgoSha384() const noexcept override; - const StructDigest* DigestAlgoSha512() const noexcept override; - StructDigestCtx* CreateDigestCtx() const noexcept override; - std::int32_t InitDigestCtx(StructDigestCtx* ctx, const StructDigest* type, Engine* impl) const noexcept override; - std::int32_t UpdateDigestCtx(StructDigestCtx* ctx, const void* data, std::size_t count) const noexcept override; - std::int32_t FinalizeDigestValue(StructDigestCtx* ctx, - unsigned char* digest_value, - unsigned int* digest_size) const noexcept override; - void ResetDigestCtx(StructDigestCtx* ctx) const noexcept override; -}; - -} // namespace openssl -} // namespace hash -} // namespace score -#endif // SCORE_LIB_HASH_CODE_OPENSSL_LIB_IMPL_H diff --git a/score/hash/code/openssl/openssl_wrapper/openssl_lib_impl_test.cpp b/score/hash/code/openssl/openssl_wrapper/openssl_lib_impl_test.cpp deleted file mode 100644 index 78fb3bf270..0000000000 --- a/score/hash/code/openssl/openssl_wrapper/openssl_lib_impl_test.cpp +++ /dev/null @@ -1,121 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2026 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0 - * - * SPDX-License-Identifier: Apache-2.0 - ********************************************************************************/ - -#include "score/hash/code/openssl/openssl_wrapper/openssl_lib_impl.h" - -#include -#include - -namespace score -{ -namespace hash -{ -namespace openssl -{ -namespace -{ - -using namespace ::testing; -using ::testing::_; - -class OpensslLibTest : public ::testing::Test -{ - public: - void SetUp() override; - void TearDown() override; - - protected: - OpensslLibImpl unit_{}; - const StructDigest* digest_type_; - StructDigestCtx* digest_context_; -}; - -void OpensslLibTest::SetUp() -{ - digest_type_ = unit_.DigestAlgoSha256(); - digest_context_ = unit_.CreateDigestCtx(); -} - -void OpensslLibTest::TearDown() -{ - unit_.ResetDigestCtx(digest_context_); - digest_context_ = nullptr; -} - -TEST_F(OpensslLibTest, Sha1Test) -{ - auto result = unit_.DigestAlgoSha1(); - - EXPECT_NE(result, nullptr); -} - -TEST_F(OpensslLibTest, Sha256Test) -{ - EXPECT_NE(digest_context_, nullptr); -} - -TEST_F(OpensslLibTest, Sha384Test) -{ - auto result = unit_.DigestAlgoSha384(); - - EXPECT_NE(result, nullptr); -} - -TEST_F(OpensslLibTest, Sha512Test) -{ - auto result = unit_.DigestAlgoSha512(); - - EXPECT_NE(result, nullptr); -} - -TEST_F(OpensslLibTest, DigestCtxNewTest) -{ - EXPECT_NE(digest_context_, nullptr); -} - -TEST_F(OpensslLibTest, DigestInitExTest) -{ - auto result = unit_.InitDigestCtx(digest_context_, digest_type_, nullptr); - - EXPECT_EQ(result, 1); -} - -TEST_F(OpensslLibTest, DigestUpdateTest) -{ - char msg[] = "Hello World\n"; - - unit_.InitDigestCtx(digest_context_, digest_type_, nullptr); - - auto result = unit_.UpdateDigestCtx(digest_context_, msg, strlen(msg)); - - EXPECT_EQ(result, 1); -} - -TEST_F(OpensslLibTest, DigestFinalExTest) -{ - char msg[] = "Hello World\n"; - unsigned char data[64]; - unsigned int size; - - unit_.InitDigestCtx(digest_context_, digest_type_, nullptr); - unit_.UpdateDigestCtx(digest_context_, msg, strlen(msg)); - - auto result = unit_.FinalizeDigestValue(digest_context_, data, &size); - - EXPECT_EQ(result, 1); -} - -} // namespace -} // namespace openssl -} // namespace hash -} // namespace score diff --git a/score/hash/code/openssl/openssl_wrapper/openssl_lib_mock.h b/score/hash/code/openssl/openssl_wrapper/openssl_lib_mock.h deleted file mode 100644 index ff8cec7c42..0000000000 --- a/score/hash/code/openssl/openssl_wrapper/openssl_lib_mock.h +++ /dev/null @@ -1,56 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2026 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0 - * - * SPDX-License-Identifier: Apache-2.0 - ********************************************************************************/ - -#ifndef SCORE_LIB_HASH_CODE_OPENSSL_LIB_MOCK_H -#define SCORE_LIB_HASH_CODE_OPENSSL_LIB_MOCK_H - -#include "score/hash/code/openssl/openssl_wrapper/i_openssl_lib.h" - -#include - -namespace score -{ -namespace hash -{ -namespace openssl -{ - -/// @brief This class mocks the Openssl library for the purpose of unit testing. -class OpensslLibMock : public IOpensslLib -{ - public: - MOCK_METHOD((const StructDigest*), DigestAlgoSha1, (), (const, noexcept, override)); - MOCK_METHOD((const StructDigest*), DigestAlgoSha256, (), (const, noexcept, override)); - MOCK_METHOD((const StructDigest*), DigestAlgoSha384, (), (const, noexcept, override)); - MOCK_METHOD((const StructDigest*), DigestAlgoSha512, (), (const, noexcept, override)); - MOCK_METHOD(StructDigestCtx*, CreateDigestCtx, (), (const, noexcept, override)); - MOCK_METHOD(std::int32_t, - InitDigestCtx, - (StructDigestCtx * ctx, const StructDigest* type, Engine* impl), - (const, noexcept, override)); - MOCK_METHOD(std::int32_t, - UpdateDigestCtx, - (StructDigestCtx * ctx, const void* data, size_t count), - (const, noexcept, override)); - MOCK_METHOD(std::int32_t, - FinalizeDigestValue, - (StructDigestCtx * ctx, unsigned char* digest_value, unsigned int* digest_size), - (const, noexcept, override)); - MOCK_METHOD(void, ResetDigestCtx, (StructDigestCtx * ctx), (const, noexcept, override)); -}; - -} // namespace openssl -} // namespace hash -} // namespace score - -#endif // SCORE_LIB_HASH_CODE_OPENSSL_LIB_MOCK_H diff --git a/score/hash/design/ClassDiagram.puml b/score/hash/design/ClassDiagram.puml index 41d2f22e10..8a1226f64b 100644 --- a/score/hash/design/ClassDiagram.puml +++ b/score/hash/design/ClassDiagram.puml @@ -72,32 +72,6 @@ class "MessageBuffer" as MessageBuffer { -size_: SizeType } -interface IOpensslLib { - using StructDigest = ::EVP_MD - using StructDigestCtx = ::EVP_MD_CTX - using Engine = ::ENGINE - -- - +DigestAlgoSha1() const: const StructDigest* - +DigestAlgoSha256() const: const StructDigest* - +DigestAlgoSha384() const: const StructDigest* - +DigestAlgoSha512() const: const StructDigest* - +CreateDigestCtx() const: StructDigestCtx* - +InitDigestCtx(ctx: StructDigestCtx* , type: const StructDigest*,impl: Engine* ) const: std::int32_t - +UpdateDigestCtx(ctx: StructDigestCtx* , data: const void*,count: std::size_t ) const: std::int32_t - +FinalizeDigestValue(ctx: StructDigestCtx* , digest_value: unsigned char* ,digest_size: unsigned int* ) const: std::int32_t - +ResetDigestCtx(ctx: StructDigestCtx* ) const: void -} - -class OpensslLibImpl { -} - -class OpensslHashCalculator { - -message_digest_context_: StructDigestCtx - -message_digest_value_: std::array - -- - +Create( algorithm: types::HashAlgorithm, openssl: const IOpensslLib&): Result -} - ' Relationships IHashCalculatorFactory <|.. HashCalculatorFactory : implements IHashCalculatorFactory <|.. SafeHashCalculatorFactory : implements @@ -108,7 +82,6 @@ SafeHashCalculatorFactory ..> IHashCalculator : create IHashCalculatorFactory ..> Hash : create IHashCalculator <|-- ICrc32HashCalculator : extends -IHashCalculator <|-- OpensslHashCalculator : implements IHashCalculator <|-- Sha256Digest : implements ICrc32HashCalculator <|-- Crc32HashCalculator : implements @@ -117,7 +90,4 @@ Crc32HashCalculator --> LookupTable : «uses» Sha256Digest o-- MessageBuffer : composition -OpensslHashCalculator --> IOpensslLib : uses -IOpensslLib <|.. OpensslLibImpl : implements - @enduml diff --git a/score/hash/design/README.md b/score/hash/design/README.md index 990c2703da..600a0228dd 100644 --- a/score/hash/design/README.md +++ b/score/hash/design/README.md @@ -4,11 +4,13 @@ The main aim of this library is to: -* provide an interface to calculate the hash values of the input stream using hash algorithms of Openssl library -* reduce the duplicated code. -* enable unit-testability of hash calculator. +* provide an exception-free checksum interface for safety-integrity use cases. +* provide the native IEEE CRC-32 implementation. +* temporarily retain the native SHA-256 implementation required by safety consumers. -The hash calculator class allows the hash value calculation using SHA1, SHA256, SHA384, and SHA512 algorithms. +The library supports IEEE CRC-32 and native SHA-256. +SHA-1, SHA-384, SHA-512, and the OpenSSL integration were removed as part of the cryptographic hash migration. +Security use cases shall use the Security Crypto feature instead. In order to easily handle hashes, we introduce a custom `Hash` class, which encapsulates necessary information. It acts as kind of _type erasure_ around the more detailed hash information, which is otherwise distributed as pair of buffer @@ -25,43 +27,31 @@ There is a native CRC32 implementation that uses the standard Ethernet CRC32 pol IHashCalculator it also implements an interface called `ICrc32HashCalculator`. It enables a user that directly instantiates the CRC32 implementation to directly retrieve the hash as one uint32 value. -The algorithm uses the usual byte-wise lookup table. The tabl eis generated by the compiler by instantiating a literal +The algorithm uses the usual byte-wise lookup table. The table is generated by the compiler by instantiating a literal type that will hold the 256 values needed in this approach. -# SHA256 implementation +# SHA-256 implementation -A native implementation of SHA256 exists which fulfills RFC6234 and is developed according to safe coding standards. +A native implementation of SHA-256 exists which fulfills RFC6234 and is developed according to safe coding standards. The algorithm supports little endian machines only. -# Openssl wrapper +This implementation is retained as a transition API for existing safety-integrity consumers. +It is not the cryptographic API for new security use cases. -The wrapper class provides an interface to functions from Openssl library. The main purpose of this wrapper is to enable -unit-testability of Openssl library functions and acheive 100% unit test coverage of Hash calculator class. - -The Openssl wrapper functions are: - -* DigestAlgoSha1(), DigestAlgoSha256(), DigestAlgoSha384(), DigestAlgoSha512() - Returns a structure(EVP_MD) of digest - algorithms respectively. - -* CreateDigestCtx() - Allocates and returns a digest context. - -* InitDigestCtx() - Sets up digest context ctx to use a digest type from ENGINE impl. - -* UpdateDigestCtx() - Hashes count bytes of data at into the digest context ctx. - -* FinalizeDigestValue() - Retrieves the digest value from ctx and places it in digest_value and stores the length of - digest in digest_size - -* InitDigestCtx(), UpdateDigestCtx(), FinalizeDigestValue() returns 1 for success and 0 for failure. +# SafeHashCalculatorFactory vs. HashCalculatorFactory -* ResetDigestCtx() - Cleans up digest context ctx and frees up the space allocated to it. +There are two factories that implement IHashCalculatorFactory: SafeHashCalculatorFactory and HashCalculatorFactory. +Both factories provide the native IEEE CRC-32 and SHA-256 implementations without an OpenSSL dependency. +SafeHashCalculatorFactory is part of the FFI-marked Bazel target `//score/hash:safe_hash` which safety-critical +software may depend on. -# SafeHashCalculatorFactory vs. HashCalculatorFactory +# Cryptographic hash ownership -There are two factories that implement IHashCalculatorFactory: SafeHashCalculatorFactory and HashCalculatorFactory. As -the name implies, SafeHashCalculatorFactory is safe to use in safety-critical code. However, this factory will not make -use of OpenSSL, which reduces the number of available digest implementations. SafeHashCalculatorFactory is part of the -FFI-marked bazel target //score/hash:safe_hash which safety-critical software may depend on. +The Security Crypto feature owns cryptographic SHA-256, SHA-384, and SHA-512 operations, including software and +hardware-backed provider selection. +See [inc_security_crypto issue #125](https://github.com/eclipse-score/inc_security_crypto/issues/125) for the +migration context. +The native Baselibs SHA-256 implementation remains only until existing safety consumers have a qualified replacement. # How to use the factories diff --git a/score/hash/docs/index.rst b/score/hash/docs/index.rst index b6f7875f44..9b86fb3afb 100644 --- a/score/hash/docs/index.rst +++ b/score/hash/docs/index.rst @@ -24,6 +24,13 @@ hash :realizes: wp__cmpt_request[version==1] :security: NO +This component provides IEEE CRC-32 and temporarily retains the native SHA-256 +implementation for existing safety-integrity consumers. Cryptographic SHA-256, +SHA-384, and SHA-512 operations are owned by the Security Crypto feature. See +`inc_security_crypto issue #125 +`_ for the +migration context. + .. toctree:: :hidden: diff --git a/score/hash/docs/requirements/index.rst b/score/hash/docs/requirements/index.rst index 1a28317528..51291dbdda 100644 --- a/score/hash/docs/requirements/index.rst +++ b/score/hash/docs/requirements/index.rst @@ -90,18 +90,19 @@ Functional Requirements the computation, so that the calling code is not coupled to any specific algorithm implementation. -.. comp_req:: Cryptographic Hash Algorithms +.. comp_req:: Transitional Safety-Integrity SHA-256 :id: comp_req__hash__sha_algorithms :reqtype: Functional - :security: YES + :security: NO :safety: ASIL_B :derived_from: feat_req__baselibs__hash_library[version==2] :status: valid - :version: 1 + :version: 2 :satisfied_by: comp__baselibs_hash[version==1] - The hash library shall support SHA-1, SHA-256, SHA-384, and SHA-512 as - cryptographic hash algorithms. + The hash library shall provide the native SHA-256 implementation required by + existing safety-integrity consumers until a qualified replacement is + available. Security use cases shall use the Security Crypto feature. .. comp_req:: CRC-32 Checksum Algorithm :id: comp_req__hash__crc32_algorithm diff --git a/third_party/openssl/BUILD b/third_party/openssl/BUILD deleted file mode 100644 index a7c244fcf1..0000000000 --- a/third_party/openssl/BUILD +++ /dev/null @@ -1,51 +0,0 @@ -# ******************************************************************************* -# Copyright (c) 2026 Contributors to the Eclipse Foundation -# -# See the NOTICE file(s) distributed with this work for additional -# information regarding copyright ownership. -# -# This program and the accompanying materials are made available under the -# terms of the Apache License Version 2.0 which is available at -# https://www.apache.org/licenses/LICENSE-2.0 -# -# SPDX-License-Identifier: Apache-2.0 -# ******************************************************************************* - -load("@rules_cc//cc:defs.bzl", "cc_test") -load("//third_party/openssl:openssl_transition.bzl", "openssl_library") - -# Allows integrating workspaces to redirect the OpenSSL crypto implementation -# without modifying this file. The default points to the BCR-provided module. -# Override example (in the integrating workspace's .bazelrc): -# build --@score_baselibs//third_party/openssl:openssl_crypto_impl=//my/openssl:target -label_flag( - name = "openssl_crypto_impl", - build_setting_default = "@openssl//:crypto", - tags = ["manual"], - visibility = ["//visibility:public"], -) - -openssl_library( - name = "openssl_default", - dep = ":openssl_crypto_impl", -) - -alias( - name = "openssl", - actual = select({ - "@platforms//os:qnx": "//third_party/qnx:openssl", - "//conditions:default": ":openssl_default", - }), - visibility = ["//visibility:public"], -) - -# Verify we have modeled all dynamic dependencies for this library correctly. -# This test will fail with RBE, when not all dependencies are modeled. -# Locally this may work, as the host system may contain the dependencies. -cc_test( - name = "test_openssl", - deps = [ - ":openssl", - "@googletest//:gtest_main", - ], -) diff --git a/third_party/openssl/openssl_transition.bzl b/third_party/openssl/openssl_transition.bzl deleted file mode 100644 index cc194cbcd6..0000000000 --- a/third_party/openssl/openssl_transition.bzl +++ /dev/null @@ -1,74 +0,0 @@ -# ******************************************************************************* -# Copyright (c) 2026 Contributors to the Eclipse Foundation -# -# See the NOTICE file(s) distributed with this work for additional -# information regarding copyright ownership. -# -# This program and the accompanying materials are made available under the -# terms of the Apache License Version 2.0 which is available at -# https://www.apache.org/licenses/LICENSE-2.0 -# -# SPDX-License-Identifier: Apache-2.0 -# ******************************************************************************* - -"""User-defined transition for building OpenSSL with relaxed compiler settings. - -OpenSSL is a C library that uses GNU extensions and patterns that trigger -warnings under strict compilation settings. This transition adjusts the -active toolchain features rather than injecting raw compiler flags, making -it portable across all integrated toolchains: - - - Enables "gnu11" so the toolchain applies the GNU C11 dialect - required by OpenSSL's GNU extensions. - - Disables "minimal_warnings", "strict_warnings", "warnings_as_errors" - so OpenSSL's legitimate warning patterns do - not cause build failures. - -Each toolchain translates these feature names into its own concrete flags, -keeping this transition platform-agnostic. - -The transition is applied only to the non-QNX case (see BUILD), since QNX -uses a separately maintained OpenSSL target. -""" - -_FEATURES_TO_DISABLE = [ - "minimal_warnings", - "strict_warnings", - "warnings_as_errors", -] - -def _openssl_transition_impl(settings, attr): - current = list(settings["//command_line_option:features"]) - updated = [] - for f in current: - if f not in _FEATURES_TO_DISABLE: - updated.append(f) - updated.append("gnu11") - return { - "//command_line_option:features": updated, - } - -_openssl_transition = transition( - implementation = _openssl_transition_impl, - inputs = ["//command_line_option:features"], - outputs = ["//command_line_option:features"], -) - -def _openssl_library_impl(ctx): - # When a Starlark transition is applied to attr.label, Bazel wraps the - # result in a list (one entry per output configuration of the transition). - dep = ctx.attr.dep[0] - return [dep[DefaultInfo], dep[CcInfo]] - -openssl_library = rule( - implementation = _openssl_library_impl, - attrs = { - "dep": attr.label( - cfg = _openssl_transition, - providers = [CcInfo], - ), - "_allowlist_function_transition": attr.label( - default = "@bazel_tools//tools/allowlists/function_transition_allowlist", - ), - }, -) diff --git a/third_party/qnx/BUILD b/third_party/qnx/BUILD index c1338931d3..45c0b754a0 100644 --- a/third_party/qnx/BUILD +++ b/third_party/qnx/BUILD @@ -31,13 +31,3 @@ cc_library( target_compatible_with = ["@platforms//os:qnx"], visibility = ["//:__subpackages__"], ) - -cc_library( - name = "openssl", - linkopts = [ - "-lssl", - "-lcrypto", - ], - target_compatible_with = ["@platforms//os:qnx"], - visibility = ["//:__subpackages__"], -)