Skip to content

Refactorings needed for injection support#186

Open
eclipse-impl wants to merge 1 commit into
eclipse-score:mainfrom
eclipse-impl:swp-260766
Open

Refactorings needed for injection support#186
eclipse-impl wants to merge 1 commit into
eclipse-score:mainfrom
eclipse-impl:swp-260766

Conversation

@eclipse-impl
Copy link
Copy Markdown
Contributor

Different SCORE users might have specific needs for supporting proprietary or copyrighted hashing functions. Therefore we need to provide the mechanism for clients injecting their extensions to the hash lib.

This commit prepares the open-source code for the injection of a copyrighted hash function by one of the clients.

Notice that the aim is to achieve a design that will be sufficiently generic that will allow for extensions without any change on the open-source side.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 8, 2026

The created documentation from the pull request is available at: docu-html

@eclipse-impl eclipse-impl temporarily deployed to workflow-approval May 12, 2026 12:20 — with GitHub Actions Inactive
@eclipse-impl eclipse-impl temporarily deployed to workflow-approval May 12, 2026 12:20 — with GitHub Actions Inactive
@eclipse-impl eclipse-impl marked this pull request as ready for review May 12, 2026 12:20
@eclipse-impl eclipse-impl requested review from 4og and antonkri as code owners May 12, 2026 12:20
@eclipse-impl eclipse-impl temporarily deployed to workflow-approval May 15, 2026 09:31 — with GitHub Actions Inactive
@eclipse-impl eclipse-impl temporarily deployed to workflow-approval May 15, 2026 09:31 — with GitHub Actions Inactive
@eclipse-impl eclipse-impl temporarily deployed to workflow-approval May 15, 2026 10:17 — with GitHub Actions Inactive
@eclipse-impl eclipse-impl temporarily deployed to workflow-approval May 15, 2026 10:17 — with GitHub Actions Inactive
@4og 4og added the comp-hash Related to score/hash component label May 15, 2026
@4og 4og requested a review from Copilot May 26, 2026 12:58
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR prepares the SCORE hash library for client-side extension/injection of hashing functionality (including proprietary implementations) by widening Bazel visibility and introducing clearer extension points around CRC variants.

Changes:

  • Expose selected hash-related Bazel targets publicly to enable external composition/overrides.
  • Refactor CRC32 IEEE implementation to share a reusable compile-time lookup table and remove custom.bzl hooks.
  • Rename HashAlgorithm::kCrc32Unused to HashAlgorithm::kCrc32Autosar and update factories/tests/logging accordingly.

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
score/hash/code/sha256digest/BUILD Makes sha256digest library publicly visible for external wiring.
score/hash/code/openssl/openssl_wrapper/BUILD Makes OpenSSL mock target publicly visible (for external tests).
score/hash/code/openssl/openssl_hash_calculator.cpp Updates unsupported algorithm switch cases for renamed CRC enum.
score/hash/code/openssl/BUILD Makes OpenSSL calculator library publicly visible for injection scenarios.
score/hash/code/crc/lookup_table.h Adds shared constexpr CRC lookup table implementation.
score/hash/code/crc/custom.bzl Removes no-op custom hook file.
score/hash/code/crc/crc32_ieee.cpp Switches CRC32 IEEE to use shared lookup table header.
score/hash/code/crc/BUILD Exposes CRC IEEE library publicly and documents extension approach.
score/hash/code/core/factory/impl/safe_hash_calculator_factory_ieee.cpp Updates unsupported algorithm cases for renamed CRC enum.
score/hash/code/core/factory/impl/hash_calculator_factory_ieee.cpp Updates unsupported algorithm cases for renamed CRC enum.
score/hash/code/core/factory/impl/hash_calculator_factory_ieee_test.cpp Updates test to use renamed CRC algorithm (but test name still says “Unused”).
score/hash/code/core/factory/impl/custom.bzl Removes no-op custom hook file.
score/hash/code/core/factory/impl/BUILD Adds a public header-only target and updates extension-point documentation.
score/hash/code/common/algorithms.h Renames CRC enum value and size constant; updates logging string.
score/hash/code/common/algorithms.cpp Updates size mapping and identification comments for renamed CRC enum.
score/hash/code/common/algorithms_test.cpp Updates tests for renamed CRC enum and log output.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +17 to +59
#include <cstdint>

namespace score
{
namespace hash
{
namespace internal
{

/// @brief Compile-time CRC32 lookup table parameterised by a reflected polynomial.
///
/// This is an implementation detail shared by CRC32 calculator classes.
/// It is not part of the public API.
template <std::uint_fast32_t ReversePolynomial>
class LookupTable final
{
public:
constexpr LookupTable() : table_{}
{
for (std::uint_fast32_t table_index = 0U; table_index < kTableSize; ++table_index)
{
auto checksum = table_index;

for (auto round = 0U; round < 8U; ++round)
{
if (static_cast<bool>(checksum & 0x1U))
{
checksum = (checksum >> 1U) ^ ReversePolynomial;
}
else
{
checksum = (checksum >> 1U) ^ 0U;
}
}
// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-constant-array-index) can't use .at() in constexpr fn
table_[table_index] = checksum;
}
}

constexpr std::uint_fast32_t operator[](size_t i) const noexcept
{
// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-constant-array-index) can't use .at() in constexpr fn
return table_[i];
Comment thread score/hash/code/crc/BUILD Outdated
Comment on lines +18 to +21
# If one needs to provide different polynomials, one can directly inherit
# from this target and use the `label_flag` at:
# score/hash/code/core/factory/impl/BUILD
# For providing the extended version as a replacement for `(safe_)crc_variant`.
Comment thread score/hash/code/core/factory/impl/BUILD Outdated
Comment on lines +74 to +79
# meaning that one may replace them by custom implementations that would
# provide different polynomials. These extensions may directly inherit from:
# //score/hash/code/crc:crc_ieee
# As that target provides a generic implementation of CRC, the custom
# implementations would then only need to provide their polynomials
# and override these two targets on their .bazelrc files.
Comment on lines +107 to +113
score::cpp::span<const std::uint8_t> data(test_input);

auto result = unit.CalculateHash(HashAlgorithm::kCrc32Unused, data);
auto result = unit.CalculateHash(HashAlgorithm::kCrc32Autosar, data);
kSha512,
kCrc32,
kCrc32Unused,
kCrc32Autosar,
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are currently no users for the API, so it's fine to break it.

Different SCORE users might have specific needs for supporting
proprietary or copyrighted hashing functions. Therefore we need
to provide the mechanism for clients injecting their extensions
to the hash lib.

This commit prepares the open-source code for the injection of
a copyrighted hash function by one of the clients.

Notice that the aim is to achieve a design that will be
sufficiently generic that will allow for extensions without any
change on the open-source side.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-hash Related to score/hash component

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

3 participants