|
1 /* |
|
2 * Copyright (c) 2006-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 * Software random implementation |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 /** |
|
21 @file |
|
22 @internalComponent |
|
23 @released |
|
24 */ |
|
25 |
|
26 #ifndef __CRYPTOAPI_RANDOMIMPL_H__ |
|
27 #define __CRYPTOAPI_RANDOMIMPL_H__ |
|
28 |
|
29 #include <cryptospi/cryptoplugin.h> |
|
30 #include <cryptospi/randomplugin.h> |
|
31 |
|
32 namespace SoftwareCrypto |
|
33 { |
|
34 using namespace CryptoSpi; |
|
35 |
|
36 NONSHARABLE_CLASS(CRandomImpl): public CBase, public MRandom |
|
37 { |
|
38 public: |
|
39 // NewL & NewLC |
|
40 static CRandomImpl* NewL(); |
|
41 static CRandomImpl* NewLC(); |
|
42 |
|
43 // From MPlugin |
|
44 void Reset(); |
|
45 void Close(); |
|
46 void GetCharacteristicsL(const TCharacteristics*& aPluginCharacteristics); |
|
47 const CExtendedCharacteristics* GetExtendedCharacteristicsL(); |
|
48 TAny* GetExtension(TUid aExtensionId); |
|
49 TUid ImplementationUid() const; |
|
50 |
|
51 // From MRandom |
|
52 void GenerateRandomBytesL(TDes8& aDest); |
|
53 |
|
54 static CExtendedCharacteristics* CreateExtendedCharacteristicsL(); |
|
55 |
|
56 private: |
|
57 //Constructor |
|
58 CRandomImpl(); |
|
59 |
|
60 //Destructor |
|
61 ~CRandomImpl(); |
|
62 |
|
63 private: |
|
64 TUid iImplementationUid; |
|
65 }; |
|
66 |
|
67 class TRandomImpl |
|
68 /** |
|
69 * The user interface to the system cryptographically |
|
70 * secure random number generator. |
|
71 * |
|
72 * @internalComponent |
|
73 * @released |
|
74 */ |
|
75 { |
|
76 public: |
|
77 |
|
78 /** |
|
79 * Fills the provided buffer with secure random data up to its |
|
80 * current length, discarding any current content. |
|
81 * |
|
82 * @param aDestination The buffer in which to write the random data. |
|
83 */ |
|
84 static void Random(TDes8& aDestination); |
|
85 }; |
|
86 |
|
87 class RRandomSessionImpl : public RSessionBase |
|
88 /** |
|
89 * The client interface to the system random number generator. End |
|
90 * users should use TRandom instead of this interface. |
|
91 * |
|
92 * @internalAll |
|
93 * @released |
|
94 */ |
|
95 { |
|
96 public: |
|
97 RRandomSessionImpl(); |
|
98 |
|
99 /** |
|
100 * Fills the provided buffer with secure random data up to its |
|
101 * current length, discarding any current content. |
|
102 * |
|
103 * @param aDestination The buffer in to which to write the random data |
|
104 */ |
|
105 TInt GetRandom(TDes8& aDestination); |
|
106 |
|
107 /** |
|
108 * Opens a new session with the random number server. |
|
109 */ |
|
110 void ConnectL(); |
|
111 }; |
|
112 } |
|
113 |
|
114 #endif // __CRYPTOAPI_RANDOMIMPL_H__ |