1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/security/crypto/weakcryptospi/source/random/random.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,119 @@
1.4 +/*
1.5 +* Copyright (c) 2005-2010 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of the License "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +*
1.19 +*/
1.20 +
1.21 +
1.22 +/**
1.23 + @file
1.24 +*/
1.25 +
1.26 +#include <e32std.h>
1.27 +#include <e32math.h>
1.28 +#include <random.h>
1.29 +#include <hash.h>
1.30 +#include "randomshim.h"
1.31 +
1.32 +extern "C" {
1.33 +EXPORT_C void RAND_bytes(unsigned char* buf,int bytes)
1.34 + {
1.35 + TPtr8 ptr(buf,bytes,bytes);
1.36 + buf[0]++;
1.37 + TRandom::Random(ptr);
1.38 + }
1.39 +}
1.40 +
1.41 +EXPORT_C CRandom::CRandom(void)
1.42 + {
1.43 + }
1.44 +
1.45 +EXPORT_C CSystemRandom* CSystemRandom::NewL(void)
1.46 + {
1.47 + CSystemRandom* self = NewLC();
1.48 + CleanupStack::Pop(self);
1.49 + return self;
1.50 + }
1.51 +
1.52 +EXPORT_C CSystemRandom* CSystemRandom::NewLC(void)
1.53 + {
1.54 + CSystemRandom* self = new(ELeave)CSystemRandom();
1.55 + CleanupStack::PushL(self);
1.56 + self->ConstructL();
1.57 + return self;
1.58 + }
1.59 +
1.60 +void CSystemRandom::GenerateBytesL(TDes8& aDest)
1.61 + {
1.62 + TRAPD(error, iShim->GenerateBytesL(aDest));
1.63 + // This method must leave on low memory conditions.
1.64 + if(error == KErrNoMemory)
1.65 + {
1.66 + User::Leave(error);
1.67 + }
1.68 + }
1.69 +
1.70 +CSystemRandom::CSystemRandom(void)
1.71 + {
1.72 + }
1.73 +
1.74 +CSystemRandom::~CSystemRandom()
1.75 + {
1.76 + delete iShim;
1.77 + }
1.78 +
1.79 +void CSystemRandom::ConstructL()
1.80 + {
1.81 + iShim = CRandomShim::NewL();
1.82 + }
1.83 +
1.84 +// Methods replace by shim are excluded from coverage.
1.85 +#ifdef _BullseyeCoverage
1.86 +#pragma suppress_warnings on
1.87 +#pragma BullseyeCoverage off
1.88 +#pragma suppress_warnings off
1.89 +#endif
1.90 +EXPORT_C void TRandom::Random(TDes8& aDestination)
1.91 + {
1.92 + // Method replaced by shim
1.93 + TRandomShim::Random(aDestination);
1.94 + }
1.95 +
1.96 +EXPORT_C void TRandom::RandomL(TDes8& aDestination)
1.97 + {
1.98 + // Method replaced by shim
1.99 + TRandomShim::RandomL(aDestination);
1.100 + }
1.101 +
1.102 +EXPORT_C void TRandom::SecureRandomL(TDes8& aDestination)
1.103 + {
1.104 + // Method replaced by shim
1.105 + TRandomShim::SecureRandomL(aDestination);
1.106 + }
1.107 +
1.108 +EXPORT_C RRandomSession::RRandomSession(void)
1.109 + {
1.110 + }
1.111 +
1.112 +EXPORT_C void RRandomSession::ConnectL(void)
1.113 + {
1.114 + // No action required
1.115 + }
1.116 +
1.117 +EXPORT_C TInt RRandomSession::GetRandom(TDes8& aDestination)
1.118 + {
1.119 + // Method replaced by shim
1.120 + TRandomShim::Random(aDestination);
1.121 + return KErrNone;
1.122 + }