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 /include/comphelper | |
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 'include/comphelper')
-rw-r--r-- | include/comphelper/hash.hxx | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/include/comphelper/hash.hxx b/include/comphelper/hash.hxx index df70757f4042..07998ad02736 100644 --- a/include/comphelper/hash.hxx +++ b/include/comphelper/hash.hxx @@ -15,6 +15,10 @@ #include <memory> #include <vector> +namespace rtl { + class OUString; +} + namespace comphelper { enum class HashType @@ -43,6 +47,65 @@ public: static std::vector<unsigned char> calculateHash(const unsigned char* pInput, size_t length, HashType eType); + /** Calculate hash value with salt (pSalt,nSaltLen) prepended to password + (pInput,nLength) and repeated iterations run if nSpinCount>0. + + For repeated iterations, each iteration's result plus a 4 byte value + (0-based, little endian) containing the number of the iteration + appended to the hash value is the input for the next iteration. + + This implements the algorithm as specified in + https://msdn.microsoft.com/en-us/library/dd920692 + + @param pSalt + may be nullptr thus no salt prepended + + @return the raw hash value + */ + static std::vector<unsigned char> calculateHash( + const unsigned char* pInput, size_t nLength, + const unsigned char* pSalt, size_t nSaltLen, + sal_uInt32 nSpinCount, + HashType eType); + + /** Convenience function to calculate a salted hash with iterations. + + @param rPassword + UTF-16LE encoded string without leading BOM character + + @param rSaltValue + Salt that will be prepended to password data. + */ + static std::vector<unsigned char> calculateHash( + const rtl::OUString& rPassword, + const std::vector<unsigned char>& rSaltValue, + sal_uInt32 nSpinCount, + HashType eType); + + /** Convenience function to calculate a salted hash with iterations. + + @param rPassword + UTF-16LE encoded string without leading BOM character + + @param rSaltValue + Base64 encoded salt that will be decoded and prepended to password + data. + + @param rAlgorithmName + One of "SHA-512", "SHA-256", ... as listed in + https://msdn.microsoft.com/en-us/library/dd920692 + that have a valid match in HashType. If not, an empty string is + returned. Not all algorithm names are supported. + + @return the base64 encoded string of the hash value, that can be + compared against a stored base64 encoded hash value. + */ + static rtl::OUString calculateHash( + const rtl::OUString& rPassword, + const rtl::OUString& rSaltValue, + sal_uInt32 nSpinCount, + const rtl::OUString& rAlgorithmName); + size_t getLength() const; }; |