summaryrefslogtreecommitdiff
path: root/vcl/source
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2024-11-21 13:13:14 +0900
committerTomaž Vajngerl <quikee@gmail.com>2024-12-23 15:22:39 +0100
commitb8ea5a835ec07d0f84cd8ec2d0dab976edcfcebe (patch)
tree813d0ba80ea3dbd6df73d74756856804e923cc5f /vcl/source
parent807f977b389f196d17701f01ddbb40b297face95 (diff)
pdf: change encryption to use new random IV on each encrypt call
This is how it's supposed to work - not to have same IV all the time we are encoding (that's why the IV is written to the stream). Change-Id: I17a1d98bd5cf6f06b830eaea04822b8793d4e0d7 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/176984 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/178761 Reviewed-by: Tomaž Vajngerl <quikee@gmail.com> Tested-by: Jenkins
Diffstat (limited to 'vcl/source')
-rw-r--r--vcl/source/pdf/PDFEncryptorR6.cxx33
1 files changed, 15 insertions, 18 deletions
diff --git a/vcl/source/pdf/PDFEncryptorR6.cxx b/vcl/source/pdf/PDFEncryptorR6.cxx
index c16d7cb1a276..d951b738246f 100644
--- a/vcl/source/pdf/PDFEncryptorR6.cxx
+++ b/vcl/source/pdf/PDFEncryptorR6.cxx
@@ -256,28 +256,25 @@ class VCL_DLLPUBLIC EncryptionContext
{
private:
std::vector<sal_uInt8> maKey;
- std::vector<sal_uInt8> maInitVector;
public:
- EncryptionContext(std::vector<sal_uInt8> const& rKey, std::vector<sal_uInt8> const& rIV)
+ EncryptionContext(std::vector<sal_uInt8> const& rKey)
: maKey(rKey)
- , maInitVector(rIV)
{
}
- /** Algorithm 1.A: Encryption of data using the AES algorithms
- *
- **/
- void encrypt(const void* pInput, sal_uInt64 nInputSize, std::vector<sal_uInt8>& rOutput)
+ /** Algorithm 1.A: Encryption of data using the AES algorithms */
+ void encrypt(const void* pInput, sal_uInt64 nInputSize, std::vector<sal_uInt8>& rOutput,
+ std::vector<sal_uInt8>& rIV)
{
- comphelper::Encrypt aEncrypt(maKey, maInitVector, comphelper::CryptoType::AES_256_CBC);
+ comphelper::Encrypt aEncrypt(maKey, rIV, comphelper::CryptoType::AES_256_CBC);
const sal_uInt8* pInputBytes = static_cast<const sal_uInt8*>(pInput);
std::vector<sal_uInt8> aInput(pInputBytes, pInputBytes + nInputSize);
size_t nPaddedSize = addPaddingToVector(aInput, BLOCK_SIZE);
std::vector<sal_uInt8> aOutput(nPaddedSize);
aEncrypt.update(aOutput, aInput);
rOutput.resize(nPaddedSize + IV_SIZE);
- std::copy(maInitVector.begin(), maInitVector.end(), rOutput.begin());
+ std::copy(rIV.begin(), rIV.end(), rOutput.begin());
std::copy(aOutput.begin(), aOutput.end(), rOutput.begin() + IV_SIZE);
}
};
@@ -357,21 +354,21 @@ sal_uInt64 PDFEncryptorR6::calculateSizeIncludingHeader(sal_uInt64 nSize)
void PDFEncryptorR6::setupEncryption(std::vector<sal_uInt8>& rEncryptionKey, sal_Int32 /*nObject*/)
{
- std::vector<sal_uInt8> aInitVector;
- generateBytes(aInitVector, IV_SIZE);
- m_pEncryptionContext = std::make_unique<EncryptionContext>(rEncryptionKey, aInitVector);
+ m_pEncryptionContext = std::make_unique<EncryptionContext>(rEncryptionKey);
}
-void PDFEncryptorR6::setupEncryptionWithIV(std::vector<sal_uInt8>& rEncryptionKey,
- std::vector<sal_uInt8>& rInitvector)
+void PDFEncryptorR6::encrypt(const void* pInput, sal_uInt64 nInputSize,
+ std::vector<sal_uInt8>& rOutput, sal_uInt64 /*nOutputSize*/)
{
- m_pEncryptionContext = std::make_unique<EncryptionContext>(rEncryptionKey, rInitvector);
+ std::vector<sal_uInt8> aIV;
+ generateBytes(aIV, IV_SIZE);
+ m_pEncryptionContext->encrypt(pInput, nInputSize, rOutput, aIV);
}
-void PDFEncryptorR6::encrypt(const void* pInput, sal_uInt64 nInputSize,
- std::vector<sal_uInt8>& rOutput, sal_uInt64 /*nOutputSize*/)
+void PDFEncryptorR6::encryptWithIV(const void* pInput, sal_uInt64 nInputSize,
+ std::vector<sal_uInt8>& rOutput, std::vector<sal_uInt8>& rIV)
{
- m_pEncryptionContext->encrypt(pInput, nInputSize, rOutput);
+ m_pEncryptionContext->encrypt(pInput, nInputSize, rOutput, rIV);
}
} // end vcl::pdf