summaryrefslogtreecommitdiff
path: root/internal/contentenc/content.go
diff options
context:
space:
mode:
authorJakob Unterwurzacher2016-08-30 00:20:31 +0200
committerJakob Unterwurzacher2016-09-25 16:43:17 +0200
commit5931eea3877ae34cdb18ac36e5cf5fba3f74b82b (patch)
treef6cd8dd41c213013741ae893e67ec1adf3ff5b4c /internal/contentenc/content.go
parent1d4c6288f29d74efce83ada1ea2a7b3819178bde (diff)
contentenc: add helpers for reverse mode
Add the reverse variant of DecryptBlocks etc: * EncryptBlocks * JointPlaintextRange * ExplodeCipherRange
Diffstat (limited to 'internal/contentenc/content.go')
-rw-r--r--internal/contentenc/content.go14
1 files changed, 14 insertions, 0 deletions
diff --git a/internal/contentenc/content.go b/internal/contentenc/content.go
index 493ec56..375221a 100644
--- a/internal/contentenc/content.go
+++ b/internal/contentenc/content.go
@@ -50,6 +50,7 @@ func (be *ContentEnc) CipherBS() uint64 {
}
// DecryptBlocks - Decrypt a number of blocks
+// TODO refactor to three-param for
func (be *ContentEnc) DecryptBlocks(ciphertext []byte, firstBlockNo uint64, fileId []byte) ([]byte, error) {
cBuf := bytes.NewBuffer(ciphertext)
var err error
@@ -110,6 +111,19 @@ func (be *ContentEnc) DecryptBlock(ciphertext []byte, blockNo uint64, fileId []b
return plaintext, nil
}
+// EncryptBlocks - Encrypt a number of blocks
+// Used for reverse mode
+func (be *ContentEnc) EncryptBlocks(plaintext []byte, firstBlockNo uint64, fileId []byte) []byte {
+ inBuf := bytes.NewBuffer(plaintext)
+ var outBuf bytes.Buffer
+ for blockNo := firstBlockNo; inBuf.Len() > 0; blockNo++ {
+ inBlock := inBuf.Next(int(be.plainBS))
+ outBlock := be.EncryptBlock(inBlock, blockNo, fileId)
+ outBuf.Write(outBlock)
+ }
+ return outBuf.Bytes()
+}
+
// encryptBlock - Encrypt and add IV and MAC
func (be *ContentEnc) EncryptBlock(plaintext []byte, blockNo uint64, fileID []byte) []byte {