os/security/cryptoplugins/cryptospiplugins/source/softwarecrypto/cmacimpl.h
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     3
* All rights reserved.
sl@0
     4
* This component and the accompanying materials are made available
sl@0
     5
* under the terms of the License "Eclipse Public License v1.0"
sl@0
     6
* which accompanies this distribution, and is available
sl@0
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
*
sl@0
     9
* Initial Contributors:
sl@0
    10
* Nokia Corporation - initial contribution.
sl@0
    11
*
sl@0
    12
* Contributors:
sl@0
    13
*
sl@0
    14
* Description: 
sl@0
    15
* Cipher MAC plugin implementation
sl@0
    16
*
sl@0
    17
*/
sl@0
    18
sl@0
    19
sl@0
    20
/**
sl@0
    21
 @file
sl@0
    22
 @internalComponent
sl@0
    23
 @released
sl@0
    24
*/
sl@0
    25
sl@0
    26
#ifndef __CRYPTOAPI_SOFTWARECIPHERMACIMPL_H__
sl@0
    27
#define __CRYPTOAPI_SOFTWARECIPHERMACIMPL_H__
sl@0
    28
sl@0
    29
#include "cryptosymmetriccipherapi.h"
sl@0
    30
#include "keys.h"
sl@0
    31
sl@0
    32
sl@0
    33
namespace SoftwareCrypto
sl@0
    34
	{
sl@0
    35
	using namespace CryptoSpi;
sl@0
    36
		
sl@0
    37
	/**
sl@0
    38
	 * This is the maximum block size in bytes currently supported by CMAC implementation.
sl@0
    39
	 * 
sl@0
    40
	 * The cipher based algorithms currently supported are
sl@0
    41
	 * AES-XCBC-MAC-96 and AES-XCBC-PRF-128.
sl@0
    42
	 */  
sl@0
    43
	const TInt KMacBlockSize = 16;		
sl@0
    44
	
sl@0
    45
	/** 
sl@0
    46
	 * The class is created from following substance classes
sl@0
    47
	 * 1. MMac
sl@0
    48
	 * 2. CSymmetricCipher
sl@0
    49
	 * Using the methods of the above classes we will transform/mould the Cipher methods in
sl@0
    50
	 * a way as to be inline with the MMac interface methods. The MMac methods will
sl@0
    51
	 * serve as the wrapper internal to which Cipher methods will work to provide the MAC value.
sl@0
    52
	 * 
sl@0
    53
	 * The class was created to provide consistency/similarity HMAC and CMAC works.
sl@0
    54
	 * Also for future extensibility of other Cipher algorithms.
sl@0
    55
	 */		
sl@0
    56
	NONSHARABLE_CLASS(CCMacImpl) : public CBase
sl@0
    57
		{		
sl@0
    58
	public:
sl@0
    59
		/**
sl@0
    60
		 * Cipher MAC implementation instance creation methods
sl@0
    61
		 *
sl@0
    62
		 *The owneship of 'aSymmetricCipher' is imparted to instance of this class.
sl@0
    63
		 */
sl@0
    64
		static CCMacImpl* NewL(const CKey& aKey,
sl@0
    65
			        		   CSymmetricCipher* aSymmetricCipher,	
sl@0
    66
				               TInt32 aAlgorithmUid);
sl@0
    67
		
sl@0
    68
		static CCMacImpl* NewLC(const CKey& aKey, 
sl@0
    69
							    CSymmetricCipher* aSymmetricCipher,	
sl@0
    70
							    TInt32 aAlgorithmUid);
sl@0
    71
		/**
sl@0
    72
		 * Simulating Methods from MPlugin
sl@0
    73
		 */
sl@0
    74
		const CExtendedCharacteristics* GetExtendedCharacteristicsL();
sl@0
    75
		
sl@0
    76
		// We will call CSymmetricBlockCipherImpl::Reset();
sl@0
    77
		void Reset();
sl@0
    78
		
sl@0
    79
		/**
sl@0
    80
		 *  Simulating MAC interfaces (Software based)
sl@0
    81
		 */
sl@0
    82
	    TPtrC8 MacL(const TDesC8& aMessage);
sl@0
    83
        void UpdateL(const TDesC8& aMessage);
sl@0
    84
        TPtrC8 FinalL(const TDesC8& aMessage);
sl@0
    85
		void ReInitialiseAndSetKeyL(const CKey& aKey);    
sl@0
    86
		void SetKeyL(const CKey& aKey);
sl@0
    87
		~CCMacImpl();
sl@0
    88
		CCMacImpl* CopyL();
sl@0
    89
		CCMacImpl* ReplicateL();
sl@0
    90
		
sl@0
    91
	private:
sl@0
    92
	    /**
sl@0
    93
		 * Constructors
sl@0
    94
		 */
sl@0
    95
    	CCMacImpl(CryptoSpi::CSymmetricCipher* aSymmetricCipher);
sl@0
    96
		CCMacImpl(const CCMacImpl&);
sl@0
    97
		
sl@0
    98
		/**
sl@0
    99
		 * Initialize the 'iCipherImpl' instances.
sl@0
   100
		 */
sl@0
   101
		void ConstructL(const CKey& aKey, TInt32 aAlgorithmUid);
sl@0
   102
		void DoUpdateL(const TDesC8& aMessage);
sl@0
   103
		TPtrC8 DoFinalL();
sl@0
   104
		void PadMessage();
sl@0
   105
		void ProcessBlockL();
sl@0
   106
		void XORKeyWithData(const TDesC8& aKey, TDes8& aOutput);
sl@0
   107
		CKey* Create128bitKeyL(const CKey& aKey);		
sl@0
   108
		
sl@0
   109
	private:			
sl@0
   110
		TInt32 iImplementationUid; 
sl@0
   111
		CKey* iKey;
sl@0
   112
		CryptoSpi::CSymmetricCipher* iCipherImpl;
sl@0
   113
		
sl@0
   114
		TBuf8<KMacBlockSize> iKey1;
sl@0
   115
		TBuf8<KMacBlockSize> iKey2;
sl@0
   116
		TBuf8<KMacBlockSize> iKey3;
sl@0
   117
		TBuf8<KMacBlockSize> iMacValue;
sl@0
   118
	
sl@0
   119
		TUint8 iE[KMacBlockSize];
sl@0
   120
		TUint8 iData[KMacBlockSize];
sl@0
   121
		TInt iCurrentTotalLength;
sl@0
   122
		// Resets the cipher with iE(128 zero bits) the next time MacL, 
sl@0
   123
		// UpdateL or FinalL are called. This was introduced as we cannot leave from the
sl@0
   124
		// non-leaving CCMacImpl::Reset() implementation of the MPlugin::Reset() pure 
sl@0
   125
		// virtual. To prevent behavioral break.
sl@0
   126
		TInt iDelayedReset;
sl@0
   127
		};
sl@0
   128
	}
sl@0
   129
sl@0
   130
#endif // __CRYPTOAPI_SOFTWARECIPHERMACIMPL_H__
sl@0
   131
sl@0
   132