aboutsummaryrefslogtreecommitdiff
path: root/internal/contentenc/content.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/contentenc/content.go')
-rw-r--r--internal/contentenc/content.go18
1 files changed, 18 insertions, 0 deletions
diff --git a/internal/contentenc/content.go b/internal/contentenc/content.go
index 524296f..80bcf54 100644
--- a/internal/contentenc/content.go
+++ b/internal/contentenc/content.go
@@ -149,6 +149,24 @@ func (be *ContentEnc) DecryptBlock(ciphertext []byte, blockNo uint64, fileID []b
return plaintext, nil
}
+// EncryptBlocks is like EncryptBlock but takes multiple plaintext blocks.
+func (be *ContentEnc) EncryptBlocks(plaintextBlocks [][]byte, firstBlockNo uint64, fileID []byte) []byte {
+ // Encrypt piecewise.
+ ciphertextBlocks := make([][]byte, len(plaintextBlocks))
+ for i, v := range plaintextBlocks {
+ ciphertextBlocks[i] = be.EncryptBlock(v, firstBlockNo+uint64(i), fileID)
+ }
+ // Concatenate ciphertext into a single byte array.
+ // Size the output buffer for the maximum possible size (all blocks complete)
+ // to allocations in out.Write()
+ tmp := make([]byte, len(plaintextBlocks)*int(be.CipherBS()))
+ out := bytes.NewBuffer(tmp[:0])
+ for _, v := range ciphertextBlocks {
+ out.Write(v)
+ }
+ return out.Bytes()
+}
+
// EncryptBlock - Encrypt plaintext using a random nonce.
// blockNo and fileID are used as associated data.
// The output is nonce + ciphertext + tag.