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