os/security/crypto/weakcryptospi/source/random/random.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 2005-2010 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     3
* All rights reserved.
sl@0
     4
* This component and the accompanying materials are made available
sl@0
     5
* under the terms of the License "Eclipse Public License v1.0"
sl@0
     6
* which accompanies this distribution, and is available
sl@0
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
*
sl@0
     9
* Initial Contributors:
sl@0
    10
* Nokia Corporation - initial contribution.
sl@0
    11
*
sl@0
    12
* Contributors:
sl@0
    13
*
sl@0
    14
* Description: 
sl@0
    15
*
sl@0
    16
*/
sl@0
    17
sl@0
    18
sl@0
    19
/**
sl@0
    20
 @file
sl@0
    21
*/
sl@0
    22
sl@0
    23
#include <e32std.h>
sl@0
    24
#include <e32math.h>
sl@0
    25
#include <random.h>
sl@0
    26
#include <hash.h>
sl@0
    27
#include "randomshim.h"
sl@0
    28
sl@0
    29
extern "C" {
sl@0
    30
EXPORT_C void RAND_bytes(unsigned char* buf,int bytes)
sl@0
    31
	{
sl@0
    32
	TPtr8 ptr(buf,bytes,bytes);
sl@0
    33
	buf[0]++;
sl@0
    34
	TRandom::Random(ptr);
sl@0
    35
	}
sl@0
    36
}
sl@0
    37
sl@0
    38
EXPORT_C CRandom::CRandom(void)
sl@0
    39
	{
sl@0
    40
	}
sl@0
    41
sl@0
    42
EXPORT_C CSystemRandom* CSystemRandom::NewL(void)
sl@0
    43
	{
sl@0
    44
	CSystemRandom* self = NewLC();
sl@0
    45
	CleanupStack::Pop(self);
sl@0
    46
	return self;
sl@0
    47
	}
sl@0
    48
sl@0
    49
EXPORT_C CSystemRandom* CSystemRandom::NewLC(void)
sl@0
    50
	{
sl@0
    51
	CSystemRandom* self = new(ELeave)CSystemRandom();
sl@0
    52
	CleanupStack::PushL(self);
sl@0
    53
	self->ConstructL();
sl@0
    54
	return self;
sl@0
    55
	}
sl@0
    56
sl@0
    57
void CSystemRandom::GenerateBytesL(TDes8& aDest)
sl@0
    58
	{
sl@0
    59
	TRAPD(error, iShim->GenerateBytesL(aDest));
sl@0
    60
    // This method must leave on low memory conditions.
sl@0
    61
    if(error == KErrNoMemory)
sl@0
    62
        {
sl@0
    63
        User::Leave(error); 
sl@0
    64
        }
sl@0
    65
    }
sl@0
    66
sl@0
    67
CSystemRandom::CSystemRandom(void)
sl@0
    68
	{
sl@0
    69
	}
sl@0
    70
sl@0
    71
CSystemRandom::~CSystemRandom()
sl@0
    72
	{
sl@0
    73
	delete iShim;
sl@0
    74
	}
sl@0
    75
sl@0
    76
void CSystemRandom::ConstructL()
sl@0
    77
	{
sl@0
    78
	iShim = CRandomShim::NewL();
sl@0
    79
	}
sl@0
    80
sl@0
    81
// Methods replace by shim are excluded from coverage.
sl@0
    82
#ifdef _BullseyeCoverage
sl@0
    83
#pragma suppress_warnings on
sl@0
    84
#pragma BullseyeCoverage off
sl@0
    85
#pragma suppress_warnings off
sl@0
    86
#endif
sl@0
    87
EXPORT_C void TRandom::Random(TDes8& aDestination)
sl@0
    88
	{
sl@0
    89
	// Method replaced by shim
sl@0
    90
	TRandomShim::Random(aDestination);
sl@0
    91
	}
sl@0
    92
sl@0
    93
EXPORT_C void TRandom::RandomL(TDes8& aDestination)
sl@0
    94
	{
sl@0
    95
	// Method replaced by shim
sl@0
    96
	TRandomShim::RandomL(aDestination);
sl@0
    97
	}
sl@0
    98
	
sl@0
    99
EXPORT_C void TRandom::SecureRandomL(TDes8& aDestination)
sl@0
   100
	{
sl@0
   101
	// Method replaced by shim
sl@0
   102
	TRandomShim::SecureRandomL(aDestination);
sl@0
   103
	}
sl@0
   104
sl@0
   105
EXPORT_C RRandomSession::RRandomSession(void)
sl@0
   106
	{
sl@0
   107
	}
sl@0
   108
sl@0
   109
EXPORT_C void RRandomSession::ConnectL(void)
sl@0
   110
	{
sl@0
   111
	// No action required
sl@0
   112
	}
sl@0
   113
sl@0
   114
EXPORT_C TInt RRandomSession::GetRandom(TDes8& aDestination)
sl@0
   115
	{
sl@0
   116
	// Method replaced by shim
sl@0
   117
	TRandomShim::Random(aDestination);
sl@0
   118
	return KErrNone;
sl@0
   119
	}