Added the SHA512 algorithm.

main
Tylan Tyson 12 months ago
parent 0c185d23a5
commit a97a047010

@ -15,6 +15,7 @@ GCL offers support for a diverse range of cryptographic algorithms, ensuring tha
- [X] BLAKE2
- [X] SHA256
- [X] SHA512
## Installation

@ -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
}

@ -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
}

@ -0,0 +1,10 @@
package sha512
// Algorithm
type Algorithm struct{}
// New
func New(size int) Algorithm {
// Return Algorithm
return Algorithm{}
}
Loading…
Cancel
Save