Debian Codegraph @

digest.go

raw
1 package desync
2
3 import (
4 "crypto"
5 "crypto/sha256"
6 "crypto/sha512"
7 )
8
9 // Digest algorithm used globally for all chunk hashing. Can be set to SHA512256
10 // (default) or to SHA256.
11 var Digest HashAlgorithm = SHA512256{}
12
13 // HashAlgorithm is a digest algorithm used to hash chunks.
14 type HashAlgorithm interface {
15 Sum([]byte) [32]byte
16 Algorithm() crypto.Hash
17 }
18
19 // SHA512-256 hashing algorithm for Digest.
20 type SHA512256 struct{}
21
22 func (h SHA512256) Sum(data []byte) [32]byte { return sha512.Sum512_256(data) }
23 func (h SHA512256) Algorithm() crypto.Hash { return crypto.SHA512_256 }
24
25 // SHA256 hashing algorithm for Digest.
26 type SHA256 struct{}
27
28 func (h SHA256) Sum(data []byte) [32]byte { return sha256.Sum256(data) }
29 func (h SHA256) Algorithm() crypto.Hash { return crypto.SHA256 }