os/security/crypto/weakcryptospi/test/tplugins/inc/softwarehashbase.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 2006-2010 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 <cryptospi/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 	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 
    65 #ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT
    66 		static CSoftwareHash* NewL(TUid aAlgorithm);
    67 #endif
    68 
    69 		//
    70 		// Destructor
    71 		//
    72 		~CSoftwareHash();
    73 		//
    74 		//From MPlugin
    75 		//
    76 		void Reset();
    77 		void Close();		
    78 		void GetCharacteristicsL(const TCharacteristics*& aPluginCharacteristics);		
    79 		const CExtendedCharacteristics* GetExtendedCharacteristicsL();
    80 		TAny* GetExtension(TUid aExtensionId);
    81 		//
    82 		//From MHash
    83 		//
    84 	    TPtrC8 Hash(const TDesC8& aMessage);
    85 	    void Update(const TDesC8& aMessage);
    86 		TPtrC8 Final(const TDesC8& aMessage);
    87 		MHash* ReplicateL();		
    88 		MHash* CopyL();
    89 		void SetKeyL(const CKey& aKey);			
    90 		void SetOperationModeL(TUid aOperationMode);
    91 	
    92 	private:
    93 		//
    94 		//Constructor
    95 		// 
    96 		CSoftwareHash();
    97 		void ConstructL(TUid aAlgorithm, TUid aOperationMode, const CKey* aKey);
    98 		
    99 		//
   100 		//get the active implementation
   101 		//
   102 		MSoftwareHash* Impl();
   103 		
   104 	private:
   105 		/**
   106 		The Key for HMAC mode operation
   107 		*/
   108 		CKey* iKey;
   109 		
   110 		/**
   111 		The Uid for the operation mode
   112 		*/
   113 		TUid iOperationMode;
   114 		
   115 		/**
   116 		The hash implementation
   117 		*/
   118 		MSoftwareHash* iHashImpl;
   119 		
   120 		/**
   121 		The Hmac implementation
   122 		*/
   123 		MSoftwareHash* iHmacImpl;
   124 		};
   125 		
   126 	GLDEF_C inline TUint CMD_R(TUint a,TUint s)
   127 		{
   128 		return (a<<s) | (a>>(32-s));
   129 		}
   130 	}
   131 	
   132 
   133 #endif // __CRYPTOAPI_SOFTWAREHASHBASE_H__