move secure random code
This commit is contained in:
@@ -6,6 +6,7 @@
|
|||||||
#include "PrefsManager.h"
|
#include "PrefsManager.h"
|
||||||
#include "RageFileManager.h"
|
#include "RageFileManager.h"
|
||||||
#include "crypto/CryptMD5.h"
|
#include "crypto/CryptMD5.h"
|
||||||
|
#include "crypto/CryptRand.h"
|
||||||
|
|
||||||
CryptManager* CRYPTMAN = NULL; // global and accessable from anywhere in our program
|
CryptManager* CRYPTMAN = NULL; // global and accessable from anywhere in our program
|
||||||
|
|
||||||
@@ -24,6 +25,13 @@ bool CryptManager::VerifyFileWithFile( RString sPath, RString sSignatureFile )
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CryptManager::GetRandomBytes( void *pData, int iBytes )
|
||||||
|
{
|
||||||
|
uint8_t *pBuf = (uint8_t *) pData;
|
||||||
|
while( iBytes-- )
|
||||||
|
*pBuf++ = (uint8_t) RandomInt( 256 );
|
||||||
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
// crypt headers
|
// crypt headers
|
||||||
@@ -232,6 +240,17 @@ RString CryptManager::GetPublicKeyFileName()
|
|||||||
return PUBLIC_KEY_PATH;
|
return PUBLIC_KEY_PATH;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CryptManager::GetRandomBytes( void *pData, int iBytes )
|
||||||
|
{
|
||||||
|
// Does the RNG need to be inited and seeded every time?
|
||||||
|
random_init();
|
||||||
|
random_add_noise( "ai8049ujr3odusj" );
|
||||||
|
|
||||||
|
uint8_t *pBuf = (uint8_t *) pData;
|
||||||
|
while( iBytes-- )
|
||||||
|
*pBuf++ = random_byte();
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* (c) 2004 Chris Danford
|
* (c) 2004 Chris Danford
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ public:
|
|||||||
static bool VerifyFileWithFile( RString sPath, RString sSignatureFile = "" );
|
static bool VerifyFileWithFile( RString sPath, RString sSignatureFile = "" );
|
||||||
static bool VerifyFileWithFile( RString sPath, RString sSignatureFile, RString sPublicKeyFile );
|
static bool VerifyFileWithFile( RString sPath, RString sSignatureFile, RString sPublicKeyFile );
|
||||||
|
|
||||||
static RString Sign( RString sPath );
|
static void GetRandomBytes( void *pData, int iBytes );
|
||||||
|
|
||||||
static RString GetMD5ForFile( RString fn ); // in Hex
|
static RString GetMD5ForFile( RString fn ); // in Hex
|
||||||
static RString GetMD5ForString( RString sData ); // in Hex
|
static RString GetMD5ForString( RString sData ); // in Hex
|
||||||
|
|||||||
@@ -15,7 +15,6 @@
|
|||||||
#include "ProfileManager.h"
|
#include "ProfileManager.h"
|
||||||
#include "RageFileManager.h"
|
#include "RageFileManager.h"
|
||||||
#include "LuaManager.h"
|
#include "LuaManager.h"
|
||||||
#include "crypto/CryptRand.h"
|
|
||||||
#include "UnlockManager.h"
|
#include "UnlockManager.h"
|
||||||
#include "XmlFile.h"
|
#include "XmlFile.h"
|
||||||
#include "XmlFileUtil.h"
|
#include "XmlFileUtil.h"
|
||||||
@@ -85,13 +84,12 @@ void Profile::InitEditableData()
|
|||||||
|
|
||||||
RString Profile::MakeGuid()
|
RString Profile::MakeGuid()
|
||||||
{
|
{
|
||||||
// Does the RNG need to be inited and seeded every time?
|
|
||||||
random_init();
|
|
||||||
random_add_noise( "ai8049ujr3odusj" );
|
|
||||||
|
|
||||||
RString s;
|
RString s;
|
||||||
|
s.resize( GUID_SIZE_BYTES );
|
||||||
|
char buf[GUID_SIZE_BYTES];
|
||||||
|
CryptManager::GetRandomBytes( buf, GUID_SIZE_BYTES );
|
||||||
for( unsigned i=0; i<GUID_SIZE_BYTES; i++ )
|
for( unsigned i=0; i<GUID_SIZE_BYTES; i++ )
|
||||||
s += ssprintf( "%02x", random_byte() );
|
s += ssprintf( "%02x", buf[i] );
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user