Update contrib.
2 * Copyright (c) 2006-2010 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 __DESEXTENDIMPL_H__
20 #define __DESEXTENDIMPL_H__
30 #include <cryptospi/keys.h>
31 #include "symmetriccipherimpl.h"
34 Plug-in class for DES block cipher (Including Extended Characterisitics for Test)
36 namespace SoftwareCrypto
38 using namespace CryptoSpi;
40 NONSHARABLE_CLASS(CDesExtendImpl) : public CSymmetricBlockCipherImpl
45 Creates an instance of a DES (Data Encryption Standard) symmetric cipher plug-in.
47 @param aCryptoMode whether to encrypt or decrypt
48 @param aOperationMode The block cipher mode ECB, CBC, CTR etc
49 @param aPadding The padding scheme to use None, SSLv3, PKCS#7
50 @return A pointer to a CDesImpl instance
52 static CDesExtendImpl* NewL(TUid aImplementationUid, const CKey& aKey,
53 TUid aCryptoMode, TUid aOperationMode, TUid aPadding);
56 Creates an instance of a DES (Data Encryption Standard) symmetric cipher plug-in.
57 A pointer to the plug-in instance is placed on the cleanup stack.
59 @param aCryptoMode Whether to encrypt or decrypt
60 @param aOperationMode T block cipher mode ECB, CBC, CTR etc
61 @param aPadding The padding scheme to use None, SSLv3, PKCS#7
62 @return A pointer to a CDesImpl instance
64 static CDesExtendImpl* NewLC(TUid aImplementationUid, const CKey& aKey,
65 TUid aCryptoMode, TUid aOperationMode, TUid aPadding);
67 // From CSymmetricCipherImpl
68 TInt GetKeyStrength() const;
69 TBool IsValidKeyLength(TInt aKeyBytes) const;
70 TUid ImplementationUid() const;
71 const CExtendedCharacteristics* GetExtendedCharacteristicsL();
73 static CExtendedCharacteristics* CreateExtendedCharacteristicsL();
81 @param aBlockBytes The block size in bytes (needed to allow
82 3DES implementation to inherit from this class)
83 @param aOperationMode The mode of operation e.g. CBC
84 @param aCryptoMode Whether to encrypt or decrypt
85 @param aPaddingMode The padding mode to use. None, SSL, PKCS#7
87 CDesExtendImpl(TUid aImplementationUid, TUint8 aBlockBytes, TUid aOperationMode, TUid aCryptoMode, TUid aPaddingMode);
90 Second phase of construction
91 @param aKey The key object
93 void ConstructL(const CKey& aKey);
95 // These protected functions are re-used by 3DES
97 Transforms a block of data
98 @param l The left half of the block to transform
99 @param r The right half of the block to transform
100 @param aKeySchedule The keyschedule to use for the transformation
102 void DoTransform(TUint32& l, TUint32& r, const TUint32* aKeySchedule);
105 Setup the key schedule for encryption
106 @param aKey The input key
107 @param aKeySchedule A pointer to the key schedule buffer
109 void SetEncryptKeySchedule(const TDesC8& aKey, TUint32* aKeySchedule);
112 Setup the key schedule for decryption
113 @param aKey The input key
114 @param aKeySchedule A pointer to the key schedule buffer
116 void SetDecryptKeySchedule(const TDesC8& aKey, TUint32* aKeySchedule);
118 static const TUint8 KDesBlockBytes = 8;
119 static const TUint8 KDesKeyBytes = 8;
124 Creates the key schedule iK from CBlockTransformationImpl::iKey.
125 This should be called from ConstructL and Reset
127 void SetKeySchedule();
129 // From CSymmetricBlockCipherImpl
130 void TransformEncrypt(TUint8* aBuffer, TUint aNumBlocks);
131 void TransformDecrypt(TUint8* aBuffer, TUint aNumBlocks);
135 TUid iImplementationUid;
137 CExtendedCharacteristics* iExtendChars;
139 /// Size of the key schedule in words
140 static const TUint KKeyScheduleSize = 32;
143 TUint32 iK[KKeyScheduleSize];
147 #endif // __DESEXTENDIMPL_H__