First public contribution.
2 * Copyright (c) 2008-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.
15 * Cipher MAC plugin implementation
26 #ifndef __CRYPTOAPI_SOFTWARECIPHERMACIMPL_H__
27 #define __CRYPTOAPI_SOFTWARECIPHERMACIMPL_H__
29 #include "cryptosymmetriccipherapi.h"
33 namespace SoftwareCrypto
35 using namespace CryptoSpi;
38 * This is the maximum block size in bytes currently supported by CMAC implementation.
40 * The cipher based algorithms currently supported are
41 * AES-XCBC-MAC-96 and AES-XCBC-PRF-128.
43 const TInt KMacBlockSize = 16;
46 * The class is created from following substance classes
49 * Using the methods of the above classes we will transform/mould the Cipher methods in
50 * a way as to be inline with the MMac interface methods. The MMac methods will
51 * serve as the wrapper internal to which Cipher methods will work to provide the MAC value.
53 * The class was created to provide consistency/similarity HMAC and CMAC works.
54 * Also for future extensibility of other Cipher algorithms.
56 NONSHARABLE_CLASS(CCMacImpl) : public CBase
60 * Cipher MAC implementation instance creation methods
62 *The owneship of 'aSymmetricCipher' is imparted to instance of this class.
64 static CCMacImpl* NewL(const CKey& aKey,
65 CSymmetricCipher* aSymmetricCipher,
66 TInt32 aAlgorithmUid);
68 static CCMacImpl* NewLC(const CKey& aKey,
69 CSymmetricCipher* aSymmetricCipher,
70 TInt32 aAlgorithmUid);
72 * Simulating Methods from MPlugin
74 const CExtendedCharacteristics* GetExtendedCharacteristicsL();
76 // We will call CSymmetricBlockCipherImpl::Reset();
80 * Simulating MAC interfaces (Software based)
82 TPtrC8 MacL(const TDesC8& aMessage);
83 void UpdateL(const TDesC8& aMessage);
84 TPtrC8 FinalL(const TDesC8& aMessage);
85 void ReInitialiseAndSetKeyL(const CKey& aKey);
86 void SetKeyL(const CKey& aKey);
89 CCMacImpl* ReplicateL();
95 CCMacImpl(CryptoSpi::CSymmetricCipher* aSymmetricCipher);
96 CCMacImpl(const CCMacImpl&);
99 * Initialize the 'iCipherImpl' instances.
101 void ConstructL(const CKey& aKey, TInt32 aAlgorithmUid);
102 void DoUpdateL(const TDesC8& aMessage);
105 void ProcessBlockL();
106 void XORKeyWithData(const TDesC8& aKey, TDes8& aOutput);
107 CKey* Create128bitKeyL(const CKey& aKey);
110 TInt32 iImplementationUid;
112 CryptoSpi::CSymmetricCipher* iCipherImpl;
114 TBuf8<KMacBlockSize> iKey1;
115 TBuf8<KMacBlockSize> iKey2;
116 TBuf8<KMacBlockSize> iKey3;
117 TBuf8<KMacBlockSize> iMacValue;
119 TUint8 iE[KMacBlockSize];
120 TUint8 iData[KMacBlockSize];
121 TInt iCurrentTotalLength;
122 // Resets the cipher with iE(128 zero bits) the next time MacL,
123 // UpdateL or FinalL are called. This was introduced as we cannot leave from the
124 // non-leaving CCMacImpl::Reset() implementation of the MPlugin::Reset() pure
125 // virtual. To prevent behavioral break.
130 #endif // __CRYPTOAPI_SOFTWARECIPHERMACIMPL_H__