os/security/crypto/weakcrypto/inc/hash.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.
     1 /*
     2 * Copyright (c) 2000-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 * ** IMPORTANT ** PublishedPartner API's in this file are published to 3rd party developers via the 
    16 * Symbian website. Changes to these API's should be treated as PublishedAll API changes and the Security TA should be consulted.
    17 * This header contains the definition of the message digest classes
    18 *
    19 */
    20 
    21 
    22 /**
    23  @file 
    24  @publishedAll
    25  @released
    26 */
    27 
    28 #ifndef __HASH_H__
    29 #define __HASH_H__
    30 
    31 #include <e32base.h>
    32 
    33 
    34 //Forward Declarations
    35 class MSHA2Impl;
    36 
    37 /**
    38  * Base class for message digests.
    39  */
    40 class CMessageDigest:public CBase
    41 	{
    42 	public:
    43 	/**
    44 	 *	Enumeration to identify hash functions (aka message-digest algorithms).
    45 	 */
    46 	enum THashId
    47 	{
    48 		/** 
    49 		 * Message Digest algorithm developed by Rivest for digital signature
    50 		 * applications (and optimized for 8-bit machines). 
    51 		 * 
    52 		 * Takes a message of arbitrary length and produces a 128-bit message digest. 
    53 		 *
    54 		 * See RFC 1319
    55 		 */
    56 		EMD2,
    57 		/** 
    58 		 * Message Digest algorithm developed by Rivest for digital signature
    59 		 * applications (and optimized for 32-bit machines). 
    60 		 * 
    61 		 * Takes a message of arbitrary length and produces a 128-bit message digest. 
    62 		 * 
    63 		 * See RFC 1321
    64 		 */
    65 		EMD5,
    66 		/** 
    67 		 * Secure Hash Algorithm (version 1) is a message digest algorithm developed by 
    68 		 * NIST, along with the NSA, for use with the Digital Signature Standard (DSS).
    69 		 * 
    70 		 * It takes a message of less than 2^64 bits in length and produces
    71 		 * a 160-bit message digest.
    72 		 *
    73 		 * See FIPS 180-1 and RFC 3174
    74 		 */
    75 		ESHA1,
    76 		/** 
    77 		 * HMAC - Hash function based Message Authentication Code is a mechanism
    78 		 * for message authentication using cryptographic hash functions. (A checksum.)
    79 		 * 
    80 		 * It can be used with any iterative cryptographic hash function,
    81    		 * e.g., MD5, SHA-1, in combination with a secret shared key
    82    		 * to produce a checksum that is appended to the message.
    83    		 * The cryptographic strength of HMAC depends on the properties
    84    		 * of the underlying hash function.
    85 		 *
    86 		 * See RFC 2104 
    87 		 */
    88 		HMAC,
    89 		/** 
    90 		 * Message Digest algorithm developed by Rivest for digital signature
    91 		 * applications (and optimized for 32-bit machines). 
    92 		 * 
    93 		 * Takes a message of arbitrary length and produces a 128-bit message digest. 
    94 		 * 
    95 		 * See RFC 1320
    96 		 */
    97 		EMD4,
    98 		/** 
    99 		 * Secure Hash Algorithm - 224 (version 2) is a message digest algorithm developed by 
   100 		 * NIST, along with the NSA, for use with the Digital Signature Standard (DSS).
   101 		 * 
   102 		 * It takes a message of less than 2^64 bits in length and produces
   103 		 * a 224-bit message digest.
   104 		 *
   105 		 * See FIPS 180-2 (with change notice), RFC3874 and FIPS 180-3
   106 		 */
   107 		ESHA224,
   108 		/** 
   109 		 * Secure Hash Algorithm - 256 (version 2) is a message digest algorithm developed by 
   110 		 * NIST, along with the NSA, for use with the Digital Signature Standard (DSS).
   111 		 * 
   112 		 * It takes a message of less than 2^64 bits in length and produces
   113 		 * a 256-bit message digest.
   114 		 *
   115 		 * See FIPS 180-2 and RFC 4634
   116 		 */
   117 		ESHA256,
   118 		/** 
   119 		 * Secure Hash Algorithm - 384 (version 2) is a message digest algorithm developed by 
   120 		 * NIST, along with the NSA, for use with the Digital Signature Standard (DSS).
   121 		 * 
   122 		 * It takes a message of less than 2^128 bits in length and produces
   123 		 * a 384-bit message digest.
   124 		 *
   125 		 * See FIPS 180-2 and RFC 4634
   126 		 */
   127 		ESHA384,
   128 		/** 
   129 		 * Secure Hash Algorithm - 512 (version 2) is a message digest algorithm developed by 
   130 		 * NIST, along with the NSA, for use with the Digital Signature Standard (DSS).
   131 		 * 
   132 		 * It takes a message of less than 2^128 bits in length and produces
   133 		 * a 512-bit message digest.
   134 		 *
   135 		 * See FIPS 180-2 and RFC 4634
   136 		 */
   137 		ESHA512
   138 	};
   139 	
   140 	public:
   141 		/** 
   142 		 * Creates a brand new reset CMessageDigest object containing no state
   143 		 * information from the current object.  
   144 		 * 
   145 		 * To make a copy of a message digest with its internal state intact,
   146 		 * see CopyL().
   147 		 *
   148 		 * @return A pointer to the new reset CMessageDigest object
   149 		 */
   150 		IMPORT_C virtual CMessageDigest* ReplicateL(void)=0;		
   151 
   152 		/** 
   153 		 * Adds aMessage to the internal representation of data to be hashed,
   154 		 * then returns a TPtrC8 of the finalised hash of all the previously
   155 		 * appended messages.
   156 		 * 
   157 		 * @param aMessage	Data to be included in the hash.
   158 		 * @return			A descriptor pointer to the buffer containing the
   159 		 *					resulting hash.
   160 		 */
   161 		IMPORT_C virtual TPtrC8 Hash(const TDesC8& aMessage)=0;
   162 
   163 		/** 
   164 		 * Creates a new CMessageDigest object with the exact same state as
   165 		 * the current object.  
   166 		 *
   167 		 * This function copies all internal state of the message digest.
   168 		 * To create a new CMessageDigest object without the state of
   169 		 * the current object, see ReplicateL().
   170 		 *
   171 		 * @return A pointer to the new CMessageDigest object
   172 		 */
   173 		IMPORT_C virtual CMessageDigest* CopyL(void)=0;
   174 		
   175 		/** 
   176 		 * Gets the internal block size of the message digest.
   177 		 * 
   178 		 * @return	Internal block size of message digest in bytes.
   179 		 */
   180 		IMPORT_C virtual TInt BlockSize(void)=0;
   181 		
   182 		/** 
   183 		 * Gets the size of the message digest output.
   184 		 *
   185 		 * @return	Output size of the message digest in bytes.
   186 		 */
   187 		IMPORT_C virtual TInt HashSize(void)=0;
   188 		
   189 		/** 
   190 		 * Resets the internal state of the message digest.  
   191 		 *
   192 		 * A reset hash object loses all internal state representing the hashed
   193 		 * data. A reset message digest is suitable to begin a new, distinct hash
   194 		 * of different data.  Any previously returned TPtrC8 from a call to
   195 		 * Final() remains valid until any subsequent call to Update() or
   196 		 * Final().
   197 		 */
   198 		IMPORT_C virtual void Reset(void)=0;
   199 		
   200 		/**
   201 		 * Destructor.
   202 		 */		
   203 		IMPORT_C ~CMessageDigest(void);
   204 	public:
   205 		/** 
   206 		 * Adds data to the internal representation of messages to be hashed.
   207 		 *
   208 		 * @param aMessage	Data to be included in the hash.
   209 		 * @since v8.0
   210 		 */
   211 		IMPORT_C virtual void Update(const TDesC8& aMessage)=0;
   212 		
   213 		/** 
   214 		 * Adds aMessage to the internal representation of data to be hashed,
   215 		 * returns a TPtrC8 of the finalised hash of all the previously
   216 		 * appended messages, and calls Reset().
   217 		 * 
   218 		 * @param aMessage	Data to be included in the hash 
   219 		 * @return			A descriptor pointer to the buffer containing the
   220 		 *					resulting hash.
   221 		 * @since v8.0
   222 		 */
   223 		IMPORT_C virtual TPtrC8 Final(const TDesC8& aMessage)=0;
   224 		
   225 		/** 
   226 		 * Gets a TPtrC8 of the finalised hash of all the previously
   227 		 * appended messages and then calls Reset().
   228 		 * 
   229 		 * @return	A descriptor pointer to the buffer containing the
   230 		 * 			resulting hash.
   231 		 * @since v8.0
   232 		 */
   233 		IMPORT_C virtual TPtrC8 Final(void)=0;
   234 	public:
   235 		/**
   236 		 * Restores the internal state of the message digest
   237 		 * to a previously stored state.
   238 		 *
   239 		 * @see StoreState()
   240 		 */
   241 		virtual void RestoreState() = 0;
   242 
   243 		/**
   244 		 * Stores the internal state of the message digest. 
   245 		 */
   246 		virtual void StoreState() = 0;
   247 	protected:
   248 		/**
   249 		 * Constructor
   250 		 */
   251 		IMPORT_C CMessageDigest(void);
   252 
   253 		/**
   254 		 * Copy constructor
   255 		 *
   256 		 * @param aMD	A CMessageDigest object
   257 		 */
   258 		IMPORT_C CMessageDigest(const CMessageDigest& aMD);
   259 	};
   260 
   261 /** 
   262  * The MD2 block size (in bytes) 
   263  * 
   264  */
   265 const TInt MD2_BLOCK=16;
   266 
   267 /** The size (in bytes) of the MD2 message digest */
   268 const TInt MD2_HASH=16;
   269 
   270 /**
   271  * An MD2 message digest
   272  */
   273 class CMD2:public CMessageDigest
   274 
   275 	{
   276 	public:
   277 		/**
   278 		 * Creates a new MD2 object.
   279 		 *
   280 		 * @return	A pointer to the new CMD2 object
   281 		 */
   282 		IMPORT_C static CMD2* NewL(void);
   283 		IMPORT_C CMessageDigest* ReplicateL(void);
   284 		IMPORT_C TPtrC8 Hash(const TDesC8& aMessage);
   285 		/** Destructor */
   286 		IMPORT_C ~CMD2(void);
   287 		IMPORT_C CMessageDigest* CopyL(void);
   288 		IMPORT_C TInt BlockSize(void);
   289 		IMPORT_C TInt HashSize(void);
   290 		IMPORT_C void Reset(void);
   291 		IMPORT_C void Update(const TDesC8& aMessage);
   292 		IMPORT_C TPtrC8 Final(const TDesC8& aMessage);
   293 		IMPORT_C TPtrC8 Final();
   294 	public:
   295 		void RestoreState();
   296 		void StoreState();
   297 	private:
   298 		void DoUpdate(const TUint8* aData,TUint aLength);
   299 		void DoFinal(void);
   300 		void Block(const TUint8* aData);
   301 	private:
   302 		CMD2(void);
   303 		CMD2(const CMD2& aMD2);
   304 	private:
   305 		TBuf8<MD2_HASH> iHash;
   306 		TInt iNum;
   307 		TUint8 iData[MD2_BLOCK];
   308 		TUint iChecksum[MD2_BLOCK];
   309 		TUint iState[MD2_BLOCK];
   310 	private:
   311 		TBuf8<MD2_HASH> iHashBuf;
   312 		TUint8 iDataTemp[MD2_BLOCK];
   313 		TUint iChecksumTemp[MD2_BLOCK];
   314 		TUint iStateTemp[MD2_BLOCK];
   315 	};
   316 
   317 /** 
   318  * The MD5 block size (in bytes)
   319  * 
   320  */
   321 const TUint MD5_LBLOCK=16;
   322 
   323 /** The size (in bytes) of the MD5 message digest */
   324 const TUint MD5_HASH=16;
   325 
   326 /**
   327  * An MD5 message digest
   328  *
   329  * Takes a message of arbitrary length as input and produces a 128-bit message digest. 
   330  *
   331  * The length of input data should not be longer than 2^32 in bits(2^31 in bytes)
   332  * which is roughly half a gig.
   333  *
   334  */
   335 class CMD5:public CMessageDigest
   336 	{
   337 	public:
   338 		/**
   339 		 * Creates a new MD5 object.
   340 		 *
   341 		 * @return	A pointer to the new CMD5 object
   342 		 */
   343 		IMPORT_C static CMD5* NewL(void);
   344 		IMPORT_C CMessageDigest* ReplicateL(void);
   345 		IMPORT_C TPtrC8 Hash(const TDesC8& aMessage);
   346 		/** Destructor */
   347 		IMPORT_C ~CMD5(void);
   348 		IMPORT_C CMessageDigest* CopyL(void);
   349 		IMPORT_C TInt BlockSize(void);
   350 		IMPORT_C TInt HashSize(void);
   351 		IMPORT_C void Reset(void);
   352 		IMPORT_C void Update(const TDesC8& aMessage);
   353 		IMPORT_C TPtrC8 Final(const TDesC8& aMessage);
   354 		IMPORT_C TPtrC8 Final();
   355 	public:
   356 		void RestoreState();
   357 		void StoreState();
   358 	private:
   359 		CMD5(void);
   360 		CMD5(const CMD5& aMD5);
   361 	private:
   362 		void DoUpdate(const TUint8* aData,TUint aLength);
   363 		void DoFinal(void);
   364 		void Block();
   365 	private:
   366 		TBuf8<MD5_HASH> iHash;
   367 	private:
   368 		TUint iA;
   369 		TUint iB;
   370 		TUint iC;
   371 		TUint iD;
   372 		TUint iNl;
   373 		TUint iNh;
   374 		TUint iData[MD5_LBLOCK];
   375 	private:
   376 		TUint iACopy;
   377 		TUint iBCopy;
   378 		TUint iCCopy;
   379 		TUint iDCopy;
   380 		TUint iNlCopy;
   381 		TUint iNhCopy;
   382 		TUint iDataCopy[MD5_LBLOCK];
   383 	};
   384 
   385 /** 
   386  * The SHA-1 block size (in bytes) 
   387  * 
   388  */
   389 const TUint SHA1_LBLOCK=16;
   390 
   391 /** The size (in bytes) of the SHA-1 message digest */
   392 const TUint SHA1_HASH=20;
   393 
   394 /** The size (in bytes) of the SHA message digest */
   395 const TUint SHA_HASH=SHA1_HASH;
   396 
   397 /**
   398  * A SHA-1 message digest
   399  */
   400 class CSHA1:public CMessageDigest
   401 	{
   402 	public:
   403 		/**
   404 		 * Creates a new SHA-1 object.
   405 		 *
   406 		 * @return	A pointer to the new SHA-1 object
   407 		 */
   408 		IMPORT_C static CSHA1* NewL(void);
   409 		IMPORT_C CMessageDigest* ReplicateL(void);
   410 		IMPORT_C TPtrC8 Hash(const TDesC8& aMessage);
   411 		/** Destructor */
   412 		IMPORT_C ~CSHA1(void);
   413 		IMPORT_C CMessageDigest* CopyL(void);
   414 		IMPORT_C TInt BlockSize(void);
   415 		IMPORT_C TInt HashSize(void);
   416 		IMPORT_C void Reset(void);
   417 		IMPORT_C void Update(const TDesC8& aMessage);
   418 		IMPORT_C TPtrC8 Final(const TDesC8& aMessage);
   419 		IMPORT_C TPtrC8 Final();
   420 	public:
   421 		void RestoreState();
   422 		void StoreState();
   423 	private:
   424 		CSHA1(void);
   425 		CSHA1(const CSHA1& aSHA1);
   426 		void ConstructL(void);
   427 	private:
   428 		void DoUpdate(const TUint8* aData,TUint aLength);
   429 		void DoFinal(void);
   430 		void Block();
   431 	private:
   432 		TBuf8<SHA1_HASH> iHash;
   433 		TUint iA;
   434 		TUint iB;
   435 		TUint iC;
   436 		TUint iD;
   437 		TUint iE;
   438 		TUint iNl;
   439 		TUint iNh;
   440 		TUint iData[SHA1_LBLOCK*5];
   441 	private:
   442 		TUint iACopy;
   443 		TUint iBCopy;
   444 		TUint iCCopy;
   445 		TUint iDCopy;
   446 		TUint iECopy;
   447 		TUint iNlCopy;
   448 		TUint iNhCopy;	
   449 		TUint iDataCopy[SHA1_LBLOCK*5];
   450 	};
   451 
   452 enum TSH2Algo
   453 	{
   454 	E224Bit,
   455 	E256Bit,
   456 	E384Bit,
   457 	E512Bit
   458 	};
   459 	
   460 /**
   461  * A SHA-2 message digest
   462  * 
   463  * SHA-2 comprises of SHA-224, SHA256, SHA384 and SHA512
   464  */
   465 class CSHA2 : public CMessageDigest
   466 	{
   467 public:
   468 	//NewL & NewLC	
   469 	IMPORT_C static CSHA2* NewL(TSH2Algo aAlgorithmId);
   470 	IMPORT_C static CSHA2* NewLC(TSH2Algo aAlgorithmId);
   471 	
   472 	/** Destructor */
   473 	IMPORT_C ~CSHA2(void);
   474 	
   475 	//From CMessageDigest
   476 	IMPORT_C CMessageDigest* ReplicateL(void);
   477 	IMPORT_C TPtrC8 Hash(const TDesC8& aMessage);
   478 	IMPORT_C CMessageDigest* CopyL(void);
   479 	IMPORT_C TInt BlockSize(void);
   480 	IMPORT_C TInt HashSize(void);
   481 	IMPORT_C void Reset(void);
   482 	IMPORT_C void Update(const TDesC8& aMessage);
   483 	IMPORT_C TPtrC8 Final(const TDesC8& aMessage);
   484 	IMPORT_C TPtrC8 Final();
   485 
   486 public:
   487 	void RestoreState();
   488 	void StoreState();
   489 	
   490 private:
   491 	//Constructors
   492 	void ConstructL(TSH2Algo aAlgorithmId);
   493 	void ConstructL(const CSHA2& aSHA512);
   494 	
   495 private:
   496 	MSHA2Impl*	iImplementation;
   497 	const TAny*	iInitValues;
   498 	TSH2Algo	iAlgorithmType;
   499 	TUint		iHashSize;
   500 	};	
   501 	
   502 /**
   503  * A SHA message digest
   504  *
   505  * @deprecated Replaced by CSHA1
   506  */
   507 class CSHA:public CMessageDigest
   508 	{
   509 	public:
   510 		/**
   511 		 * Creates a new SHA object.
   512 		 *
   513 		 * @return	A pointer to the new SHA object
   514 		 */
   515 		IMPORT_C static CSHA* NewL(void);
   516 		IMPORT_C CMessageDigest* ReplicateL(void);
   517 		IMPORT_C TPtrC8 Hash(const TDesC8& aMessage);
   518 		/** Destructor */
   519 		IMPORT_C ~CSHA(void);
   520 		IMPORT_C CMessageDigest* CopyL(void);
   521 		IMPORT_C TInt BlockSize(void);
   522 		IMPORT_C TInt HashSize(void);
   523 		IMPORT_C void Reset(void);
   524 		IMPORT_C void Update(const TDesC8& aMessage);
   525 		IMPORT_C TPtrC8 Final(const TDesC8& aMessage);
   526 		IMPORT_C TPtrC8 Final();
   527 	public:
   528 		void RestoreState();
   529 		void StoreState();
   530 	};
   531 
   532 /**
   533  * This is the maximum block size currently supported by HMAC implementation.
   534  */ 
   535 	const TUint KMaxBlockSize=128;
   536 
   537 /**
   538  * An HMAC (Hashed Message Authentication Code)
   539  */
   540 	class CHMAC:public CMessageDigest
   541 
   542 	{
   543 	public:
   544 		/**
   545 		 * Creates a new HMAC object from a specified type of message digest 
   546 		 * and authentication key.
   547 		 * 
   548 		 * @param aKey		Authentication key.
   549 		 * @param aDigest	A message digest to construct the HMAC from.
   550 		 * @return			A pointer to the new CHMAC object. 
   551 		 *					The resulting HMAC object takes ownership of aDigest
   552 		 *					and is responsible for its deletion.
   553 		 */
   554 		IMPORT_C static CHMAC* NewL(const TDesC8& aKey,CMessageDigest* aDigest);
   555 		IMPORT_C CMessageDigest* ReplicateL(void);
   556 		IMPORT_C TPtrC8 Hash(const TDesC8& aMessage);
   557 		/** Destructor */
   558 		IMPORT_C ~CHMAC(void);
   559 		IMPORT_C CMessageDigest* CopyL(void);
   560 		IMPORT_C TInt BlockSize(void);
   561 		IMPORT_C TInt HashSize(void);
   562 		IMPORT_C void Reset(void);
   563 		IMPORT_C void Update(const TDesC8& aMessage);
   564 		IMPORT_C TPtrC8 Final(const TDesC8& aMessage);
   565 		IMPORT_C TPtrC8 Final();
   566 	public:
   567 		void RestoreState();
   568 		void StoreState();
   569 	private:
   570 		CHMAC(void);
   571 		CHMAC(CMessageDigest* aDigest);
   572 		CHMAC(const CHMAC& aHMAC);
   573 		void InitialiseL(const TDesC8& aKey);
   574 		void InitBlockSizeL();
   575 		
   576 	private:
   577 		CMessageDigest* iDigest;
   578 		TBuf8<KMaxBlockSize> iInnerPad;
   579 		TBuf8<KMaxBlockSize> iOuterPad;
   580 		TBuf8<KMaxBlockSize> iInnerPadCopy;
   581 		TBuf8<KMaxBlockSize> iOuterPadCopy;		
   582 		TInt iBlockSize;
   583 	};
   584 	
   585 /** 
   586  * The MD4 block size 
   587  */
   588  const TUint MD4_LBLOCK=16;
   589 
   590 /** The size (in bytes) of the MD4 message digest */
   591  const TUint MD4_HASH=16;
   592 
   593 
   594 /**
   595  * An MD4 message digest Algorithm.
   596  *
   597  * Takes a message of arbitrary length as input and produces a 128-bit message digest. 
   598  *
   599  * The total input length of data should not be longer than 2^32 in bits(2^31 in bytes)
   600  * which is roughly half a gig.
   601  *
   602  */
   603 class CMD4:public CMessageDigest
   604 	{
   605 	public:
   606 		/**
   607 		 * Creates a new MD4 object.
   608 		 *
   609 		 * @return	A pointer to the new CMD4 object
   610 		 */
   611 		IMPORT_C static CMD4* NewL(void);
   612 		IMPORT_C CMessageDigest* ReplicateL(void);
   613 		IMPORT_C TPtrC8 Hash(const TDesC8& aMessage);
   614 		/** Destructor */
   615 		IMPORT_C ~CMD4(void);
   616 		IMPORT_C CMessageDigest* CopyL(void);
   617 		IMPORT_C TInt BlockSize(void);
   618 		IMPORT_C TInt HashSize(void);
   619 		IMPORT_C void Reset(void);
   620 		IMPORT_C void Update(const TDesC8& aMessage);
   621 		IMPORT_C TPtrC8 Final(const TDesC8& aMessage);
   622 		IMPORT_C TPtrC8 Final();
   623 	public:
   624 		virtual void RestoreState();
   625 		virtual void StoreState();
   626 	private:
   627 		CMD4(void);
   628 		CMD4(const CMD4& aMD4);
   629 	private:
   630 	   /**
   631 		* Divides the message into blocks of 512 bits and performs the
   632 		* Block operation on them.
   633 		*/
   634 		void DoUpdate(const TUint8* aData,TUint aLength);
   635 	   /**
   636 		* Performs the Block operation on the last 512 bit block.
   637 		* This function does the padding on the last 512 bit block
   638 		* and also appends the length of the message to the last 64-bits
   639 		* of the block.
   640 		*/
   641 		void DoFinal(void);
   642 	   /**
   643 		* Performs the Block operation on the 512 bit blocks
   644 		*/
   645 		void Block();
   646 	private:
   647 		/*Holds the generated 128-bit Message Digest*/
   648 		TBuf8<MD4_HASH> iHash;
   649 	private:
   650 		TUint iA;
   651 		TUint iB;
   652 		TUint iC;
   653 		TUint iD;
   654 		TUint iNl;
   655 		TUint iNh;
   656 		TUint iData[MD4_LBLOCK];
   657 	private:
   658 		TUint iACopy;
   659 		TUint iBCopy;
   660 		TUint iCCopy;
   661 		TUint iDCopy;
   662 		TUint iNlCopy;
   663 		TUint iNhCopy;
   664 		TUint iDataCopy[MD4_LBLOCK];
   665 	};
   666 
   667 
   668 /**
   669  *	Factory to create a CMessageDigest derived object according to the identity of the hash algorithm.
   670  */
   671 class CMessageDigestFactory : public CBase
   672 {
   673 public:
   674 	/**
   675 	 * Creates a CMessageDigest derived object according to the specified type of hash algorithm.
   676 	 *
   677 	 * @param aHashId	The identity of the hash algorithm
   678 	 * @return			A pointer to a CMessageDigest object
   679 	 */
   680 	IMPORT_C static CMessageDigest* NewDigestL(CMessageDigest::THashId aHashId);
   681 
   682 	/**
   683 	 * Creates a CMessageDigest derived object according to the specified type of hash algorithm.
   684 	 * 
   685 	 * The returned pointer is put onto the cleanup stack.
   686 	 *
   687 	 * @param aHashId	The identity of the hash algorithm
   688 	 * @return			A pointer to a CMessageDigest object
   689 	 */
   690 	IMPORT_C static CMessageDigest* NewDigestLC(CMessageDigest::THashId aHashId);
   691 
   692 	/**
   693 	 * Creates a CMessageDigest derived object according to the specified type of hash algorithm
   694 	 * and authentication key.
   695 	 *
   696 	 * @param aHashId	The identity of the hash algorithm
   697 	 * @param aKey		The authentication key 
   698 	 * @return			A pointer to a CMessageDigest object
   699 	 */
   700 	IMPORT_C static CMessageDigest* NewHMACL(CMessageDigest::THashId aHashId, const TDesC8& aKey);
   701 
   702 	/**
   703 	 * Creates a CMessageDigest derived object according to the specified type of hash algorithm
   704 	 * and authentication key.
   705 	 * 
   706 	 * The returned pointer is put onto the cleanup stack.
   707 	 *
   708 	 * @param aHashId	The identity of the hash algorithm
   709 	 * @param aKey		The authentication key 
   710 	 * @return			A pointer to a CMessageDigest object
   711 	 */
   712 	IMPORT_C static CMessageDigest* NewHMACLC(CMessageDigest::THashId aHashId, const TDesC8& aKey);
   713 };
   714 
   715 #endif // __HASH_H__