sl@0: /* sl@0: * Copyright (c) 2006-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: * crypto symmetric cipher application interface sl@0: * sl@0: */ sl@0: sl@0: sl@0: /** sl@0: @file sl@0: @publishedPartner sl@0: @released sl@0: */ sl@0: sl@0: #ifndef __CRYPTOAPI_SYMMETRICCIPHERAPI_H__ sl@0: #define __CRYPTOAPI_SYMMETRICCIPHERAPI_H__ sl@0: sl@0: #include sl@0: #include sl@0: sl@0: namespace CryptoSpi sl@0: { sl@0: class MSymmetricCipherBase; sl@0: class MSymmetricCipher; sl@0: class MAsyncSymmetricCipher; sl@0: class CKey; sl@0: class CCryptoParams; sl@0: sl@0: NONSHARABLE_CLASS(CSymmetricCipherBase) : public CCryptoBase sl@0: { sl@0: public: sl@0: /** sl@0: Destructor sl@0: */ sl@0: virtual ~CSymmetricCipherBase(); sl@0: sl@0: /** sl@0: Set the key of this cipher. Reset() is called to reinitialise the cipher. sl@0: @param aKey The symmetric key. sl@0: @leave KErrArgument if aKey is not of the expected type. sl@0: @leave KErrNotSupported if the key is not of valid length. sl@0: @leave ... Any of the crypto error codes defined in sl@0: cryptospi_errs.h or any of the system-wide error codes. sl@0: */ sl@0: IMPORT_C void SetKeyL(const CKey& aKey); sl@0: sl@0: /** sl@0: Set the operation mode of this cipher. Reset() is called to reinitialise the cipher. sl@0: @param aOperationMode The operation mode e.g. CBC, ECB etc sl@0: @leave KErrNotSupported if the operation mode is not supported. sl@0: @leave ... Any of the crypto error codes defined in sl@0: cryptospi_errs.h or any of the system-wide error codes. sl@0: */ sl@0: IMPORT_C void SetOperationModeL(TUid aOperationMode); sl@0: sl@0: /** sl@0: Set the crypto mode of this cipher. Reset() is called to reinitialise the cipher. sl@0: @param aCryptoMode The crypto mode e.g encryption, decryption sl@0: @leave KErrNotSupported if the crypto mode is not supported. sl@0: @leave ... Any of the crypto error codes defined in sl@0: cryptospi_errs.h or any of the system-wide error codes. sl@0: */ sl@0: IMPORT_C void SetCryptoModeL(TUid aCryptoMode); sl@0: sl@0: /** sl@0: Set padding mode of this cipher. Reset() is called to reinitialise the cipher. sl@0: @param aPaddingMode The padding mode e.g. SSLv3, PKCS7 sl@0: @leave KErrNotSupported if the padding mode is not supported. sl@0: @leave ... Any of the crypto error codes defined in sl@0: cryptospi_errs.h or any of the system-wide error codes. sl@0: */ sl@0: IMPORT_C void SetPaddingModeL(TUid aPaddingMode); sl@0: sl@0: /** sl@0: Set the initialization vector of this cipher. Reset() is called to reinitialise the cipher. sl@0: @param aIV The initialization vector. sl@0: @leave KErrNotSupported if the current mode of operation does not support this. sl@0: @leave KErrArgument If the length of the Iv is not equal to the block size. sl@0: @leave ... Any of the crypto error codes defined in sl@0: cryptospi_errs.h or any of the system-wide error codes. sl@0: */ sl@0: IMPORT_C void SetIvL(const TDesC8& aIv); sl@0: sl@0: /** sl@0: Returns the maximum length that an output buffer would need to be in order to hold the result sl@0: of the next process operation, given the input length inputLen and the internal sl@0: state of the state of the cipher. sl@0: @param aInputLength The length of the input to process sl@0: @return The length of the output buffer sl@0: */ sl@0: IMPORT_C TInt MaxOutputLength(TInt aInputLength); sl@0: sl@0: /** sl@0: Returns the maximum length that an output buffer would need to be in order to hold the result sl@0: of the next processfinal operation, given the input length inputLen and the sl@0: internal state of the cipher. sl@0: @param aInputLength The length of input to process sl@0: @return The length of the output buffer sl@0: */ sl@0: IMPORT_C TInt MaxFinalOutputLength(TInt aInputLength); sl@0: sl@0: /** sl@0: Returns the block size in bits. For stream ciphers this is defined to be sl@0: 8-bits. sl@0: @return The block size in bits sl@0: */ sl@0: IMPORT_C TInt BlockSize(); sl@0: sl@0: /** sl@0: Returns the size of the current key in bits. sl@0: @return The size of the current key in bits sl@0: */ sl@0: IMPORT_C TInt KeySize(); sl@0: sl@0: protected: sl@0: /** sl@0: * @internalComponent sl@0: * sl@0: * Constructor sl@0: **/ sl@0: CSymmetricCipherBase(MSymmetricCipherBase* aSymmetricCipher, TInt aHandle); sl@0: }; sl@0: sl@0: sl@0: /** sl@0: Symmetric Cipher API, which wraps a synchronous Symmetric Cipher plugin implementation sl@0: */ sl@0: NONSHARABLE_CLASS(CSymmetricCipher) : public CSymmetricCipherBase sl@0: { sl@0: public: sl@0: sl@0: /** sl@0: * @internalComponent sl@0: * sl@0: * Create a CSymmetricCipher instance from the given MSymmetricCipher instance sl@0: * @param aSymmetricCipher an Sync Symmetric Cipher plugin instance sl@0: * @return A pointer to a CSymmetricCipher instance sl@0: **/ sl@0: static CSymmetricCipher* NewL(MSymmetricCipher* aSymmetricCipher, TInt aHandle); sl@0: sl@0: /** sl@0: Destructor sl@0: */ sl@0: IMPORT_C ~CSymmetricCipher(); sl@0: sl@0: /** sl@0: Encrypts or decrypts aInput and appends the result to aOutput. sl@0: @param aInput The input data to be processed. sl@0: @param aOutput The resulting processed data appended to aOutput. sl@0: @leave ... Any of the crypto error codes defined in sl@0: cryptospi_errs.h or any of the system-wide error codes. sl@0: */ sl@0: IMPORT_C void ProcessL(const TDesC8& aInput, TDes8& aOutput); sl@0: sl@0: /** sl@0: Pads aInput to be block aligned using the underlying padding system, then sl@0: encrypts or decrypts the input data, and appends the result to aOutput sl@0: @param aInput The input buffer to be encrypted or decrypted. sl@0: @param aOutput The resulting, padded, processed data is appended to aOutput. sl@0: @leave ... Any of the crypto error codes defined in sl@0: cryptospi_errs.h or any of the system-wide error codes. sl@0: */ sl@0: IMPORT_C void ProcessFinalL(const TDesC8& aInput, TDes8& aOutput); sl@0: sl@0: private: sl@0: /** sl@0: Constructor sl@0: */ sl@0: CSymmetricCipher(MSymmetricCipher* aSymmetricCipher, TInt aHandle); sl@0: }; sl@0: sl@0: /** sl@0: Async Symmetric Cipher API, which wraps an asynchronous Symmetric Cipher plugin implementation sl@0: */ sl@0: NONSHARABLE_CLASS(CAsyncSymmetricCipher) : public CSymmetricCipherBase sl@0: { sl@0: public: sl@0: sl@0: /** sl@0: * @internalComponent sl@0: * sl@0: * Create a CAsyncSymmetricCipher instance from the given MAsyncSymmetricCipher instance sl@0: * @param aAsyncSymmetricCipher an async Symmetric Cipher plugin instance sl@0: * @return A pointer to a CAsyncSymmetricCipher instance sl@0: **/ sl@0: static CAsyncSymmetricCipher* NewL(MAsyncSymmetricCipher* aAsyncSymmetricCipher, TInt aHandle); sl@0: sl@0: /** sl@0: Destructor sl@0: */ sl@0: IMPORT_C ~CAsyncSymmetricCipher(); sl@0: sl@0: /** sl@0: Encrypts or decrypts aInput and appends the result to aOutput asynchronously sl@0: @param aInput The input data to be processed. sl@0: @param aOutput The resulting processed data appended to aOutput. sl@0: @param aRequestStatus sl@0: @leave ... Any of the crypto error codes defined in sl@0: cryptospi_errs.h or any of the system-wide error codes. sl@0: */ sl@0: IMPORT_C void ProcessL(const TDesC8& aInput, TDes8& aOutput, TRequestStatus& aRequestStatus); sl@0: sl@0: /** sl@0: Asynchronously pads aInput to be block aligned using the underlying padding system, sl@0: encrypts or decrypts the input data, and appends the result to aOutput sl@0: @param aInput The input buffer to be encrypted or decrypted. sl@0: @param aOutput The resulting, padded, processed data is appended to aOutput. sl@0: @param aRequestStatus sl@0: @leave ... Any of the crypto error codes defined in sl@0: cryptospi_errs.h or any of the system-wide error codes. sl@0: */ sl@0: IMPORT_C void ProcessFinalL(const TDesC8& aInput, TDes8& aOutput, TRequestStatus& aRequestStatus); sl@0: sl@0: /** sl@0: Cancel the outstanding request sl@0: */ sl@0: IMPORT_C void Cancel(); sl@0: sl@0: private: sl@0: /** sl@0: Construtor sl@0: */ sl@0: CAsyncSymmetricCipher(MAsyncSymmetricCipher* aAsyncSymmetricCipher, TInt aHandle); sl@0: }; sl@0: sl@0: sl@0: /** sl@0: This Factory to create synchronous and asynchronous symmetric cipher instances sl@0: */ sl@0: class CSymmetricCipherFactory sl@0: { sl@0: public: sl@0: sl@0: /** sl@0: Creates a new synchronous instance of a symmetric cipher sl@0: sl@0: @param aCipher A reference to a pointer that should be set to point to the new symmetric object. sl@0: @param aAlgorithmUid The algorithm to use sl@0: @param aKey The encryption/decryption key. sl@0: @param aCryptoMode The Symmetric cipher mode. sl@0: @param aOperationMode The Symmetric cipher operation mode. sl@0: @param aPaddingMode The Symmetric cipher padding mode. sl@0: @param aAlgorithmParams Parameters that are specific to a particular algorithm. This is for extendibility and will normally be null. sl@0: @return KErrNone if successful; otherwise, a system wide error code. sl@0: */ sl@0: IMPORT_C static void CreateSymmetricCipherL(CSymmetricCipher*& aCipher, sl@0: TUid aAlgorithmUid, sl@0: const CKey& aKey, sl@0: TUid aCryptoMode, sl@0: TUid aOperationMode, sl@0: TUid aPaddingMode, sl@0: const CCryptoParams* aAlgorithmParams); sl@0: sl@0: /** sl@0: Creates a new asynchronous instance of a symmetric cipher sl@0: sl@0: @param aAsyncCipher A reference to a pointer that should be set to point to the new symmetric object. sl@0: @param aAlgorithmUid The algorithm to use sl@0: @param aKey The encryption/decryption key. sl@0: @param aCryptoMode The Symmetric cipher mode. sl@0: @param aOperationMode The Symmetric cipher operation mode. sl@0: @param aPaddingMode The Symmetric cipher padding mode. sl@0: @param aAlgorithmParams Parameters that are specific to a particular algorithm. This is for extendibility and will normally be null. sl@0: @return KErrNone if successful; otherwise, a system wide error code. sl@0: */ sl@0: IMPORT_C static void CreateAsyncSymmetricCipherL(CAsyncSymmetricCipher*& aAsyncCipher, sl@0: TUid aAlgorithmUid, sl@0: const CKey& aKey, sl@0: TUid aCryptoMode, sl@0: TUid aOperationMode, sl@0: TUid aPaddingMode, sl@0: const CCryptoParams* aAlgorithmParams); sl@0: sl@0: }; sl@0: } sl@0: sl@0: #endif //__CRYPTOAPI_SYMMETRICCIPHERAPI_H__