sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 2003-2009 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 |
* ** IMPORTANT ** API's in this file are published to 3rd party developers via the
|
sl@0
|
16 |
* Symbian website. Changes to these API's should be treated as PublishedAll API changes and the Security TA should be consulted.
|
sl@0
|
17 |
* Asymmetric keys implementation
|
sl@0
|
18 |
*
|
sl@0
|
19 |
*/
|
sl@0
|
20 |
|
sl@0
|
21 |
|
sl@0
|
22 |
/**
|
sl@0
|
23 |
@file
|
sl@0
|
24 |
@publishedAll
|
sl@0
|
25 |
@released
|
sl@0
|
26 |
*/
|
sl@0
|
27 |
|
sl@0
|
28 |
#ifndef __ASYMMETRICKEYS_H__
|
sl@0
|
29 |
#define __ASYMMETRICKEYS_H__
|
sl@0
|
30 |
|
sl@0
|
31 |
#include <e32base.h>
|
sl@0
|
32 |
#include <random.h>
|
sl@0
|
33 |
#include <bigint.h>
|
sl@0
|
34 |
|
sl@0
|
35 |
/**
|
sl@0
|
36 |
* Defines the various ways of representing supported RSA private keys.
|
sl@0
|
37 |
*
|
sl@0
|
38 |
*/
|
sl@0
|
39 |
enum TRSAPrivateKeyType
|
sl@0
|
40 |
{
|
sl@0
|
41 |
/**
|
sl@0
|
42 |
* Standard type of RSA private key
|
sl@0
|
43 |
*
|
sl@0
|
44 |
* This consists of the modulus (n) and decryption exponent (d).
|
sl@0
|
45 |
*/
|
sl@0
|
46 |
EStandard,
|
sl@0
|
47 |
/**
|
sl@0
|
48 |
* CRT (Chinese Remainder Theorem) type of RSA private key
|
sl@0
|
49 |
*
|
sl@0
|
50 |
* This consists of the the first factor (p), the second factor (q),
|
sl@0
|
51 |
* the first factor's CRT exponent (dP), the second factor's CRT exponent (dQ),
|
sl@0
|
52 |
* and the (first) CRT coefficient (qInv). The two factors, p and q, are the
|
sl@0
|
53 |
* first two prime factors of the RSA modulus, n.
|
sl@0
|
54 |
*/
|
sl@0
|
55 |
EStandardCRT
|
sl@0
|
56 |
//We may support types like this in the future (currently these are a patent
|
sl@0
|
57 |
//minefield):
|
sl@0
|
58 |
//EMulti, //multi prime version of EStandard
|
sl@0
|
59 |
//EMultiCRT //multi prime version of EStandardCRT
|
sl@0
|
60 |
};
|
sl@0
|
61 |
|
sl@0
|
62 |
/**
|
sl@0
|
63 |
* Concrete class representing the parameters common to both an RSA public and
|
sl@0
|
64 |
* private key.
|
sl@0
|
65 |
*
|
sl@0
|
66 |
* See ANSI X9.31 and RSA PKCS#1
|
sl@0
|
67 |
*
|
sl@0
|
68 |
*/
|
sl@0
|
69 |
class CRSAParameters : public CBase
|
sl@0
|
70 |
{
|
sl@0
|
71 |
public:
|
sl@0
|
72 |
/**
|
sl@0
|
73 |
* Gets the RSA parameter, n (the modulus)
|
sl@0
|
74 |
*
|
sl@0
|
75 |
* @return The RSA parameter, n
|
sl@0
|
76 |
*/
|
sl@0
|
77 |
IMPORT_C const TInteger& N(void) const;
|
sl@0
|
78 |
|
sl@0
|
79 |
/** Destructor */
|
sl@0
|
80 |
IMPORT_C virtual ~CRSAParameters(void);
|
sl@0
|
81 |
protected:
|
sl@0
|
82 |
/**
|
sl@0
|
83 |
* Constructor
|
sl@0
|
84 |
*
|
sl@0
|
85 |
* @param aN The RSA parameter, n (the modulus)
|
sl@0
|
86 |
*/
|
sl@0
|
87 |
IMPORT_C CRSAParameters(RInteger& aN);
|
sl@0
|
88 |
|
sl@0
|
89 |
/** Default constructor */
|
sl@0
|
90 |
IMPORT_C CRSAParameters(void);
|
sl@0
|
91 |
protected:
|
sl@0
|
92 |
/** The RSA modulus, n, a positive integer */
|
sl@0
|
93 |
RInteger iN;
|
sl@0
|
94 |
private:
|
sl@0
|
95 |
CRSAParameters(const CRSAParameters&);
|
sl@0
|
96 |
CRSAParameters& operator=(const CRSAParameters&);
|
sl@0
|
97 |
};
|
sl@0
|
98 |
|
sl@0
|
99 |
/**
|
sl@0
|
100 |
* Representation of an RSA public key.
|
sl@0
|
101 |
*
|
sl@0
|
102 |
* An RSA public key is identified by its modulus (n) and its encryption exponent
|
sl@0
|
103 |
* (e).
|
sl@0
|
104 |
*
|
sl@0
|
105 |
*/
|
sl@0
|
106 |
class CRSAPublicKey : public CRSAParameters
|
sl@0
|
107 |
{
|
sl@0
|
108 |
public:
|
sl@0
|
109 |
/**
|
sl@0
|
110 |
* Creates a new CRSAPublicKey object from a specified
|
sl@0
|
111 |
* modulus and encryption exponent.
|
sl@0
|
112 |
*
|
sl@0
|
113 |
* @param aN The RSA parameter, n (the modulus)
|
sl@0
|
114 |
* @param aE The RSA parameter, e (the encryption exponent)
|
sl@0
|
115 |
* @return A pointer to a new CRSAPublicKey object
|
sl@0
|
116 |
*
|
sl@0
|
117 |
* @leave KErrArgument If either aN or aE are not positive integers,
|
sl@0
|
118 |
* and releases ownership.
|
sl@0
|
119 |
*/
|
sl@0
|
120 |
IMPORT_C static CRSAPublicKey* NewL(RInteger& aN, RInteger& aE);
|
sl@0
|
121 |
|
sl@0
|
122 |
/**
|
sl@0
|
123 |
* Creates a new CRSAPublicKey object from a specified
|
sl@0
|
124 |
* modulus and encryption exponent.
|
sl@0
|
125 |
*
|
sl@0
|
126 |
* The returned pointer is put onto the cleanup stack.
|
sl@0
|
127 |
*
|
sl@0
|
128 |
* @param aN The RSA parameter, n (the modulus)
|
sl@0
|
129 |
* @param aE The RSA parameter, e (the encryption exponent)
|
sl@0
|
130 |
* @return A pointer to a new CRSAPublicKey object
|
sl@0
|
131 |
*
|
sl@0
|
132 |
* @leave KErrArgument If either aN or aE are not positive integers,
|
sl@0
|
133 |
* and releases ownership.
|
sl@0
|
134 |
*/
|
sl@0
|
135 |
IMPORT_C static CRSAPublicKey* NewLC(RInteger& aN, RInteger& aE);
|
sl@0
|
136 |
|
sl@0
|
137 |
/**
|
sl@0
|
138 |
* Gets the RSA parameter, e (the encryption exponent)
|
sl@0
|
139 |
*
|
sl@0
|
140 |
* @return The RSA parameter, e
|
sl@0
|
141 |
*/
|
sl@0
|
142 |
IMPORT_C const TInteger& E(void) const;
|
sl@0
|
143 |
|
sl@0
|
144 |
/** Destructor */
|
sl@0
|
145 |
IMPORT_C virtual ~CRSAPublicKey(void);
|
sl@0
|
146 |
protected:
|
sl@0
|
147 |
/**
|
sl@0
|
148 |
* Constructor
|
sl@0
|
149 |
*
|
sl@0
|
150 |
* @param aN The RSA parameter, n (the modulus)
|
sl@0
|
151 |
* @param aE The RSA parameter, e (the encryption exponent)
|
sl@0
|
152 |
*/
|
sl@0
|
153 |
IMPORT_C CRSAPublicKey(RInteger& aN, RInteger& aE);
|
sl@0
|
154 |
|
sl@0
|
155 |
/** Default constructor */
|
sl@0
|
156 |
IMPORT_C CRSAPublicKey(void);
|
sl@0
|
157 |
protected:
|
sl@0
|
158 |
/** The RSA encryption exponent, e */
|
sl@0
|
159 |
RInteger iE;
|
sl@0
|
160 |
private:
|
sl@0
|
161 |
CRSAPublicKey(const CRSAPublicKey&);
|
sl@0
|
162 |
CRSAPublicKey& operator=(const CRSAPublicKey&);
|
sl@0
|
163 |
void ConstructL();
|
sl@0
|
164 |
};
|
sl@0
|
165 |
|
sl@0
|
166 |
/**
|
sl@0
|
167 |
* Non-exported container class for the various ways of representing an RSA
|
sl@0
|
168 |
* private key.
|
sl@0
|
169 |
*
|
sl@0
|
170 |
* To instantiate a representation of an RSA private key, find a
|
sl@0
|
171 |
* subclass of this appropriate to your key type.
|
sl@0
|
172 |
*
|
sl@0
|
173 |
*/
|
sl@0
|
174 |
class CRSAPrivateKey : public CRSAParameters
|
sl@0
|
175 |
{
|
sl@0
|
176 |
public:
|
sl@0
|
177 |
/**
|
sl@0
|
178 |
* Constructor
|
sl@0
|
179 |
*
|
sl@0
|
180 |
* @param aKeyType The type of the RSA private key
|
sl@0
|
181 |
* @param aN The RSA parameter, n (the modulus)
|
sl@0
|
182 |
* @internalAll
|
sl@0
|
183 |
*/
|
sl@0
|
184 |
CRSAPrivateKey(const TRSAPrivateKeyType aKeyType, RInteger& aN);
|
sl@0
|
185 |
public:
|
sl@0
|
186 |
/**
|
sl@0
|
187 |
* Gets the type of RSA private key
|
sl@0
|
188 |
*
|
sl@0
|
189 |
* @return The RSA private key type
|
sl@0
|
190 |
*/
|
sl@0
|
191 |
inline const TRSAPrivateKeyType PrivateKeyType() const {return (iKeyType);};
|
sl@0
|
192 |
protected:
|
sl@0
|
193 |
/** The type of the RSA private key */
|
sl@0
|
194 |
const TRSAPrivateKeyType iKeyType;
|
sl@0
|
195 |
private:
|
sl@0
|
196 |
CRSAPrivateKey(const CRSAPrivateKey&);
|
sl@0
|
197 |
CRSAPrivateKey& operator=(const CRSAPrivateKey&);
|
sl@0
|
198 |
};
|
sl@0
|
199 |
|
sl@0
|
200 |
/**
|
sl@0
|
201 |
* The 'classical' representation of a RSA private key.
|
sl@0
|
202 |
*
|
sl@0
|
203 |
* Such a private key is composed of a modulus (n) and a decryption exponent (d).
|
sl@0
|
204 |
*
|
sl@0
|
205 |
*/
|
sl@0
|
206 |
class CRSAPrivateKeyStandard : public CRSAPrivateKey
|
sl@0
|
207 |
{
|
sl@0
|
208 |
public:
|
sl@0
|
209 |
/**
|
sl@0
|
210 |
* Creates a new CRSAPrivateKeyStandard object from a specified
|
sl@0
|
211 |
* modulus and decryption exponent.
|
sl@0
|
212 |
*
|
sl@0
|
213 |
* @param aN The RSA parameter, n (the modulus)
|
sl@0
|
214 |
* @param aD The RSA parameter, d (the decryption exponent)
|
sl@0
|
215 |
* @return A pointer to a new CRSAPrivateKeyStandard object
|
sl@0
|
216 |
*
|
sl@0
|
217 |
* @leave KErrArgument If either aN or aD are not positive integers,
|
sl@0
|
218 |
* and releases ownership.
|
sl@0
|
219 |
*/
|
sl@0
|
220 |
IMPORT_C static CRSAPrivateKeyStandard* NewL(RInteger& aN, RInteger& aD);
|
sl@0
|
221 |
|
sl@0
|
222 |
/**
|
sl@0
|
223 |
* Creates a new CRSAPrivateKeyStandard object from a specified
|
sl@0
|
224 |
* modulus and decryption exponent.
|
sl@0
|
225 |
*
|
sl@0
|
226 |
* The returned pointer is put onto the cleanup stack.
|
sl@0
|
227 |
*
|
sl@0
|
228 |
* @param aN The RSA parameter, n (the modulus)
|
sl@0
|
229 |
* @param aD The RSA parameter, d (the decryption exponent)
|
sl@0
|
230 |
* @return A pointer to a new CRSAPrivateKeyStandard object
|
sl@0
|
231 |
*
|
sl@0
|
232 |
* @leave KErrArgument If either aN or aD are not positive integers,
|
sl@0
|
233 |
* and releases ownership.
|
sl@0
|
234 |
*/
|
sl@0
|
235 |
IMPORT_C static CRSAPrivateKeyStandard* NewLC(RInteger& aN, RInteger& aD);
|
sl@0
|
236 |
|
sl@0
|
237 |
/**
|
sl@0
|
238 |
* Gets the RSA parameter, d (the decryption exponent)
|
sl@0
|
239 |
*
|
sl@0
|
240 |
* @return The RSA parameter, d
|
sl@0
|
241 |
*/
|
sl@0
|
242 |
IMPORT_C const TInteger& D(void) const;
|
sl@0
|
243 |
|
sl@0
|
244 |
/** Destructor */
|
sl@0
|
245 |
IMPORT_C virtual ~CRSAPrivateKeyStandard(void);
|
sl@0
|
246 |
protected:
|
sl@0
|
247 |
/**
|
sl@0
|
248 |
* Constructor
|
sl@0
|
249 |
*
|
sl@0
|
250 |
* @param aN The RSA parameter, n (the modulus)
|
sl@0
|
251 |
* @param aD The RSA parameter, d (the decryption exponent)
|
sl@0
|
252 |
*/
|
sl@0
|
253 |
IMPORT_C CRSAPrivateKeyStandard(RInteger& aN, RInteger& aD);
|
sl@0
|
254 |
protected:
|
sl@0
|
255 |
/** The RSA decryption exponent, d */
|
sl@0
|
256 |
RInteger iD;
|
sl@0
|
257 |
private:
|
sl@0
|
258 |
CRSAPrivateKeyStandard(const CRSAPrivateKeyStandard&);
|
sl@0
|
259 |
CRSAPrivateKeyStandard& operator=(const CRSAPrivateKeyStandard&);
|
sl@0
|
260 |
void ConstructL();
|
sl@0
|
261 |
};
|
sl@0
|
262 |
|
sl@0
|
263 |
/**
|
sl@0
|
264 |
* An alternate representation of an RSA private key providing significant
|
sl@0
|
265 |
* speed enhancements through its use of the Chinese Remainder Theorem (CRT).
|
sl@0
|
266 |
*
|
sl@0
|
267 |
* Here, a private key is represented by a modulus (n), the two prime factors of
|
sl@0
|
268 |
* the modulus (p, q), p's CRT exponent (dP), q's CRT exponent (dQ), and the CRT
|
sl@0
|
269 |
* coefficient (qInv). See PKCS#1 at http://www.rsasecurity.com/rsalabs/pkcs/
|
sl@0
|
270 |
* for more information.
|
sl@0
|
271 |
*
|
sl@0
|
272 |
*/
|
sl@0
|
273 |
class CRSAPrivateKeyCRT : public CRSAPrivateKey
|
sl@0
|
274 |
{
|
sl@0
|
275 |
public:
|
sl@0
|
276 |
/**
|
sl@0
|
277 |
* Creates a new CRSAPrivateKeyCRT object from a specified
|
sl@0
|
278 |
* modulus and decryption exponent.
|
sl@0
|
279 |
*
|
sl@0
|
280 |
* @param iN The RSA parameter, n (the modulus)
|
sl@0
|
281 |
* @param aP The RSA parameter, p (the first factor)
|
sl@0
|
282 |
* @param aQ The RSA parameter, q (the second factor)
|
sl@0
|
283 |
* @param aDP The RSA parameter, dP (the first factor's CRT exponent)
|
sl@0
|
284 |
* @param aDQ The RSA parameter, dQ (the second factor's CRT exponent)
|
sl@0
|
285 |
* @param aQInv The RSA parameter, qInv (the CRT coefficient)
|
sl@0
|
286 |
* @return A pointer to a new CRSAPrivateKeyCRT object
|
sl@0
|
287 |
*
|
sl@0
|
288 |
* @leave KErrArgument If any of the parameters are not positive integers,
|
sl@0
|
289 |
* and releases ownership.
|
sl@0
|
290 |
*/
|
sl@0
|
291 |
IMPORT_C static CRSAPrivateKeyCRT* NewL(RInteger& iN, RInteger& aP,
|
sl@0
|
292 |
RInteger& aQ, RInteger& aDP, RInteger& aDQ, RInteger& aQInv);
|
sl@0
|
293 |
|
sl@0
|
294 |
/**
|
sl@0
|
295 |
* Creates a new CRSAPrivateKeyCRT object from a specified
|
sl@0
|
296 |
* modulus and decryption exponent.
|
sl@0
|
297 |
*
|
sl@0
|
298 |
* The returned pointer is put onto the cleanup stack.
|
sl@0
|
299 |
*
|
sl@0
|
300 |
* @param iN The RSA parameter, n (the modulus)
|
sl@0
|
301 |
* @param aP The RSA parameter, p (the first factor)
|
sl@0
|
302 |
* @param aQ The RSA parameter, q (the second factor)
|
sl@0
|
303 |
* @param aDP The RSA parameter, dP (the first factor's CRT exponent)
|
sl@0
|
304 |
* @param aDQ The RSA parameter, dQ (the second factor's CRT exponent)
|
sl@0
|
305 |
* @param aQInv The RSA parameter, qInv (the CRT coefficient)
|
sl@0
|
306 |
* @return A pointer to a new CRSAPrivateKeyCRT object
|
sl@0
|
307 |
*
|
sl@0
|
308 |
* @leave KErrArgument If any of the parameters are not positive integers,
|
sl@0
|
309 |
* and releases ownership.
|
sl@0
|
310 |
*/
|
sl@0
|
311 |
IMPORT_C static CRSAPrivateKeyCRT* NewLC(RInteger& iN, RInteger& aP,
|
sl@0
|
312 |
RInteger& aQ, RInteger& aDP, RInteger& aDQ, RInteger& aQInv);
|
sl@0
|
313 |
|
sl@0
|
314 |
/** Destructor */
|
sl@0
|
315 |
IMPORT_C virtual ~CRSAPrivateKeyCRT(void);
|
sl@0
|
316 |
|
sl@0
|
317 |
/**
|
sl@0
|
318 |
* Gets the RSA parameter, p (the first factor)
|
sl@0
|
319 |
*
|
sl@0
|
320 |
* @return The first factor
|
sl@0
|
321 |
*/
|
sl@0
|
322 |
IMPORT_C const TInteger& P(void) const;
|
sl@0
|
323 |
|
sl@0
|
324 |
/**
|
sl@0
|
325 |
* Gets the RSA parameter, q (the second factor)
|
sl@0
|
326 |
*
|
sl@0
|
327 |
* @return The second factor
|
sl@0
|
328 |
*/
|
sl@0
|
329 |
IMPORT_C const TInteger& Q(void) const;
|
sl@0
|
330 |
|
sl@0
|
331 |
/**
|
sl@0
|
332 |
* Gets the RSA parameter, dP (the first factor's CRT exponent)
|
sl@0
|
333 |
*
|
sl@0
|
334 |
* @return The first factor's CRT exponent
|
sl@0
|
335 |
*/
|
sl@0
|
336 |
IMPORT_C const TInteger& DP(void) const;
|
sl@0
|
337 |
|
sl@0
|
338 |
/**
|
sl@0
|
339 |
* Gets the RSA parameter, dQ (the second factor's CRT exponent)
|
sl@0
|
340 |
*
|
sl@0
|
341 |
* @return The second factor's CRT exponent
|
sl@0
|
342 |
*/
|
sl@0
|
343 |
IMPORT_C const TInteger& DQ(void) const;
|
sl@0
|
344 |
|
sl@0
|
345 |
/**
|
sl@0
|
346 |
* Gets the RSA parameter, qInv (the CRT coefficient)
|
sl@0
|
347 |
*
|
sl@0
|
348 |
* @return The CRT coefficient
|
sl@0
|
349 |
*/
|
sl@0
|
350 |
IMPORT_C const TInteger& QInv(void) const;
|
sl@0
|
351 |
protected:
|
sl@0
|
352 |
/**
|
sl@0
|
353 |
* Constructor
|
sl@0
|
354 |
*
|
sl@0
|
355 |
* @param aN The RSA parameter, n (the modulus)
|
sl@0
|
356 |
* @param aP The RSA parameter, p (the first factor)
|
sl@0
|
357 |
* @param aQ The RSA parameter, q (the second factor)
|
sl@0
|
358 |
* @param aDP The RSA parameter, dP (the first factor's CRT exponent)
|
sl@0
|
359 |
* @param aDQ The RSA parameter, dQ (the second factor's CRT exponent)
|
sl@0
|
360 |
* @param aQInv The RSA parameter, qInv (the CRT coefficient)
|
sl@0
|
361 |
*/
|
sl@0
|
362 |
IMPORT_C CRSAPrivateKeyCRT(RInteger& aN, RInteger& aP, RInteger& aQ,
|
sl@0
|
363 |
RInteger& aDP, RInteger& aDQ, RInteger& aQInv);
|
sl@0
|
364 |
protected:
|
sl@0
|
365 |
/** The RSA parameter, p, which is the first factor */
|
sl@0
|
366 |
RInteger iP;
|
sl@0
|
367 |
/** The RSA parameter, q, which is the second factor */
|
sl@0
|
368 |
RInteger iQ;
|
sl@0
|
369 |
/** The RSA parameter, dP, which is the first factor's CRT exponent */
|
sl@0
|
370 |
RInteger iDP;
|
sl@0
|
371 |
/** The RSA parameter, dQ, which is the second factor's CRT exponent */
|
sl@0
|
372 |
RInteger iDQ;
|
sl@0
|
373 |
/** The RSA parameter, qInv, which is the CRT coefficient */
|
sl@0
|
374 |
RInteger iQInv;
|
sl@0
|
375 |
private:
|
sl@0
|
376 |
CRSAPrivateKeyCRT(const CRSAPrivateKeyCRT&);
|
sl@0
|
377 |
CRSAPrivateKeyCRT& operator=(const CRSAPrivateKeyCRT&);
|
sl@0
|
378 |
void ConstructL();
|
sl@0
|
379 |
};
|
sl@0
|
380 |
|
sl@0
|
381 |
/**
|
sl@0
|
382 |
* This class is capable of generating an RSA public/private key pair.
|
sl@0
|
383 |
*
|
sl@0
|
384 |
* By default, it generates 2 prime (standard) CRT private keys.
|
sl@0
|
385 |
*
|
sl@0
|
386 |
*/
|
sl@0
|
387 |
class CRSAKeyPair : public CBase
|
sl@0
|
388 |
{
|
sl@0
|
389 |
public:
|
sl@0
|
390 |
/**
|
sl@0
|
391 |
* Creates a new RSA key pair
|
sl@0
|
392 |
*
|
sl@0
|
393 |
* @param aModulusBits The length of the modulus, n (in bits)
|
sl@0
|
394 |
* @param aKeyType The type of the RSA key
|
sl@0
|
395 |
* @return A pointer to a new CRSAKeyPair object
|
sl@0
|
396 |
*
|
sl@0
|
397 |
* @leave KErrNotSupported If the type of RSA key is not supported
|
sl@0
|
398 |
*/
|
sl@0
|
399 |
IMPORT_C static CRSAKeyPair* NewL(TUint aModulusBits,
|
sl@0
|
400 |
TRSAPrivateKeyType aKeyType = EStandardCRT);
|
sl@0
|
401 |
|
sl@0
|
402 |
/**
|
sl@0
|
403 |
* Creates a new RSA key pair
|
sl@0
|
404 |
*
|
sl@0
|
405 |
* The returned pointer is put onto the cleanup stack.
|
sl@0
|
406 |
*
|
sl@0
|
407 |
* @param aModulusBits The length of the modulus, n (in bits)
|
sl@0
|
408 |
* @param aKeyType The type of the RSA key
|
sl@0
|
409 |
* @return A pointer to a new CRSAKeyPair object
|
sl@0
|
410 |
*
|
sl@0
|
411 |
* @leave KErrNotSupported If the type of RSA key is not supported
|
sl@0
|
412 |
*/
|
sl@0
|
413 |
IMPORT_C static CRSAKeyPair* NewLC(TUint aModulusBits,
|
sl@0
|
414 |
TRSAPrivateKeyType aKeyType = EStandardCRT);
|
sl@0
|
415 |
|
sl@0
|
416 |
/**
|
sl@0
|
417 |
* Gets the RSA public key
|
sl@0
|
418 |
*
|
sl@0
|
419 |
* @return A CRSAPublicKey object
|
sl@0
|
420 |
*/
|
sl@0
|
421 |
IMPORT_C const CRSAPublicKey& PublicKey(void) const;
|
sl@0
|
422 |
|
sl@0
|
423 |
/**
|
sl@0
|
424 |
* Gets the RSA private key
|
sl@0
|
425 |
*
|
sl@0
|
426 |
* @return A CRSAPrivateKey object
|
sl@0
|
427 |
*/
|
sl@0
|
428 |
IMPORT_C const CRSAPrivateKey& PrivateKey(void) const;
|
sl@0
|
429 |
|
sl@0
|
430 |
/** The destructor frees all resources owned by the object, prior to its destruction. */
|
sl@0
|
431 |
IMPORT_C virtual ~CRSAKeyPair(void);
|
sl@0
|
432 |
protected:
|
sl@0
|
433 |
/** Default destructor */
|
sl@0
|
434 |
IMPORT_C CRSAKeyPair(void);
|
sl@0
|
435 |
protected:
|
sl@0
|
436 |
/** The RSA public key */
|
sl@0
|
437 |
CRSAPublicKey* iPublic;
|
sl@0
|
438 |
/** The RSA private key */
|
sl@0
|
439 |
CRSAPrivateKey* iPrivate;
|
sl@0
|
440 |
private:
|
sl@0
|
441 |
void ConstructL(TUint aModulusBits, TRSAPrivateKeyType aKeyType,
|
sl@0
|
442 |
TUint aPublicExponent);
|
sl@0
|
443 |
CRSAKeyPair(const CRSAKeyPair&);
|
sl@0
|
444 |
CRSAKeyPair& operator=(const CRSAKeyPair&);
|
sl@0
|
445 |
};
|
sl@0
|
446 |
|
sl@0
|
447 |
/**
|
sl@0
|
448 |
* Representation of the parameters used to generate the primes in a
|
sl@0
|
449 |
* CDSAParameters object.
|
sl@0
|
450 |
*
|
sl@0
|
451 |
* Given such a certificate, one can ensure that the DSA
|
sl@0
|
452 |
* primes contained in CDSAParameters were generated correctly.
|
sl@0
|
453 |
*
|
sl@0
|
454 |
* @see CDSAParameters::ValidatePrimesL()
|
sl@0
|
455 |
*
|
sl@0
|
456 |
*/
|
sl@0
|
457 |
class CDSAPrimeCertificate : public CBase
|
sl@0
|
458 |
{
|
sl@0
|
459 |
public:
|
sl@0
|
460 |
/**
|
sl@0
|
461 |
* Creates a new DSA prime certificate from a specified
|
sl@0
|
462 |
* seed and counter value.
|
sl@0
|
463 |
*
|
sl@0
|
464 |
* @param aSeed The seed from a DSA key generation process
|
sl@0
|
465 |
* @param aCounter The counter value from a DSA key generation process
|
sl@0
|
466 |
* @return A pointer to a new CDSAPrimeCertificate object
|
sl@0
|
467 |
*/
|
sl@0
|
468 |
IMPORT_C static CDSAPrimeCertificate* NewL(const TDesC8& aSeed,
|
sl@0
|
469 |
TUint aCounter);
|
sl@0
|
470 |
|
sl@0
|
471 |
/**
|
sl@0
|
472 |
* Creates a new DSA prime certificate from a specified
|
sl@0
|
473 |
* seed and counter value.
|
sl@0
|
474 |
*
|
sl@0
|
475 |
* The returned pointer is put onto the cleanup stack.
|
sl@0
|
476 |
*
|
sl@0
|
477 |
* @param aSeed The seed from a DSA key generation process
|
sl@0
|
478 |
* @param aCounter The counter value from a DSA key generation process
|
sl@0
|
479 |
* @return A pointer to a new CDSAPrimeCertificate object
|
sl@0
|
480 |
*/
|
sl@0
|
481 |
IMPORT_C static CDSAPrimeCertificate* NewLC(const TDesC8& aSeed,
|
sl@0
|
482 |
TUint aCounter);
|
sl@0
|
483 |
|
sl@0
|
484 |
/**
|
sl@0
|
485 |
* Gets the seed of the DSA prime certificate
|
sl@0
|
486 |
*
|
sl@0
|
487 |
* @return The seed
|
sl@0
|
488 |
*/
|
sl@0
|
489 |
IMPORT_C const TDesC8& Seed(void) const;
|
sl@0
|
490 |
|
sl@0
|
491 |
/**
|
sl@0
|
492 |
* Gets the counter value of the DSA prime certificate
|
sl@0
|
493 |
*
|
sl@0
|
494 |
* @return The counter's value
|
sl@0
|
495 |
*/
|
sl@0
|
496 |
IMPORT_C TUint Counter(void) const;
|
sl@0
|
497 |
|
sl@0
|
498 |
/** Destructor */
|
sl@0
|
499 |
IMPORT_C virtual ~CDSAPrimeCertificate(void);
|
sl@0
|
500 |
protected:
|
sl@0
|
501 |
/**
|
sl@0
|
502 |
* Constructor
|
sl@0
|
503 |
*
|
sl@0
|
504 |
* @param aCounter The DSA key generation counter
|
sl@0
|
505 |
*/
|
sl@0
|
506 |
IMPORT_C CDSAPrimeCertificate(TUint aCounter);
|
sl@0
|
507 |
|
sl@0
|
508 |
/** Default constructor */
|
sl@0
|
509 |
IMPORT_C CDSAPrimeCertificate(void);
|
sl@0
|
510 |
/** @internalAll */
|
sl@0
|
511 |
void ConstructL(const TDesC8& aSeed);
|
sl@0
|
512 |
protected:
|
sl@0
|
513 |
/** The DSA key generation seed */
|
sl@0
|
514 |
const HBufC8* iSeed;
|
sl@0
|
515 |
/** The DSA key generation counter */
|
sl@0
|
516 |
TUint iCounter;
|
sl@0
|
517 |
private:
|
sl@0
|
518 |
CDSAPrimeCertificate(const CDSAPrimeCertificate&);
|
sl@0
|
519 |
CDSAPrimeCertificate& operator=(const CDSAPrimeCertificate&);
|
sl@0
|
520 |
};
|
sl@0
|
521 |
|
sl@0
|
522 |
/**
|
sl@0
|
523 |
* Concrete class representing the parameters common to both a DSA public and
|
sl@0
|
524 |
* private key.
|
sl@0
|
525 |
*
|
sl@0
|
526 |
* See FIPS 186-2, Digital Signature Standard
|
sl@0
|
527 |
*
|
sl@0
|
528 |
*/
|
sl@0
|
529 |
class CDSAParameters : public CBase
|
sl@0
|
530 |
{
|
sl@0
|
531 |
public:
|
sl@0
|
532 |
/**
|
sl@0
|
533 |
* Gets the DSA parameter, p (the prime)
|
sl@0
|
534 |
*
|
sl@0
|
535 |
* @return The DSA parameter, p
|
sl@0
|
536 |
*/
|
sl@0
|
537 |
IMPORT_C const TInteger& P(void) const;
|
sl@0
|
538 |
|
sl@0
|
539 |
/**
|
sl@0
|
540 |
* Gets the DSA parameter, q (the subprime)
|
sl@0
|
541 |
*
|
sl@0
|
542 |
* @return The DSA parameter, q
|
sl@0
|
543 |
*/
|
sl@0
|
544 |
IMPORT_C const TInteger& Q(void) const;
|
sl@0
|
545 |
|
sl@0
|
546 |
/**
|
sl@0
|
547 |
* Gets the DSA parameter, g (the base)
|
sl@0
|
548 |
*
|
sl@0
|
549 |
* @return The DSA parameter, g
|
sl@0
|
550 |
*/
|
sl@0
|
551 |
IMPORT_C const TInteger& G(void) const;
|
sl@0
|
552 |
|
sl@0
|
553 |
/**
|
sl@0
|
554 |
* Validates the primes regenerated from a DSA prime certificate
|
sl@0
|
555 |
*
|
sl@0
|
556 |
* @param aCert The DSA prime certificate that contains the seed and
|
sl@0
|
557 |
* counter value from a DSA key generation process
|
sl@0
|
558 |
* @return Whether or not the primes are valid
|
sl@0
|
559 |
*/
|
sl@0
|
560 |
IMPORT_C TBool ValidatePrimesL(const CDSAPrimeCertificate& aCert) const;
|
sl@0
|
561 |
|
sl@0
|
562 |
/**
|
sl@0
|
563 |
* Whether or not the prime is of a valid length
|
sl@0
|
564 |
*
|
sl@0
|
565 |
* It is valid if the length of the prime modulus is between KMinPrimeLength
|
sl@0
|
566 |
* and KMaxPrimeLength bits, and the prime is a multiple of KPrimeLengthMultiple.
|
sl@0
|
567 |
*
|
sl@0
|
568 |
* @param aPrimeBits The prime modulus
|
sl@0
|
569 |
* @return ETrue, if within the constraints; EFalse, otherwise.
|
sl@0
|
570 |
*/
|
sl@0
|
571 |
IMPORT_C static TBool ValidPrimeLength(TUint aPrimeBits);
|
sl@0
|
572 |
|
sl@0
|
573 |
/** Destructor */
|
sl@0
|
574 |
IMPORT_C virtual ~CDSAParameters(void);
|
sl@0
|
575 |
|
sl@0
|
576 |
/**
|
sl@0
|
577 |
* Creates a new DSA parameters object from a specified
|
sl@0
|
578 |
* prime, subprime, and base.
|
sl@0
|
579 |
*
|
sl@0
|
580 |
* @param aP The DSA parameter, p (the prime)
|
sl@0
|
581 |
* @param aQ The DSA parameter, g (the subprime)
|
sl@0
|
582 |
* @param aG The DSA parameter, g (the base)
|
sl@0
|
583 |
* @return A pointer to a new CDSAParameters object
|
sl@0
|
584 |
*/
|
sl@0
|
585 |
IMPORT_C static CDSAParameters* NewL(RInteger& aP, RInteger& aQ,
|
sl@0
|
586 |
RInteger& aG);
|
sl@0
|
587 |
public:
|
sl@0
|
588 |
/** @internalAll */
|
sl@0
|
589 |
static TBool GeneratePrimesL(const TDesC8& aSeed, TUint& aCounter,
|
sl@0
|
590 |
RInteger& aP, TUint aL, RInteger& aQ, TBool aUseInputCounter=EFalse);
|
sl@0
|
591 |
protected:
|
sl@0
|
592 |
/**
|
sl@0
|
593 |
* Constructor
|
sl@0
|
594 |
*
|
sl@0
|
595 |
* @param aP The DSA parameter, p (the prime)
|
sl@0
|
596 |
* @param aQ The DSA parameter, g (the subprime)
|
sl@0
|
597 |
* @param aG The DSA parameter, g (the base)
|
sl@0
|
598 |
*/
|
sl@0
|
599 |
IMPORT_C CDSAParameters(RInteger& aP, RInteger& aQ, RInteger& aG);
|
sl@0
|
600 |
|
sl@0
|
601 |
/** Default constructor */
|
sl@0
|
602 |
IMPORT_C CDSAParameters(void);
|
sl@0
|
603 |
protected:
|
sl@0
|
604 |
/**
|
sl@0
|
605 |
* The DSA parameter, p (the prime).
|
sl@0
|
606 |
*
|
sl@0
|
607 |
* A prime modulus whose length is between KMinPrimeLength and KMaxPrimeLength bits,
|
sl@0
|
608 |
* and is a multiple of KPrimeLengthMultiple.
|
sl@0
|
609 |
*/
|
sl@0
|
610 |
RInteger iP;
|
sl@0
|
611 |
|
sl@0
|
612 |
/**
|
sl@0
|
613 |
* The DSA parameter, q (the subprime)
|
sl@0
|
614 |
*
|
sl@0
|
615 |
* This is a 160-bit prime divisor of <code>p-1</code>.
|
sl@0
|
616 |
*/
|
sl@0
|
617 |
RInteger iQ;
|
sl@0
|
618 |
|
sl@0
|
619 |
/**
|
sl@0
|
620 |
* The DSA parameter, g (the base)
|
sl@0
|
621 |
*
|
sl@0
|
622 |
* <code>g = h^((p-1)/q) mod p</code>,
|
sl@0
|
623 |
*
|
sl@0
|
624 |
* where h is any integer less than <code>p-1</code> such that <code>g > 1</code>
|
sl@0
|
625 |
*/
|
sl@0
|
626 |
RInteger iG;
|
sl@0
|
627 |
private:
|
sl@0
|
628 |
CDSAParameters(const CDSAParameters&);
|
sl@0
|
629 |
CDSAParameters& operator=(const CDSAParameters&);
|
sl@0
|
630 |
};
|
sl@0
|
631 |
|
sl@0
|
632 |
/**
|
sl@0
|
633 |
* Representation of a DSA public key.
|
sl@0
|
634 |
*
|
sl@0
|
635 |
*/
|
sl@0
|
636 |
class CDSAPublicKey : public CDSAParameters
|
sl@0
|
637 |
{
|
sl@0
|
638 |
public:
|
sl@0
|
639 |
/**
|
sl@0
|
640 |
* Creates a new DSA public key object from a specified
|
sl@0
|
641 |
* primes, base, and public key.
|
sl@0
|
642 |
*
|
sl@0
|
643 |
* @param aP The DSA parameter, p (the prime)
|
sl@0
|
644 |
* @param aQ The DSA parameter, q (the subprime)
|
sl@0
|
645 |
* @param aG The DSA parameter, g (the base)
|
sl@0
|
646 |
* @param aY The DSA parameter, y (the public key)
|
sl@0
|
647 |
* @return A pointer to a new CDSAPublicKey object
|
sl@0
|
648 |
*/
|
sl@0
|
649 |
IMPORT_C static CDSAPublicKey* NewL(RInteger& aP, RInteger& aQ,
|
sl@0
|
650 |
RInteger& aG, RInteger& aY);
|
sl@0
|
651 |
|
sl@0
|
652 |
/**
|
sl@0
|
653 |
* Creates a new DSA public key object from a specified
|
sl@0
|
654 |
* primes, base, and public key.
|
sl@0
|
655 |
*
|
sl@0
|
656 |
* The returned pointer is put onto the cleanup stack.
|
sl@0
|
657 |
*
|
sl@0
|
658 |
* @param aP The DSA parameter, p (the prime)
|
sl@0
|
659 |
* @param aQ The DSA parameter, q (the subprime)
|
sl@0
|
660 |
* @param aG The DSA parameter, g (the base)
|
sl@0
|
661 |
* @param aY The DSA parameter, y (the public key)
|
sl@0
|
662 |
* @return A pointer to a new CDSAPublicKey object
|
sl@0
|
663 |
*/
|
sl@0
|
664 |
IMPORT_C static CDSAPublicKey* NewLC(RInteger& aP, RInteger& aQ,
|
sl@0
|
665 |
RInteger& aG, RInteger& aY);
|
sl@0
|
666 |
|
sl@0
|
667 |
/**
|
sl@0
|
668 |
* Gets the DSA parameter, y (the public key)
|
sl@0
|
669 |
*
|
sl@0
|
670 |
* @return The DSA parameter, y
|
sl@0
|
671 |
*/
|
sl@0
|
672 |
IMPORT_C const TInteger& Y(void) const;
|
sl@0
|
673 |
|
sl@0
|
674 |
/** Destructor */
|
sl@0
|
675 |
IMPORT_C virtual ~CDSAPublicKey(void);
|
sl@0
|
676 |
protected:
|
sl@0
|
677 |
/**
|
sl@0
|
678 |
* Constructor
|
sl@0
|
679 |
*
|
sl@0
|
680 |
* @param aP The DSA parameter, p (the prime)
|
sl@0
|
681 |
* @param aQ The DSA parameter, q (the subprime)
|
sl@0
|
682 |
* @param aG The DSA parameter, g (the base)
|
sl@0
|
683 |
* @param aY The DSA parameter, y (the public key)
|
sl@0
|
684 |
*/
|
sl@0
|
685 |
IMPORT_C CDSAPublicKey(RInteger& aP, RInteger& aQ, RInteger& aG,
|
sl@0
|
686 |
RInteger& aY);
|
sl@0
|
687 |
|
sl@0
|
688 |
/** Default constructor */
|
sl@0
|
689 |
IMPORT_C CDSAPublicKey(void);
|
sl@0
|
690 |
protected:
|
sl@0
|
691 |
/**
|
sl@0
|
692 |
* The DSA parameter, y, which is the public key
|
sl@0
|
693 |
*
|
sl@0
|
694 |
* <code>y = g^x mod p</code>
|
sl@0
|
695 |
*/
|
sl@0
|
696 |
RInteger iY;
|
sl@0
|
697 |
private:
|
sl@0
|
698 |
CDSAPublicKey(const CDSAPublicKey&);
|
sl@0
|
699 |
CDSAPublicKey& operator=(const CDSAPublicKey&);
|
sl@0
|
700 |
};
|
sl@0
|
701 |
|
sl@0
|
702 |
/**
|
sl@0
|
703 |
* Representation of a DSA private key.
|
sl@0
|
704 |
*
|
sl@0
|
705 |
*/
|
sl@0
|
706 |
class CDSAPrivateKey : public CDSAParameters
|
sl@0
|
707 |
{
|
sl@0
|
708 |
public:
|
sl@0
|
709 |
/**
|
sl@0
|
710 |
* Creates a new DSA private key object from a specified
|
sl@0
|
711 |
* primes, base, and private key.
|
sl@0
|
712 |
*
|
sl@0
|
713 |
* @param aP The DSA parameter, p (the prime)
|
sl@0
|
714 |
* @param aQ The DSA parameter, q (the subprime)
|
sl@0
|
715 |
* @param aG The DSA parameter, g (the base)
|
sl@0
|
716 |
* @param aX The DSA parameter, x (the private key)
|
sl@0
|
717 |
* @return A pointer to a new CDSAPrivateKey object
|
sl@0
|
718 |
*/
|
sl@0
|
719 |
IMPORT_C static CDSAPrivateKey* NewL(RInteger& aP, RInteger& aQ,
|
sl@0
|
720 |
RInteger& aG, RInteger& aX);
|
sl@0
|
721 |
|
sl@0
|
722 |
/**
|
sl@0
|
723 |
* Creates a new DSA private key object from a specified
|
sl@0
|
724 |
* primes, base, and private key.
|
sl@0
|
725 |
*
|
sl@0
|
726 |
* The returned pointer is put onto the cleanup stack.
|
sl@0
|
727 |
*
|
sl@0
|
728 |
* @param aP The DSA parameter, p (the prime)
|
sl@0
|
729 |
* @param aQ The DSA parameter, q (the subprime)
|
sl@0
|
730 |
* @param aG The DSA parameter, g (the base)
|
sl@0
|
731 |
* @param aX The DSA parameter, x (the private key)
|
sl@0
|
732 |
* @return A pointer to a new CDSAPrivateKey object
|
sl@0
|
733 |
*/
|
sl@0
|
734 |
IMPORT_C static CDSAPrivateKey* NewLC(RInteger& aP, RInteger& aQ,
|
sl@0
|
735 |
RInteger& aG, RInteger& aX);
|
sl@0
|
736 |
|
sl@0
|
737 |
/**
|
sl@0
|
738 |
* Gets the DSA parameter, x (the private key)
|
sl@0
|
739 |
*
|
sl@0
|
740 |
* @return The DSA parameter, x
|
sl@0
|
741 |
*/
|
sl@0
|
742 |
IMPORT_C const TInteger& X(void) const;
|
sl@0
|
743 |
|
sl@0
|
744 |
/** Destructor */
|
sl@0
|
745 |
IMPORT_C virtual ~CDSAPrivateKey(void);
|
sl@0
|
746 |
protected:
|
sl@0
|
747 |
/**
|
sl@0
|
748 |
* Constructor
|
sl@0
|
749 |
*
|
sl@0
|
750 |
* @param aP The DSA parameter, p (the prime)
|
sl@0
|
751 |
* @param aQ The DSA parameter, q (the subprime)
|
sl@0
|
752 |
* @param aG The DSA parameter, g (the base)
|
sl@0
|
753 |
* @param aX The DSA parameter, x (the private key)
|
sl@0
|
754 |
*/
|
sl@0
|
755 |
IMPORT_C CDSAPrivateKey(RInteger& aP, RInteger& aQ, RInteger& aG,
|
sl@0
|
756 |
RInteger& aX);
|
sl@0
|
757 |
|
sl@0
|
758 |
/** Default constructor */
|
sl@0
|
759 |
IMPORT_C CDSAPrivateKey(void);
|
sl@0
|
760 |
protected:
|
sl@0
|
761 |
/**
|
sl@0
|
762 |
* The DSA parameter, x, which is the private key
|
sl@0
|
763 |
*
|
sl@0
|
764 |
* A pseudorandomly generated integer whose value is between 0 and q.
|
sl@0
|
765 |
*/
|
sl@0
|
766 |
RInteger iX;
|
sl@0
|
767 |
private:
|
sl@0
|
768 |
CDSAPrivateKey(const CDSAPrivateKey&);
|
sl@0
|
769 |
CDSAPrivateKey& operator=(const CDSAPrivateKey&);
|
sl@0
|
770 |
};
|
sl@0
|
771 |
|
sl@0
|
772 |
/**
|
sl@0
|
773 |
* This class is capable of generating a DSA public/private key pair.
|
sl@0
|
774 |
*
|
sl@0
|
775 |
*/
|
sl@0
|
776 |
class CDSAKeyPair : public CBase
|
sl@0
|
777 |
{
|
sl@0
|
778 |
public:
|
sl@0
|
779 |
/**
|
sl@0
|
780 |
* Creates a new DSA key pair and also a DSA prime certificate
|
sl@0
|
781 |
*
|
sl@0
|
782 |
* @param aSize The length (in bits) of the DSA parameter, p (the prime)
|
sl@0
|
783 |
* @return A pointer to a new CDSAKeyPair object
|
sl@0
|
784 |
*/
|
sl@0
|
785 |
IMPORT_C static CDSAKeyPair* NewL(TUint aSize);
|
sl@0
|
786 |
|
sl@0
|
787 |
/**
|
sl@0
|
788 |
* Creates a new DSA key pair and also a DSA prime certificate
|
sl@0
|
789 |
*
|
sl@0
|
790 |
* The returned pointer is put onto the cleanup stack.
|
sl@0
|
791 |
*
|
sl@0
|
792 |
* @param aSize The length (in bits) of the DSA parameter, p (the prime)
|
sl@0
|
793 |
* @return A pointer to a new CDSAKeyPair object
|
sl@0
|
794 |
*/
|
sl@0
|
795 |
IMPORT_C static CDSAKeyPair* NewLC(TUint aSize);
|
sl@0
|
796 |
|
sl@0
|
797 |
/**
|
sl@0
|
798 |
* Gets the DSA public key
|
sl@0
|
799 |
*
|
sl@0
|
800 |
* @return The DSA public key object
|
sl@0
|
801 |
*/
|
sl@0
|
802 |
IMPORT_C const CDSAPublicKey& PublicKey(void) const;
|
sl@0
|
803 |
|
sl@0
|
804 |
/**
|
sl@0
|
805 |
* Gets the DSA private key
|
sl@0
|
806 |
*
|
sl@0
|
807 |
* @return The DSA private key object
|
sl@0
|
808 |
*/
|
sl@0
|
809 |
IMPORT_C const CDSAPrivateKey& PrivateKey(void) const;
|
sl@0
|
810 |
|
sl@0
|
811 |
/**
|
sl@0
|
812 |
* Gets the DSA prime certificate (i.e., the seed and counter)
|
sl@0
|
813 |
*
|
sl@0
|
814 |
* @return The DSA prime certificate object
|
sl@0
|
815 |
*/
|
sl@0
|
816 |
IMPORT_C const CDSAPrimeCertificate& PrimeCertificate(void) const;
|
sl@0
|
817 |
|
sl@0
|
818 |
/** The destructor frees all resources owned by the object, prior to its destruction. */
|
sl@0
|
819 |
IMPORT_C virtual ~CDSAKeyPair(void);
|
sl@0
|
820 |
protected:
|
sl@0
|
821 |
/** Default constructor */
|
sl@0
|
822 |
IMPORT_C CDSAKeyPair(void);
|
sl@0
|
823 |
protected:
|
sl@0
|
824 |
/** The DSA public key */
|
sl@0
|
825 |
CDSAPublicKey* iPublic;
|
sl@0
|
826 |
/** The DSA private key */
|
sl@0
|
827 |
CDSAPrivateKey* iPrivate;
|
sl@0
|
828 |
/** The DSA prime certificate */
|
sl@0
|
829 |
CDSAPrimeCertificate* iPrimeCertificate;
|
sl@0
|
830 |
private:
|
sl@0
|
831 |
void ConstructL(TUint aSize);
|
sl@0
|
832 |
CDSAKeyPair(const CDSAKeyPair&);
|
sl@0
|
833 |
CDSAKeyPair& operator=(const CDSAKeyPair&);
|
sl@0
|
834 |
};
|
sl@0
|
835 |
|
sl@0
|
836 |
/**
|
sl@0
|
837 |
* Concrete class representing the parameters common to both
|
sl@0
|
838 |
* a Diffie-Hellman (DH) public and private key.
|
sl@0
|
839 |
*
|
sl@0
|
840 |
*/
|
sl@0
|
841 |
class CDHParameters : public CBase
|
sl@0
|
842 |
{
|
sl@0
|
843 |
public:
|
sl@0
|
844 |
/**
|
sl@0
|
845 |
* Gets the DH parameter, n
|
sl@0
|
846 |
*
|
sl@0
|
847 |
* @return An integer representing the DH parameter, n
|
sl@0
|
848 |
*/
|
sl@0
|
849 |
IMPORT_C const TInteger& N(void) const;
|
sl@0
|
850 |
|
sl@0
|
851 |
/**
|
sl@0
|
852 |
* Gets the DH parameter, g
|
sl@0
|
853 |
*
|
sl@0
|
854 |
* @return An integer representing the DH parameter, g
|
sl@0
|
855 |
*/
|
sl@0
|
856 |
IMPORT_C const TInteger& G(void) const;
|
sl@0
|
857 |
|
sl@0
|
858 |
/** Destructor */
|
sl@0
|
859 |
IMPORT_C virtual ~CDHParameters(void);
|
sl@0
|
860 |
protected:
|
sl@0
|
861 |
/**
|
sl@0
|
862 |
* Constructor
|
sl@0
|
863 |
*
|
sl@0
|
864 |
* @param aN The DH parameter, n
|
sl@0
|
865 |
* @param aG The DH parameter, g
|
sl@0
|
866 |
*/
|
sl@0
|
867 |
IMPORT_C CDHParameters(RInteger& aN, RInteger& aG);
|
sl@0
|
868 |
|
sl@0
|
869 |
/** Default constructor */
|
sl@0
|
870 |
IMPORT_C CDHParameters(void);
|
sl@0
|
871 |
protected:
|
sl@0
|
872 |
/**
|
sl@0
|
873 |
* The DH parameter, n (a prime number)
|
sl@0
|
874 |
*
|
sl@0
|
875 |
* <code>X = g^x mod n</code> (note the case sensitivity)
|
sl@0
|
876 |
*/
|
sl@0
|
877 |
RInteger iN;
|
sl@0
|
878 |
/**
|
sl@0
|
879 |
* The DH parameter, g (the generator)
|
sl@0
|
880 |
*
|
sl@0
|
881 |
* <code>X = g^x mod n</code> (note the case sensitivity)
|
sl@0
|
882 |
*/
|
sl@0
|
883 |
RInteger iG;
|
sl@0
|
884 |
private:
|
sl@0
|
885 |
CDHParameters(const CDHParameters&);
|
sl@0
|
886 |
CDHParameters& operator=(const CDHParameters&);
|
sl@0
|
887 |
};
|
sl@0
|
888 |
|
sl@0
|
889 |
/**
|
sl@0
|
890 |
* Representation of a Diffie-Hellman (DH) public key.
|
sl@0
|
891 |
*
|
sl@0
|
892 |
*/
|
sl@0
|
893 |
class CDHPublicKey : public CDHParameters
|
sl@0
|
894 |
{
|
sl@0
|
895 |
public:
|
sl@0
|
896 |
/**
|
sl@0
|
897 |
* Creates a new DH public key from a specified
|
sl@0
|
898 |
* large prime, generator, and random large integer.
|
sl@0
|
899 |
*
|
sl@0
|
900 |
* @param aN The DH parameter, n (a large prime)
|
sl@0
|
901 |
* @param aG The DH parameter, g (the generator)
|
sl@0
|
902 |
* @param aX The DH value, X
|
sl@0
|
903 |
* @return A pointer to a new CDHPublicKey object
|
sl@0
|
904 |
*/
|
sl@0
|
905 |
IMPORT_C static CDHPublicKey* NewL(RInteger& aN, RInteger& aG,
|
sl@0
|
906 |
RInteger& aX);
|
sl@0
|
907 |
|
sl@0
|
908 |
/**
|
sl@0
|
909 |
* Creates a new DH public key from a specified
|
sl@0
|
910 |
* large prime, generator, and random large integer.
|
sl@0
|
911 |
*
|
sl@0
|
912 |
* The returned pointer is put onto the cleanup stack.
|
sl@0
|
913 |
*
|
sl@0
|
914 |
* @param aN The DH parameter, n (a large prime)
|
sl@0
|
915 |
* @param aG The DH parameter, g (the generator)
|
sl@0
|
916 |
* @param aX The DH value, X
|
sl@0
|
917 |
* @return A pointer to a new CDHPublicKey object
|
sl@0
|
918 |
*/
|
sl@0
|
919 |
IMPORT_C static CDHPublicKey* NewLC(RInteger& aN, RInteger& aG,
|
sl@0
|
920 |
RInteger& aX);
|
sl@0
|
921 |
|
sl@0
|
922 |
/**
|
sl@0
|
923 |
* Gets the DH value, X
|
sl@0
|
924 |
*
|
sl@0
|
925 |
* @return The DH value, X
|
sl@0
|
926 |
*/
|
sl@0
|
927 |
IMPORT_C const TInteger& X(void) const;
|
sl@0
|
928 |
|
sl@0
|
929 |
/** Destructor */
|
sl@0
|
930 |
IMPORT_C virtual ~CDHPublicKey(void);
|
sl@0
|
931 |
protected:
|
sl@0
|
932 |
/**
|
sl@0
|
933 |
* Constructor
|
sl@0
|
934 |
*
|
sl@0
|
935 |
* @param aN The DH parameter, n (a large prime)
|
sl@0
|
936 |
* @param aG The DH parameter, g (the generator)
|
sl@0
|
937 |
* @param aX The DH value, X
|
sl@0
|
938 |
*/
|
sl@0
|
939 |
IMPORT_C CDHPublicKey(RInteger& aN, RInteger& aG, RInteger& aX);
|
sl@0
|
940 |
|
sl@0
|
941 |
/** Constructor */
|
sl@0
|
942 |
IMPORT_C CDHPublicKey(void);
|
sl@0
|
943 |
protected:
|
sl@0
|
944 |
/**
|
sl@0
|
945 |
* The DH value, X
|
sl@0
|
946 |
*
|
sl@0
|
947 |
* <code>X = g^x mod n</code> (note the case sensitivity)
|
sl@0
|
948 |
*/
|
sl@0
|
949 |
RInteger iX;
|
sl@0
|
950 |
private:
|
sl@0
|
951 |
CDHPublicKey(const CDHPublicKey&);
|
sl@0
|
952 |
CDHPublicKey& operator=(const CDHPublicKey&);
|
sl@0
|
953 |
};
|
sl@0
|
954 |
|
sl@0
|
955 |
/**
|
sl@0
|
956 |
* Representation of a Diffie-Hellman (DH) private key.
|
sl@0
|
957 |
*
|
sl@0
|
958 |
*/
|
sl@0
|
959 |
class CDHPrivateKey : public CDHParameters
|
sl@0
|
960 |
{
|
sl@0
|
961 |
public:
|
sl@0
|
962 |
/**
|
sl@0
|
963 |
* Creates a new DH private key from a specified
|
sl@0
|
964 |
* large prime, generator, and random large integer.
|
sl@0
|
965 |
*
|
sl@0
|
966 |
* @param aN The DH parameter, n (a large prime)
|
sl@0
|
967 |
* @param aG The DH parameter, g (the generator)
|
sl@0
|
968 |
* @param ax The DH value, x (a random large integer)
|
sl@0
|
969 |
* @return A pointer to a new CDHPrivateKey object
|
sl@0
|
970 |
*/
|
sl@0
|
971 |
IMPORT_C static CDHPrivateKey* NewL(RInteger& aN, RInteger& aG,
|
sl@0
|
972 |
RInteger& ax);
|
sl@0
|
973 |
|
sl@0
|
974 |
/**
|
sl@0
|
975 |
* Creates a new DH private key from a specified
|
sl@0
|
976 |
* large prime, generator, and random large integer.
|
sl@0
|
977 |
*
|
sl@0
|
978 |
* The returned pointer is put onto the cleanup stack.
|
sl@0
|
979 |
*
|
sl@0
|
980 |
* @param aN The DH parameter, n (a large prime)
|
sl@0
|
981 |
* @param aG The DH parameter, g (the generator)
|
sl@0
|
982 |
* @param ax The DH value, x (a random large integer)
|
sl@0
|
983 |
* @return A pointer to a new CDHPrivateKey object
|
sl@0
|
984 |
*/
|
sl@0
|
985 |
IMPORT_C static CDHPrivateKey* NewLC(RInteger& aN, RInteger& aG,
|
sl@0
|
986 |
RInteger& ax);
|
sl@0
|
987 |
|
sl@0
|
988 |
/**
|
sl@0
|
989 |
* Gets the DH value, x, which is a random large integer.
|
sl@0
|
990 |
*
|
sl@0
|
991 |
* @return The DH value, x
|
sl@0
|
992 |
*/
|
sl@0
|
993 |
IMPORT_C const TInteger& x(void) const;
|
sl@0
|
994 |
|
sl@0
|
995 |
/** Destructor */
|
sl@0
|
996 |
IMPORT_C virtual ~CDHPrivateKey(void);
|
sl@0
|
997 |
protected:
|
sl@0
|
998 |
/**
|
sl@0
|
999 |
* Constructor
|
sl@0
|
1000 |
*
|
sl@0
|
1001 |
* @param aN The DH parameter, n (a large prime)
|
sl@0
|
1002 |
* @param aG The DH parameter, g (the generator)
|
sl@0
|
1003 |
* @param ax The DH value, x (a random large integer)
|
sl@0
|
1004 |
*/
|
sl@0
|
1005 |
IMPORT_C CDHPrivateKey(RInteger& aN, RInteger& aG, RInteger& ax);
|
sl@0
|
1006 |
|
sl@0
|
1007 |
/** Constructor */
|
sl@0
|
1008 |
IMPORT_C CDHPrivateKey(void);
|
sl@0
|
1009 |
protected:
|
sl@0
|
1010 |
/**
|
sl@0
|
1011 |
* The DH value, x, which is a random large integer.
|
sl@0
|
1012 |
*
|
sl@0
|
1013 |
* <code>X = g^x mod n</code> (note the case sensitivity)
|
sl@0
|
1014 |
*/
|
sl@0
|
1015 |
RInteger ix;
|
sl@0
|
1016 |
private:
|
sl@0
|
1017 |
CDHPrivateKey(const CDHPrivateKey&);
|
sl@0
|
1018 |
CDHPrivateKey& operator=(const CDHPrivateKey&);
|
sl@0
|
1019 |
};
|
sl@0
|
1020 |
|
sl@0
|
1021 |
/**
|
sl@0
|
1022 |
* This class is capable of generating a Diffie-Hellman (DH) public/private key pair.
|
sl@0
|
1023 |
*
|
sl@0
|
1024 |
*/
|
sl@0
|
1025 |
class CDHKeyPair : public CBase
|
sl@0
|
1026 |
{
|
sl@0
|
1027 |
public:
|
sl@0
|
1028 |
/**
|
sl@0
|
1029 |
* Creates a new DH key pair from a random large integer,
|
sl@0
|
1030 |
* and a specified large prime and generator.
|
sl@0
|
1031 |
*
|
sl@0
|
1032 |
* @param aN The DH parameter, n (a large prime)
|
sl@0
|
1033 |
* @param aG The DH parameter, g (the generator)
|
sl@0
|
1034 |
* @return A pointer to a new CDHKeyPair object
|
sl@0
|
1035 |
*
|
sl@0
|
1036 |
* @leave KErrArgument If aG is out of bounds
|
sl@0
|
1037 |
*/
|
sl@0
|
1038 |
IMPORT_C static CDHKeyPair* NewL(RInteger& aN, RInteger& aG);
|
sl@0
|
1039 |
|
sl@0
|
1040 |
/**
|
sl@0
|
1041 |
* Creates a new DH key pair from a random large integer,
|
sl@0
|
1042 |
* and a specified large prime and generator.
|
sl@0
|
1043 |
*
|
sl@0
|
1044 |
* The returned pointer is put onto the cleanup stack.
|
sl@0
|
1045 |
*
|
sl@0
|
1046 |
* @param aN The DH parameter, n (a large prime)
|
sl@0
|
1047 |
* @param aG The DH parameter, g (the generator)
|
sl@0
|
1048 |
* @return A pointer to a new CDHKeyPair object
|
sl@0
|
1049 |
*
|
sl@0
|
1050 |
* @leave KErrArgument If aG is out of bounds
|
sl@0
|
1051 |
*/
|
sl@0
|
1052 |
IMPORT_C static CDHKeyPair* NewLC(RInteger& aN, RInteger& aG);
|
sl@0
|
1053 |
|
sl@0
|
1054 |
/**
|
sl@0
|
1055 |
* Creates a new DH key pair from a specified
|
sl@0
|
1056 |
* large prime, generator, and random large integer.
|
sl@0
|
1057 |
*
|
sl@0
|
1058 |
* @param aN The DH parameter, n (a large prime)
|
sl@0
|
1059 |
* @param aG The DH parameter, g (the generator)
|
sl@0
|
1060 |
* @param ax The DH value, x (a random large integer)
|
sl@0
|
1061 |
* @return A pointer to a new CDHKeyPair object
|
sl@0
|
1062 |
*
|
sl@0
|
1063 |
* @leave KErrArgument If either aG or ax are out of bounds
|
sl@0
|
1064 |
*/
|
sl@0
|
1065 |
IMPORT_C static CDHKeyPair* NewL(RInteger& aN, RInteger& aG, RInteger& ax);
|
sl@0
|
1066 |
|
sl@0
|
1067 |
/**
|
sl@0
|
1068 |
* Creates a new DH key pair from a specified
|
sl@0
|
1069 |
* large prime, generator, and random large integer.
|
sl@0
|
1070 |
*
|
sl@0
|
1071 |
* The returned pointer is put onto the cleanup stack.
|
sl@0
|
1072 |
*
|
sl@0
|
1073 |
* @param aN The DH parameter, n (a large prime)
|
sl@0
|
1074 |
* @param aG The DH parameter, g (the generator)
|
sl@0
|
1075 |
* @param ax The DH value, x (a random large integer)
|
sl@0
|
1076 |
* @return A pointer to a new CDHKeyPair object
|
sl@0
|
1077 |
*
|
sl@0
|
1078 |
* @leave KErrArgument If either aG or ax are out of bounds
|
sl@0
|
1079 |
*/
|
sl@0
|
1080 |
IMPORT_C static CDHKeyPair* NewLC(RInteger& aN, RInteger& aG, RInteger& ax);
|
sl@0
|
1081 |
|
sl@0
|
1082 |
/**
|
sl@0
|
1083 |
* Gets the DH public key
|
sl@0
|
1084 |
*
|
sl@0
|
1085 |
* @return The DH public key
|
sl@0
|
1086 |
*/
|
sl@0
|
1087 |
IMPORT_C const CDHPublicKey& PublicKey(void) const;
|
sl@0
|
1088 |
|
sl@0
|
1089 |
/**
|
sl@0
|
1090 |
* Gets the DH private key
|
sl@0
|
1091 |
*
|
sl@0
|
1092 |
* @return The DH private key
|
sl@0
|
1093 |
*/
|
sl@0
|
1094 |
IMPORT_C const CDHPrivateKey& PrivateKey(void) const;
|
sl@0
|
1095 |
|
sl@0
|
1096 |
/** The destructor frees all resources owned by the object, prior to its destruction. */
|
sl@0
|
1097 |
IMPORT_C virtual ~CDHKeyPair(void);
|
sl@0
|
1098 |
protected:
|
sl@0
|
1099 |
/** Default constructor */
|
sl@0
|
1100 |
IMPORT_C CDHKeyPair(void);
|
sl@0
|
1101 |
|
sl@0
|
1102 |
/**
|
sl@0
|
1103 |
* Constructor
|
sl@0
|
1104 |
*
|
sl@0
|
1105 |
* @param aN The DH parameter, n (a large prime)
|
sl@0
|
1106 |
* @param aG The DH parameter, g (the generator)
|
sl@0
|
1107 |
*/
|
sl@0
|
1108 |
IMPORT_C void ConstructL(RInteger& aN, RInteger& aG);
|
sl@0
|
1109 |
|
sl@0
|
1110 |
/**
|
sl@0
|
1111 |
* Constructor
|
sl@0
|
1112 |
*
|
sl@0
|
1113 |
* @param aN The DH parameter, n (a large prime)
|
sl@0
|
1114 |
* @param aG The DH parameter, g (the generator)
|
sl@0
|
1115 |
* @param ax The DH value, x (a random large integer)
|
sl@0
|
1116 |
*/
|
sl@0
|
1117 |
IMPORT_C void ConstructL(RInteger& aN, RInteger& aG, RInteger& ax);
|
sl@0
|
1118 |
|
sl@0
|
1119 |
protected:
|
sl@0
|
1120 |
/** The DH public key */
|
sl@0
|
1121 |
CDHPublicKey* iPublic;
|
sl@0
|
1122 |
/** The DH private key */
|
sl@0
|
1123 |
CDHPrivateKey* iPrivate;
|
sl@0
|
1124 |
private:
|
sl@0
|
1125 |
CDHKeyPair(const CDHKeyPair&);
|
sl@0
|
1126 |
CDHKeyPair& operator=(const CDHKeyPair&);
|
sl@0
|
1127 |
};
|
sl@0
|
1128 |
#endif // __ASYMMETRICKEYS_H__
|