crypto/weakcryptospi/source/random/random.cpp
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Sat, 20 Feb 2010 00:36:18 +0200
branchRCL_3
changeset 43 9b5a3a9fddf8
parent 17 cd501b96611d
child 50 d07aa956024a
child 60 11c66574c2a2
permissions -rw-r--r--
Revision: 201007 Kit: 201007

/*
* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of the License "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description: 
*
*/


/**
 @file
*/

#include <e32std.h>
#include <e32math.h>
#include <random.h>
#include <hash.h>
#include "randomshim.h"

extern "C" {
EXPORT_C void RAND_bytes(unsigned char* buf,int bytes)
	{
	TPtr8 ptr(buf,bytes,bytes);
	buf[0]++;
	TRandom::Random(ptr);
	}
}

EXPORT_C CRandom::CRandom(void)
	{
	}

EXPORT_C CSystemRandom* CSystemRandom::NewL(void)
	{
	CSystemRandom* self = NewLC();
	CleanupStack::Pop(self);
	return self;
	}

EXPORT_C CSystemRandom* CSystemRandom::NewLC(void)
	{
	CSystemRandom* self = new(ELeave)CSystemRandom();
	CleanupStack::PushL(self);
	self->ConstructL();
	return self;
	}

void CSystemRandom::GenerateBytesL(TDes8& aDest)
	{
	iShim->GenerateBytesL(aDest);
	}

CSystemRandom::CSystemRandom(void)
	{
	}

CSystemRandom::~CSystemRandom()
	{
	delete iShim;
	}

void CSystemRandom::ConstructL()
	{
	iShim = CRandomShim::NewL();
	}

// Methods replace by shim are excluded from coverage.
#ifdef _BullseyeCoverage
#pragma suppress_warnings on
#pragma BullseyeCoverage off
#pragma suppress_warnings off
#endif
EXPORT_C void TRandom::Random(TDes8& aDestination)
	{
	// Method replaced by shim
	TRandomShim::Random(aDestination);
	}

EXPORT_C void TRandom::RandomL(TDes8& aDestination)
	{
	// Method replaced by shim
	TRandomShim::RandomL(aDestination);
	}
	
EXPORT_C void TRandom::SecureRandomL(TDes8& aDestination)
	{
	// Method replaced by shim
	TRandomShim::SecureRandomL(aDestination);
	}

EXPORT_C RRandomSession::RRandomSession(void)
	{
	}

EXPORT_C void RRandomSession::ConnectL(void)
	{
	// All of the ConnectL() code has moved to randomimpl.cpp
	// in the new CryptoSPI pluggable framework. This is just
	// a stub now that is retained for binary compatibility.

	// Method replaced by shim
	ASSERT(EFalse);
	}

EXPORT_C TInt RRandomSession::GetRandom(TDes8& aDestination)
	{
	// Method replaced by shim
	TRandomShim::Random(aDestination);
	return KErrNone;
	}