aboutsummaryrefslogtreecommitdiff
path: root/internal/pathiv
diff options
context:
space:
mode:
authorJakob Unterwurzacher2017-05-28 18:09:02 +0200
committerJakob Unterwurzacher2017-05-28 18:09:02 +0200
commitab10cf63ed21d09e239986ac125b990fe06b5572 (patch)
tree575db69995d180bcdc5463713855847947b70ada /internal/pathiv
parentd59e7da6a6ee9883d61958ccd3ed3acb7c6ba8dc (diff)
fusefrontend_reverse: move pathiv to its own package
We will also need it in forward mode.
Diffstat (limited to 'internal/pathiv')
-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]
+}