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 RC2 block cipher
36 namespace SoftwareCrypto
38 using namespace CryptoSpi;
40 NONSHARABLE_CLASS(CRc2Impl) : public CSymmetricBlockCipherImpl
44 Creates an instance of an RC2 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 @param aEffectiveKeyLenBits The effective key length in bits
50 @return A pointer to a CRc2Impl instance
52 static CRc2Impl* NewL(const CKey& aKey,
53 TUid aCryptoMode, TUid aOperationMode, TUid aPadding, TInt aEffectiveKeyLenBits);
56 Creates an instance of an RC2 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 The block cipher mode ECB, CBC, CTR etc
61 @param aPadding The padding scheme to use None, SSLv3, PKCS#7
62 @param aEffectiveKeyLenBits The effective key length in bits
63 @return A pointer to a CRc2Impl instance
65 static CRc2Impl* NewLC(const CKey& aKey,
66 TUid aCryptoMode, TUid aOperationMode, TUid aPadding, TInt aEffectiveKeyLenBits);
68 // From CSymmetricCipherImpl
69 TBool IsValidKeyLength(TInt aKeyBytes) const;
70 TUid ImplementationUid() const;
71 TInt GetKeyStrength() const;
72 const CExtendedCharacteristics* GetExtendedCharacteristicsL();
74 static CExtendedCharacteristics* CreateExtendedCharacteristicsL();
79 /** SSL Effective Key Length Compatibility - for compatibility with SSL */
80 static const TUint KDefaultEffectiveKeyLenBits = 1024;
85 @param aOperationMode The mode of operation e.g. CBC
86 @param aCryptoMode Whether to encrypt or decrypt
87 @param aPaddingMode The padding mode to use. None, SSL, PKCS#7
89 CRc2Impl(TUid aOperationMode, TUid aCryptoMode, TUid aPaddingMode);
91 /// second phase of construction
92 void ConstructL(const CKey& aKey, TInt aEffectiveKeyLenBits);
95 Expands the key (iKey) to iEffectiveKeyLenBits and stores the result in iK
97 void SetKeySchedule();
99 // From CSymmetricBlockCipherImpl
100 void TransformEncrypt(TUint8* aBuffer, TUint aNumBlocks);
101 void TransformDecrypt(TUint8* aBuffer, TUint aNumBlocks);
104 static const TUint8 KRc2BlockBytes = 8;
105 static const TInt KRc2MaxKeySizeBytes = 128;
106 static const TInt KRc2ExpandedKeyLen = 64;
108 The expanded key buffer.
109 Each iK[i] is a 16-bit word.
111 TUint16 iK[KRc2ExpandedKeyLen]; // 128 bytes
113 /** The effective key length in bits */
114 TInt iEffectiveKeyLenBits;