summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2018-02-26 19:58:12 +0100
committerEike Rathke <erack@redhat.com>2018-02-26 20:06:56 +0100
commit5a1fabb9969772242f2c2aef34b10bed17adebb6 (patch)
treeaddf179371965ac9ac449235f1c7b008779b959b /include
parent7c30bf05ec891b0d8cba117838ff20e9d0b6d63e (diff)
Introduce enum comphelper::Hash::IterCount instead of bool
Clarifies intention, and with IterCount::NONE prepared to handle something like old PBKDF1, if anything actually used that. See https://tools.ietf.org/html/rfc8018#section-5.1 where iteration count is not part of the re-hash. Change-Id: I5f97ca7a91f611eced8ced0a0c64961c04535d36
Diffstat (limited to 'include')
-rw-r--r--include/comphelper/docpasswordhelper.hxx21
-rw-r--r--include/comphelper/hash.hxx30
2 files changed, 34 insertions, 17 deletions
diff --git a/include/comphelper/docpasswordhelper.hxx b/include/comphelper/docpasswordhelper.hxx
index 30243c347884..e37a6c71de22 100644
--- a/include/comphelper/docpasswordhelper.hxx
+++ b/include/comphelper/docpasswordhelper.hxx
@@ -24,6 +24,7 @@
#include <comphelper/comphelperdllapi.h>
#include <vector>
#include <comphelper/docpasswordrequest.hxx>
+#include <comphelper/hash.hxx>
namespace com { namespace sun { namespace star { namespace task { class XInteractionHandler; } } } }
namespace com { namespace sun { namespace star { namespace beans { struct PropertyValue; } } } }
@@ -194,12 +195,14 @@ public:
@param nSpinCount
If >0 the number of repeated iterations.
- @param bPrependNotAppend
- If <FALSE/>, append spin count in iterations as per
+ @param eIterCount
+ If Hash::IterCount::APPEND, append iteration count as per
https://msdn.microsoft.com/en-us/library/dd920692
- If <TRUE/>, prepend spin count in iterations as per
+ If Hash::IterCount::PREPEND, prepend iteration count as per
https://msdn.microsoft.com/en-us/library/dd924776 and
https://msdn.microsoft.com/en-us/library/dd925430
+ If Hash::IterCount::NONE, do not add the iteration count to hash
+ iterations.
@param rAlgorithmName
One of "SHA-512", "SHA-256", ... as listed for AlgorithmName in
@@ -216,7 +219,7 @@ public:
const rtl::OUString& rPassword,
const rtl::OUString& rSaltValue,
sal_uInt32 nSpinCount,
- bool bPrependNotAppend,
+ comphelper::Hash::IterCount eIterCount,
const rtl::OUString& rAlgorithmName);
@@ -234,12 +237,14 @@ public:
@param nSpinCount
If >0 the number of repeated iterations.
- @param bPrependNotAppend
- If <FALSE/>, append spin count in iterations as per
+ @param eIterCount
+ If Hash::IterCount::APPEND, append iteration count as per
https://msdn.microsoft.com/en-us/library/dd920692
- If <TRUE/>, prepend spin count in iterations as per
+ If Hash::IterCount::PREPEND, prepend iteration count as per
https://msdn.microsoft.com/en-us/library/dd924776 and
https://msdn.microsoft.com/en-us/library/dd925430
+ If Hash::IterCount::NONE, do not add the iteration count to hash
+ iterations.
@param rAlgorithmName
One of "SHA-512", "SHA-256", ... as listed for AlgorithmName in
@@ -257,7 +262,7 @@ public:
const rtl::OUString& rPassword,
const rtl::OUString& rSaltValue,
sal_uInt32 nSpinCount,
- bool bPrependNotAppend,
+ comphelper::Hash::IterCount eIterCount,
const rtl::OUString& rAlgorithmName);
diff --git a/include/comphelper/hash.hxx b/include/comphelper/hash.hxx
index 08ae5fd119a8..52ad5e5cdf1e 100644
--- a/include/comphelper/hash.hxx
+++ b/include/comphelper/hash.hxx
@@ -38,6 +38,13 @@ private:
public:
+ enum class IterCount
+ {
+ NONE, /// Iteration count not added to hash iterations.
+ PREPEND, /// Iteration count prepended to hash iterations.
+ APPEND /// Iteration count appended to hash iterations.
+ };
+
Hash(HashType eType);
~Hash();
@@ -50,10 +57,6 @@ public:
/** 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 algorithms as specified in
https://msdn.microsoft.com/en-us/library/dd920692 or
https://msdn.microsoft.com/en-us/library/dd924776 and
@@ -62,12 +65,21 @@ public:
@param pSalt
may be nullptr thus no salt prepended
- @param bPrependNotAppend
- If <FALSE/>, append spin count in iterations as per
+ @param nSpinCount
+ If >0, repeat nSpinCount iterations. For each iteration, the
+ previous iteration's result plus a 4 byte value (0-based,
+ little endian) containing the number of the iteration prepended
+ or appended to the hash value is the input for the next
+ iteration.
+
+ @param eIterCount
+ If IterCount::APPEND, append iteration count as per
https://msdn.microsoft.com/en-us/library/dd920692
- If <TRUE/>, prepend spin count in iterations as per
+ If IterCount::PREPEND, prepend iteration count as per
https://msdn.microsoft.com/en-us/library/dd924776 and
https://msdn.microsoft.com/en-us/library/dd925430
+ If IterCount::NONE, do not add the iteration count to hash
+ iterations.
@return the raw hash value
*/
@@ -75,7 +87,7 @@ public:
const unsigned char* pInput, size_t nLength,
const unsigned char* pSalt, size_t nSaltLen,
sal_uInt32 nSpinCount,
- bool bPrependNotAppend,
+ IterCount eIterCount,
HashType eType);
/** Convenience function to calculate a salted hash with iterations.
@@ -90,7 +102,7 @@ public:
const rtl::OUString& rPassword,
const std::vector<unsigned char>& rSaltValue,
sal_uInt32 nSpinCount,
- bool bPrependNotAppend,
+ IterCount eIterCount,
HashType eType);
size_t getLength() const;