os/security/cryptoplugins/cryptospiplugins/source/softwarecrypto/cmacimpl.h
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/security/cryptoplugins/cryptospiplugins/source/softwarecrypto/cmacimpl.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,132 @@
     1.4 +/*
     1.5 +* Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of the License "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description: 
    1.18 +* Cipher MAC plugin implementation
    1.19 +*
    1.20 +*/
    1.21 +
    1.22 +
    1.23 +/**
    1.24 + @file
    1.25 + @internalComponent
    1.26 + @released
    1.27 +*/
    1.28 +
    1.29 +#ifndef __CRYPTOAPI_SOFTWARECIPHERMACIMPL_H__
    1.30 +#define __CRYPTOAPI_SOFTWARECIPHERMACIMPL_H__
    1.31 +
    1.32 +#include "cryptosymmetriccipherapi.h"
    1.33 +#include "keys.h"
    1.34 +
    1.35 +
    1.36 +namespace SoftwareCrypto
    1.37 +	{
    1.38 +	using namespace CryptoSpi;
    1.39 +		
    1.40 +	/**
    1.41 +	 * This is the maximum block size in bytes currently supported by CMAC implementation.
    1.42 +	 * 
    1.43 +	 * The cipher based algorithms currently supported are
    1.44 +	 * AES-XCBC-MAC-96 and AES-XCBC-PRF-128.
    1.45 +	 */  
    1.46 +	const TInt KMacBlockSize = 16;		
    1.47 +	
    1.48 +	/** 
    1.49 +	 * The class is created from following substance classes
    1.50 +	 * 1. MMac
    1.51 +	 * 2. CSymmetricCipher
    1.52 +	 * Using the methods of the above classes we will transform/mould the Cipher methods in
    1.53 +	 * a way as to be inline with the MMac interface methods. The MMac methods will
    1.54 +	 * serve as the wrapper internal to which Cipher methods will work to provide the MAC value.
    1.55 +	 * 
    1.56 +	 * The class was created to provide consistency/similarity HMAC and CMAC works.
    1.57 +	 * Also for future extensibility of other Cipher algorithms.
    1.58 +	 */		
    1.59 +	NONSHARABLE_CLASS(CCMacImpl) : public CBase
    1.60 +		{		
    1.61 +	public:
    1.62 +		/**
    1.63 +		 * Cipher MAC implementation instance creation methods
    1.64 +		 *
    1.65 +		 *The owneship of 'aSymmetricCipher' is imparted to instance of this class.
    1.66 +		 */
    1.67 +		static CCMacImpl* NewL(const CKey& aKey,
    1.68 +			        		   CSymmetricCipher* aSymmetricCipher,	
    1.69 +				               TInt32 aAlgorithmUid);
    1.70 +		
    1.71 +		static CCMacImpl* NewLC(const CKey& aKey, 
    1.72 +							    CSymmetricCipher* aSymmetricCipher,	
    1.73 +							    TInt32 aAlgorithmUid);
    1.74 +		/**
    1.75 +		 * Simulating Methods from MPlugin
    1.76 +		 */
    1.77 +		const CExtendedCharacteristics* GetExtendedCharacteristicsL();
    1.78 +		
    1.79 +		// We will call CSymmetricBlockCipherImpl::Reset();
    1.80 +		void Reset();
    1.81 +		
    1.82 +		/**
    1.83 +		 *  Simulating MAC interfaces (Software based)
    1.84 +		 */
    1.85 +	    TPtrC8 MacL(const TDesC8& aMessage);
    1.86 +        void UpdateL(const TDesC8& aMessage);
    1.87 +        TPtrC8 FinalL(const TDesC8& aMessage);
    1.88 +		void ReInitialiseAndSetKeyL(const CKey& aKey);    
    1.89 +		void SetKeyL(const CKey& aKey);
    1.90 +		~CCMacImpl();
    1.91 +		CCMacImpl* CopyL();
    1.92 +		CCMacImpl* ReplicateL();
    1.93 +		
    1.94 +	private:
    1.95 +	    /**
    1.96 +		 * Constructors
    1.97 +		 */
    1.98 +    	CCMacImpl(CryptoSpi::CSymmetricCipher* aSymmetricCipher);
    1.99 +		CCMacImpl(const CCMacImpl&);
   1.100 +		
   1.101 +		/**
   1.102 +		 * Initialize the 'iCipherImpl' instances.
   1.103 +		 */
   1.104 +		void ConstructL(const CKey& aKey, TInt32 aAlgorithmUid);
   1.105 +		void DoUpdateL(const TDesC8& aMessage);
   1.106 +		TPtrC8 DoFinalL();
   1.107 +		void PadMessage();
   1.108 +		void ProcessBlockL();
   1.109 +		void XORKeyWithData(const TDesC8& aKey, TDes8& aOutput);
   1.110 +		CKey* Create128bitKeyL(const CKey& aKey);		
   1.111 +		
   1.112 +	private:			
   1.113 +		TInt32 iImplementationUid; 
   1.114 +		CKey* iKey;
   1.115 +		CryptoSpi::CSymmetricCipher* iCipherImpl;
   1.116 +		
   1.117 +		TBuf8<KMacBlockSize> iKey1;
   1.118 +		TBuf8<KMacBlockSize> iKey2;
   1.119 +		TBuf8<KMacBlockSize> iKey3;
   1.120 +		TBuf8<KMacBlockSize> iMacValue;
   1.121 +	
   1.122 +		TUint8 iE[KMacBlockSize];
   1.123 +		TUint8 iData[KMacBlockSize];
   1.124 +		TInt iCurrentTotalLength;
   1.125 +		// Resets the cipher with iE(128 zero bits) the next time MacL, 
   1.126 +		// UpdateL or FinalL are called. This was introduced as we cannot leave from the
   1.127 +		// non-leaving CCMacImpl::Reset() implementation of the MPlugin::Reset() pure 
   1.128 +		// virtual. To prevent behavioral break.
   1.129 +		TInt iDelayedReset;
   1.130 +		};
   1.131 +	}
   1.132 +
   1.133 +#endif // __CRYPTOAPI_SOFTWARECIPHERMACIMPL_H__
   1.134 +
   1.135 +