12 #include <com/sun/star/uno/RuntimeException.hpp>
14 #include <rtl/ustring.hxx>
15 #include <rtl/alloc.h>
16 #include <osl/endian.h>
17 #include <config_oox.h>
23 #include <openssl/evp.h>
24 #include <openssl/sha.h>
25 #endif // USE_TLS_OPENSSL
35 HASH_HashType getNSSType()
const
44 return HASH_AlgSHA256;
46 return HASH_AlgSHA512;
52 EVP_MD_CTX* mpContext;
54 const EVP_MD* getOpenSSLType()
const
79 auto const e = NSS_NoDB_Init(
nullptr);
80 if (e != SECSuccess) {
81 throw css::uno::RuntimeException(
"NSS_NoDB_Init failed with " + OUString::number(e));
83 mpContext = HASH_Create(getNSSType());
84 HASH_Begin(mpContext);
86 mpContext = EVP_MD_CTX_create();
87 EVP_DigestInit_ex(mpContext, getOpenSSLType(),
nullptr);
94 HASH_Destroy(mpContext);
96 EVP_MD_CTX_destroy(mpContext);
113 HASH_Update(
mpImpl->mpContext, pInput, length);
114 #elif USE_TLS_OPENSSL
115 EVP_DigestUpdate(
mpImpl->mpContext, pInput, length);
124 std::vector<unsigned char> hash(
getLength(), 0);
125 unsigned int digestWrittenLength;
127 HASH_End(
mpImpl->mpContext, hash.data(), &digestWrittenLength,
getLength());
128 #elif USE_TLS_OPENSSL
129 EVP_DigestFinal_ex(
mpImpl->mpContext, hash.data(), &digestWrittenLength);
131 (
void)digestWrittenLength;
157 aHash.
update(pInput, length);
162 const unsigned char* pInput,
size_t nLength,
163 const unsigned char* pSalt,
size_t nSaltLen,
164 sal_uInt32 nSpinCount,
171 if (!nSaltLen && !nSpinCount)
177 std::vector<unsigned char> initialData( nSaltLen + nLength);
178 std::copy( pSalt, pSalt + nSaltLen, initialData.begin());
179 std::copy( pInput, pInput + nLength, initialData.begin() + nSaltLen);
180 aHash.
update( initialData.data(), initialData.size());
181 rtl_secureZeroMemory( initialData.data(), initialData.size());
185 aHash.
update( pInput, nLength);
187 std::vector<unsigned char> hash( aHash.
finalize());
199 std::vector<unsigned char>
data( hash.size() + nAddIter, 0);
200 for (sal_uInt32
i = 0;
i < nSpinCount; ++
i)
202 std::copy( hash.begin(), hash.end(),
data.begin() + nHashPos);
208 std::swap( p[0], p[3] );
209 std::swap( p[1], p[2] );
210 memcpy(
data.data() + nIterPos, &be, nAddIter);
212 memcpy(
data.data() + nIterPos, &
i, nAddIter);
227 const OUString& rPassword,
228 const std::vector<unsigned char>& rSaltValue,
229 sal_uInt32 nSpinCount,
230 IterCount eIterCount,
233 const unsigned char* pPassBytes =
reinterpret_cast<const unsigned char*
>(rPassword.getStr());
234 const size_t nPassBytesLen = rPassword.getLength() * 2;
237 std::vector<unsigned char> vPass;
240 vPass.resize( nPassBytesLen);
241 std::copy( pPassBytes, pPassBytes + nPassBytesLen, vPass.begin());
242 unsigned char*
p = vPass.data();
243 unsigned char const *
const pEnd = p + nPassBytesLen;
244 for ( ; p < pEnd; p += 2 )
246 std::swap( p[0], p[1] );
248 pPassBytes = vPass.data();
251 return calculateHash( pPassBytes, nPassBytesLen, rSaltValue.data(), rSaltValue.size(), nSpinCount,
std::unique_ptr< HashImpl > mpImpl
ParserContextSharedPtr mpContext
Iteration count prepended to hash iterations.
const sal_uInt32 SHA512_HASH_LENGTH
Iteration count not added to hash iterations.
const sal_uInt32 SHA1_HASH_LENGTH
exports com.sun.star.chart2. data
const sal_uInt32 SHA256_HASH_LENGTH
void update(const unsigned char *pInput, size_t length)
static std::vector< unsigned char > calculateHash(const unsigned char *pInput, size_t length, HashType eType)
const sal_uInt32 MD5_HASH_LENGTH
std::vector< unsigned char > finalize()