os/security/cryptoplugins/cryptospiplugins/source/softwarecrypto/asymmetriccipherimpl.h
First public contribution.
2 * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
19 #ifndef __ASYMMETRICCIPHERIMPL_H__
20 #define __ASYMMETRICCIPHERIMPL_H__
29 #include <cryptospi/cryptospidef.h>
31 #include "asymmetriccipherplugin.h"
33 #include "common/inlines.h"
36 * Abstract base class for symmetric cipher plug-ins.
38 namespace SoftwareCrypto
40 using namespace CryptoSpi;
42 NONSHARABLE_CLASS(CAsymmetricCipherImpl) : public CBase, public MAsymmetricCipher
46 // Override MPlugin virtual functions
48 void Reset(); // Always call reset in super-class if you override this
49 TAny* GetExtension(TUid aExtensionId);
50 void GetCharacteristicsL(const TCharacteristics*& aPluginCharacteristics);
53 // Override MAsymmetricCipherBase virtual functions
54 void SetKeyL(const CKey& aKey); // override DoSetKeyL instead
55 void SetCryptoModeL(TUid aCryptoMode); // override DoSetCryptoModeL instead
56 void SetPaddingModeL(TUid aPaddingMode); // override DoSetPaddingModeL instead
57 virtual TInt GetMaximumInputLengthL() const;
58 virtual TInt GetMaximumOutputLengthL() const;
59 // End of MAsymmetricCipherBase
61 // Override MAsymmetricCipher virtual functions
62 virtual void ProcessL(const TDesC8& aInput, TDes8& aOutput) = 0;
63 // End of MAsymmetricCipher
66 ~CAsymmetricCipherImpl();
71 @param aCryptoMode Whether to encrypt or decrypt
72 @param aPaddingMode The padding mode
74 CAsymmetricCipherImpl(TUid aCryptoMode, TUid aPaddingMode);
77 Second phase of construction. Always call ConstructL in the super-class
78 if you override this method.
80 @param aKey The key to initialise the cipher with.
82 virtual void ConstructL(const CKey& aKey);
85 Implemented by each cipher subclass to determine whether the
86 specified key length is valid for that cipher.
87 This is called by ConstructL and SetKeyL
88 @param aKeyBytes The key length in bytes to verify.
89 @return ETrue if key length is acceptable
91 virtual TBool IsValidKeyLengthL(TInt aKeyBytes) const = 0;
94 Helper function implemented by concrete cipher sub-class that allows
95 GetCharacteristicsL to return the correct characteristics object.
96 @return The implemention uid
98 virtual TUid ImplementationUid() const = 0;
101 Validates and sets the crypto mode (iCryptoMode)
102 @param aCryptoMode The crypto mode
104 virtual void DoSetCryptoModeL(TUid aCryptoMode);
107 Extracts the raw key from aKey and sets iKey and iKeyBytes
108 The key length is also checked to meet export restrictions and
109 to ensure that it is appropriate for the cipher.
112 virtual void DoSetKeyL(const CKey& aKey);
115 Validates and sets the padding mode (iPaddingMode & iPadding)
116 @param aPadding The desired padding mode
118 virtual void DoSetPaddingModeL(TUid aPadding);
123 /// encryption or decryption
126 /// the current padding scheme
132 /// current padding scheme implementation
137 #endif // __ASYMMETRICCIPHERIMPL_H__