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: * 3DES 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 __3DES_H__ sl@0: #define __3DES_H__ sl@0: sl@0: #include sl@0: sl@0: /** sl@0: * Abstract base class for triple-DES. sl@0: * sl@0: * Implements features common to triple-DES encryption and decryption. sl@0: * sl@0: */ sl@0: class C3DES : public CDES sl@0: { sl@0: public: sl@0: virtual void Transform(TDes8& aBlock); 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: C3DES(); sl@0: virtual void ConstructL(const TDesC8& aKey); sl@0: /** sl@0: * Initialises the three key schedule arrays from the specified key. sl@0: * sl@0: * @param aKey The key to be used for encryption. The key length sl@0: * must be K3DESKeySize = 24 bytes. sl@0: */ sl@0: virtual void DoSetKey(const TDesC8& aKey) = 0; sl@0: sl@0: protected: sl@0: /** The second key schedule array */ sl@0: TUint32 iK2[KDESScheduleSizeInWords]; // = 32 sl@0: /** The third key schedule array */ sl@0: TUint32 iK3[KDESScheduleSizeInWords]; sl@0: }; sl@0: sl@0: /** sl@0: * Concrete class for triple-DES encryption. sl@0: * sl@0: */ sl@0: class C3DESEncryptor : public C3DES 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 sl@0: * must be K3DESKeySize = 24 bytes. sl@0: * @return A pointer to the new C3DESEncryptor object. 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 C3DESEncryptor* NewL(const TDesC8& aKey); 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 encryption. The key length sl@0: * must be K3DESKeySize = 24 bytes. sl@0: * @return A pointer to the new C3DESEncryptor object. 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 C3DESEncryptor* NewLC(const TDesC8& aKey); sl@0: protected: sl@0: virtual void DoSetKey(const TDesC8& aKey); sl@0: }; sl@0: sl@0: /** sl@0: * Concrete class for triple-DES decryption. sl@0: * sl@0: */ sl@0: class C3DESDecryptor : public C3DES 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 sl@0: * must be K3DESKeySize = 24 bytes. sl@0: * @return A pointer to the new C3DESDecryptor object. 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 C3DESDecryptor* NewL(const TDesC8& aKey); 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 sl@0: * must be K3DESKeySize = 24 bytes. sl@0: * @return A pointer to the new C3DESDecryptor object. 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 C3DESDecryptor* NewLC(const TDesC8& aKey); sl@0: protected: sl@0: virtual void DoSetKey(const TDesC8& aKey); sl@0: }; sl@0: sl@0: #endif // __3DES_H__