crypto/weakcryptospi/inc/spi/cryptoasymmetriccipherapi.h
changeset 8 35751d3474b7
child 33 cf642210ecb7
equal deleted inserted replaced
2:675a964f4eb5 8:35751d3474b7
       
     1 /*
       
     2 * Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 * crypto asymmetric cipher application interface
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 /**
       
    21  @file
       
    22  @publishedPartner
       
    23  @released
       
    24 */
       
    25 
       
    26 #ifndef __CRYPTOAPI_ASYMMETRICCIPHERAPI_H__
       
    27 #define __CRYPTOAPI_ASYMMETRICCIPHERAPI_H__
       
    28 
       
    29 #include <e32base.h>
       
    30 #include <cryptospi/cryptobaseapi.h>
       
    31 
       
    32 namespace CryptoSpi
       
    33 	{
       
    34 	class MAsymmetricCipherBase;
       
    35 	class MAsymmetricCipher;
       
    36 	class MAsyncAsymmetricCipher;
       
    37 	class CKey;
       
    38 	class CCryptoParam;
       
    39 	class CCryptoParams;
       
    40 	
       
    41 	/**
       
    42 	Asymmetric Cipher API base class
       
    43 	*/
       
    44 	NONSHARABLE_CLASS(CAsymmetricCipherBase) : public CCryptoBase
       
    45 		{
       
    46 	public:
       
    47 		/**
       
    48 		Destructor
       
    49 		*/
       
    50 		virtual ~CAsymmetricCipherBase();
       
    51 	
       
    52 		/**
       
    53 		Set the public key of this cipher. Reset() is called to reinitialise the cipher.
       
    54 		@param aKey  the public key.
       
    55 		*/
       
    56 		IMPORT_C void SetKeyL(const CKey& aKey);
       
    57 
       
    58 		/**
       
    59 		Set the crypto mode of this cipher. Reset() is called to reinitialise the cipher.
       
    60 		@param aCryptoMode crypto mode
       
    61 		*/
       
    62 		IMPORT_C void SetCryptoModeL(TUid aCryptoMode);
       
    63 
       
    64 		/**
       
    65 		Set padding Mode of this cipher. Reset() is called to reinitialise the cipher.
       
    66 		@param aPaddingMode padding mode
       
    67 		*/
       
    68 		IMPORT_C void SetPaddingModeL(TUid aPaddingMode);
       
    69 
       
    70 		/**
       
    71 		Gets the maximum size of input accepted by this object.	
       
    72 		@return	The maximum input length allowed in bytes.
       
    73 		*/	 
       
    74 		IMPORT_C TInt GetMaximumInputLengthL();
       
    75 
       
    76 		/**
       
    77 		Gets the maximum size of output that can be generated by this object.
       
    78 		@return	The maximum output length in bytes.
       
    79 		 */	 
       
    80 		IMPORT_C TInt GetMaximumOutputLengthL();
       
    81 		
       
    82 	
       
    83 	protected:
       
    84 		/**
       
    85 		Constructor
       
    86 		*/
       
    87 		CAsymmetricCipherBase(MAsymmetricCipherBase* aAsymmetricCipher, TInt aHandle);		
       
    88 		};
       
    89 
       
    90 	/**
       
    91 	Synchronous asymmetric cipher API, which wraps a synchronous asymmetric plugin implementation
       
    92 	*/
       
    93 	NONSHARABLE_CLASS(CAsymmetricCipher) : public CAsymmetricCipherBase
       
    94 		{
       
    95 	public:
       
    96 
       
    97 		/**
       
    98 		 * @internalComponent
       
    99 		 *
       
   100 		 * Create a CSyncAsymmetricCipher instance from the given MSyncAsymmetricCipher instance
       
   101 		 * @param aAsymmetricCipher a  Async Asymmetric Cipher plugin instance
       
   102 		 * @return Pointer to CSyncAsymmetricCipher
       
   103 		 */
       
   104 		static CAsymmetricCipher* NewL(MAsymmetricCipher* aAsymmetricCipher, TInt aHandle);
       
   105 
       
   106 		/**
       
   107 		Destructor
       
   108 		*/
       
   109 		IMPORT_C ~CAsymmetricCipher();
       
   110 
       
   111 
       
   112 		/**
       
   113 		Encrypts or decrypts aInput and appends the result to aOutput.
       
   114 		@param aInput	The input data to be processed.
       
   115 		@param aOutput	The resulting processed data appended to aOutput.
       
   116 		*/
       
   117 		IMPORT_C void ProcessL(const TDesC8& aInput, TDes8& aOutput);
       
   118 
       
   119 	private:
       
   120 		
       
   121 		/**
       
   122 		Constructor
       
   123 		*/
       
   124 		CAsymmetricCipher(MAsymmetricCipher* aAsymmetricCipher, TInt aHandle);
       
   125 		};
       
   126 
       
   127 	/**
       
   128 	Asynchronous asymmetric cipher API, which wraps a Asynchronous asymmetric plugin implementation
       
   129 	*/
       
   130 	NONSHARABLE_CLASS(CAsyncAsymmetricCipher) : public CAsymmetricCipherBase
       
   131 		{
       
   132 	public:
       
   133 
       
   134 		/**
       
   135 		 * @internalComponent
       
   136 		 * 
       
   137 		 * Create a CAsyncAsymmetricCipher instance from the given MAsyncAsymmetricCipher instance
       
   138 		 * @param aAsyncAsymmetricCipher an async asymmetric Cipher plugin instance
       
   139 		 * @return Pointer to CAsyncAsymmetricCipher
       
   140 		 */
       
   141 		static CAsyncAsymmetricCipher* NewL(MAsyncAsymmetricCipher* aAsyncAsymmetricCipher, TInt aHandle);
       
   142 
       
   143 		/**
       
   144 		Destructor
       
   145 		*/
       
   146 		IMPORT_C ~CAsyncAsymmetricCipher();
       
   147 
       
   148 		/**
       
   149 		Encrypts or decrypts aInput and appends the result to aOutput asynchronously
       
   150 		@param aInput		The input data to be processed.
       
   151 		@param aOutput	The resulting processed data appended to aOutput.
       
   152 		@param aRequestStatus
       
   153 		*/
       
   154 		IMPORT_C void ProcessL(const TDesC8& aInput, TDes8& aOutput, TRequestStatus& aRequestStatus);
       
   155 
       
   156 		/**
       
   157 		Cancel the outstanding request
       
   158 		*/
       
   159 		IMPORT_C void Cancel();
       
   160 
       
   161 	private:
       
   162 		/**
       
   163 		Constructor
       
   164 		*/
       
   165 		CAsyncAsymmetricCipher(MAsyncAsymmetricCipher* aAsyncAsymmetricCipher, TInt aHandle);
       
   166 		};
       
   167 
       
   168 
       
   169 	/**
       
   170 	the Factory to create synchronous and asynchronous asymmetric cipher instance 
       
   171 	*/
       
   172 	class CAsymmetricCipherFactory
       
   173 		{
       
   174 	public:
       
   175 
       
   176 		/**
       
   177 		Creates a new instance of an asymmetric cipher
       
   178 		
       
   179 		@param aCipher A reference to a pointer that should be set to point to the new asymmetric cipher object.
       
   180 		@param aAlgorithmUid The asymmetric cipher algorithm to use (e.g. KRsaCipherUid)
       
   181 		@param aKey The encryption/decryption key.
       
   182 		@param aCryptoMode whether to encrypt or decrypt
       
   183 		@param aPaddingMode The padding mode to use
       
   184 		@param aAlgorithmParams Parameters that are specific to a particular algorithm. This is for extendibility and will normally be null.
       
   185 		@return KErrNone if successful; otherwise, a system wide error code.
       
   186 		*/
       
   187 		IMPORT_C static void CreateAsymmetricCipherL(
       
   188 												CAsymmetricCipher*& aCipher,
       
   189 												TUid aAlgorithmUid,
       
   190 												const CKey& aKey,
       
   191 												TUid aCryptoMode,
       
   192 												TUid aPaddingMode,
       
   193 												const CCryptoParams* aAlgorithmParams);
       
   194 
       
   195 		/**
       
   196 		Creates a new instance of an asymmetric cipher.
       
   197 		
       
   198 		@param aCipher A reference to a pointer that should be set to point to the new asymmetric cipher object.
       
   199 		@param aAlgorithmUid The asymmetric cipher algorithm to use (e.g. KRsaCipherUid)
       
   200 		@param aKey The encryption/decryption key.
       
   201 		@param aCryptoMode whether to encrypt or decrypt
       
   202 		@param aPaddingMode The padding mode to use
       
   203 		@param aAlgorithmParams Parameters that are specific to a particular algorithm. This is for extendibility and will normally be null.
       
   204 		@return KErrNone if successful; otherwise, a system wide error code.
       
   205 		*/
       
   206 		IMPORT_C static void CreateAsyncAsymmetricCipherL(
       
   207 												CAsyncAsymmetricCipher*& aCipher,
       
   208 												TUid aAlgorithmUid,
       
   209 												const CKey& aKey,
       
   210 												TUid aCryptoMode,
       
   211 												TUid aPaddingMode,
       
   212 												const CCryptoParams* aAlgorithmParams);
       
   213 		};
       
   214 		
       
   215 	}
       
   216 
       
   217 #endif //__CRYPTOAPI_ASYMMETRICCIPHERAPI_H__
       
   218