You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
package blake2
|
|
|
|
|
|
|
|
import (
|
|
|
|
// Standard
|
|
|
|
"crypto/subtle"
|
|
|
|
"encoding/hex"
|
|
|
|
|
|
|
|
// Standard Extended
|
|
|
|
"golang.org/x/crypto/blake2b"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Check Hash
|
|
|
|
func (algorithm Algorithm) CheckHash(data []byte, hashToCheck string) (bool, error) {
|
|
|
|
// Hasher
|
|
|
|
hasher, err := blake2b.New(algorithm.size, nil)
|
|
|
|
// Handle Error
|
|
|
|
if err != nil {
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
// Write To Hasher
|
|
|
|
_, err = hasher.Write(data)
|
|
|
|
// Handle Error
|
|
|
|
if err != nil {
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
// Decode Hash To Check
|
|
|
|
decodedHashToCheck, err := hex.DecodeString(hashToCheck)
|
|
|
|
// Handle Error
|
|
|
|
if err != nil {
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
// Return Match
|
|
|
|
return subtle.ConstantTimeCompare(hasher.Sum(nil), decodedHashToCheck) == 1, err
|
|
|
|
}
|