From 857507e8b100626ae0471fae793efc52bf552821 Mon Sep 17 00:00:00 2001
From: Jakob Unterwurzacher
Date: Sun, 28 May 2017 18:09:02 +0200
Subject: fusefrontend_reverse: move pathiv to its own package

We will also need it in forward mode.
---
 internal/pathiv/pathiv.go | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
 create mode 100644 internal/pathiv/pathiv.go

(limited to 'internal/pathiv')

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]
+}
-- 
cgit v1.2.3