sl@0: /*
sl@0: * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0: * All rights reserved.
sl@0: * This component and the accompanying materials are made available
sl@0: * under the terms of the License "Eclipse Public License v1.0"
sl@0: * which accompanies this distribution, and is available
sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0: *
sl@0: * Initial Contributors:
sl@0: * Nokia Corporation - initial contribution.
sl@0: *
sl@0: * Contributors:
sl@0: *
sl@0: * Description: 
sl@0: *
sl@0: */
sl@0: 
sl@0: 
sl@0: #ifndef __DSAKEYPAIRGENIMPL_H__
sl@0: #define __DSAKEYPAIRGENIMPL_H__
sl@0: 
sl@0: /**
sl@0: @file 
sl@0: @internalComponent
sl@0: @released
sl@0: */
sl@0: 
sl@0: #include <e32base.h>
sl@0: #include <e32cmn.h>
sl@0: #include "keypairgenimpl.h"
sl@0: //#include <asymmetrickeys.h>
sl@0: 
sl@0: /**
sl@0:  * Implementation of DSA key pair generation.
sl@0:  */
sl@0: namespace SoftwareCrypto
sl@0: 	{
sl@0: 	NONSHARABLE_CLASS(CDSAPrimeCertificate) : public CBase
sl@0: 		{
sl@0: 	public:
sl@0: 		/** 
sl@0: 		Creates a new DSA prime certificate from a specified 
sl@0: 		seed and counter value.
sl@0:  
sl@0: 		@param aSeed	The seed from a DSA key generation process
sl@0: 		@param aCounter	The counter value from a DSA key generation process
sl@0: 		@return			A pointer to a CDSAPrimeCertificate instance
sl@0: 		*/
sl@0: 		static CDSAPrimeCertificate* NewL(const TDesC8& aSeed, TUint aCounter);
sl@0: 
sl@0: 		/** 
sl@0: 		Creates a new DSA prime certificate from a specified 
sl@0: 		seed and counter value.
sl@0: 		
sl@0: 		The returned pointer is put onto the cleanup stack.
sl@0: 		
sl@0: 		@param aSeed		The seed from a DSA key generation process
sl@0: 		@param aCounter	The counter value from a DSA key generation process
sl@0: 		@return			A pointer to a CDSAPrimeCertificate instance
sl@0: 		*/
sl@0: 		static CDSAPrimeCertificate* NewLC(const TDesC8& aSeed, TUint aCounter);
sl@0: 
sl@0: 		/**
sl@0: 		Gets the seed of the DSA prime certificate
sl@0: 		@return	The seed
sl@0: 		*/
sl@0: 		const TDesC8& Seed() const;
sl@0: 		
sl@0: 		/**
sl@0: 		Gets the counter value of the DSA prime certificate
sl@0: 
sl@0: 		@return	The counter's value
sl@0: 		*/
sl@0: 		TUint Counter() const;
sl@0: 		
sl@0: 		/** 
sl@0: 		Destructor 
sl@0: 		*/
sl@0: 		~CDSAPrimeCertificate();
sl@0: 		
sl@0: 	protected:
sl@0: 		/** 
sl@0: 		Constructor
sl@0: 		@param aCounter	The DSA key generation counter
sl@0: 		*/
sl@0: 		CDSAPrimeCertificate(TUint aCounter);
sl@0: 
sl@0: 		/**
sl@0: 		Default constructor
sl@0: 		*/
sl@0: 		CDSAPrimeCertificate();
sl@0: 
sl@0: 		void ConstructL(const TDesC8& aSeed);
sl@0: 		
sl@0: 	protected:
sl@0: 		/** 
sl@0: 		The DSA key generation seed 
sl@0: 		*/
sl@0: 		const HBufC8* iSeed;
sl@0: 		/** 
sl@0: 		The DSA key generation counter 
sl@0: 		*/
sl@0: 		TUint iCounter;
sl@0: 	private:
sl@0: 		CDSAPrimeCertificate(const CDSAPrimeCertificate&);
sl@0: 		CDSAPrimeCertificate& operator=(const CDSAPrimeCertificate&);
sl@0: 		};
sl@0: 		
sl@0: 	NONSHARABLE_CLASS(CDSAKeyPairGenImpl) : public CKeyPairGenImpl
sl@0: 		{
sl@0: 	public:
sl@0: 	
sl@0: 		static CDSAKeyPairGenImpl* NewL();
sl@0: 		static CDSAKeyPairGenImpl* NewLC();
sl@0: 
sl@0: 		// from MPlugin
sl@0: 		void Reset();
sl@0: 
sl@0: 		// from MKeyPairGenerator
sl@0: 		void GenerateKeyPairL(TInt aKeySize, const CCryptoParams& aKeyParameters, CKeyPair*& aKeyPair);
sl@0: 		
sl@0: 		// Override CKeyPairGenImpl virtual functions
sl@0: 		TUid ImplementationUid() const;
sl@0: 		
sl@0: 		// Destructor
sl@0: 		~CDSAKeyPairGenImpl();
sl@0: 
sl@0: 		static TBool GeneratePrimesL(const TDesC8& aSeed,
sl@0: 									 TUint& aCounter, 
sl@0: 									 RInteger& aP, 
sl@0: 									 TUint aL, 
sl@0: 									 RInteger& aQ, 
sl@0: 									 TBool aUseInputCounter=EFalse);
sl@0: 									 
sl@0: 		static TBool ValidPrimeLength(TUint aPrimeBits);
sl@0: 		
sl@0: 	private:
sl@0: 		/**
sl@0: 		Constructor
sl@0: 		*/
sl@0: 		CDSAKeyPairGenImpl();
sl@0: 			
sl@0: 		/// second phase of construction
sl@0: 		void ConstructL();
sl@0: 		
sl@0: 		CDSAPrimeCertificate* iPrimeCertificate;
sl@0: 		};
sl@0: 	}
sl@0: 
sl@0: #endif // __DSAKEYPAIRGENIMPL_H__