Skip to content

Commit

Permalink
x/crypto/blake2s: Allow computing variable-length digests.
Browse files Browse the repository at this point in the history
Current implementation provides only XOF-based method for
digest size other than 16 or 32 bytes. This commit allows
digest size between 1 and 32 bytes, as defined by the BLAKE2s
paper.

Fixes #36429

Signed-off-by: Jiří Keresteš <jiri@kerestes.cz>
  • Loading branch information
Nephirus authored and mikroskeem committed Apr 4, 2021
1 parent 7383442 commit 7475c5b
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions blake2s.go
Expand Up @@ -66,6 +66,15 @@ func New128(key []byte) (hash.Hash, error) {
return newDigest(Size128, key)
}

// New returns a new hash.Hash computing the BLAKE2s checksum with a hashSize
// long output.
func New(hashSize int, key []byte) (hash.Hash, error) {
if hashSize < 1 || hashSize > 32 {
return nil, errors.New("blake2s: hash size must be between 1 and 32 bytes")
}
return newDigest(hashSize, key)
}

func newDigest(hashSize int, key []byte) (*digest, error) {
if len(key) > Size {
return nil, errKeySize
Expand Down

0 comments on commit 7475c5b

Please sign in to comment.