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

     1  // Package signature
     2  //
     3  // @author: xwc1125
     4  package signature
     5  
     6  import (
     7  	"crypto"
     8  	"hash"
     9  )
    10  
    11  // HashMsg hash data
    12  func HashMsg(curveName string, msg []byte) []byte {
    13  	ecdsa, err := GetECDSA(curveName)
    14  	if err != nil {
    15  		return nil
    16  	}
    17  	bytes, err := ecdsa.HashMsg(curveName, msg)
    18  	if err != nil {
    19  		return nil
    20  	}
    21  	return bytes
    22  }
    23  
    24  // HashType hash type
    25  func HashType(curveName string) crypto.Hash {
    26  	ecdsa, err := GetECDSA(curveName)
    27  	if err != nil {
    28  		return crypto.SHA256
    29  	}
    30  	return ecdsa.HashType(curveName)
    31  }
    32  
    33  // HashFunc get hash.Hash
    34  func HashFunc(curveName string) func() hash.Hash {
    35  	ecdsa, err := GetECDSA(curveName)
    36  	if err != nil {
    37  		return nil
    38  	}
    39  	return ecdsa.HashFunc(curveName)
    40  }