Skip to content

Commit 97bf787

Browse files
qiulaidongfenggopherbot
authored andcommitted
blake2b: implement hash.XOF
Fixes golang/go#69518 Change-Id: Id9989ac9b28262df77017e97f985f67c1571c3ce Reviewed-on: https://go-review.googlesource.com/c/crypto/+/644255 Reviewed-by: Austin Clements <[email protected]> Auto-Submit: Austin Clements <[email protected]> Reviewed-by: Cherry Mui <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent 952517d commit 97bf787

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

blake2b/blake2x.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import (
1212

1313
// XOF defines the interface to hash functions that
1414
// support arbitrary-length output.
15+
//
16+
// New callers should prefer the standard library [hash.XOF].
1517
type XOF interface {
1618
// Write absorbs more data into the hash's state. It panics if called
1719
// after Read.
@@ -47,6 +49,8 @@ const maxOutputLength = (1 << 32) * 64
4749
//
4850
// A non-nil key turns the hash into a MAC. The key must between
4951
// zero and 32 bytes long.
52+
//
53+
// The result can be safely interface-upgraded to [hash.XOF].
5054
func NewXOF(size uint32, key []byte) (XOF, error) {
5155
if len(key) > Size {
5256
return nil, errKeySize
@@ -93,6 +97,10 @@ func (x *xof) Clone() XOF {
9397
return &clone
9498
}
9599

100+
func (x *xof) BlockSize() int {
101+
return x.d.BlockSize()
102+
}
103+
96104
func (x *xof) Reset() {
97105
x.cfg[0] = byte(Size)
98106
binary.LittleEndian.PutUint32(x.cfg[4:], uint32(Size)) // leaf length

blake2b/go125.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright 2025 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
//go:build go1.25
6+
7+
package blake2b
8+
9+
import "hash"
10+
11+
var _ hash.XOF = (*xof)(nil)

0 commit comments

Comments
 (0)