aboutsummaryrefslogtreecommitdiff
path: root/pathfs_frontend/file.go
diff options
context:
space:
mode:
authorJakob Unterwurzacher2015-10-06 22:27:37 +0200
committerJakob Unterwurzacher2015-10-06 22:27:37 +0200
commita3d286069f989dd16c6f91930a0df9fedfa2dd64 (patch)
treef4f27e09c63b5d777b14fa448c149f0132fffbae /pathfs_frontend/file.go
parent45ea8aa5463942b0b777fcc0b354cef5821c908d (diff)
Use block number as authentication data
Diffstat (limited to 'pathfs_frontend/file.go')
-rw-r--r--pathfs_frontend/file.go11
1 files changed, 5 insertions, 6 deletions
diff --git a/pathfs_frontend/file.go b/pathfs_frontend/file.go
index 7f5cc90..3304267 100644
--- a/pathfs_frontend/file.go
+++ b/pathfs_frontend/file.go
@@ -80,13 +80,12 @@ func (f *file) doRead(off uint64, length uint64) ([]byte, fuse.Status) {
}
// Truncate ciphertext buffer down to actually read bytes
ciphertext = ciphertext[0:n]
- {
- blockNo := alignedOffset / f.cfs.CipherBS()
- cryptfs.Debug.Printf("ReadAt offset=%d bytes (%d blocks), want=%d, got=%d\n", alignedOffset, blockNo, alignedLength, n)
- }
+
+ blockNo := alignedOffset / f.cfs.CipherBS()
+ cryptfs.Debug.Printf("ReadAt offset=%d bytes (%d blocks), want=%d, got=%d\n", alignedOffset, blockNo, alignedLength, n)
// Decrypt it
- plaintext, err := f.cfs.DecryptBlocks(ciphertext)
+ plaintext, err := f.cfs.DecryptBlocks(ciphertext, blockNo)
if err != nil {
blockNo := (alignedOffset + uint64(len(plaintext))) / f.cfs.PlainBS()
cipherOff := blockNo * f.cfs.CipherBS()
@@ -159,7 +158,7 @@ func (f *file) doWrite(data []byte, off int64) (uint32, fuse.Status) {
// Write
blockOffset, _ := b.CiphertextRange()
- blockData = f.cfs.EncryptBlock(blockData)
+ blockData = f.cfs.EncryptBlock(blockData, b.BlockNo)
cryptfs.Debug.Printf("ino%d: Writing %d bytes to block #%d, md5=%s\n", f.ino, len(blockData), b.BlockNo, cryptfs.Debug.Md5sum(blockData))
if len(blockData) != int(f.cfs.CipherBS()) {
cryptfs.Debug.Printf("ino%d: Writing partial block #%d (%d bytes)\n", f.ino, b.BlockNo, len(blockData))