move secure random code

This commit is contained in:
Glenn Maynard
2006-12-20 23:17:57 +00:00
parent b8cb44c0be
commit ea7e48e08e
3 changed files with 24 additions and 7 deletions
+19
View File
@@ -6,6 +6,7 @@
#include "PrefsManager.h"
#include "RageFileManager.h"
#include "crypto/CryptMD5.h"
#include "crypto/CryptRand.h"
CryptManager* CRYPTMAN = NULL; // global and accessable from anywhere in our program
@@ -24,6 +25,13 @@ bool CryptManager::VerifyFileWithFile( RString sPath, RString sSignatureFile )
return true;
}
void CryptManager::GetRandomBytes( void *pData, int iBytes )
{
uint8_t *pBuf = (uint8_t *) pData;
while( iBytes-- )
*pBuf++ = (uint8_t) RandomInt( 256 );
}
#else
// crypt headers
@@ -232,6 +240,17 @@ RString CryptManager::GetPublicKeyFileName()
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
* All rights reserved.
+1 -1
View File
@@ -16,7 +16,7 @@ public:
static bool VerifyFileWithFile( RString sPath, RString sSignatureFile = "" );
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 GetMD5ForString( RString sData ); // in Hex
+4 -6
View File
@@ -15,7 +15,6 @@
#include "ProfileManager.h"
#include "RageFileManager.h"
#include "LuaManager.h"
#include "crypto/CryptRand.h"
#include "UnlockManager.h"
#include "XmlFile.h"
#include "XmlFileUtil.h"
@@ -85,13 +84,12 @@ void Profile::InitEditableData()
RString Profile::MakeGuid()
{
// Does the RNG need to be inited and seeded every time?
random_init();
random_add_noise( "ai8049ujr3odusj" );
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++ )
s += ssprintf( "%02x", random_byte() );
s += ssprintf( "%02x", buf[i] );
return s;
}