aboutsummaryrefslogtreecommitdiff
path: root/verifysetup/core/crypt.go
diff options
context:
space:
mode:
Diffstat (limited to 'verifysetup/core/crypt.go')
-rw-r--r--verifysetup/core/crypt.go18
1 files changed, 18 insertions, 0 deletions
diff --git a/verifysetup/core/crypt.go b/verifysetup/core/crypt.go
new file mode 100644
index 0000000..81130a3
--- /dev/null
+++ b/verifysetup/core/crypt.go
@@ -0,0 +1,18 @@
+package core
+
+import (
+ "bytes"
+ "crypto/sha256"
+ "fmt"
+ "io"
+ "strings"
+)
+
+func CalculateBlockHash(block []byte) (string, error) {
+ hash := sha256.New()
+ if _, err := io.Copy(hash, bytes.NewReader(block)); err != nil {
+ return "", err
+ }
+ hashInBytes := hash.Sum(nil)[:32]
+ return strings.TrimSpace(fmt.Sprintf("%x", hashInBytes)), nil
+}