-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support SHA256 digest algorithm (#121)
- Loading branch information
Showing
13 changed files
with
71 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters