diff --git a/README.md b/README.md index f3460bb..fb6a1da 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,7 @@ GCL offers support for a diverse range of cryptographic algorithms, ensuring tha - [X] BLAKE2 - [X] SHA256 +- [X] SHA512 ## Installation diff --git a/algorithms/sha512/CheckHash.go b/algorithms/sha512/CheckHash.go new file mode 100644 index 0000000..49ebf62 --- /dev/null +++ b/algorithms/sha512/CheckHash.go @@ -0,0 +1,21 @@ +package sha512 + +import ( + // Standard + "crypto/sha512" + "crypto/subtle" +) + +// Check Hash +func (Algorithm) CheckHash(data []byte, hashToCheck []byte) (bool, error) { + // Hasher + hasher := sha512.New() + // Write To Hasher + _, err := hasher.Write(data) + // Handle Error + if err != nil { + return false, err + } + // Return Hash + return subtle.ConstantTimeCompare(hasher.Sum(nil), hashToCheck) == 1, err +} diff --git a/algorithms/sha512/Hash.go b/algorithms/sha512/Hash.go new file mode 100644 index 0000000..8258178 --- /dev/null +++ b/algorithms/sha512/Hash.go @@ -0,0 +1,20 @@ +package sha512 + +import ( + // Standard + "crypto/sha512" +) + +// Hash +func (Algorithm) Hash(data []byte) ([]byte, error) { + // Hasher + hasher := sha512.New() + // Write To Hasher + _, err := hasher.Write(data) + // Handle Error + if err != nil { + return []byte(""), err + } + // Return Hash + return hasher.Sum(nil), err +} diff --git a/algorithms/sha512/algorithm.go b/algorithms/sha512/algorithm.go new file mode 100644 index 0000000..d53e308 --- /dev/null +++ b/algorithms/sha512/algorithm.go @@ -0,0 +1,10 @@ +package sha512 + +// Algorithm +type Algorithm struct{} + +// New +func New(size int) Algorithm { + // Return Algorithm + return Algorithm{} +}