First public contribution.
2 * Copyright (c) 2006-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.
31 #include "symmetriccipherimpl.h"
34 Plug-in class for DES block cipher
36 namespace SoftwareCrypto
38 using namespace CryptoSpi;
40 NONSHARABLE_CLASS(CDesImpl) : public CSymmetricBlockCipherImpl
44 Creates an instance of a DES (Data Encryption Standard) symmetric cipher plug-in.
46 @param aCryptoMode whether to encrypt or decrypt
47 @param aOperationMode The block cipher mode ECB, CBC, CTR etc
48 @param aPadding The padding scheme to use None, SSLv3, PKCS#7
49 @return A pointer to a CDesImpl instance
51 static CDesImpl* NewL(const CKey& aKey,
52 TUid aCryptoMode, TUid aOperationMode, TUid aPadding);
55 Creates an instance of a DES (Data Encryption Standard) symmetric cipher plug-in.
56 A pointer to the plug-in instance is placed on the cleanup stack.
58 @param aCryptoMode Whether to encrypt or decrypt
59 @param aOperationMode T block cipher mode ECB, CBC, CTR etc
60 @param aPadding The padding scheme to use None, SSLv3, PKCS#7
61 @return A pointer to a CDesImpl instance
63 static CDesImpl* NewLC(const CKey& aKey,
64 TUid aCryptoMode, TUid aOperationMode, TUid aPadding);
66 // From CSymmetricCipherImpl
67 TInt GetKeyStrength() const;
68 TBool IsValidKeyLength(TInt aKeyBytes) const;
69 TUid ImplementationUid() const;
70 const CExtendedCharacteristics* GetExtendedCharacteristicsL();
72 static CExtendedCharacteristics* CreateExtendedCharacteristicsL();
79 @param aBlockBytes The block size in bytes (needed to allow
80 3DES implementation to inherit from this class)
81 @param aOperationMode The mode of operation e.g. CBC
82 @param aCryptoMode Whether to encrypt or decrypt
83 @param aPaddingMode The padding mode to use. None, SSL, PKCS#7
85 CDesImpl(TUint8 aBlockBytes, TUid aOperationMode, TUid aCryptoMode, TUid aPaddingMode);
88 Second phase of construction
89 @param aKey The key object
91 void ConstructL(const CKey& aKey);
93 // These protected functions are re-used by 3DES
95 Transforms a block of data
96 @param l The left half of the block to transform
97 @param r The right half of the block to transform
98 @param aKeySchedule The keyschedule to use for the transformation
100 void DoTransform(TUint32& l, TUint32& r, const TUint32* aKeySchedule);
103 Setup the key schedule for encryption
104 @param aKey The input key
105 @param aKeySchedule A pointer to the key schedule buffer
107 void SetEncryptKeySchedule(const TDesC8& aKey, TUint32* aKeySchedule);
110 Setup the key schedule for decryption
111 @param aKey The input key
112 @param aKeySchedule A pointer to the key schedule buffer
114 void SetDecryptKeySchedule(const TDesC8& aKey, TUint32* aKeySchedule);
116 static const TUint8 KDesBlockBytes = 8;
117 static const TUint8 KDesKeyBytes = 8;
122 Creates the key schedule iK from CBlockTransformationImpl::iKey.
123 This should be called from ConstructL and Reset
125 void SetKeySchedule();
127 // From CSymmetricBlockCipherImpl
128 void TransformEncrypt(TUint8* aBuffer, TUint aNumBlocks);
129 void TransformDecrypt(TUint8* aBuffer, TUint aNumBlocks);
132 /// Size of the key schedule in words
133 static const TUint KKeyScheduleSize = 32;
136 TUint32 iK[KKeyScheduleSize];
140 #endif // __DESIMPL_H__