30 #include <com/sun/star/xml/sax/XFastParser.hpp>
31 #include <com/sun/star/xml/sax/XFastTokenHandler.hpp>
32 #include <com/sun/star/xml/sax/FastParser.hpp>
33 #include <com/sun/star/xml/sax/FastToken.hpp>
47 std::u16string_view stripNamespacePrefix(std::u16string_view rsInputName)
49 size_t idx = rsInputName.find(
':');
50 if (idx == std::u16string_view::npos)
52 return rsInputName.substr(idx + 1);
60 return FastToken::DONTKNOW;
63 virtual Sequence<sal_Int8> SAL_CALL getUTF8Identifier(sal_Int32 )
override
65 return Sequence<sal_Int8>();
68 virtual sal_Int32 getTokenDirect(
const char * , sal_Int32 )
const override
74 class AgileDocumentHandler :
public ::cppu::WeakImplHelper<XFastDocumentHandler>
79 explicit AgileDocumentHandler(AgileEncryptionInfo& rInfo) :
83 void SAL_CALL startDocument()
override {}
84 void SAL_CALL endDocument()
override {}
85 void SAL_CALL processingInstruction(
const OUString& ,
const OUString& )
override {}
86 void SAL_CALL setDocumentLocator(
const Reference< XLocator >& )
override {}
87 void SAL_CALL startFastElement( sal_Int32 ,
const Reference< XFastAttributeList >& )
override {}
89 void SAL_CALL startUnknownElement(
const OUString& ,
const OUString& rName,
const Reference< XFastAttributeList >& aAttributeList )
override
91 std::u16string_view rLocalName = stripNamespacePrefix(rName);
93 const css::uno::Sequence<Attribute> aUnknownAttributes = aAttributeList->getUnknownAttributes();
94 for (
const Attribute& rAttribute : aUnknownAttributes)
96 std::u16string_view rAttrLocalName = stripNamespacePrefix(rAttribute.Name);
98 if (rAttrLocalName == u
"spinCount")
102 else if (rAttrLocalName == u
"saltSize")
106 else if (rAttrLocalName == u
"blockSize")
110 else if (rAttrLocalName == u
"keyBits")
114 else if (rAttrLocalName == u
"hashSize")
118 else if (rAttrLocalName == u
"cipherAlgorithm")
120 mInfo.cipherAlgorithm = rAttribute.Value;
122 else if (rAttrLocalName == u
"cipherChaining")
124 mInfo.cipherChaining = rAttribute.Value;
126 else if (rAttrLocalName == u
"hashAlgorithm")
128 mInfo.hashAlgorithm = rAttribute.Value;
130 else if (rAttrLocalName == u
"saltValue")
132 Sequence<sal_Int8> saltValue;
134 if (rLocalName == u
"encryptedKey")
135 mInfo.saltValue = comphelper::sequenceToContainer<std::vector<sal_uInt8>>(saltValue);
136 else if (rLocalName == u
"keyData")
137 mInfo.keyDataSalt = comphelper::sequenceToContainer<std::vector<sal_uInt8>>(saltValue);
139 else if (rAttrLocalName == u
"encryptedVerifierHashInput")
141 Sequence<sal_Int8> encryptedVerifierHashInput;
143 mInfo.encryptedVerifierHashInput = comphelper::sequenceToContainer<std::vector<sal_uInt8>>(encryptedVerifierHashInput);
145 else if (rAttrLocalName == u
"encryptedVerifierHashValue")
147 Sequence<sal_Int8> encryptedVerifierHashValue;
149 mInfo.encryptedVerifierHashValue = comphelper::sequenceToContainer<std::vector<sal_uInt8>>(encryptedVerifierHashValue);
151 else if (rAttrLocalName == u
"encryptedKeyValue")
153 Sequence<sal_Int8> encryptedKeyValue;
155 mInfo.encryptedKeyValue = comphelper::sequenceToContainer<std::vector<sal_uInt8>>(encryptedKeyValue);
157 if (rAttrLocalName == u
"encryptedHmacKey")
159 Sequence<sal_Int8> aValue;
161 mInfo.hmacEncryptedKey = comphelper::sequenceToContainer<std::vector<sal_uInt8>>(aValue);
163 if (rAttrLocalName == u
"encryptedHmacValue")
165 Sequence<sal_Int8> aValue;
167 mInfo.hmacEncryptedValue = comphelper::sequenceToContainer<std::vector<sal_uInt8>>(aValue);
172 void SAL_CALL endFastElement( sal_Int32 )
override
174 void SAL_CALL endUnknownElement(
const OUString& ,
const OUString& )
override
177 Reference< XFastContextHandler > SAL_CALL createFastChildContext( sal_Int32 ,
const Reference< XFastAttributeList >& )
override
182 Reference< XFastContextHandler > SAL_CALL createUnknownChildContext(
const OUString& ,
const OUString& ,
const Reference< XFastAttributeList >& )
override
187 void SAL_CALL characters(
const OUString& )
override
191 constexpr
const sal_uInt32 constSegmentLength = 4096;
193 const std::vector<sal_uInt8> constBlock1 { 0xfe, 0xa7, 0xd2, 0x76, 0x3b, 0x4b, 0x9e, 0x79 };
194 const std::vector<sal_uInt8> constBlock2 { 0xd7, 0xaa, 0x0f, 0x6d, 0x30, 0x61, 0x34, 0x4e };
195 const std::vector<sal_uInt8> constBlock3 { 0x14, 0x6e, 0x0b, 0xe7, 0xab, 0xac, 0xd0, 0xd6 };
196 const std::vector<sal_uInt8> constBlockHmac1 { 0x5f, 0xb2, 0xad, 0x01, 0x0c, 0xb9, 0xe1, 0xf6 };
197 const std::vector<sal_uInt8> constBlockHmac2 { 0xa0, 0x67, 0x7f, 0x02, 0xb2, 0x2c, 0x84, 0x33 };
199 bool hashCalc(std::vector<sal_uInt8>& output,
200 std::vector<sal_uInt8>& input,
201 std::u16string_view sAlgorithm )
203 if (sAlgorithm == u
"SHA1")
209 else if (sAlgorithm == u
"SHA512")
218 CryptoHashType cryptoHashTypeFromString(std::u16string_view sAlgorithm)
220 if (sAlgorithm == u
"SHA512")
221 return CryptoHashType::SHA512;
222 return CryptoHashType::SHA1;
227 AgileEngine::AgileEngine()
241 std::vector<sal_uInt8>
const & rSalt,
242 std::vector<sal_uInt8>
const & rBlock,
243 sal_Int32 nCipherBlockSize)
246 aHasher.
update(rSalt.data(), rSalt.size());
247 aHasher.
update(rBlock.data(), rBlock.size());
248 std::vector<sal_uInt8> aIV = aHasher.
finalize();
249 aIV.resize(
roundUp(sal_Int32(aIV.size()), nCipherBlockSize), 0x36);
254 std::vector<sal_uInt8>
const & rBlock,
255 std::vector<sal_uInt8>& rHashFinal,
256 std::vector<sal_uInt8>& rInput,
257 std::vector<sal_uInt8>& rOutput)
259 std::vector<sal_uInt8> hash(mInfo.hashSize, 0);
260 std::vector<sal_uInt8> dataFinal(mInfo.hashSize + rBlock.size(), 0);
261 std::copy(rHashFinal.begin(), rHashFinal.end(), dataFinal.begin());
262 std::copy(rBlock.begin(), rBlock.end(), dataFinal.begin() + mInfo.hashSize);
264 hashCalc(hash, dataFinal, mInfo.hashAlgorithm);
266 sal_Int32 keySize = mInfo.keyBits / 8;
267 std::vector<sal_uInt8> key(keySize, 0);
269 std::copy(hash.begin(), hash.begin() + keySize, key.begin());
272 aDecryptor.update(rOutput, rInput);
276 std::vector<sal_uInt8>
const & rBlock,
277 std::vector<sal_uInt8> & rHashFinal,
278 std::vector<sal_uInt8> & rInput,
279 std::vector<sal_uInt8> & rOutput)
281 std::vector<sal_uInt8> hash(mInfo.hashSize, 0);
282 std::vector<sal_uInt8> dataFinal(mInfo.hashSize + rBlock.size(), 0);
283 std::copy(rHashFinal.begin(), rHashFinal.end(), dataFinal.begin());
284 std::copy(rBlock.begin(), rBlock.end(), dataFinal.begin() + mInfo.hashSize);
286 hashCalc(hash, dataFinal, mInfo.hashAlgorithm);
288 sal_Int32 keySize = mInfo.keyBits / 8;
289 std::vector<sal_uInt8> key(keySize, 0);
291 std::copy(hash.begin(), hash.begin() + keySize, key.begin());
295 aEncryptor.update(rOutput, rInput);
301 rPassword, mInfo.saltValue, mInfo.spinCount,
308 bool generateBytes(std::vector<sal_uInt8> & rBytes, sal_Int32 nSize)
310 size_t nMax = std::min(rBytes.size(), size_t(nSize));
312 for (
size_t i = 0;
i < nMax; ++
i)
324 std::vector<sal_uInt8>& encryptedHashValue = mInfo.encryptedVerifierHashValue;
325 size_t encryptedHashValueSize = encryptedHashValue.size();
326 size_t nHashValueSize = mInfo.hashSize;
327 if (nHashValueSize > encryptedHashValueSize)
330 std::vector<sal_uInt8> hashFinal(nHashValueSize, 0);
333 std::vector<sal_uInt8>& encryptedHashInput = mInfo.encryptedVerifierHashInput;
335 sal_Int32 nSaltSize =
roundUp(mInfo.saltSize, mInfo.blockSize);
336 std::vector<sal_uInt8> hashInput(nSaltSize, 0);
337 calculateBlock(constBlock1, hashFinal, encryptedHashInput, hashInput);
339 std::vector<sal_uInt8> hashValue(encryptedHashValueSize, 0);
340 calculateBlock(constBlock2, hashFinal, encryptedHashValue, hashValue);
342 std::vector<sal_uInt8> hash(nHashValueSize, 0);
343 hashCalc(hash, hashInput, mInfo.hashAlgorithm);
345 return std::equal(hash.begin(), hash.end(), hashValue.begin());
350 sal_Int32 nKeySize = mInfo.keyBits / 8;
353 mKey.resize(nKeySize, 0);
355 std::vector<sal_uInt8> aPasswordHash(mInfo.hashSize, 0);
378 mInfo.hmacKey.clear();
379 mInfo.hmacKey.resize(mInfo.hmacEncryptedKey.size(), 0);
383 if (mInfo.hashAlgorithm ==
"SHA1")
385 else if (mInfo.hashAlgorithm ==
"SHA512")
390 std::vector<sal_uInt8> iv =
calculateIV(eType, mInfo.keyDataSalt, constBlockHmac1, mInfo.blockSize);
394 aDecrypt.
update(mInfo.hmacKey, mInfo.hmacEncryptedKey);
396 mInfo.hmacKey.resize(mInfo.hashSize, 0);
404 mInfo.hmacHash.clear();
405 mInfo.hmacHash.resize(mInfo.hmacEncryptedValue.size(), 0);
409 if (mInfo.hashAlgorithm ==
"SHA1")
411 else if (mInfo.hashAlgorithm ==
"SHA512")
415 std::vector<sal_uInt8> iv =
calculateIV(eType, mInfo.keyDataSalt, constBlockHmac2, mInfo.blockSize);
419 aDecrypt.
update(mInfo.hmacHash, mInfo.hmacEncryptedValue);
421 mInfo.hmacHash.resize(mInfo.hashSize, 0);
428 bool bResult = (mInfo.hmacHash.size() == mInfo.hmacCalculatedHash.size() &&
429 std::equal(mInfo.hmacHash.begin(), mInfo.hmacHash.end(), mInfo.hmacCalculatedHash.begin()));
437 CryptoHash aCryptoHash(mInfo.hmacKey, cryptoHashTypeFromString(mInfo.hashAlgorithm));
439 sal_uInt32 totalSize = aInputStream.
readuInt32();
441 std::vector<sal_uInt8> aSizeBytes(
sizeof(sal_uInt32));
443 aCryptoHash.
update(aSizeBytes);
445 aInputStream.
skip(4);
447 std::vector<sal_uInt8> aReserved{0,0,0,0};
448 aCryptoHash.
update(aReserved);
451 std::vector<sal_uInt8>& keyDataSalt = mInfo.keyDataSalt;
453 sal_uInt32 saltSize = mInfo.saltSize;
454 sal_uInt32 keySize = mInfo.keyBits / 8;
456 sal_uInt32 segment = 0;
458 std::vector<sal_uInt8> saltWithBlockKey(saltSize +
sizeof(segment), 0);
459 std::copy(keyDataSalt.begin(), keyDataSalt.end(), saltWithBlockKey.begin());
461 std::vector<sal_uInt8> hash(mInfo.hashSize, 0);
462 std::vector<sal_uInt8> iv(keySize, 0);
464 std::vector<sal_uInt8> inputBuffer(constSegmentLength);
465 std::vector<sal_uInt8> outputBuffer(constSegmentLength);
466 sal_uInt32 inputLength;
467 sal_uInt32 outputLength;
468 sal_uInt32 remaining = totalSize;
470 while ((inputLength = aInputStream.
readMemory(inputBuffer.data(), inputBuffer.size())) > 0)
472 auto p = saltWithBlockKey.begin() + saltSize;
473 p[0] = segment & 0xFF;
474 p[1] = (segment >> 8) & 0xFF;
475 p[2] = (segment >> 16) & 0xFF;
476 p[3] = segment >> 24;
478 hashCalc(hash, saltWithBlockKey, mInfo.hashAlgorithm);
481 std::copy(hash.begin(), hash.begin() + keySize, iv.begin());
484 outputLength = aDecryptor.update(outputBuffer, inputBuffer, inputLength);
486 sal_uInt32 writeLength = std::min(outputLength, remaining);
488 aCryptoHash.
update(inputBuffer, inputLength);
490 aOutputStream.
writeMemory(outputBuffer.data(), writeLength);
492 remaining -= outputLength;
496 mInfo.hmacCalculatedHash = aCryptoHash.
finalize();
504 std::vector<sal_uInt8> aExpectedReservedBytes(
sizeof(sal_uInt32));
507 uno::Sequence<sal_Int8> aReadReservedBytes(
sizeof(sal_uInt32));
508 rxInputStream->readBytes(aReadReservedBytes, aReadReservedBytes.getLength());
510 if (!std::equal(std::cbegin(aReadReservedBytes), std::cend(aReadReservedBytes), aExpectedReservedBytes.begin()))
519 Reference<XFastDocumentHandler> xFastDocumentHandler(
new AgileDocumentHandler(mInfo));
520 Reference<XFastTokenHandler> xFastTokenHandler(
new AgileTokenHandler);
524 xParser->setFastDocumentHandler(xFastDocumentHandler);
525 xParser->setTokenHandler(xFastTokenHandler);
527 InputSource aInputSource;
528 aInputSource.aInputStream = rxInputStream;
529 xParser->parseStream(aInputSource);
532 if (2 > mInfo.blockSize || mInfo.blockSize > 4096)
535 if (0 > mInfo.spinCount || mInfo.spinCount > 10000000)
538 if (1 > mInfo.saltSize|| mInfo.saltSize > 65536)
542 if (mInfo.keyBits == 128 &&
543 mInfo.cipherAlgorithm ==
"AES" &&
544 mInfo.cipherChaining ==
"ChainingModeCBC" &&
545 mInfo.hashAlgorithm ==
"SHA1" &&
552 if (mInfo.keyBits == 256 &&
553 mInfo.cipherAlgorithm ==
"AES" &&
554 mInfo.cipherChaining ==
"ChainingModeCBC" &&
555 mInfo.hashAlgorithm ==
"SHA512" &&
566 if (!generateBytes(mInfo.saltValue, mInfo.saltSize))
569 std::vector<sal_uInt8> unencryptedVerifierHashInput(mInfo.saltSize);
570 if (!generateBytes(unencryptedVerifierHashInput, mInfo.saltSize))
574 sal_Int32 nVerifierHash =
roundUp(mInfo.hashSize, mInfo.blockSize);
575 std::vector<sal_uInt8> unencryptedVerifierHashValue;
576 if (!hashCalc(unencryptedVerifierHashValue, unencryptedVerifierHashInput, mInfo.hashAlgorithm))
578 unencryptedVerifierHashValue.resize(nVerifierHash, 0);
580 std::vector<sal_uInt8> hashFinal(mInfo.hashSize, 0);
583 encryptBlock(constBlock1, hashFinal, unencryptedVerifierHashInput, mInfo.encryptedVerifierHashInput);
585 encryptBlock(constBlock2, hashFinal, unencryptedVerifierHashValue, mInfo.encryptedVerifierHashValue);
593 mInfo.hmacKey.clear();
594 mInfo.hmacKey.resize(mInfo.hashSize, 0);
596 if (!generateBytes(mInfo.hmacKey, mInfo.hashSize))
603 std::vector<sal_uInt8> extendedSalt(mInfo.hmacKey);
604 extendedSalt.resize(nEncryptedSaltSize, 0x36);
607 mInfo.hmacEncryptedKey.clear();
608 mInfo.hmacEncryptedKey.resize(nEncryptedSaltSize, 0);
612 if (mInfo.hashAlgorithm ==
"SHA1")
614 else if (mInfo.hashAlgorithm ==
"SHA512")
619 std::vector<sal_uInt8> iv =
calculateIV(eType, mInfo.keyDataSalt, constBlockHmac1, mInfo.blockSize);
623 aEncryptor.
update(mInfo.hmacEncryptedKey, extendedSalt);
630 sal_Int32 nEncryptedValueSize =
roundUp(mInfo.hashSize, mInfo.blockSize);
631 mInfo.hmacEncryptedValue.clear();
632 mInfo.hmacEncryptedValue.resize(nEncryptedValueSize, 0);
634 std::vector<sal_uInt8> extendedHash(mInfo.hmacHash);
635 extendedHash.resize(nEncryptedValueSize, 0x36);
639 if (mInfo.hashAlgorithm ==
"SHA1")
641 else if (mInfo.hashAlgorithm ==
"SHA512")
646 std::vector<sal_uInt8> iv =
calculateIV(eType, mInfo.keyDataSalt, constBlockHmac2, mInfo.blockSize);
650 aEncryptor.
update(mInfo.hmacEncryptedValue, extendedHash);
657 sal_Int32 nKeySize = mInfo.keyBits / 8;
660 mKey.resize(nKeySize, 0);
662 mInfo.encryptedKeyValue.clear();
663 mInfo.encryptedKeyValue.resize(nKeySize, 0);
665 if (!generateBytes(
mKey, nKeySize))
668 std::vector<sal_uInt8> aPasswordHash(mInfo.hashSize, 0);
681 setupEncryptionParameters({ 100000, 16, 256, 64, 16, OUString(
"AES"), OUString(
"ChainingModeCBC"), OUString(
"SHA512") });
688 mInfo.spinCount = rAgileEncryptionParameters.
spinCount;
689 mInfo.saltSize = rAgileEncryptionParameters.
saltSize;
690 mInfo.keyBits = rAgileEncryptionParameters.
keyBits;
691 mInfo.hashSize = rAgileEncryptionParameters.
hashSize;
692 mInfo.blockSize = rAgileEncryptionParameters.
blockSize;
696 mInfo.hashAlgorithm = rAgileEncryptionParameters.
hashAlgorithm;
698 mInfo.keyDataSalt.resize(mInfo.saltSize);
699 mInfo.saltValue.resize(mInfo.saltSize);
700 mInfo.encryptedVerifierHashInput.resize(mInfo.saltSize);
701 mInfo.encryptedVerifierHashValue.resize(
roundUp(mInfo.hashSize, mInfo.blockSize), 0);
710 if (!generateBytes(mInfo.keyDataSalt, mInfo.saltSize))
727 aXmlWriter.
startElement(
"",
"encryption",
"http://schemas.microsoft.com/office/2006/encryption");
728 aXmlWriter.
attribute(
"xmlns:p", OString(
"http://schemas.microsoft.com/office/2006/keyEncryptor/password"));
731 aXmlWriter.
attribute(
"saltSize", mInfo.saltSize);
732 aXmlWriter.
attribute(
"blockSize", mInfo.blockSize);
733 aXmlWriter.
attribute(
"keyBits", mInfo.keyBits);
734 aXmlWriter.
attribute(
"hashSize", mInfo.hashSize);
735 aXmlWriter.
attribute(
"cipherAlgorithm", mInfo.cipherAlgorithm);
736 aXmlWriter.
attribute(
"cipherChaining", mInfo.cipherChaining);
737 aXmlWriter.
attribute(
"hashAlgorithm", mInfo.hashAlgorithm);
742 aXmlWriter.
attributeBase64(
"encryptedHmacKey", mInfo.hmacEncryptedKey);
743 aXmlWriter.
attributeBase64(
"encryptedHmacValue", mInfo.hmacEncryptedValue);
748 aXmlWriter.
attribute(
"uri", OString(
"http://schemas.microsoft.com/office/2006/keyEncryptor/password"));
751 aXmlWriter.
attribute(
"spinCount", mInfo.spinCount);
752 aXmlWriter.
attribute(
"saltSize", mInfo.saltSize);
753 aXmlWriter.
attribute(
"blockSize", mInfo.blockSize);
754 aXmlWriter.
attribute(
"keyBits", mInfo.keyBits);
755 aXmlWriter.
attribute(
"hashSize", mInfo.hashSize);
756 aXmlWriter.
attribute(
"cipherAlgorithm", mInfo.cipherAlgorithm);
757 aXmlWriter.
attribute(
"cipherChaining", mInfo.cipherChaining);
758 aXmlWriter.
attribute(
"hashAlgorithm", mInfo.hashAlgorithm);
760 aXmlWriter.
attributeBase64(
"encryptedVerifierHashInput", mInfo.encryptedVerifierHashInput);
761 aXmlWriter.
attributeBase64(
"encryptedVerifierHashValue", mInfo.encryptedVerifierHashValue);
762 aXmlWriter.
attributeBase64(
"encryptedKeyValue", mInfo.encryptedKeyValue);
775 css::uno::Reference<css::io::XOutputStream> & rxOutputStream,
778 CryptoHash aCryptoHash(mInfo.hmacKey, cryptoHashTypeFromString(mInfo.hashAlgorithm));
783 std::vector<sal_uInt8> aSizeBytes(
sizeof(sal_uInt32));
785 aBinaryOutputStream.
writeMemory(aSizeBytes.data(), aSizeBytes.size());
786 aCryptoHash.
update(aSizeBytes, aSizeBytes.size());
788 std::vector<sal_uInt8> aNull{0,0,0,0};
789 aBinaryOutputStream.
writeMemory(aNull.data(), aNull.size());
790 aCryptoHash.
update(aNull, aNull.size());
792 std::vector<sal_uInt8>& keyDataSalt = mInfo.keyDataSalt;
794 sal_uInt32 saltSize = mInfo.saltSize;
795 sal_uInt32 keySize = mInfo.keyBits / 8;
797 sal_uInt32 nSegment = 0;
798 sal_uInt32 nSegmentByteSize =
sizeof(nSegment);
800 std::vector<sal_uInt8> saltWithBlockKey(saltSize + nSegmentByteSize, 0);
801 std::copy(keyDataSalt.begin(), keyDataSalt.end(), saltWithBlockKey.begin());
803 std::vector<sal_uInt8> hash(mInfo.hashSize, 0);
804 std::vector<sal_uInt8> iv(keySize, 0);
806 std::vector<sal_uInt8> inputBuffer(constSegmentLength);
807 std::vector<sal_uInt8> outputBuffer(constSegmentLength);
808 sal_uInt32 inputLength;
809 sal_uInt32 outputLength;
811 while ((inputLength = aBinaryInputStream.
readMemory(inputBuffer.data(), inputBuffer.size())) > 0)
813 sal_uInt32 correctedInputLength = inputLength % mInfo.blockSize == 0 ?
817 auto p = saltWithBlockKey.begin() + saltSize;
818 p[0] = nSegment & 0xFF;
819 p[1] = (nSegment >> 8) & 0xFF;
820 p[2] = (nSegment >> 16) & 0xFF;
821 p[3] = nSegment >> 24;
823 hashCalc(hash, saltWithBlockKey, mInfo.hashAlgorithm);
826 std::copy(hash.begin(), hash.begin() + keySize, iv.begin());
829 outputLength = aEncryptor.update(outputBuffer, inputBuffer, correctedInputLength);
830 aBinaryOutputStream.
writeMemory(outputBuffer.data(), outputLength);
831 aCryptoHash.
update(outputBuffer, outputLength);
835 mInfo.hmacHash = aCryptoHash.
finalize();
void writeEncryptionInfo(BinaryXOutputStream &rStream) override
static std::vector< unsigned char > GetOoxHashAsVector(const OUString &rPassword, const std::vector< unsigned char > &rSaltValue, sal_uInt32 nSpinCount, comphelper::Hash::IterCount eIterCount, std::u16string_view rAlgorithmName)
sal_uInt32 update(std::vector< sal_uInt8 > &output, std::vector< sal_uInt8 > &input, sal_uInt32 inputLength=0)
virtual void writeMemory(const void *pMem, sal_Int32 nBytes, size_t nAtomSize=1) override
Write nBytes bytes from the (preallocated!) buffer pMem.
static void decode(css::uno::Sequence< sal_Int8 > &aPass, std::u16string_view sBuffer)
static std::vector< sal_uInt8 > calculateIV(comphelper::HashType eType, std::vector< sal_uInt8 > const &rSalt, std::vector< sal_uInt8 > const &rBlock, sal_Int32 nCipherBlockSize)
sal_uInt32 update(std::vector< sal_uInt8 > &output, std::vector< sal_uInt8 > &input, sal_uInt32 inputLength=0)
unsigned int uniform_uint_distribution(unsigned int a, unsigned int b)
const sal_uInt32 AGILE_ENCRYPTION_RESERVED
Wraps a UNO output stream and provides convenient access functions.
bool update(std::vector< sal_uInt8 > &rInput, sal_uInt32 nInputLength=0)
BinaryOutputStream & WriteUInt32(sal_uInt32 x)
const sal_uInt32 VERSION_INFO_AGILE
bool generateEncryptionKey(OUString const &rPassword) override
const sal_uInt32 SHA512_HASH_LENGTH
bool readEncryptionInfo(css::uno::Reference< css::io::XInputStream > &rxInputStream) override
T roundUp(T input, T multiple)
Rounds up the input to the nearest multiple.
bool encryptEncryptionKey(OUString const &rPassword)
bool decryptAndCheckVerifierHash(OUString const &rPassword)
void calculateHashFinal(const OUString &rPassword, std::vector< sal_uInt8 > &aHashFinal)
AgileEncryptionInfo & mInfo
bool checkDataIntegrity() override
static Crypto::CryptoType cryptoType(const AgileEncryptionInfo &rInfo)
void encryptBlock(std::vector< sal_uInt8 > const &rBlock, std::vector< sal_uInt8 > &rHashFinal, std::vector< sal_uInt8 > &rInput, std::vector< sal_uInt8 > &rOutput)
const sal_uInt32 SHA1_HASH_LENGTH
static void writeLittleEndian(void *pDstBuffer, Type nValue)
Writes a value to memory, while converting it to little-endian.
bool generateAndEncryptVerifierHash(OUString const &rPassword)
void update(const unsigned char *pInput, size_t length)
bool decrypt(BinaryXInputStream &aInputStream, BinaryXOutputStream &aOutputStream) override
void decryptEncryptionKey(OUString const &rPassword)
Reference< XComponentContext > getProcessComponentContext()
bool setupEncryption(OUString const &rPassword) override
AgileEncryptionPreset meEncryptionPreset
static std::vector< unsigned char > calculateHash(const unsigned char *pInput, size_t length, HashType eType)
std::vector< sal_uInt8 > finalize()
bool setupEncryptionKey(OUString const &rPassword)
std::vector< sal_uInt8 > mKey
void encrypt(const css::uno::Reference< css::io::XInputStream > &rxInputStream, css::uno::Reference< css::io::XOutputStream > &rxOutputStream, sal_uInt32 nSize) override
std::vector< unsigned char > finalize()
void setupEncryptionParameters(AgileEncryptionParameters const &rAgileEncryptionParameters)
void calculateBlock(std::vector< sal_uInt8 > const &rBlock, std::vector< sal_uInt8 > &rHashFinal, std::vector< sal_uInt8 > &rInput, std::vector< sal_uInt8 > &rOutput)
static bool convertNumber(sal_Int32 &rValue, std::u16string_view aString, sal_Int32 nMin=SAL_MIN_INT32, sal_Int32 nMax=SAL_MAX_INT32)