sl@0: /* sl@0: * Copyright (c) 2008-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: * Cipher MAC plugin implementation sl@0: * sl@0: */ sl@0: sl@0: sl@0: /** sl@0: @file sl@0: @internalComponent sl@0: @released sl@0: */ sl@0: sl@0: #ifndef __CRYPTOAPI_SOFTWARECIPHERMACIMPL_H__ sl@0: #define __CRYPTOAPI_SOFTWARECIPHERMACIMPL_H__ sl@0: sl@0: #include "cryptosymmetriccipherapi.h" sl@0: #include "keys.h" sl@0: sl@0: sl@0: namespace SoftwareCrypto sl@0: { sl@0: using namespace CryptoSpi; sl@0: sl@0: /** sl@0: * This is the maximum block size in bytes currently supported by CMAC implementation. sl@0: * sl@0: * The cipher based algorithms currently supported are sl@0: * AES-XCBC-MAC-96 and AES-XCBC-PRF-128. sl@0: */ sl@0: const TInt KMacBlockSize = 16; sl@0: sl@0: /** sl@0: * The class is created from following substance classes sl@0: * 1. MMac sl@0: * 2. CSymmetricCipher sl@0: * Using the methods of the above classes we will transform/mould the Cipher methods in sl@0: * a way as to be inline with the MMac interface methods. The MMac methods will sl@0: * serve as the wrapper internal to which Cipher methods will work to provide the MAC value. sl@0: * sl@0: * The class was created to provide consistency/similarity HMAC and CMAC works. sl@0: * Also for future extensibility of other Cipher algorithms. sl@0: */ sl@0: NONSHARABLE_CLASS(CCMacImpl) : public CBase sl@0: { sl@0: public: sl@0: /** sl@0: * Cipher MAC implementation instance creation methods sl@0: * sl@0: *The owneship of 'aSymmetricCipher' is imparted to instance of this class. sl@0: */ sl@0: static CCMacImpl* NewL(const CKey& aKey, sl@0: CSymmetricCipher* aSymmetricCipher, sl@0: TInt32 aAlgorithmUid); sl@0: sl@0: static CCMacImpl* NewLC(const CKey& aKey, sl@0: CSymmetricCipher* aSymmetricCipher, sl@0: TInt32 aAlgorithmUid); sl@0: /** sl@0: * Simulating Methods from MPlugin sl@0: */ sl@0: const CExtendedCharacteristics* GetExtendedCharacteristicsL(); sl@0: sl@0: // We will call CSymmetricBlockCipherImpl::Reset(); sl@0: void Reset(); sl@0: sl@0: /** sl@0: * Simulating MAC interfaces (Software based) sl@0: */ sl@0: TPtrC8 MacL(const TDesC8& aMessage); sl@0: void UpdateL(const TDesC8& aMessage); sl@0: TPtrC8 FinalL(const TDesC8& aMessage); sl@0: void ReInitialiseAndSetKeyL(const CKey& aKey); sl@0: void SetKeyL(const CKey& aKey); sl@0: ~CCMacImpl(); sl@0: CCMacImpl* CopyL(); sl@0: CCMacImpl* ReplicateL(); sl@0: sl@0: private: sl@0: /** sl@0: * Constructors sl@0: */ sl@0: CCMacImpl(CryptoSpi::CSymmetricCipher* aSymmetricCipher); sl@0: CCMacImpl(const CCMacImpl&); sl@0: sl@0: /** sl@0: * Initialize the 'iCipherImpl' instances. sl@0: */ sl@0: void ConstructL(const CKey& aKey, TInt32 aAlgorithmUid); sl@0: void DoUpdateL(const TDesC8& aMessage); sl@0: TPtrC8 DoFinalL(); sl@0: void PadMessage(); sl@0: void ProcessBlockL(); sl@0: void XORKeyWithData(const TDesC8& aKey, TDes8& aOutput); sl@0: CKey* Create128bitKeyL(const CKey& aKey); sl@0: sl@0: private: sl@0: TInt32 iImplementationUid; sl@0: CKey* iKey; sl@0: CryptoSpi::CSymmetricCipher* iCipherImpl; sl@0: sl@0: TBuf8 iKey1; sl@0: TBuf8 iKey2; sl@0: TBuf8 iKey3; sl@0: TBuf8 iMacValue; sl@0: sl@0: TUint8 iE[KMacBlockSize]; sl@0: TUint8 iData[KMacBlockSize]; sl@0: TInt iCurrentTotalLength; sl@0: // Resets the cipher with iE(128 zero bits) the next time MacL, sl@0: // UpdateL or FinalL are called. This was introduced as we cannot leave from the sl@0: // non-leaving CCMacImpl::Reset() implementation of the MPlugin::Reset() pure sl@0: // virtual. To prevent behavioral break. sl@0: TInt iDelayedReset; sl@0: }; sl@0: } sl@0: sl@0: #endif // __CRYPTOAPI_SOFTWARECIPHERMACIMPL_H__ sl@0: sl@0: