drop requirement for rtl_random_getBytes to have "Pool" arg
Seeing as since:
commit e9531b792d
Date: Tue Feb 6 14:39:47 2024 +0100
sal: rtlRandomPool: require OS random device, abort if not present
Both rtl_random_createPool() and rtl_random_getBytes() first try to get
random data from the OS, via /dev/urandom or rand_s() (documented to
call RtlGenRandom(), see [1]).
we don't use the initial arg to rtl_random_getBytes anymore, drop the
requirement to have one. Then simplify our usages of that, and
addtionally deprecate rtl_random_createPool and rtl_random_destroyPool.
Change-Id: I13dcc067714a8a741a4e8f2bfcf2006373f832c4
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/167067
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolan.mcnamara@collabora.com>
This commit is contained in:
parent
1eaae3966d
commit
e5aa87aeeb
25 changed files with 54 additions and 160 deletions
|
@ -74,9 +74,7 @@ namespace {
|
|||
|
||||
sal_Int32 random() {
|
||||
sal_Int32 n;
|
||||
rtlRandomPool pool = rtl_random_createPool();
|
||||
(void)rtl_random_getBytes(pool, &n, sizeof n);
|
||||
rtl_random_destroyPool(pool);
|
||||
(void)rtl_random_getBytes(nullptr, &n, sizeof n);
|
||||
return n;
|
||||
}
|
||||
|
||||
|
|
|
@ -426,12 +426,10 @@ OUString DocPasswordHelper::GetOoxHashAsBase64(
|
|||
{
|
||||
uno::Sequence< sal_Int8 > aResult( nLength );
|
||||
|
||||
rtlRandomPool aRandomPool = rtl_random_createPool ();
|
||||
if (rtl_random_getBytes(aRandomPool, aResult.getArray(), nLength) != rtl_Random_E_None)
|
||||
if (rtl_random_getBytes(nullptr, aResult.getArray(), nLength) != rtl_Random_E_None)
|
||||
{
|
||||
throw uno::RuntimeException(u"rtl_random_getBytes failed"_ustr);
|
||||
}
|
||||
rtl_random_destroyPool ( aRandomPool );
|
||||
|
||||
return aResult;
|
||||
}
|
||||
|
|
|
@ -60,10 +60,8 @@ struct RandomNumberGenerator
|
|||
}
|
||||
|
||||
size_t seed = 0;
|
||||
rtlRandomPool aRandomPool = rtl_random_createPool();
|
||||
if (rtl_random_getBytes(aRandomPool, &seed, sizeof(seed)) != rtl_Random_E_None)
|
||||
if (rtl_random_getBytes(nullptr, &seed, sizeof(seed)) != rtl_Random_E_None)
|
||||
seed = 0;
|
||||
rtl_random_destroyPool(aRandomPool);
|
||||
|
||||
// initialises the state of the global random number generator
|
||||
// should only be called once.
|
||||
|
|
|
@ -437,17 +437,13 @@ uno::Sequence< beans::NamedValue > OStorageHelper::CreateGpgPackageEncryptionDat
|
|||
// generate session key
|
||||
// --------------------
|
||||
|
||||
rtlRandomPool aRandomPool = rtl_random_createPool();
|
||||
|
||||
// get 32 random chars out of it
|
||||
uno::Sequence < sal_Int8 > aVector(32);
|
||||
if (rtl_random_getBytes(aRandomPool, aVector.getArray(), aVector.getLength()) != rtl_Random_E_None)
|
||||
if (rtl_random_getBytes(nullptr, aVector.getArray(), aVector.getLength()) != rtl_Random_E_None)
|
||||
{
|
||||
throw uno::RuntimeException(u"rtl_random_getBytes failed"_ustr);
|
||||
}
|
||||
|
||||
rtl_random_destroyPool(aRandomPool);
|
||||
|
||||
std::vector< uno::Sequence< beans::NamedValue > > aGpgEncryptions;
|
||||
|
||||
uno::Reference< security::XDocumentDigitalSignatures > xSigner(
|
||||
|
|
|
@ -77,17 +77,13 @@ namespace comphelper::xml
|
|||
// See SvXMLExport::addChaffWhenEncryptedStorage
|
||||
OString makeXMLChaff()
|
||||
{
|
||||
rtlRandomPool pool = rtl_random_createPool();
|
||||
|
||||
sal_Int8 n;
|
||||
(void)rtl_random_getBytes(pool, &n, 1);
|
||||
(void)rtl_random_getBytes(nullptr, &n, 1);
|
||||
|
||||
sal_Int32 nLength = 1024+n;
|
||||
// coverity[tainted_data] - 1024 deliberate random minus max -127/plus max 128
|
||||
std::vector<sal_uInt8> aChaff(nLength);
|
||||
(void)rtl_random_getBytes(pool, aChaff.data(), nLength);
|
||||
|
||||
rtl_random_destroyPool(pool);
|
||||
(void)rtl_random_getBytes(nullptr, aChaff.data(), nLength);
|
||||
|
||||
encodeChaff(aChaff);
|
||||
|
||||
|
|
|
@ -139,14 +139,10 @@ Reference< XComponentContext > SAL_CALL bootstrap()
|
|||
throw BootstrapException( u"no local component context!"_ustr );
|
||||
|
||||
// create a random pipe name
|
||||
rtlRandomPool hPool = rtl_random_createPool();
|
||||
if ( hPool == nullptr )
|
||||
throw BootstrapException( u"cannot create random pool!"_ustr );
|
||||
sal_uInt8 bytes[ 16 ];
|
||||
if ( rtl_random_getBytes( hPool, bytes, std::size( bytes ) )
|
||||
if ( rtl_random_getBytes( nullptr, bytes, std::size( bytes ) )
|
||||
!= rtl_Random_E_None )
|
||||
throw BootstrapException( u"random pool error!"_ustr );
|
||||
rtl_random_destroyPool( hPool );
|
||||
OUStringBuffer buf("uno");
|
||||
for (unsigned char byte : bytes)
|
||||
buf.append( static_cast< sal_Int32 >( byte ) );
|
||||
|
|
|
@ -409,12 +409,9 @@ oslProcess raiseProcess(
|
|||
OUString generateRandomPipeId()
|
||||
{
|
||||
// compute some good pipe id:
|
||||
static rtlRandomPool s_hPool = rtl_random_createPool();
|
||||
if (s_hPool == nullptr)
|
||||
throw RuntimeException( u"cannot create random pool!?"_ustr, nullptr );
|
||||
sal_uInt8 bytes[ 32 ];
|
||||
if (rtl_random_getBytes(
|
||||
s_hPool, bytes, std::size(bytes) ) != rtl_Random_E_None) {
|
||||
nullptr, bytes, std::size(bytes) ) != rtl_Random_E_None) {
|
||||
throw RuntimeException( u"random pool error!?"_ustr, nullptr );
|
||||
}
|
||||
OUStringBuffer buf;
|
||||
|
|
|
@ -53,15 +53,29 @@ enum __rtl_RandomError
|
|||
*/
|
||||
typedef enum __rtl_RandomError rtlRandomError;
|
||||
|
||||
/** Retrieve random bytes
|
||||
@param[in] Pool use NULL, non-NULL Random Pools are deprecated
|
||||
@param[in,out] Buffer a buffer to receive the random bytes.
|
||||
@param[in] Bytes the number of bytes to write to the buffer.
|
||||
@retval rtl_Random_E_None upon success.
|
||||
*/
|
||||
SAL_DLLPUBLIC rtlRandomError SAL_CALL rtl_random_getBytes (
|
||||
rtlRandomPool Pool,
|
||||
void *Buffer,
|
||||
sal_Size Bytes
|
||||
) SAL_THROW_EXTERN_C();
|
||||
|
||||
|
||||
/** Create a Random Pool.
|
||||
@return initialized Random Pool, or NULL upon failure.
|
||||
@deprecated Instead use rtl_random_getBytes with a NULL Pool
|
||||
*/
|
||||
SAL_DLLPUBLIC rtlRandomPool SAL_CALL rtl_random_createPool (void) SAL_THROW_EXTERN_C();
|
||||
|
||||
|
||||
/** Destroy a Random Pool.
|
||||
@param[in] Pool a Random Pool.
|
||||
@deprecated Instead use rtl_random_getBytes with a NULL Pool
|
||||
*/
|
||||
SAL_DLLPUBLIC void SAL_CALL rtl_random_destroyPool (
|
||||
rtlRandomPool Pool
|
||||
|
@ -73,7 +87,8 @@ SAL_DLLPUBLIC void SAL_CALL rtl_random_destroyPool (
|
|||
@param[in] Buffer a buffer containing the bytes to add.
|
||||
@param[in] Bytes the number of bytes to read from the buffer.
|
||||
@retval rtl_Random_E_None upon success.
|
||||
@deprecated This now does nothing.
|
||||
@deprecated This now does nothing, instead use rtl_random_getBytes with a
|
||||
NULL Pool
|
||||
*/
|
||||
SAL_DLLPUBLIC rtlRandomError SAL_CALL rtl_random_addBytes (
|
||||
rtlRandomPool Pool,
|
||||
|
@ -82,18 +97,6 @@ SAL_DLLPUBLIC rtlRandomError SAL_CALL rtl_random_addBytes (
|
|||
) SAL_THROW_EXTERN_C();
|
||||
|
||||
|
||||
/** Retrieve bytes from a Random Pool.
|
||||
@param[in] Pool a Random Pool.
|
||||
@param[in,out] Buffer a buffer to receive the random bytes.
|
||||
@param[in] Bytes the number of bytes to write to the buffer.
|
||||
@retval rtl_Random_E_None upon success.
|
||||
*/
|
||||
SAL_DLLPUBLIC rtlRandomError SAL_CALL rtl_random_getBytes (
|
||||
rtlRandomPool Pool,
|
||||
void *Buffer,
|
||||
sal_Size Bytes
|
||||
) SAL_THROW_EXTERN_C();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -27,12 +27,10 @@ namespace
|
|||
|
||||
void lclRandomGenerateValues(sal_uInt8* aArray, sal_uInt32 aSize)
|
||||
{
|
||||
rtlRandomPool aRandomPool = rtl_random_createPool();
|
||||
if (rtl_random_getBytes(aRandomPool, aArray, aSize) != rtl_Random_E_None)
|
||||
if (rtl_random_getBytes(nullptr, aArray, aSize) != rtl_Random_E_None)
|
||||
{
|
||||
throw css::uno::RuntimeException("rtl_random_getBytes failed");
|
||||
}
|
||||
rtl_random_destroyPool(aRandomPool);
|
||||
}
|
||||
|
||||
constexpr OUString lclCspName = u"Microsoft Enhanced RSA and AES Cryptographic Provider"_ustr;
|
||||
|
|
|
@ -32,7 +32,6 @@
|
|||
#include <optional>
|
||||
#include <tuple>
|
||||
|
||||
typedef void* rtlRandomPool;
|
||||
class ZipOutputStream;
|
||||
class ZipPackageFolder;
|
||||
|
||||
|
@ -69,8 +68,7 @@ public:
|
|||
ZipOutputStream & rZipOut,
|
||||
const css::uno::Sequence < sal_Int8 >& rEncryptionKey,
|
||||
::std::optional<sal_Int32> oPBKDF2IterationCount,
|
||||
::std::optional<::std::tuple<sal_Int32, sal_Int32, sal_Int32>> oArgon2Args,
|
||||
const rtlRandomPool &rRandomPool ) = 0;
|
||||
::std::optional<::std::tuple<sal_Int32, sal_Int32, sal_Int32>> oArgon2Args) = 0;
|
||||
|
||||
void clearParent()
|
||||
{
|
||||
|
|
|
@ -99,8 +99,7 @@ public:
|
|||
ZipOutputStream & rZipOut,
|
||||
const css::uno::Sequence < sal_Int8 >& rEncryptionKey,
|
||||
::std::optional<sal_Int32> oPBKDF2IterationCount,
|
||||
::std::optional<::std::tuple<sal_Int32, sal_Int32, sal_Int32>> oArgon2Args,
|
||||
const rtlRandomPool &rRandomPool ) override;
|
||||
::std::optional<::std::tuple<sal_Int32, sal_Int32, sal_Int32>> oArgon2Args) override;
|
||||
|
||||
// Recursive functions
|
||||
/// @throws css::uno::RuntimeException
|
||||
|
@ -110,8 +109,7 @@ public:
|
|||
ZipOutputStream & rZipOut,
|
||||
const css::uno::Sequence< sal_Int8 > &rEncryptionKey,
|
||||
::std::optional<sal_Int32> oPBKDF2IterationCount,
|
||||
::std::optional<::std::tuple<sal_Int32, sal_Int32, sal_Int32>> oArgon2Args,
|
||||
const rtlRandomPool & rRandomPool) const;
|
||||
::std::optional<::std::tuple<sal_Int32, sal_Int32, sal_Int32>> oArgon2Args) const;
|
||||
|
||||
// XNameContainer
|
||||
virtual void SAL_CALL insertByName( const OUString& aName, const css::uno::Any& aElement ) override;
|
||||
|
|
|
@ -139,8 +139,7 @@ public:
|
|||
ZipOutputStream & rZipOut,
|
||||
const css::uno::Sequence < sal_Int8 >& rEncryptionKey,
|
||||
::std::optional<sal_Int32> oPBKDF2IterationCount,
|
||||
::std::optional<::std::tuple<sal_Int32, sal_Int32, sal_Int32>> oArgon2Args,
|
||||
const rtlRandomPool &rRandomPool ) override;
|
||||
::std::optional<::std::tuple<sal_Int32, sal_Int32, sal_Int32>> oArgon2Args) override;
|
||||
|
||||
void setZipEntryOnLoading( const ZipEntry &rInEntry);
|
||||
void successfullyWritten( ZipEntry const *pEntry );
|
||||
|
|
|
@ -1216,28 +1216,6 @@ void ZipPackage::ConnectTo( const uno::Reference< io::XInputStream >& xInStream
|
|||
m_pZipFile.emplace(m_aMutexHolder, m_xContentStream, m_xContext, false);
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
class RandomPool
|
||||
{
|
||||
private:
|
||||
rtlRandomPool m_aRandomPool;
|
||||
public:
|
||||
RandomPool() : m_aRandomPool(rtl_random_createPool ())
|
||||
{
|
||||
}
|
||||
rtlRandomPool get()
|
||||
{
|
||||
return m_aRandomPool;
|
||||
}
|
||||
~RandomPool()
|
||||
{
|
||||
// Clean up random pool memory
|
||||
rtl_random_destroyPool(m_aRandomPool);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
uno::Reference< io::XInputStream > ZipPackage::writeTempFile()
|
||||
{
|
||||
// In case the target local file does not exist or empty
|
||||
|
@ -1349,10 +1327,6 @@ uno::Reference< io::XInputStream > ZipPackage::writeTempFile()
|
|||
}
|
||||
|
||||
{
|
||||
// This will be used to generate random salt and initialisation vectors
|
||||
// for encrypted streams
|
||||
RandomPool aRandomPool;
|
||||
|
||||
::std::optional<sal_Int32> oPBKDF2IterationCount;
|
||||
::std::optional<::std::tuple<sal_Int32, sal_Int32, sal_Int32>> oArgon2Args;
|
||||
|
||||
|
@ -1371,7 +1345,7 @@ uno::Reference< io::XInputStream > ZipPackage::writeTempFile()
|
|||
|
||||
// call saveContents - it will recursively save sub-directories
|
||||
m_xRootFolder->saveContents(u""_ustr, aManList, aZipOut, GetEncryptionKey(),
|
||||
oPBKDF2IterationCount, oArgon2Args, aRandomPool.get());
|
||||
oPBKDF2IterationCount, oArgon2Args);
|
||||
}
|
||||
|
||||
if( m_nFormat == embed::StorageFormats::PACKAGE )
|
||||
|
|
|
@ -232,8 +232,7 @@ bool ZipPackageFolder::saveChild(
|
|||
ZipOutputStream & rZipOut,
|
||||
const uno::Sequence < sal_Int8 >& rEncryptionKey,
|
||||
::std::optional<sal_Int32> const oPBKDF2IterationCount,
|
||||
::std::optional<::std::tuple<sal_Int32, sal_Int32, sal_Int32>> const oArgon2Args,
|
||||
const rtlRandomPool &rRandomPool)
|
||||
::std::optional<::std::tuple<sal_Int32, sal_Int32, sal_Int32>> const oArgon2Args)
|
||||
{
|
||||
uno::Sequence < PropertyValue > aPropSet (PKG_SIZE_NOENCR_MNFST);
|
||||
OUString sTempName = rPath + "/";
|
||||
|
@ -251,7 +250,7 @@ bool ZipPackageFolder::saveChild(
|
|||
else
|
||||
aPropSet.realloc( 0 );
|
||||
|
||||
saveContents(sTempName, rManList, rZipOut, rEncryptionKey, oPBKDF2IterationCount, oArgon2Args, rRandomPool);
|
||||
saveContents(sTempName, rManList, rZipOut, rEncryptionKey, oPBKDF2IterationCount, oArgon2Args);
|
||||
|
||||
// folder can have a mediatype only in package format
|
||||
if ( aPropSet.hasElements() && ( m_nFormat == embed::StorageFormats::PACKAGE ) )
|
||||
|
@ -266,8 +265,7 @@ void ZipPackageFolder::saveContents(
|
|||
ZipOutputStream & rZipOut,
|
||||
const uno::Sequence < sal_Int8 >& rEncryptionKey,
|
||||
::std::optional<sal_Int32> const oPBKDF2IterationCount,
|
||||
::std::optional<::std::tuple<sal_Int32, sal_Int32, sal_Int32>> const oArgon2Args,
|
||||
const rtlRandomPool &rRandomPool ) const
|
||||
::std::optional<::std::tuple<sal_Int32, sal_Int32, sal_Int32>> const oArgon2Args) const
|
||||
{
|
||||
if ( maContents.empty() && !rPath.isEmpty() && m_nFormat != embed::StorageFormats::OFOPXML )
|
||||
{
|
||||
|
@ -303,7 +301,7 @@ void ZipPackageFolder::saveContents(
|
|||
{
|
||||
bMimeTypeStreamStored = true;
|
||||
if (!aIter->second.pStream->saveChild(rPath + aIter->first, rManList, rZipOut,
|
||||
rEncryptionKey, oPBKDF2IterationCount, oArgon2Args, rRandomPool))
|
||||
rEncryptionKey, oPBKDF2IterationCount, oArgon2Args))
|
||||
{
|
||||
throw uno::RuntimeException( THROW_WHERE );
|
||||
}
|
||||
|
@ -317,7 +315,7 @@ void ZipPackageFolder::saveContents(
|
|||
if (rInfo.bFolder)
|
||||
{
|
||||
if (!rInfo.pFolder->saveChild(rPath + rShortName, rManList, rZipOut,
|
||||
rEncryptionKey, oPBKDF2IterationCount, oArgon2Args, rRandomPool))
|
||||
rEncryptionKey, oPBKDF2IterationCount, oArgon2Args))
|
||||
{
|
||||
throw uno::RuntimeException( THROW_WHERE );
|
||||
}
|
||||
|
@ -325,7 +323,7 @@ void ZipPackageFolder::saveContents(
|
|||
else
|
||||
{
|
||||
if (!rInfo.pStream->saveChild(rPath + rShortName, rManList, rZipOut,
|
||||
rEncryptionKey, oPBKDF2IterationCount, oArgon2Args, rRandomPool))
|
||||
rEncryptionKey, oPBKDF2IterationCount, oArgon2Args))
|
||||
{
|
||||
throw uno::RuntimeException( THROW_WHERE );
|
||||
}
|
||||
|
|
|
@ -452,8 +452,7 @@ bool ZipPackageStream::saveChild(
|
|||
ZipOutputStream & rZipOut,
|
||||
const uno::Sequence < sal_Int8 >& rEncryptionKey,
|
||||
::std::optional<sal_Int32> const oPBKDF2IterationCount,
|
||||
::std::optional<::std::tuple<sal_Int32, sal_Int32, sal_Int32>> const oArgon2Args,
|
||||
const rtlRandomPool &rRandomPool)
|
||||
::std::optional<::std::tuple<sal_Int32, sal_Int32, sal_Int32>> const oArgon2Args)
|
||||
{
|
||||
bool bSuccess = true;
|
||||
|
||||
|
@ -592,11 +591,11 @@ bool ZipPackageStream::saveChild(
|
|||
uno::Sequence<sal_Int8> aSalt(16);
|
||||
// note: for GCM it's particularly important that IV is unique
|
||||
uno::Sequence<sal_Int8> aVector(GetIVSize());
|
||||
if (rtl_random_getBytes(rRandomPool, aSalt.getArray(), 16) != rtl_Random_E_None)
|
||||
if (rtl_random_getBytes(nullptr, aSalt.getArray(), 16) != rtl_Random_E_None)
|
||||
{
|
||||
throw uno::RuntimeException(u"rtl_random_getBytes failed"_ustr);
|
||||
}
|
||||
if (rtl_random_getBytes(rRandomPool, aVector.getArray(), aVector.getLength()) != rtl_Random_E_None)
|
||||
if (rtl_random_getBytes(nullptr, aVector.getArray(), aVector.getLength()) != rtl_Random_E_None)
|
||||
{
|
||||
throw uno::RuntimeException(u"rtl_random_getBytes failed"_ustr);
|
||||
}
|
||||
|
|
|
@ -63,12 +63,11 @@ rtlRandomError SAL_CALL rtl_random_addBytes(
|
|||
}
|
||||
|
||||
rtlRandomError SAL_CALL rtl_random_getBytes (
|
||||
rtlRandomPool Pool, void *Buffer, sal_Size Bytes) SAL_THROW_EXTERN_C()
|
||||
rtlRandomPool, void *Buffer, sal_Size Bytes) SAL_THROW_EXTERN_C()
|
||||
{
|
||||
RandomPool_Impl *pImpl = static_cast< RandomPool_Impl* >(Pool);
|
||||
sal_uInt8 *pBuffer = static_cast< sal_uInt8* >(Buffer);
|
||||
|
||||
if (!pImpl || !pBuffer)
|
||||
if (!pBuffer)
|
||||
return rtl_Random_E_Argument;
|
||||
|
||||
if (!osl_get_system_random_data(static_cast<char*>(Buffer), Bytes))
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
||||
*/
|
||||
|
||||
#include <mutex>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
@ -84,28 +83,13 @@ extern "C" void SAL_CALL rtl_createUuid(sal_uInt8 *pTargetUUID ,
|
|||
SAL_UNUSED_PARAMETER const sal_uInt8 *,
|
||||
SAL_UNUSED_PARAMETER sal_Bool)
|
||||
{
|
||||
if (rtl_random_getBytes(nullptr, pTargetUUID, 16) != rtl_Random_E_None)
|
||||
{
|
||||
static rtlRandomPool pool = []() {
|
||||
rtlRandomPool aPool = rtl_random_createPool();
|
||||
if (!aPool)
|
||||
{
|
||||
abort();
|
||||
// only possible way to signal failure here (rtl_createUuid
|
||||
// being part of a fixed C API)
|
||||
}
|
||||
return aPool;
|
||||
}();
|
||||
|
||||
static std::mutex aMutex;
|
||||
|
||||
std::scoped_lock g(aMutex);
|
||||
if (rtl_random_getBytes(pool, pTargetUUID, 16) != rtl_Random_E_None)
|
||||
{
|
||||
abort();
|
||||
// only possible way to signal failure here (rtl_createUuid
|
||||
// being part of a fixed C API)
|
||||
}
|
||||
abort();
|
||||
// only possible way to signal failure here (rtl_createUuid
|
||||
// being part of a fixed C API)
|
||||
}
|
||||
|
||||
// See ITU-T Recommendation X.667:
|
||||
pTargetUUID[6] &= 0x0F;
|
||||
pTargetUUID[6] |= 0x40;
|
||||
|
|
|
@ -315,13 +315,11 @@ uno::Sequence< beans::NamedValue > XclExpRoot::GenerateEncryptionData( std::u16s
|
|||
|
||||
if ( !aPass.empty() && aPass.size() < 16 )
|
||||
{
|
||||
rtlRandomPool aRandomPool = rtl_random_createPool ();
|
||||
sal_uInt8 pnDocId[16];
|
||||
if (rtl_random_getBytes(aRandomPool, pnDocId, 16) != rtl_Random_E_None)
|
||||
if (rtl_random_getBytes(nullptr, pnDocId, 16) != rtl_Random_E_None)
|
||||
{
|
||||
throw uno::RuntimeException("rtl_random_getBytes failed");
|
||||
}
|
||||
rtl_random_destroyPool( aRandomPool );
|
||||
|
||||
sal_uInt16 pnPasswd[16] = {};
|
||||
for( size_t nChar = 0; nChar < aPass.size(); ++nChar )
|
||||
|
|
|
@ -563,12 +563,10 @@ void XclExpBiff8Encrypter::Init( const Sequence< NamedValue >& rEncryptionData )
|
|||
maCodec.GetDocId( mpnDocId );
|
||||
|
||||
// generate the salt here
|
||||
rtlRandomPool aRandomPool = rtl_random_createPool ();
|
||||
if (rtl_random_getBytes(aRandomPool, mpnSalt, 16) != rtl_Random_E_None)
|
||||
if (rtl_random_getBytes(nullptr, mpnSalt, 16) != rtl_Random_E_None)
|
||||
{
|
||||
throw uno::RuntimeException("rtl_random_getBytes failed");
|
||||
}
|
||||
rtl_random_destroyPool( aRandomPool );
|
||||
|
||||
memset( mpnSaltDigest, 0, sizeof( mpnSaltDigest ) );
|
||||
|
||||
|
|
|
@ -90,12 +90,9 @@ namespace {
|
|||
OUString generateRandomPipeId()
|
||||
{
|
||||
// compute some good pipe id:
|
||||
static rtlRandomPool s_hPool = rtl_random_createPool();
|
||||
if (s_hPool == nullptr)
|
||||
throw RuntimeException( "cannot create random pool!?", nullptr );
|
||||
sal_uInt8 bytes[ 32 ];
|
||||
if (rtl_random_getBytes(
|
||||
s_hPool, bytes, SAL_N_ELEMENTS(bytes) ) != rtl_Random_E_None) {
|
||||
nullptr, bytes, SAL_N_ELEMENTS(bytes) ) != rtl_Random_E_None) {
|
||||
throw RuntimeException( "random pool error!?", nullptr );
|
||||
}
|
||||
OUStringBuffer buf;
|
||||
|
|
|
@ -650,9 +650,8 @@ void SAL_CALL PasswordContainer::addPersistent( const OUString& Url, const OUStr
|
|||
|
||||
OUString PasswordContainer::createIV()
|
||||
{
|
||||
rtlRandomPool randomPool = mRandomPool.get();
|
||||
unsigned char iv[RTL_DIGEST_LENGTH_MD5];
|
||||
if (rtl_random_getBytes(randomPool, iv, RTL_DIGEST_LENGTH_MD5) != rtl_Random_E_None)
|
||||
if (rtl_random_getBytes(nullptr, iv, RTL_DIGEST_LENGTH_MD5) != rtl_Random_E_None)
|
||||
{
|
||||
throw uno::RuntimeException("rtl_random_getBytes failed");
|
||||
}
|
||||
|
|
|
@ -245,28 +245,7 @@ private:
|
|||
css::uno::Reference< css::lang::XComponent > mComponent;
|
||||
SysCredentialsConfig mUrlContainer;
|
||||
|
||||
class RandomPool
|
||||
{
|
||||
private:
|
||||
rtlRandomPool m_aRandomPool;
|
||||
public:
|
||||
RandomPool() : m_aRandomPool(rtl_random_createPool())
|
||||
{
|
||||
}
|
||||
rtlRandomPool get()
|
||||
{
|
||||
return m_aRandomPool;
|
||||
}
|
||||
~RandomPool()
|
||||
{
|
||||
// Clean up random pool memory
|
||||
rtl_random_destroyPool(m_aRandomPool);
|
||||
}
|
||||
};
|
||||
|
||||
RandomPool mRandomPool;
|
||||
|
||||
OUString createIV();
|
||||
static OUString createIV();
|
||||
|
||||
/// @throws css::uno::RuntimeException
|
||||
css::uno::Sequence< css::task::UserRecord > CopyToUserRecordSequence(
|
||||
|
|
|
@ -3524,13 +3524,11 @@ bool SwWW8Writer::InitStd97CodecUpdateMedium( ::msfilter::MSCodec_Std97& rCodec
|
|||
if ( pPasswordItem && !pPasswordItem->GetValue().isEmpty() && pPasswordItem->GetValue().getLength() <= 15 )
|
||||
{
|
||||
// Generate random number with a seed of time as salt.
|
||||
rtlRandomPool aRandomPool = rtl_random_createPool ();
|
||||
sal_uInt8 pDocId[ 16 ];
|
||||
if (rtl_random_getBytes(aRandomPool, pDocId, 16) != rtl_Random_E_None)
|
||||
if (rtl_random_getBytes(nullptr, pDocId, 16) != rtl_Random_E_None)
|
||||
{
|
||||
throw uno::RuntimeException("rtl_random_getBytes failed");
|
||||
}
|
||||
rtl_random_destroyPool( aRandomPool );
|
||||
|
||||
sal_uInt16 aPassword[16] = {};
|
||||
|
||||
|
|
|
@ -5673,13 +5673,11 @@ namespace
|
|||
// in the MediaDescriptor
|
||||
::msfilter::MSCodec_Std97 aCodec97;
|
||||
|
||||
rtlRandomPool aRandomPool = rtl_random_createPool();
|
||||
sal_uInt8 pDocId[ 16 ];
|
||||
if (rtl_random_getBytes(aRandomPool, pDocId, 16) != rtl_Random_E_None)
|
||||
if (rtl_random_getBytes(nullptr, pDocId, 16) != rtl_Random_E_None)
|
||||
{
|
||||
throw uno::RuntimeException("rtl_random_getBytes failed");
|
||||
}
|
||||
rtl_random_destroyPool( aRandomPool );
|
||||
|
||||
sal_uInt16 pStd97Pass[16] = {};
|
||||
for( sal_Int32 nChar = 0; nChar < nLen; ++nChar )
|
||||
|
|
|
@ -325,12 +325,10 @@ uno::Sequence< ::sal_Int8 > SAL_CALL OCipherContext::finalizeCipherContextAndDis
|
|||
|
||||
if ( nPaddingSize > 1 )
|
||||
{
|
||||
rtlRandomPool aRandomPool = rtl_random_createPool();
|
||||
if (rtl_random_getBytes(aRandomPool, pLastBlock + nOldLastBlockLen, nPaddingSize - 1) != rtl_Random_E_None)
|
||||
if (rtl_random_getBytes(nullptr, pLastBlock + nOldLastBlockLen, nPaddingSize - 1) != rtl_Random_E_None)
|
||||
{
|
||||
throw uno::RuntimeException("rtl_random_getBytes failed");
|
||||
}
|
||||
rtl_random_destroyPool ( aRandomPool );
|
||||
}
|
||||
pLastBlock[m_aLastBlock.getLength() - 1] = static_cast< sal_Int8 >( nPaddingSize );
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue