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