Skip to content

Implement dynamic hash registration - #62

Merged
vbatts merged 1 commit into
opencontainers:masterfrom
sargun:hash-registry
Apr 21, 2021
Merged

vbatts merged 1 commit into
opencontainers:masterfrom
sargun:hash-registry

Conversation

@sargun

@sargun sargun commented Apr 21, 2021

Copy link
Copy Markdown
Contributor

This adds a new interface to go-digest allowing for it to act as a registry
for various hash implementations. It includes the new "CryptoHash" interface
which hashers must implement. By default the SHA variants that were
historically available are available.

The cryptoHash interface mimics crypto.Hash, but is a subset of the methods
that we require. crypto.Hash is a concrete type that makes it hard to bring
new hash function implementations in.

The primary impetus is to allow for out-of-tree hash implementations to be
added. For example, if someone wanted to add the out-of-tree BLAKE3 AVX
implementation, they could do that. Right now, if two versions of the same
implementation are added, the one that is added first will take precedence,
but in the future, we can add the ability to force registration.

Signed-off-by: Sargun Dhillon [email protected]

@sargun sargun mentioned this pull request Apr 21, 2021
@sargun

sargun commented Apr 21, 2021

Copy link
Copy Markdown
Contributor Author

Made one small fix around the comment from @stevvooe. I think I fulfilled the proposed ask.

@vbatts vbatts left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Good stuff

Comment thread algorithm.go Outdated
algorithmsLock.Lock()
defer algorithmsLock.Unlock()

if _, ok := algorithms[algorithm]; ok {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We made the standard keys lowercase. Perhaps we should force the same here of all keys (and comment as such) so that "SHA256" doesn't confuse with "sha256"

@sargun sargun Apr 21, 2021 •

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.

This adds a new interface to go-digest allowing for it to act as a registry
for various hash implementations. It includes the new "CryptoHash" interface
which hashers must implement. By default the SHA variants that were
historically available are available.

The cryptoHash interface mimics crypto.Hash, but is a subset of the methods
that we require. crypto.Hash is a concrete type that makes it hard to bring
new hash function implementations in.

The primary impetus is to allow for out-of-tree hash implementations to be
added. For example, if someone wanted to add the out-of-tree BLAKE3 AVX
implementation, they could do that. Right now, if two versions of the same
implementation are added, the one that is added first will take precedence,
but in the future, we can add the ability to force registration.

Signed-off-by: Sargun Dhillon <[email protected]>

@dmcgowan dmcgowan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@vbatts vbatts left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants