author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Sat, 20 Feb 2010 00:36:18 +0200 | |
branch | RCL_3 |
changeset 41 | 9b5a3a9fddf8 |
parent 19 | cd501b96611d |
permissions | -rw-r--r-- |
19 | 1 |
/* |
2 |
* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 |
* All rights reserved. |
|
4 |
* This component and the accompanying materials are made available |
|
5 |
* under the terms of the License "Eclipse Public License v1.0" |
|
6 |
* which accompanies this distribution, and is available |
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 |
* |
|
9 |
* Initial Contributors: |
|
10 |
* Nokia Corporation - initial contribution. |
|
11 |
* |
|
12 |
* Contributors: |
|
13 |
* |
|
14 |
* Description: |
|
15 |
* |
|
16 |
*/ |
|
17 |
||
18 |
||
19 |
/** |
|
20 |
@file |
|
21 |
*/ |
|
22 |
||
23 |
#include <e32std.h> |
|
41
9b5a3a9fddf8
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
24 |
#include <e32math.h> |
19 | 25 |
#include <e32debug.h> |
26 |
||
27 |
#include "randomimpl.h" |
|
28 |
#include "pluginentry.h" |
|
29 |
#include "pluginconfig.h" |
|
41
9b5a3a9fddf8
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
30 |
#include "securityerr.h" |
19 | 31 |
|
32 |
using namespace SoftwareCrypto; |
|
33 |
||
34 |
CRandomImpl* CRandomImpl::NewL(void) |
|
35 |
{ |
|
36 |
CRandomImpl* self = new(ELeave)CRandomImpl(); |
|
37 |
return self; |
|
38 |
} |
|
39 |
||
40 |
CRandomImpl* CRandomImpl::NewLC(void) |
|
41 |
{ |
|
42 |
CRandomImpl* self = NewL(); |
|
43 |
CleanupStack::PushL(self); |
|
44 |
return self; |
|
45 |
} |
|
46 |
||
41
9b5a3a9fddf8
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
47 |
void CRandomImpl::GenerateRandomBytesL(TDes8& aDestination) |
19 | 48 |
{ |
41
9b5a3a9fddf8
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
49 |
// Call the Math library to populate the buffer with random data. |
9b5a3a9fddf8
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
50 |
TRAPD(err, Math::RandomL(aDestination)); |
9b5a3a9fddf8
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
51 |
if(err != KErrNone) |
9b5a3a9fddf8
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
52 |
{ |
9b5a3a9fddf8
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
53 |
// As the end users are interested only in the security aspect of the output but not |
9b5a3a9fddf8
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
54 |
// the internal states, accordingly translate the kernel side error code if required. |
9b5a3a9fddf8
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
55 |
err = (err == KErrNotReady) ? KErrNotSecure : err; |
9b5a3a9fddf8
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
56 |
User::Leave(err); |
9b5a3a9fddf8
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
57 |
} |
19 | 58 |
} |
59 |
||
60 |
CRandomImpl::CRandomImpl(void) |
|
61 |
{ |
|
62 |
} |
|
63 |
||
64 |
void CRandomImpl::GetCharacteristicsL(const TCharacteristics*& aPluginCharacteristics) |
|
65 |
{ |
|
66 |
TInt randomNum = sizeof(KRandomCharacteristics)/sizeof(TRandomCharacteristics*); |
|
67 |
for (TInt i = 0; i < randomNum; i++) |
|
68 |
{ |
|
69 |
if (KRandomCharacteristics[i]->cmn.iImplementationUID == ImplementationUid().iUid) |
|
70 |
{ |
|
71 |
aPluginCharacteristics = KRandomCharacteristics[i]; |
|
72 |
break; |
|
73 |
} |
|
74 |
} |
|
75 |
} |
|
76 |
||
77 |
CExtendedCharacteristics* CRandomImpl::CreateExtendedCharacteristicsL() |
|
78 |
{ |
|
79 |
// All Symbian software plug-ins have unlimited concurrency, cannot be reserved |
|
80 |
// for exclusive use and are not CERTIFIED to be standards compliant. |
|
81 |
return CExtendedCharacteristics::NewL(KMaxTInt, EFalse); |
|
82 |
} |
|
83 |
||
84 |
const CExtendedCharacteristics* CRandomImpl::GetExtendedCharacteristicsL() |
|
85 |
{ |
|
86 |
return CRandomImpl::CreateExtendedCharacteristicsL(); |
|
87 |
} |
|
88 |
||
89 |
TUid CRandomImpl::ImplementationUid() const |
|
90 |
{ |
|
91 |
return KCryptoPluginRandomUid; |
|
92 |
} |
|
93 |
||
94 |
CRandomImpl::~CRandomImpl() |
|
95 |
{ |
|
96 |
} |
|
97 |
||
98 |
void CRandomImpl::Close() |
|
99 |
{ |
|
100 |
delete this; |
|
101 |
} |
|
102 |
||
103 |
// All crypto plugins must implement this, to reset |
|
104 |
// hardware if required. Do nothing in this version |
|
105 |
void CRandomImpl::Reset() |
|
106 |
{ |
|
107 |
} |
|
108 |
||
109 |
// Methods which are not supported can be excluded from the coverage. |
|
110 |
#ifdef _BullseyeCoverage |
|
111 |
#pragma suppress_warnings on |
|
112 |
#pragma BullseyeCoverage off |
|
113 |
#pragma suppress_warnings off |
|
114 |
#endif |
|
115 |
||
116 |
TAny* CRandomImpl::GetExtension(TUid /*aExtensionId*/) |
|
117 |
{ |
|
118 |
return NULL; |
|
119 |
} |