mirror of
https://github.com/TecharoHQ/anubis.git
synced 2026-06-09 22:08:15 +00:00
04b3a835cd
Signed-off-by: jvoisin <julien.voisin@dustri.org>
25 lines
698 B
Go
25 lines
698 B
Go
package internal
|
|
|
|
import (
|
|
"crypto/sha256"
|
|
"encoding/hex"
|
|
"strconv"
|
|
|
|
"github.com/cespare/xxhash/v2"
|
|
)
|
|
|
|
// SHA256sum computes a cryptographic hash. Still used for proof-of-work challenges
|
|
// where we need the security properties of a cryptographic hash function.
|
|
func SHA256sum(text string) string {
|
|
sum := sha256.Sum256([]byte(text))
|
|
return hex.EncodeToString(sum[:])
|
|
}
|
|
|
|
// FastHash is a high-performance non-cryptographic hash function suitable for
|
|
// internal caching, policy rule identification, and other performance-critical
|
|
// use cases where cryptographic security is not required.
|
|
func FastHash(text string) string {
|
|
h := xxhash.Sum64String(text)
|
|
return strconv.FormatUint(h, 16)
|
|
}
|