github.com/chain5j/chain5j-pkg@v1.0.7/crypto/keccak/keccak.go (about)

     1  // Package keccak
     2  //
     3  // @author: xwc1125
     4  package keccak
     5  
     6  import (
     7  	"github.com/chain5j/chain5j-pkg/crypto/hashalg/sha3"
     8  	"github.com/chain5j/chain5j-pkg/types"
     9  )
    10  
    11  // Keccak256 calculates and returns the Keccak256 hash of the input data.
    12  func Keccak256(data ...[]byte) []byte {
    13  	d := sha3.NewKeccak256()
    14  	for _, b := range data {
    15  		d.Write(b)
    16  	}
    17  	return d.Sum(nil)
    18  }
    19  
    20  // Keccak256Hash calculates and returns the Keccak256 hash of the input data,
    21  // converting it to an internal Hash data structure.
    22  func Keccak256Hash(data ...[]byte) (h types.Hash) {
    23  	d := sha3.NewKeccak256()
    24  	for _, b := range data {
    25  		d.Write(b)
    26  	}
    27  	d.Sum(h[:0])
    28  	return h
    29  }
    30  
    31  // Keccak512 calculates and returns the Keccak512 hash of the input data.
    32  func Keccak512(data ...[]byte) []byte {
    33  	d := sha3.NewKeccak512()
    34  	for _, b := range data {
    35  		d.Write(b)
    36  	}
    37  	return d.Sum(nil)
    38  }