aboutsummaryrefslogtreecommitdiff
path: root/cryptfs
diff options
context:
space:
mode:
authorJakob Unterwurzacher2015-09-08 00:54:24 +0200
committerJakob Unterwurzacher2015-09-08 00:55:03 +0200
commit889ae900814aac1c17c38a76882b1aafa5744be6 (patch)
tree67b5c1e873574e208971ec6f98fa5febb76f3fa7 /cryptfs
parentb65882985dd7aa3ea7ae76c49d592ff30b353a8b (diff)
Add pathfs frontend (uses go-fuse instead of bazil-fuse), part I
Currently fails main_test.go, will be fixed in part II
Diffstat (limited to 'cryptfs')
-rw-r--r--cryptfs/cryptfs_content.go39
-rw-r--r--cryptfs/log.go2
2 files changed, 39 insertions, 2 deletions
diff --git a/cryptfs/cryptfs_content.go b/cryptfs/cryptfs_content.go
index 4658529..e23d9b5 100644
--- a/cryptfs/cryptfs_content.go
+++ b/cryptfs/cryptfs_content.go
@@ -77,7 +77,7 @@ func (be *CryptFS) EncryptBlock(plaintext []byte) []byte {
return ciphertext
}
-// Split a plaintext byte range into (possible partial) blocks
+// Split a plaintext byte range into (possibly partial) blocks
func (be *CryptFS) SplitRange(offset uint64, length uint64) []intraBlock {
var b intraBlock
var parts []intraBlock
@@ -113,6 +113,22 @@ func (be *CryptFS) minu64(x uint64, y uint64) uint64 {
return y
}
+// CiphertextRange - Get byte range in backing ciphertext corresponding
+// to plaintext range. Returns a range aligned to ciphertext blocks.
+func (be *CryptFS) CiphertextRange(offset uint64, length uint64) (uint64, uint64, int) {
+ // Decrypting the ciphertext will yield too many plaintext bytes. Skip this number
+ // of bytes from the front.
+ skip := offset % be.plainBS
+
+ firstBlockNo := offset / be.plainBS
+ lastBlockNo := ( offset + length - 1 ) / be.plainBS
+
+ alignedOffset := firstBlockNo * be.cipherBS
+ alignedLength := (lastBlockNo - firstBlockNo + 1) * be.cipherBS
+
+ return alignedOffset, alignedLength, int(skip)
+}
+
// Get the byte range in the ciphertext corresponding to blocks
// (full blocks!)
func (be *CryptFS) JoinCiphertextRange(blocks []intraBlock) (uint64, uint64) {
@@ -138,3 +154,24 @@ func (be *CryptFS) CropPlaintext(plaintext []byte, blocks []intraBlock) []byte {
}
return cropped
}
+
+// MergeBlocks - Merge newData into oldData at offset
+// New block may be bigger than both newData and oldData
+func (be *CryptFS) MergeBlocks(oldData []byte, newData []byte, offset int) []byte {
+
+ // Make block of maximum size
+ out := make([]byte, be.plainBS)
+
+ // Copy old and new data into it
+ copy(out, oldData)
+ l := len(newData)
+ copy(out[offset:offset + l], newData)
+
+ // Crop to length
+ outLen := len(oldData)
+ newLen := offset + len(newData)
+ if outLen < newLen {
+ outLen = newLen
+ }
+ return out[0:outLen]
+}
diff --git a/cryptfs/log.go b/cryptfs/log.go
index f9c46c8..8233529 100644
--- a/cryptfs/log.go
+++ b/cryptfs/log.go
@@ -15,5 +15,5 @@ func (l logChannel) Printf(format string, args ...interface{}) {
}
-var Debug = logChannel{false}
+var Debug = logChannel{true}
var Warn = logChannel{true}