feat: add tari_crypto hashing api support #4328
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Added a hashing domain API for general use based on the new domain separated hashing API from
tari_crypto
; this is a proposal to implement the hashing domain API system wide. A new structHashingDomain
was added to provide a standardized way of implementing the new tari_crypto hashing api, which provides standardized domain separated hashing, with two tari project specific hash domain structs,DefaultHashDomain
andMacHashDomain
.USe of
HashingDomain
allows differentiated domain declarations per "hash originating generation" crate level (see Suggested hashing domains below). The domain labels were chosen to complement the tari project specific hash domain label prefixes provided byDefaultHashDomain
andMacHashDomain
as"com.tari.tari_project.hash_domain.v1"
and"com.tari.tari_project.mac_domain.v1"
. As an example, resulting domain labels forCOMMON_HASH_DOMAIN
that specifies its own label"common"
will then be"com.tari.tari_project.hash_domain.v1.common"
and"com.tari.tari_project.mac_domain.v1.common"
.An example use case is:
The general idea is to use the lowest level hashing domain for the crate where an original hash needs to be generated, and where no higher level hash domain is defined for a specific crate,
common_hash_domain()
needs to be used. Code that replays a specific hash needs to use the same hash domain where the hash originated, for example the mempool.This standardized domain declarations should make code maintenance where domain hashing is used simpler and more efficient. The next PR will demonstrate use of
tari_script_hash_domain()
andmmr_hash_domain()
.Suggested hashing domains (This can easily be modified as needed.)
Motivation and Context
Needed to implement the
tari_crypto
standardized domain separated hashing.How Has This Been Tested?
Unit tests (no system level impact with this PR yet).