diff options
author | Eike Rathke <erack@redhat.com> | 2018-02-23 18:23:04 +0100 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2018-02-24 11:28:54 +0100 |
commit | 556c2eaffcdb541317ed148d58c6c973fa6fd0e6 (patch) | |
tree | 8461e4af0e8bf0361d02bc7e8f2cb1af33137def /comphelper/qa | |
parent | 40c33132cfa6582dfccf17e787f10dd4dbd0819d (diff) |
Implement OOXML password hashing algorithm, tdf#104250 prep
As per https://msdn.microsoft.com/en-us/library/dd920692
Change-Id: Iebacaf3549dab28fd3033f9c241130fd66782b25
Reviewed-on: https://gerrit.libreoffice.org/50259
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Eike Rathke <erack@redhat.com>
Diffstat (limited to 'comphelper/qa')
-rw-r--r-- | comphelper/qa/unit/test_hash.cxx | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/comphelper/qa/unit/test_hash.cxx b/comphelper/qa/unit/test_hash.cxx index f83f91d3286a..beec2c537cf4 100644 --- a/comphelper/qa/unit/test_hash.cxx +++ b/comphelper/qa/unit/test_hash.cxx @@ -9,6 +9,7 @@ #include <comphelper/hash.hxx> +#include <rtl/ustring.hxx> #include <sal/log.hxx> #include <iomanip> @@ -22,12 +23,16 @@ public: void testSHA1(); void testSHA256(); void testSHA512(); + void testSHA512_NoSaltNoSpin(); + void testSHA512_saltspin(); CPPUNIT_TEST_SUITE(TestHash); CPPUNIT_TEST(testMD5); CPPUNIT_TEST(testSHA1); CPPUNIT_TEST(testSHA256); CPPUNIT_TEST(testSHA512); + CPPUNIT_TEST(testSHA512_NoSaltNoSpin); + CPPUNIT_TEST(testSHA512_saltspin); CPPUNIT_TEST_SUITE_END(); }; @@ -87,6 +92,30 @@ void TestHash::testSHA512() CPPUNIT_ASSERT_EQUAL(aStr, tostring(calculate_hash)); } +// Must be identical to testSHA512() +void TestHash::testSHA512_NoSaltNoSpin() +{ + const char* const pInput = ""; + std::vector<unsigned char> calculate_hash = + comphelper::Hash::calculateHash( reinterpret_cast<const unsigned char*>(pInput), 0, + nullptr, 0, 0, comphelper::HashType::SHA512); + CPPUNIT_ASSERT_EQUAL(size_t(64), calculate_hash.size()); + std::string aStr("cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e"); + CPPUNIT_ASSERT_EQUAL(aStr, tostring(calculate_hash)); +} + +// Password, salt, hash and spin count taken from OOXML sheetProtection of +// tdf#104250 https://bugs.documentfoundation.org/attachment.cgi?id=129104 +void TestHash::testSHA512_saltspin() +{ + const OUString aPass("pwd"); + const OUString aAlgo("SHA-512"); + const OUString aSalt("876MLoKTq42+/DLp415iZQ=="); + const OUString aHash = comphelper::Hash::calculateHash( aPass, aSalt, 100000, aAlgo); + OUString aStr("5l3mgNHXpWiFaBPv5Yso1Xd/UifWvQWmlDnl/hsCYbFT2sJCzorjRmBCQ/3qeDu6Q/4+GIE8a1DsdaTwYh1q2g=="); + CPPUNIT_ASSERT_EQUAL(aStr, aHash); +} + CPPUNIT_TEST_SUITE_REGISTRATION(TestHash); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |