cryptoplugins/cryptospiplugins/source/softwarecrypto/softwarehashbase.h
changeset 17 cd501b96611d
equal deleted inserted replaced
15:da2ae96f639b 17:cd501b96611d
       
     1 /*
       
     2 * Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     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".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 * Software hash base definition
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 /**
       
    21  @file
       
    22  @internalComponent
       
    23  @released
       
    24 */
       
    25 
       
    26 #ifndef __CRYPTOAPI_SOFTWAREHASHBASE_H__
       
    27 #define __CRYPTOAPI_SOFTWAREHASHBASE_H__
       
    28 
       
    29 #include <cryptospi/hashplugin.h>
       
    30 #include "keys.h"
       
    31 
       
    32 namespace SoftwareCrypto
       
    33 	{
       
    34 	using namespace CryptoSpi;
       
    35 	/**
       
    36 	Interfaces for Software Hash
       
    37 	*/
       
    38 	class MSoftwareHash : public MHash
       
    39 		{
       
    40 	public:
       
    41 		/**
       
    42 		Restores the internal state of the message digest
       
    43 		to a previously stored state.
       
    44 		*/
       
    45 		virtual void RestoreState() = 0;
       
    46 
       
    47 		/**
       
    48 		Stores the internal state of the message digest.
       
    49 		*/
       
    50 		virtual void StoreState() = 0;
       
    51 		};
       
    52 			
       
    53 	/**
       
    54 	Proxy class Software Hash and Hmac implementation
       
    55 	*/
       
    56 	NONSHARABLE_CLASS(CSoftwareHash) : public MHash, public CBase
       
    57 		{
       
    58 	public:
       
    59 		//
       
    60 		//NewL & NewLC
       
    61 		//
       
    62 		static CSoftwareHash* NewL(TUid aAlgorithm, TUid aOperationMode, const CKey* aKey);
       
    63 		static CSoftwareHash* NewLC(TUid aAlgorithm, TUid aOperationMode, const CKey* aKey);
       
    64 		static CSoftwareHash* NewL(TUid aAlgorithm);
       
    65 
       
    66 		//
       
    67 		// Destructor
       
    68 		//
       
    69 		~CSoftwareHash();
       
    70 		//
       
    71 		//From MPlugin
       
    72 		//
       
    73 		void Reset();
       
    74 		void Close();		
       
    75 		void GetCharacteristicsL(const TCharacteristics*& aPluginCharacteristics);		
       
    76 		const CExtendedCharacteristics* GetExtendedCharacteristicsL();
       
    77 		TAny* GetExtension(TUid aExtensionId);
       
    78 		//
       
    79 		//From MHash
       
    80 		//
       
    81 	    TPtrC8 Hash(const TDesC8& aMessage);
       
    82 	    void Update(const TDesC8& aMessage);
       
    83 		TPtrC8 Final(const TDesC8& aMessage);
       
    84 		MHash* ReplicateL();		
       
    85 		MHash* CopyL();
       
    86 		void SetKeyL(const CKey& aKey);			
       
    87 		void SetOperationModeL(TUid aOperationMode);
       
    88 	
       
    89 	private:
       
    90 		//
       
    91 		//Constructor
       
    92 		// 
       
    93 		CSoftwareHash();
       
    94 		void ConstructL(TUid aAlgorithm, TUid aOperationMode, const CKey* aKey);
       
    95 		
       
    96 		//
       
    97 		//get the active implementation
       
    98 		//
       
    99 		MSoftwareHash* Impl();
       
   100 		
       
   101 	private:
       
   102 		/**
       
   103 		The Key for HMAC mode operation
       
   104 		*/
       
   105 		CKey* iKey;
       
   106 		
       
   107 		/**
       
   108 		The Uid for the operation mode
       
   109 		*/
       
   110 		TUid iOperationMode;
       
   111 		
       
   112 		/**
       
   113 		The hash implementation
       
   114 		*/
       
   115 		MSoftwareHash* iHashImpl;
       
   116 		
       
   117 		/**
       
   118 		The Hmac implementation
       
   119 		*/
       
   120 		MSoftwareHash* iHmacImpl;
       
   121 		};
       
   122 		
       
   123 	GLDEF_C inline TUint CMD_R(TUint a,TUint s)
       
   124 		{
       
   125 		return (a<<s) | (a>>(32-s));
       
   126 		}
       
   127 	}
       
   128 	
       
   129 
       
   130 #endif // __CRYPTOAPI_SOFTWAREHASHBASE_H__