package blake3
import "git.sr.ht/~pingoo/stdx/crypto/internal/blake3"
Package blake3 implements the BLAKE3 cryptographic hash function.
Index ¶
- func BaoDecode(dst io.Writer, data, outboard io.Reader, root [32]byte) (bool, error)
- func BaoEncode(dst io.WriterAt, data io.Reader, dataLen int64, outboard bool) ([32]byte, error)
- func BaoEncodeBuf(data []byte, outboard bool) ([]byte, [32]byte)
- func BaoEncodedSize(dataLen int, outboard bool) int
- func BaoVerifyBuf(data, outboard []byte, root [32]byte) bool
- func DeriveKey(subKey []byte, ctx string, srcKey []byte)
- func Sum256(b []byte) (out [32]byte)
- func Sum512(b []byte) (out [64]byte)
- type Hasher
- func New(size int, key []byte) *Hasher
- func (h *Hasher) BlockSize() int
- func (h *Hasher) Reset()
- func (h *Hasher) Size() int
- func (h *Hasher) Sum(b []byte) (sum []byte)
- func (h *Hasher) Write(p []byte) (int, error)
- func (h *Hasher) XOF() *OutputReader
- type OutputReader
Functions ¶
func BaoDecode ¶
BaoDecode reads content and tree data from the provided reader(s), and streams the verified content to dst. It returns false if verification fails. If the content and tree data are interleaved, outboard should be nil.
func BaoEncode ¶
BaoEncode computes the intermediate BLAKE3 tree hashes of data and writes them to dst. If outboard is false, the contents of data are also written to dst, interleaved with the tree hashes. It also returns the tree root, i.e. the 256-bit BLAKE3 hash.
Note that dst is not written sequentially, and therefore must be initialized with sufficient capacity to hold the encoding; see BaoEncodedSize.
func BaoEncodeBuf ¶
BaoEncodeBuf returns the Bao encoding and root (i.e. BLAKE3 hash) for data.
func BaoEncodedSize ¶
BaoEncodedSize returns the size of a Bao encoding for the provided quantity of data.
func BaoVerifyBuf ¶
BaoVerifyBuf verifies the Bao encoding and root (i.e. BLAKE3 hash) for data. If the content and tree data are interleaved, outboard should be nil.
func DeriveKey ¶
DeriveKey derives a subkey from ctx and srcKey. ctx should be hardcoded, globally unique, and application-specific. A good format for ctx strings is:
[application] [commit timestamp] [purpose]
e.g.:
example.com 2019-12-25 16:18:03 session tokens v1
The purpose of these requirements is to ensure that an attacker cannot trick two different applications into using the same context string.
func Sum256 ¶
Sum256 returns the unkeyed BLAKE3 hash of b, truncated to 256 bits.
func Sum512 ¶
Sum512 returns the unkeyed BLAKE3 hash of b, truncated to 512 bits.
Types ¶
type Hasher ¶
type Hasher struct {
// contains filtered or unexported fields
}
Hasher implements hash.Hash.
func New ¶
New returns a Hasher for the specified digest size and key. If key is nil, the hash is unkeyed. Otherwise, len(key) must be 32.
func (*Hasher) BlockSize ¶
BlockSize implements hash.Hash.
func (*Hasher) Reset ¶
func (h *Hasher) Reset()
Reset implements hash.Hash.
func (*Hasher) Size ¶
Size implements hash.Hash.
func (*Hasher) Sum ¶
Sum implements hash.Hash.
func (*Hasher) Write ¶
Write implements hash.Hash.
func (*Hasher) XOF ¶
func (h *Hasher) XOF() *OutputReader
XOF returns an OutputReader initialized with the current hash state.
type OutputReader ¶
type OutputReader struct {
// contains filtered or unexported fields
}
An OutputReader produces an seekable stream of 2^64 - 1 pseudorandom output bytes.
func (*OutputReader) Read ¶
func (or *OutputReader) Read(p []byte) (int, error)
Read implements io.Reader. Callers may assume that Read returns len(p), nil unless the read would extend beyond the end of the stream.
func (*OutputReader) Seek ¶
func (or *OutputReader) Seek(offset int64, whence int) (int64, error)
Seek implements io.Seeker.
Source Files ¶
bao.go blake3.go compress_amd64.go compress_generic.go cpu.go
- Version
- v0.0.0-20240218134121-094174641f6e (latest)
- Published
- Feb 18, 2024
- Platform
- linux/amd64
- Imports
- 9 packages
- Last checked
- 4 months ago –
Tools for package owners.