aboutsummaryrefslogtreecommitdiff
path: root/internal/pathiv/pathiv.go
diff options
context:
space:
mode:
authorJakob Unterwurzacher2017-05-28 20:43:48 +0200
committerJakob Unterwurzacher2017-05-28 20:43:48 +0200
commite2341c93d5b113457905b338b414e41892113ec4 (patch)
tree7888288fd38ecc9b8ec14220ad486ce4670f31fb /internal/pathiv/pathiv.go
parent1f5201da5ebb0180717f63d77bbe2338876bfd29 (diff)
pathiv: move block IV algorithm into this package
This was implemented in fusefrontend_reverse, but we need it in fusefrontend as well. Move the algorithm into pathiv.BlockIV().
Diffstat (limited to 'internal/pathiv/pathiv.go')
-rw-r--r--internal/pathiv/pathiv.go13
1 files changed, 13 insertions, 0 deletions
diff --git a/internal/pathiv/pathiv.go b/internal/pathiv/pathiv.go
index aa11b75..08042e9 100644
--- a/internal/pathiv/pathiv.go
+++ b/internal/pathiv/pathiv.go
@@ -2,6 +2,7 @@ package pathiv
import (
"crypto/sha256"
+ "encoding/binary"
"github.com/rfjakob/gocryptfs/internal/nametransform"
)
@@ -42,3 +43,15 @@ func DeriveFile(path string) (fileIVs FileIVs) {
fileIVs.Block0IV = Derive(path, PurposeBlock0IV)
return fileIVs
}
+
+// BlockIV returns the block IV for block number "blockNo". "block0iv" is the block
+// IV of block #0.
+func BlockIV(block0iv []byte, blockNo uint64) []byte {
+ iv := make([]byte, len(block0iv))
+ copy(iv, block0iv)
+ // Add blockNo to one half of the iv
+ lowBytes := iv[8:]
+ lowInt := binary.BigEndian.Uint64(lowBytes)
+ binary.BigEndian.PutUint64(lowBytes, lowInt+blockNo)
+ return iv
+}