crypto/weakcryptospi/inc/spi/cryptosymmetriccipherapi.h
changeset 8 35751d3474b7
child 30 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 symmetric cipher application interface
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 /**
       
    21  @file
       
    22  @publishedPartner
       
    23  @released
       
    24 */
       
    25 
       
    26 #ifndef __CRYPTOAPI_SYMMETRICCIPHERAPI_H__
       
    27 #define __CRYPTOAPI_SYMMETRICCIPHERAPI_H__
       
    28 
       
    29 #include <e32base.h>
       
    30 #include <cryptospi/cryptobaseapi.h>
       
    31 
       
    32 namespace CryptoSpi
       
    33 	{
       
    34 	class MSymmetricCipherBase;
       
    35 	class MSymmetricCipher;
       
    36 	class MAsyncSymmetricCipher;
       
    37 	class CKey;
       
    38 	class CCryptoParams;
       
    39 	
       
    40 	NONSHARABLE_CLASS(CSymmetricCipherBase) : public CCryptoBase
       
    41 		{
       
    42 	public:
       
    43 		/**
       
    44 		Destructor
       
    45 		*/		
       
    46 		virtual ~CSymmetricCipherBase();
       
    47 		
       
    48 		/**
       
    49 		Set the key of this cipher. Reset() is called to reinitialise the cipher.
       
    50 		@param aKey	The symmetric key.
       
    51 		*/
       
    52 		IMPORT_C void SetKeyL(const CKey& aKey);
       
    53 
       
    54 		/**
       
    55 		Set the operation mode of this cipher. Reset() is called to reinitialise the cipher.
       
    56 		@param aOperationMode	The operation mode e.g. CBC, ECB etc
       
    57 		*/
       
    58 		IMPORT_C void SetOperationModeL(TUid aOperationMode);
       
    59 
       
    60 		/**
       
    61 		Set the crypto mode of this cipher. Reset() is called to reinitialise the cipher.
       
    62 		@param aCryptoMode	The crypto mode e.g encryption, decryption
       
    63 		*/
       
    64 		IMPORT_C void SetCryptoModeL(TUid aCryptoMode);
       
    65 
       
    66 		/**
       
    67 		Set padding mode of this cipher. Reset() is called to reinitialise the cipher.
       
    68 		@param aPaddingMode	The padding mode e.g. SSLv3, PKCS7
       
    69 		*/
       
    70 		IMPORT_C void SetPaddingModeL(TUid aPaddingMode);
       
    71 
       
    72 		/**
       
    73 		Set the initialization vector of this cipher. Reset() is called to reinitialise the cipher.
       
    74 		@param aIV The initialization vector.
       
    75 		*/
       
    76 		IMPORT_C void SetIvL(const TDesC8& aIv);
       
    77 
       
    78 		/**
       
    79 		Returns the maximum length that an output buffer would need to be in order to hold the result 
       
    80 		of the next process operation, given the input length inputLen and the internal
       
    81 		state of the state of the cipher.
       
    82 		@param aInputLength	The length of the input to process
       
    83 		@return The length of the output buffer
       
    84 		*/
       
    85 		IMPORT_C TInt MaxOutputLength(TInt aInputLength);
       
    86 		
       
    87 		/**
       
    88 		Returns the maximum length that an output buffer would need to be in order to hold the result 
       
    89 		of the next processfinal operation, given the input length inputLen and the
       
    90 		internal state of the cipher.
       
    91 		@param aInputLength	The length of input to process
       
    92 		@return The length of the output buffer
       
    93 		*/
       
    94 		IMPORT_C TInt MaxFinalOutputLength(TInt aInputLength);
       
    95 
       
    96 		/**
       
    97 		Returns the block size in bits. For stream ciphers this is defined to be
       
    98 		8-bits.
       
    99 		@return The block size in bits
       
   100 		*/
       
   101 		IMPORT_C TInt BlockSize();
       
   102 		
       
   103 		/**
       
   104 		Returns the size of the current key in bits.
       
   105 		@return The size of the current key in bits
       
   106 		*/
       
   107 		IMPORT_C TInt KeySize();
       
   108 
       
   109 	protected:
       
   110 		/**
       
   111 		 * @internalComponent
       
   112 		 *
       
   113 		 * Constructor
       
   114 		 **/
       
   115 		CSymmetricCipherBase(MSymmetricCipherBase* aSymmetricCipher, TInt aHandle);		
       
   116 		};
       
   117 
       
   118 
       
   119 	/**
       
   120 	Symmetric Cipher API, which wraps a synchronous Symmetric Cipher plugin implementation
       
   121 	*/
       
   122 	NONSHARABLE_CLASS(CSymmetricCipher) : public CSymmetricCipherBase
       
   123 		{
       
   124 	public:
       
   125 
       
   126 		/**
       
   127 		 * @internalComponent
       
   128 		 *
       
   129 		 * Create a CSymmetricCipher instance from the given MSymmetricCipher instance
       
   130 		 * @param aSymmetricCipher an Sync Symmetric Cipher plugin instance
       
   131 		 * @return A pointer to a CSymmetricCipher instance
       
   132 		 **/
       
   133 		static CSymmetricCipher* NewL(MSymmetricCipher* aSymmetricCipher, TInt aHandle);
       
   134 
       
   135 		/**
       
   136 		Destructor
       
   137 		*/
       
   138 		IMPORT_C ~CSymmetricCipher();
       
   139 
       
   140 		/**
       
   141 		Encrypts or decrypts aInput and appends the result to aOutput.
       
   142 		@param aInput	The input data to be processed.
       
   143 		@param aOutput	The resulting processed data appended to aOutput.		
       
   144 		*/
       
   145 		IMPORT_C void ProcessL(const TDesC8& aInput, TDes8& aOutput);
       
   146 
       
   147 		/**
       
   148 		Pads aInput to be block aligned using the underlying padding system, then
       
   149 		encrypts or decrypts the input data, and appends the result to aOutput
       
   150 		@param aInput  The input buffer to be encrypted or decrypted.
       
   151 		@param aOutput The resulting, padded, processed data is appended to aOutput.
       
   152 		*/
       
   153 		IMPORT_C void ProcessFinalL(const TDesC8& aInput, TDes8& aOutput);
       
   154 		
       
   155 	private:
       
   156 		/**
       
   157 		Constructor
       
   158 		*/
       
   159 		CSymmetricCipher(MSymmetricCipher* aSymmetricCipher, TInt aHandle);
       
   160 		};
       
   161 
       
   162 	/**
       
   163 	Async Symmetric Cipher API, which wraps an asynchronous Symmetric Cipher plugin implementation
       
   164 	*/
       
   165 	NONSHARABLE_CLASS(CAsyncSymmetricCipher) : public CSymmetricCipherBase
       
   166 		{
       
   167 	public:
       
   168 
       
   169 		/**
       
   170 		 * @internalComponent
       
   171 		 *
       
   172 		 * Create a CAsyncSymmetricCipher instance from the given MAsyncSymmetricCipher instance
       
   173 		 * @param aAsyncSymmetricCipher an async Symmetric Cipher plugin instance
       
   174 		 * @return A pointer to a CAsyncSymmetricCipher instance
       
   175 		 **/
       
   176 		static CAsyncSymmetricCipher* NewL(MAsyncSymmetricCipher* aAsyncSymmetricCipher, TInt aHandle);
       
   177 
       
   178 		/**
       
   179 		Destructor
       
   180 		*/
       
   181 		IMPORT_C ~CAsyncSymmetricCipher();
       
   182 
       
   183 		/**
       
   184 		Encrypts or decrypts aInput and appends the result to aOutput asynchronously
       
   185 		@param aInput	The input data to be processed.
       
   186 		@param aOutput	The resulting processed data appended to aOutput.		
       
   187 		@param aRequestStatus
       
   188 		*/
       
   189 		IMPORT_C void ProcessL(const TDesC8& aInput, TDes8& aOutput, TRequestStatus& aRequestStatus);
       
   190 
       
   191 		/**
       
   192 		Asynchronously pads aInput to be block aligned using the underlying padding system,
       
   193 		encrypts or decrypts the input data, and appends the result to aOutput
       
   194 		@param aInput  The input buffer to be encrypted or decrypted.
       
   195 		@param aOutput The resulting, padded, processed data is appended to aOutput.
       
   196 		@param aRequestStatus
       
   197 		*/
       
   198 		IMPORT_C void ProcessFinalL(const TDesC8& aInput, TDes8& aOutput, TRequestStatus& aRequestStatus);
       
   199 
       
   200 		/**
       
   201 		Cancel the outstanding request
       
   202 		*/
       
   203 		IMPORT_C void Cancel();
       
   204 		
       
   205 	private:
       
   206 		/**
       
   207 		Construtor
       
   208 		*/
       
   209 		CAsyncSymmetricCipher(MAsyncSymmetricCipher* aAsyncSymmetricCipher, TInt aHandle);
       
   210 		};
       
   211 
       
   212 
       
   213 	/**
       
   214 	This Factory to create synchronous and asynchronous symmetric cipher instances
       
   215 	*/
       
   216 	class CSymmetricCipherFactory
       
   217 		{
       
   218 	public:
       
   219 
       
   220 		/**
       
   221 		Creates a new synchronous instance of a symmetric cipher
       
   222 		
       
   223 		@param aCipher	A reference to a pointer that should be set to point to the new symmetric object.
       
   224 		@param aAlgorithmUid The algorithm to use
       
   225 		@param aKey The encryption/decryption key.
       
   226 		@param aCryptoMode The Symmetric cipher mode.
       
   227 		@param aOperationMode The Symmetric cipher operation mode.
       
   228 		@param aPaddingMode The Symmetric cipher padding mode.
       
   229 		@param aAlgorithmParams Parameters that are specific to a particular algorithm. This is for extendibility and will normally be null.
       
   230 		@return KErrNone if successful; otherwise, a system wide error code.
       
   231 		*/
       
   232 		IMPORT_C static void CreateSymmetricCipherL(CSymmetricCipher*& aCipher,
       
   233 													TUid aAlgorithmUid,
       
   234 													const CKey& aKey,
       
   235 													TUid aCryptoMode,
       
   236 													TUid aOperationMode,
       
   237 													TUid aPaddingMode,
       
   238 													const CCryptoParams* aAlgorithmParams);
       
   239 
       
   240 		/**
       
   241 		Creates a new asynchronous instance of a symmetric cipher
       
   242 
       
   243 		@param aAsyncCipher A reference to a pointer that should be set to point to the new symmetric object.
       
   244 		@param aAlgorithmUid The algorithm to use
       
   245 		@param aKey The encryption/decryption key.
       
   246 		@param aCryptoMode The Symmetric cipher mode.
       
   247 		@param aOperationMode The Symmetric cipher operation mode.
       
   248 		@param aPaddingMode The Symmetric cipher padding mode.
       
   249 		@param aAlgorithmParams Parameters that are specific to a particular algorithm. This is for extendibility and will normally be null.
       
   250 		@return KErrNone if successful; otherwise, a system wide error code.
       
   251 		*/
       
   252 		IMPORT_C static void CreateAsyncSymmetricCipherL(CAsyncSymmetricCipher*& aAsyncCipher,
       
   253 														TUid aAlgorithmUid,
       
   254 														const CKey& aKey,
       
   255 														TUid aCryptoMode,
       
   256 														TUid aOperationMode,
       
   257 														TUid aPaddingMode,
       
   258 														const CCryptoParams* aAlgorithmParams);
       
   259 
       
   260 		};
       
   261 	}
       
   262 
       
   263 #endif //__CRYPTOAPI_SYMMETRICCIPHERAPI_H__