aboutsummaryrefslogtreecommitdiff
path: root/internal/pathiv/pathiv.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/pathiv/pathiv.go')
-rw-r--r--internal/pathiv/pathiv.go24
1 files changed, 24 insertions, 0 deletions
diff --git a/internal/pathiv/pathiv.go b/internal/pathiv/pathiv.go
new file mode 100644
index 0000000..d2d90a2
--- /dev/null
+++ b/internal/pathiv/pathiv.go
@@ -0,0 +1,24 @@
+package pathiv
+
+import (
+ "crypto/sha256"
+
+ "github.com/rfjakob/gocryptfs/internal/nametransform"
+)
+
+type Purpose string
+
+const (
+ PurposeDirIV Purpose = "DIRIV"
+ PurposeFileID Purpose = "FILEID"
+ PurposeSymlinkIV Purpose = "SYMLINKIV"
+ PurposeBlock0IV Purpose = "BLOCK0IV"
+)
+
+// Derive derives an IV from an encrypted path by hashing it with sha256
+func Derive(path string, purpose Purpose) []byte {
+ // Use null byte as separator as it cannot occur in the path
+ extended := []byte(path + "\000" + string(purpose))
+ hash := sha256.Sum256(extended)
+ return hash[:nametransform.DirIVLen]
+}