diff options
| author | qiulaidongfeng <2645477756@qq.com> | 2025-01-25 17:26:55 +0800 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2025-06-30 09:39:26 -0700 |
| commit | 97bf78725562ce22e18036873215f2203b3e0e1e (patch) | |
| tree | a8c948ed31b6e0e19fd804f18d45e3646bebc21d | |
| parent | 952517d181d424f6c77f7460bf728205cb048411 (diff) | |
| download | go-x-crypto-97bf78725562ce22e18036873215f2203b3e0e1e.tar.xz | |
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 <austin@google.com>
Auto-Submit: Austin Clements <austin@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
| -rw-r--r-- | blake2b/blake2x.go | 8 | ||||
| -rw-r--r-- | blake2b/go125.go | 11 |
2 files changed, 19 insertions, 0 deletions
diff --git a/blake2b/blake2x.go b/blake2b/blake2x.go index 52c414d..7692bb3 100644 --- a/blake2b/blake2x.go +++ b/blake2b/blake2x.go @@ -12,6 +12,8 @@ import ( // XOF defines the interface to hash functions that // support arbitrary-length output. +// +// New callers should prefer the standard library [hash.XOF]. type XOF interface { // Write absorbs more data into the hash's state. It panics if called // after Read. @@ -47,6 +49,8 @@ const maxOutputLength = (1 << 32) * 64 // // A non-nil key turns the hash into a MAC. The key must between // zero and 32 bytes long. +// +// The result can be safely interface-upgraded to [hash.XOF]. func NewXOF(size uint32, key []byte) (XOF, error) { if len(key) > Size { return nil, errKeySize @@ -93,6 +97,10 @@ func (x *xof) Clone() XOF { return &clone } +func (x *xof) BlockSize() int { + return x.d.BlockSize() +} + func (x *xof) Reset() { x.cfg[0] = byte(Size) binary.LittleEndian.PutUint32(x.cfg[4:], uint32(Size)) // leaf length diff --git a/blake2b/go125.go b/blake2b/go125.go new file mode 100644 index 0000000..67e990b --- /dev/null +++ b/blake2b/go125.go @@ -0,0 +1,11 @@ +// Copyright 2025 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +//go:build go1.25 + +package blake2b + +import "hash" + +var _ hash.XOF = (*xof)(nil) |
