LibreOffice Module comphelper (master)  1
Public Types | Public Member Functions | Static Public Member Functions | Private Attributes | List of all members
comphelper::Hash Class Reference

#include <hash.hxx>

Public Types

enum  IterCount {
  IterCount::NONE,
  IterCount::PREPEND,
  IterCount::APPEND
}
 

Public Member Functions

 Hash (HashType eType)
 
 ~Hash ()
 
void update (const unsigned char *pInput, size_t length)
 
std::vector< unsigned char > finalize ()
 
size_t getLength () const
 

Static Public Member Functions

static std::vector< unsigned char > calculateHash (const unsigned char *pInput, size_t length, HashType eType)
 
static std::vector< unsigned char > calculateHash (const unsigned char *pInput, size_t nLength, const unsigned char *pSalt, size_t nSaltLen, sal_uInt32 nSpinCount, IterCount eIterCount, HashType eType)
 Calculate hash value with salt (pSalt,nSaltLen) prepended to password (pInput,nLength) and repeated iterations run if nSpinCount>0. More...
 
static std::vector< unsigned char > calculateHash (const rtl::OUString &rPassword, const std::vector< unsigned char > &rSaltValue, sal_uInt32 nSpinCount, IterCount eIterCount, HashType eType)
 Convenience function to calculate a salted hash with iterations. More...
 

Private Attributes

std::unique_ptr< HashImplmpImpl
 

Detailed Description

Definition at line 34 of file hash.hxx.

Member Enumeration Documentation

Enumerator
NONE 
PREPEND 

Iteration count not added to hash iterations.

APPEND 

Iteration count prepended to hash iterations.

Iteration count appended to hash iterations.

Definition at line 41 of file hash.hxx.

Constructor & Destructor Documentation

Hash::Hash ( HashType  eType)

Definition at line 95 of file hash.cxx.

Hash::~Hash ( )

Definition at line 100 of file hash.cxx.

Member Function Documentation

std::vector< unsigned char > Hash::calculateHash ( const unsigned char *  pInput,
size_t  length,
HashType  eType 
)
static
std::vector< unsigned char > Hash::calculateHash ( const unsigned char *  pInput,
size_t  nLength,
const unsigned char *  pSalt,
size_t  nSaltLen,
sal_uInt32  nSpinCount,
IterCount  eIterCount,
HashType  eType 
)
static

Calculate hash value with salt (pSalt,nSaltLen) prepended to password (pInput,nLength) and repeated iterations run if nSpinCount>0.

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 https://msdn.microsoft.com/en-us/library/dd925430

Parameters
pSaltmay be nullptr thus no salt prepended
nSpinCountIf >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.
eIterCountIf IterCount::APPEND, append iteration count as per https://msdn.microsoft.com/en-us/library/dd920692 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.
Returns
the raw hash value

Definition at line 155 of file hash.cxx.

References APPEND, calculateHash(), finalize(), i, NONE, PREPEND, and update().

static std::vector<unsigned char> comphelper::Hash::calculateHash ( const rtl::OUString &  rPassword,
const std::vector< unsigned char > &  rSaltValue,
sal_uInt32  nSpinCount,
IterCount  eIterCount,
HashType  eType 
)
static

Convenience function to calculate a salted hash with iterations.

Parameters
rPasswordUTF-16 encoded string, hashed byte-wise as unsigned char.
rSaltValueSalt that will be prepended to password data.
std::vector< unsigned char > Hash::finalize ( )

Definition at line 116 of file hash.cxx.

References getLength(), mpImpl, and void().

Referenced by calculateHash().

size_t Hash::getLength ( ) const

Definition at line 131 of file hash.cxx.

References comphelper::MD5, mpImpl, comphelper::SHA1, comphelper::SHA256, and comphelper::SHA512.

Referenced by finalize().

void Hash::update ( const unsigned char *  pInput,
size_t  length 
)

Definition at line 104 of file hash.cxx.

References mpImpl, and void().

Referenced by calculateHash().

Member Data Documentation

std::unique_ptr<HashImpl> comphelper::Hash::mpImpl
private

Definition at line 37 of file hash.hxx.

Referenced by finalize(), getLength(), and update().


The documentation for this class was generated from the following files: