Skip to content

Add BLAKE3 hash function - #61

Merged
dmcgowan merged 2 commits into
opencontainers:masterfrom
sargun:blake3
May 18, 2021
Merged

dmcgowan merged 2 commits into
opencontainers:masterfrom
sargun:blake3

Conversation

@sargun

@sargun sargun commented Feb 15, 2021

Copy link
Copy Markdown
Contributor

This adds the default BLAKE3 hash function with a default output size of 256-bit. If we want to add support for other sizes in the future, I suggest that we do something like blake3-512 or blake3_512. Given that BLAKE3 can have an arbitrary output size, I'm unsure which "variants" we should add.

@sargun

sargun commented Feb 15, 2021

Copy link
Copy Markdown
Contributor Author

See: opencontainers/image-spec#819

@vbatts

vbatts commented Feb 25, 2021

Copy link
Copy Markdown
Member

to what extent is github.com/zeebo/blake3 still being vetted?
Even comparing to golang.org/x/crypto/blake2b as a more reliable option?

@sargun

sargun commented Mar 1, 2021

Copy link
Copy Markdown
Contributor Author

@vbatts that's blake2b which is != blake3. I can also add blake2b, but it's a fundamentally different hash.

@sargun

sargun commented Mar 1, 2021

Copy link
Copy Markdown
Contributor Author

We use zeebo/blake3 in prod. Blake2 doesn't have formal specifications for XOF, or a a tree hash, whereas blake3 does. IIRC, there are variants of blake2b that support XOF and tree hash, but AFAIK, they're not formalized.

@vbatts

vbatts commented Mar 4, 2021

Copy link
Copy Markdown
Member

ah, i wasn't saying that "2b" and "3" were the same or equivalent.
I was more commenting on how established the implementation is, for the golang team to have an implementation of blake2b that they "support", vs a community member's implementation of blake3

Comment thread blake3.go
import (
"hash"

"github.com/zeebo/blake3"

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.

I'm not sure we want blake3 dependency in this repo (until blake3 becomes popular in the OCI ecosystem).

Instead, can we add functions for dynamically adding algorithms?

e.g.,

package digest

func Register(algorithm string, siz int, newHash func ()hash.Hash)

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.

oh clever

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.

I can do that refactor.

@sargun

sargun commented Apr 21, 2021

Copy link
Copy Markdown
Contributor Author

Please see:
#62

This PR can move forward if we add a "sub-module" that has the blake3 bits, and people can import that in order to get that function to register.

@AkihiroSuda
AkihiroSuda marked this pull request as draft April 21, 2021 08:39
@AkihiroSuda

Copy link
Copy Markdown
Member

Can we have blake3.go in a separate pacakge: github.com/opencontainers/go-digest/blake3

@sargun

sargun commented Apr 22, 2021

Copy link
Copy Markdown
Contributor Author

That's my plan.

@sargun
sargun force-pushed the blake3 branch 2 times, most recently from fc04afd to eec210a Compare April 22, 2021 06:28
@sargun
sargun requested review from AkihiroSuda and vbatts April 22, 2021 08:09
Comment thread blake3/blake3_test.go Resolved
Comment thread blake3/blake3.go
"hash"

"github.com/opencontainers/go-digest"
"github.com/zeebo/blake3"

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.

Is there any chance that this implementation will substantively change if there is a canonical (e.g. golang.org/x/crypto/...) package for blake3?

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.

No. The cryptoHash interface is a subset of the hash interface in standard Go.

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.

Oh, I meant the hash algorithm itself, not the interface itself.:-)

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.

The algorithm itself has been released and specified. It's in production use in a bunch of places. I'm pretty sure it's considered stable at this point.

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.

👍

@vbatts

vbatts commented Apr 24, 2021

Copy link
Copy Markdown
Member

Is this still a draft?

@sargun
sargun marked this pull request as ready for review April 27, 2021 23:19
@sargun

sargun commented Apr 27, 2021

Copy link
Copy Markdown
Contributor Author

@vbatts it's good to go. I have one small additional change of moving around the definition of the digest (name), but that can be next.

This adds support for the BLAKE3 hash family with a default output
size of 256-bit.

Signed-off-by: Sargun Dhillon <[email protected]>
Because blake3 is a different go module, go test ./... doesn't
traverse into it, so it needs a separate stanza in the github
actions to test it.

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

sargun commented May 7, 2021

Copy link
Copy Markdown
Contributor Author

@vbatts This should be ready for review.
@AkihiroSuda Changes since last time:

  • Fixed test code
  • Moved the declaration of the blake3 "name" into the root module.

@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.

Thanks for the iterations on this.

LGTM

@sargun

sargun commented May 17, 2021

Copy link
Copy Markdown
Contributor Author

@AkihiroSuda Do you have any outstanding concerns?

@AkihiroSuda

Copy link
Copy Markdown
Member

@dmcgowan PTAL

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.

5 participants