sl@0: /* sl@0: * Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of the License "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * ** IMPORTANT ** PublishedPartner API's in this file are published to 3rd party developers via the sl@0: * Symbian website. Changes to these API's should be treated as PublishedAll API changes and the Security TA should be consulted. sl@0: * RC2 implementation sl@0: * sl@0: */ sl@0: sl@0: sl@0: /** sl@0: @file sl@0: @publishedPartner sl@0: @released sl@0: */ sl@0: sl@0: #ifndef __RC2_H__ sl@0: #define __RC2_H__ sl@0: sl@0: #include "blocktransformation.h" sl@0: sl@0: #ifndef SYMBIAN_ENABLE_SPLIT_HEADERS sl@0: sl@0: /** OpenSSL PKCS8 Effective Key Length Compatibility.*/ sl@0: const TUint KPkcs8CompatibilityBits = 128; sl@0: sl@0: /** PKCS12 PBE Effective Key Length Compatibility.*/ sl@0: const TUint KPkcs12CompatibilityBits = 40; sl@0: sl@0: #endif sl@0: sl@0: /** The expanded key length of an RC2 key.*/ sl@0: const TUint KRC2ExpandedKeyLen = 64; sl@0: sl@0: /** SSL Effective Key Length Compatibility.*/ sl@0: const TUint KSSLCompatibilityBits = 1024; sl@0: sl@0: /** The maximum size in bytes for a RC2 key.*/ sl@0: const TUint KRC2MaxKeySizeBytes = 128; // Max key size in this implementation = 128 bytes sl@0: sl@0: /** sl@0: * Abstract base class for RC2 encipherment. sl@0: * sl@0: */ sl@0: class CRC2 : public CBlockTransformation sl@0: { sl@0: public: sl@0: virtual void Reset(); sl@0: virtual TInt BlockSize() const; sl@0: virtual TInt KeySize() const; sl@0: protected: sl@0: /** @internalAll */ sl@0: CRC2(void); sl@0: virtual void SetKey(const TDesC8& aKey, TInt aEffectiveKeyLenBits); sl@0: protected: sl@0: /** sl@0: * The expanded key buffer. sl@0: * sl@0: * Each iK[i] is a 16-bit word. sl@0: */ sl@0: TUint16 iK[KRC2ExpandedKeyLen]; // 128 bytes sl@0: /** sl@0: * The input key sl@0: * sl@0: * The key length must fall between 1 and KRC2MaxKeySizeBytes (=128) bytes inclusive. sl@0: */ sl@0: TBuf8 iKey; sl@0: /** The effective key length in bits */ sl@0: TInt iEffectiveKeyLenBits; sl@0: }; sl@0: sl@0: /** sl@0: * Concrete class for RC2 encryption. sl@0: * sl@0: */ sl@0: class CRC2Encryptor : public CRC2 sl@0: { sl@0: public: sl@0: /** sl@0: * Creates an instance of this class. sl@0: * sl@0: * @param aKey The key to be used for encryption. The key length must fall between sl@0: * 1 and KRC2MaxKeySizeBytes (=128) bytes inclusive. sl@0: * @param aEffectiveKeyLenBits Effective key length bits sl@0: * (defaults KSSLCompatibilityBits = 1024). sl@0: * sl@0: * @leave KErrKeyNotWeakEnough If the key size is larger than that allowed by the sl@0: * cipher strength restrictions of the crypto library. sl@0: * See TCrypto::IsSymmetricWeakEnoughL() sl@0: */ sl@0: IMPORT_C static CRC2Encryptor* NewL(const TDesC8& aKey, sl@0: TInt aEffectiveKeyLenBits = KSSLCompatibilityBits); sl@0: /** sl@0: * Creates an instance of this class and leaves it on the cleanup stack. sl@0: * sl@0: * @param aKey The key to be used for encryption. The key length must fall between sl@0: * 1 and KRC2MaxKeySizeBytes (=128) bytes inclusive. sl@0: * @param aEffectiveKeyLenBits Effective key length bits sl@0: * (defaults KSSLCompatibilityBits = 1024). sl@0: * sl@0: * @leave KErrKeyNotWeakEnough If the key size is larger than that allowed by the sl@0: * cipher strength restrictions of the crypto library. sl@0: * See TCrypto::IsSymmetricWeakEnoughL() sl@0: */ sl@0: IMPORT_C static CRC2Encryptor* NewLC(const TDesC8& aKey, sl@0: TInt aEffectiveKeyLenBits = KSSLCompatibilityBits); sl@0: virtual void Transform(TDes8& aBlock); sl@0: protected: sl@0: /** @internalAll */ sl@0: CRC2Encryptor(void); sl@0: }; sl@0: sl@0: /** sl@0: * Concrete class for RC2 decryption. sl@0: * sl@0: */ sl@0: class CRC2Decryptor : public CRC2 sl@0: { sl@0: public: sl@0: /** sl@0: * Creates an instance of this class. sl@0: * sl@0: * @param aKey The key to be used for decryption. The key length must fall between sl@0: * 1 and KRC2MaxKeySizeBytes (=128) bytes inclusive. sl@0: * @param aEffectiveKeyLenBits Effective key length bits sl@0: * (defaults KSSLCompatibilityBits = 1024). sl@0: * sl@0: * @leave KErrKeyNotWeakEnough If the key size is larger than that allowed by the sl@0: * cipher strength restrictions of the crypto library. sl@0: * See TCrypto::IsSymmetricWeakEnoughL() sl@0: */ sl@0: IMPORT_C static CRC2Decryptor* NewL(const TDesC8& aKey, sl@0: TInt aEffectiveKeyLenBits = KSSLCompatibilityBits); sl@0: sl@0: /** sl@0: * Creates an instance of this class and leaves it on the cleanup stack. sl@0: * sl@0: * @param aKey The key to be used for decryption. The key length must fall between sl@0: * 1 and KRC2MaxKeySizeBytes (=128) bytes inclusive. sl@0: * @param aEffectiveKeyLenBits Effective key length bits sl@0: * (defaults KSSLCompatibilityBits = 1024). sl@0: * sl@0: * @leave KErrKeyNotWeakEnough If the key size is larger than that allowed by the sl@0: * cipher strength restrictions of the crypto library. sl@0: * See TCrypto::IsSymmetricWeakEnoughL() sl@0: */ sl@0: IMPORT_C static CRC2Decryptor* NewLC(const TDesC8& aKey, sl@0: TInt aEffectiveKeyLenBits = KSSLCompatibilityBits); sl@0: virtual void Transform(TDes8& aBlock); sl@0: protected: sl@0: /** @internalAll */ sl@0: CRC2Decryptor(void); sl@0: sl@0: }; sl@0: sl@0: #endif // __RC2_H__