git.sr.ht/~pingoo/stdx@v0.0.0-20240218134121-094174641f6e/crypto/hash/sha2.go (about)

     1  package hash
     2  
     3  import (
     4  	"crypto/sha512"
     5  	"hash"
     6  
     7  	"crypto/sha256"
     8  )
     9  
    10  // NewSha256 returns a new `hash.Hash` computing the SHA2-256 checksum.
    11  func NewSha256() hash.Hash {
    12  	return sha256.New()
    13  }
    14  
    15  // Sha256 returns the SHA2-256 checksum of the data.
    16  func Sha256(data []byte) []byte {
    17  	sum := sha256.Sum256(data)
    18  	return sum[:]
    19  }
    20  
    21  // NewSha512 returns a new `hash.Hash` computing the SHA2-512 checksum.
    22  func NewSha512() hash.Hash {
    23  	return sha512.New()
    24  }
    25  
    26  // SHA512 returns the SHA2-512 checksum of the data.
    27  func SHA512(data []byte) []byte {
    28  	sum := sha512.Sum512(data)
    29  	return sum[:]
    30  }