From 5931eea3877ae34cdb18ac36e5cf5fba3f74b82b Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Tue, 30 Aug 2016 00:20:31 +0200 Subject: contentenc: add helpers for reverse mode Add the reverse variant of DecryptBlocks etc: * EncryptBlocks * JointPlaintextRange * ExplodeCipherRange --- internal/contentenc/content.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'internal/contentenc/content.go') 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 { -- cgit v1.2.3