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 __ASYMMETRICCIPHERIMPL_H__ sl@0: #define __ASYMMETRICCIPHERIMPL_H__ sl@0: sl@0: /** sl@0: @file sl@0: @internalComponent sl@0: @released sl@0: */ sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include "asymmetriccipherplugin.h" sl@0: #include "keys.h" sl@0: #include "common/inlines.h" sl@0: sl@0: /** sl@0: * Abstract base class for symmetric cipher plug-ins. sl@0: */ sl@0: namespace SoftwareCrypto sl@0: { sl@0: using namespace CryptoSpi; sl@0: sl@0: NONSHARABLE_CLASS(CAsymmetricCipherImpl) : public CBase, public MAsymmetricCipher sl@0: { sl@0: public: sl@0: sl@0: // Override MPlugin virtual functions sl@0: void Close(); sl@0: void Reset(); // Always call reset in super-class if you override this sl@0: TAny* GetExtension(TUid aExtensionId); sl@0: void GetCharacteristicsL(const TCharacteristics*& aPluginCharacteristics); sl@0: // End of MPlugin sl@0: sl@0: // Override MAsymmetricCipherBase virtual functions sl@0: void SetKeyL(const CKey& aKey); // override DoSetKeyL instead sl@0: void SetCryptoModeL(TUid aCryptoMode); // override DoSetCryptoModeL instead sl@0: void SetPaddingModeL(TUid aPaddingMode); // override DoSetPaddingModeL instead sl@0: virtual TInt GetMaximumInputLengthL() const; sl@0: virtual TInt GetMaximumOutputLengthL() const; sl@0: // End of MAsymmetricCipherBase sl@0: sl@0: // Override MAsymmetricCipher virtual functions sl@0: virtual void ProcessL(const TDesC8& aInput, TDes8& aOutput) = 0; sl@0: // End of MAsymmetricCipher sl@0: sl@0: /// Destructor sl@0: ~CAsymmetricCipherImpl(); sl@0: sl@0: protected: sl@0: /** sl@0: Constructor sl@0: @param aCryptoMode Whether to encrypt or decrypt sl@0: @param aPaddingMode The padding mode sl@0: */ sl@0: CAsymmetricCipherImpl(TUid aCryptoMode, TUid aPaddingMode); sl@0: sl@0: /** sl@0: Second phase of construction. Always call ConstructL in the super-class sl@0: if you override this method. sl@0: sl@0: @param aKey The key to initialise the cipher with. sl@0: */ sl@0: virtual void ConstructL(const CKey& aKey); sl@0: sl@0: /** sl@0: Implemented by each cipher subclass to determine whether the sl@0: specified key length is valid for that cipher. sl@0: This is called by ConstructL and SetKeyL sl@0: @param aKeyBytes The key length in bytes to verify. sl@0: @return ETrue if key length is acceptable sl@0: */ sl@0: virtual TBool IsValidKeyLengthL(TInt aKeyBytes) const = 0; sl@0: sl@0: /** sl@0: Helper function implemented by concrete cipher sub-class that allows sl@0: GetCharacteristicsL to return the correct characteristics object. sl@0: @return The implemention uid sl@0: */ sl@0: virtual TUid ImplementationUid() const = 0; sl@0: sl@0: /** sl@0: Validates and sets the crypto mode (iCryptoMode) sl@0: @param aCryptoMode The crypto mode sl@0: */ sl@0: virtual void DoSetCryptoModeL(TUid aCryptoMode); sl@0: sl@0: /** sl@0: Extracts the raw key from aKey and sets iKey and iKeyBytes sl@0: The key length is also checked to meet export restrictions and sl@0: to ensure that it is appropriate for the cipher. sl@0: @param aKey The key sl@0: */ sl@0: virtual void DoSetKeyL(const CKey& aKey); sl@0: sl@0: /** sl@0: Validates and sets the padding mode (iPaddingMode & iPadding) sl@0: @param aPadding The desired padding mode sl@0: */ sl@0: virtual void DoSetPaddingModeL(TUid aPadding); sl@0: sl@0: private: sl@0: sl@0: protected: sl@0: /// encryption or decryption sl@0: TUid iCryptoMode; sl@0: sl@0: /// the current padding scheme sl@0: TUid iPaddingMode; sl@0: sl@0: /// the key sl@0: CKey* iKey; sl@0: sl@0: /// current padding scheme implementation sl@0: CPadding* iPadding; sl@0: }; sl@0: } sl@0: sl@0: #endif // __ASYMMETRICCIPHERIMPL_H__