diff options
author | Jakob Unterwurzacher | 2017-05-28 18:09:02 +0200 |
---|---|---|
committer | Jakob Unterwurzacher | 2017-05-30 17:04:46 +0200 |
commit | 857507e8b100626ae0471fae793efc52bf552821 (patch) | |
tree | 155ff21467d8b35887e9a7fd984d37e23f7e6e70 /internal/pathiv/pathiv.go | |
parent | 4d2cc551cf6fa71e425fad8f397e96d69f016a6b (diff) |
fusefrontend_reverse: move pathiv to its own package
We will also need it in forward mode.
Diffstat (limited to 'internal/pathiv/pathiv.go')
-rw-r--r-- | internal/pathiv/pathiv.go | 24 |
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] +} |