os/security/cryptoplugins/cryptospiplugins/test/h4drv/crypto_h4_plugin/h4cipherimpl.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.
24 #ifndef __SYMMETRICCIPHERIMPL_H__
25 #define __SYMMETRICCIPHERIMPL_H__
29 #include <cryptospi/cryptospidef.h>
31 #include "symmetriccipherplugin.h"
35 #define __NOTSHARED __declspec(notshared)
40 /** The maximum block size supported (in bytes) */
41 const TUint KMaxBlockSizeSupported = 32;
44 Abstract base class for symmetric cipher plug-ins.
48 using namespace CryptoSpi;
50 class __NOTSHARED CH4CipherImpl : public CBase, public MSymmetricCipher
54 Implemented by each cipher subclass to determine whether the
55 specified key length is valid for that cipher.
56 This is called by ConstructL and SetKeyL
57 @param aKeyLength The key length in bytes to verify.
59 virtual TBool IsValidKeyLength(TInt aKeyBytes) const = 0;
62 Helper function implemented by concrete cipher sub-class that
63 allows GetCharacteristicsL to return the correct characteristics object.
64 @return The implemention uid
66 virtual TUid ImplementationUid() const = 0;
69 Gets the strength of the current key, needed to check whether the cipher
70 may operate if strong cryptography is not enabled.
71 @return The strength of the current key
73 virtual TInt GetKeyStrength() const;
76 // Override MPlugin virtual functions
78 TAny* GetExtension(TUid aExtensionId);
80 void GetCharacteristicsL(const TCharacteristics*& aPluginCharacteristics);
83 void Reset(); // Always call reset in super-class if you override this
84 // End of MPlugin virtual functions
86 // Override MSymmetricCipherBase virtual functions
88 virtual void SetKeyL(const CKey& aKey);
90 TInt BlockSize() const;
91 void SetCryptoModeL(TUid aCryptoMode);
92 void SetOperationModeL(TUid aOperationMode);
93 void SetPaddingModeL(TUid aPaddingMode);
94 void SetIvL(const TDesC8& aIv);
96 TInt MaxOutputLength(TInt aInputLength) const;
97 TInt MaxFinalOutputLength(TInt aInputLength) const;
99 void ProcessL(const TDesC8& aInput, TDes8& aOutput);
100 void ProcessFinalL(const TDesC8& aInput, TDes8& aOutput);
101 // End of MSymmetricCipherBase
110 @param aBlockBytes The block size in bytes
111 @param aOperationMode The mode of operation e.g. CBC
112 @param aCryptoMode Whether to encrypt or decrypt
114 CH4CipherImpl(TUint8 aBlockBytes,
120 Second phase of construction. Always call ConstructL in the super-class
121 if your override this method.
123 @param aKey The key to initialise the cipher with.
125 virtual void ConstructL(const CKey& aKey);
128 Creates the extended characteristics object. Concrete plug-in classes
129 may override this to customise the object returned by GetCharacteristics();
131 The default configuration is that plug-ins have unlimited concurrency,
132 cannot be reserved for exclusive use and are not CERTIFIED to be standards compliant.
133 @return The extended characteristics object
135 virtual CExtendedCharacteristics* CreateExtendedCharacteristicsL();
138 Extracts the raw symmetric key from a generic key object. The buffer
139 is placed on the cleanup stack.
141 @param aKey The key object
142 @return A buffer containing the raw key value
144 HBufC8* ExtractKeyDataLC(const CKey& aKey) const;
150 Reconfigure h/w based on iCryptoMode/iOperationMode/iKey/iIv
152 Implemented by each cipher subclass.
154 virtual void DoSetupL() = 0;
159 Blocking write of data to be transformed. Need not be a
160 multiple of the block size.
162 Implemented by each cipher subclass.
164 virtual void DoWriteL(const TUint8* aBuffer, TUint aNumBytes) = 0;
169 Blocking read of transformed data.
171 Need not be a multiple of the block size, but caller should
172 ensure enough blocks of data have been written to satisfy
175 The data is appended to the supplied descriptor.
177 Implemented by each cipher subclass.
179 virtual void DoReadL(TDes8 &aBuffer, TUint32 aLength) = 0;
184 /// the key, extracted from a CKey object
187 /// key size in bytes
190 /// Standards conformance information.
191 RArray<TUid> iStandardsConformance;
193 /// block size in bytes, current largest block size is 16 bytes (AES)
195 /// encryption or decryption
197 /// The block cipher mode e.g. ECB, CBC
199 /// the current padding scheme
202 /// the initialisation vector
205 /// current padding scheme implementation
207 /// buffer to store blocks
209 /// buffer to store input / output of padding
213 TBool iNeedToSetupHw;
219 #endif // __SYMMETRICCIPHERIMPL_H__