diff options
author | Jakob Unterwurzacher | 2021-05-25 13:24:18 +0200 |
---|---|---|
committer | Jakob Unterwurzacher | 2021-05-26 13:17:56 +0200 |
commit | bebd7ed81f9dd99113672ed9e22456d3fdbc24f6 (patch) | |
tree | d019648a980191c5cd9c42c3f6a62f95a6120483 | |
parent | 2a5ac3e9ba1fb3cdf2220524bc1633755092c794 (diff) |
contentenc: update comments
Also, replace one open-coded calculation with a
helper function.
-rw-r--r-- | internal/contentenc/content.go | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/internal/contentenc/content.go b/internal/contentenc/content.go index efdec9f..747bb4c 100644 --- a/internal/contentenc/content.go +++ b/internal/contentenc/content.go @@ -43,9 +43,11 @@ const ( type ContentEnc struct { // Cryptographic primitives cryptoCore *cryptocore.CryptoCore - // Plaintext block size + // plainBS is the plaintext block size. Usually 4096 bytes. plainBS uint64 - // Ciphertext block size + // cipherBS is the ciphertext block size. Usually 4128 bytes. + // `cipherBS - plainBS`is the per-block overhead + // (use BlockOverhead() to calculate it for you!) cipherBS uint64 // All-zero block of size cipherBS, for fast compares allZeroBlock []byte @@ -302,7 +304,7 @@ func (be *ContentEnc) doEncryptBlock(plaintext []byte, blockNo uint64, fileID [] cBlock = cBlock[0:len(nonce)] // Encrypt plaintext and append to nonce ciphertext := be.cryptoCore.AEADCipher.Seal(cBlock, nonce, plaintext, aData) - overhead := int(be.cipherBS - be.plainBS) + overhead := int(be.BlockOverhead()) if len(plaintext)+overhead != len(ciphertext) { log.Panicf("unexpected ciphertext length: plaintext=%d, overhead=%d, ciphertext=%d", len(plaintext), overhead, len(ciphertext)) |