From 97bf78725562ce22e18036873215f2203b3e0e1e Mon Sep 17 00:00:00 2001 From: qiulaidongfeng <2645477756@qq.com> Date: Sat, 25 Jan 2025 17:26:55 +0800 Subject: 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 Auto-Submit: Austin Clements Reviewed-by: Cherry Mui LUCI-TryBot-Result: Go LUCI --- blake2b/blake2x.go | 8 ++++++++ blake2b/go125.go | 11 +++++++++++ 2 files changed, 19 insertions(+) create mode 100644 blake2b/go125.go 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) -- cgit v1.3