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

     1  package crypto
     2  
     3  // HashSize is the size of a hash, in bytes.
     4  type HashSize uint32
     5  
     6  const (
     7  	// HashSize256 is the size in bytes of a 256 bits hash
     8  	HashSize256 HashSize = 32
     9  	// HashSize384 is the size in bytes of a 384 bits hash
    10  	HashSize384 HashSize = 48
    11  	// HashSize512 is the size in bytes of a 512 bits hash
    12  	HashSize512 HashSize = 64
    13  )
    14  
    15  // // NewHashBlake2b returns a new `hash.Hash` computing the BLAKE2b checksum with a custom length.
    16  // // size can be a value between 1 and 64.
    17  // // It is highly recommended to use values equal or greater than 32.
    18  // func NewHashBlake2b(size HashSize, key []byte) (hash.Hash, error) {
    19  // 	return blake2b.New(int(size), key)
    20  // }
    21  
    22  // // Hash256 returns the BLAKE2b-256 checksum of the data.
    23  // func HashBlake2b256(data []byte) []byte {
    24  // 	sum := blake2b.Sum256(data)
    25  // 	return sum[:]
    26  // }
    27  
    28  // // Hash384 returns the BLAKE2b-384 checksum of the data.
    29  // func HashBlake2b384(data []byte) []byte {
    30  // 	sum := blake2b.Sum384(data)
    31  // 	return sum[:]
    32  // }
    33  
    34  // // Hash512 returns the BLAKE2b-512 checksum of the data.
    35  // func HashBlake2b512(data []byte) []byte {
    36  // 	sum := blake2b.Sum512(data)
    37  // 	return sum[:]
    38  // }
    39  
    40  // // NewHashSha256Hash returns a new `hash.Hash` computing the SHA256 checksum.
    41  // func NewHashSha256() hash.Hash {
    42  // 	return sha256.New()
    43  // }
    44  
    45  // // HashSha256 returns the SHA256 checksum of the data.
    46  // func HashSha256(data []byte) []byte {
    47  // 	sum := sha256.Sum256(data)
    48  // 	return sum[:]
    49  // }