williamr@2: /*
williamr@2: * Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
williamr@2: * All rights reserved.
williamr@2: * This component and the accompanying materials are made available
williamr@2: * under the terms of the License "Eclipse Public License v1.0"
williamr@2: * which accompanies this distribution, and is available
williamr@2: * at the URL "http://www.eclipse.org/legal/epl-v10.html".
williamr@2: *
williamr@2: * Initial Contributors:
williamr@2: * Nokia Corporation - initial contribution.
williamr@2: *
williamr@2: * Contributors:
williamr@2: *
williamr@2: * Description: 
williamr@2: * ** IMPORTANT ** PublishedPartner API's in this file are published to 3rd party developers via the 
williamr@2: * Symbian website. Changes to these API's should be treated as PublishedAll API changes and the Security TA should be consulted.
williamr@2: * This header contains the definition of the message digest classes
williamr@2: *
williamr@2: */
williamr@2: 
williamr@2: 
williamr@2: /**
williamr@2:  @file 
williamr@2:  @publishedAll
williamr@2:  @released
williamr@2: */
williamr@2: 
williamr@2: #ifndef __HASH_H__
williamr@2: #define __HASH_H__
williamr@2: 
williamr@2: #include <e32base.h>
williamr@2: 
williamr@2: /**
williamr@2:  * Base class for message digests.
williamr@2:  */
williamr@2: class CMessageDigest:public CBase
williamr@2: 	{
williamr@2: 	public:
williamr@2: 	/**
williamr@2: 	 *	Enumeration to identify hash functions (aka message-digest algorithms).
williamr@2: 	 */
williamr@2: 	enum THashId
williamr@2: 	{
williamr@2: 		/** 
williamr@2: 		 * Message Digest algorithm developed by Rivest for digital signature
williamr@2: 		 * applications (and optimized for 8-bit machines). 
williamr@2: 		 * 
williamr@2: 		 * Takes a message of arbitrary length and produces a 128-bit message digest. 
williamr@2: 		 *
williamr@2: 		 * See RFC 1319
williamr@2: 		 */
williamr@2: 		EMD2,
williamr@2: 		/** 
williamr@2: 		 * Message Digest algorithm developed by Rivest for digital signature
williamr@2: 		 * applications (and optimized for 32-bit machines). 
williamr@2: 		 * 
williamr@2: 		 * Takes a message of arbitrary length and produces a 128-bit message digest. 
williamr@2: 		 * 
williamr@2: 		 * See RFC 1321
williamr@2: 		 */
williamr@2: 		EMD5,
williamr@2: 		/** 
williamr@2: 		 * Secure Hash Algorithm (version 1) is a message digest algorithm developed by 
williamr@2: 		 * NIST, along with the NSA, for use with the Digital Signature Standard (DSS).
williamr@2: 		 * 
williamr@2: 		 * It takes a message of less than 2^64 bits in length and produces
williamr@2: 		 * a 160-bit message digest.
williamr@2: 		 *
williamr@2: 		 * See FIPS 180-1 and RFC 3174
williamr@2: 		 */
williamr@2: 		ESHA1,
williamr@2: 		/** 
williamr@2: 		 * HMAC - Hash function based Message Authentication Code is a mechanism
williamr@2: 		 * for message authentication using cryptographic hash functions. (A checksum.)
williamr@2: 		 * 
williamr@2: 		 * It can be used with any iterative cryptographic hash function,
williamr@2:    		 * e.g., MD5, SHA-1, in combination with a secret shared key
williamr@2:    		 * to produce a checksum that is appended to the message.
williamr@2:    		 * The cryptographic strength of HMAC depends on the properties
williamr@2:    		 * of the underlying hash function.
williamr@2: 		 *
williamr@2: 		 * See RFC 2104 
williamr@2: 		 */
williamr@2: 		HMAC,
williamr@2: 		/** 
williamr@2: 		 * Message Digest algorithm developed by Rivest for digital signature
williamr@2: 		 * applications (and optimized for 32-bit machines). 
williamr@2: 		 * 
williamr@2: 		 * Takes a message of arbitrary length and produces a 128-bit message digest. 
williamr@2: 		 * 
williamr@2: 		 * See RFC 1320
williamr@2: 		 */
williamr@2: 		EMD4,
williamr@2: 		/** 
williamr@2: 		 * Secure Hash Algorithm - 224 (version 2) is a message digest algorithm developed by 
williamr@2: 		 * NIST, along with the NSA, for use with the Digital Signature Standard (DSS).
williamr@2: 		 * 
williamr@2: 		 * It takes a message of less than 2^64 bits in length and produces
williamr@2: 		 * a 224-bit message digest.
williamr@2: 		 *
williamr@2: 		 * See FIPS 180-2 (with change notice), RFC3874 and FIPS 180-3
williamr@2: 		 */
williamr@2: 		ESHA224,
williamr@2: 		/** 
williamr@2: 		 * Secure Hash Algorithm - 256 (version 2) is a message digest algorithm developed by 
williamr@2: 		 * NIST, along with the NSA, for use with the Digital Signature Standard (DSS).
williamr@2: 		 * 
williamr@2: 		 * It takes a message of less than 2^64 bits in length and produces
williamr@2: 		 * a 256-bit message digest.
williamr@2: 		 *
williamr@2: 		 * See FIPS 180-2 and RFC 4634
williamr@2: 		 */
williamr@2: 		ESHA256,
williamr@2: 		/** 
williamr@2: 		 * Secure Hash Algorithm - 384 (version 2) is a message digest algorithm developed by 
williamr@2: 		 * NIST, along with the NSA, for use with the Digital Signature Standard (DSS).
williamr@2: 		 * 
williamr@2: 		 * It takes a message of less than 2^128 bits in length and produces
williamr@2: 		 * a 384-bit message digest.
williamr@2: 		 *
williamr@2: 		 * See FIPS 180-2 and RFC 4634
williamr@2: 		 */
williamr@2: 		ESHA384,
williamr@2: 		/** 
williamr@2: 		 * Secure Hash Algorithm - 512 (version 2) is a message digest algorithm developed by 
williamr@2: 		 * NIST, along with the NSA, for use with the Digital Signature Standard (DSS).
williamr@2: 		 * 
williamr@2: 		 * It takes a message of less than 2^128 bits in length and produces
williamr@2: 		 * a 512-bit message digest.
williamr@2: 		 *
williamr@2: 		 * See FIPS 180-2 and RFC 4634
williamr@2: 		 */
williamr@2: 		ESHA512
williamr@2: 	};
williamr@2: 	
williamr@2: 	public:
williamr@2: 		/** 
williamr@2: 		 * Creates a brand new reset CMessageDigest object containing no state
williamr@2: 		 * information from the current object.  
williamr@2: 		 * 
williamr@2: 		 * To make a copy of a message digest with its internal state intact,
williamr@2: 		 * see CopyL().
williamr@2: 		 *
williamr@2: 		 * @return A pointer to the new reset CMessageDigest object
williamr@2: 		 */
williamr@2: 		IMPORT_C virtual CMessageDigest* ReplicateL(void)=0;		
williamr@2: 
williamr@2: 		/** 
williamr@2: 		 * Adds aMessage to the internal representation of data to be hashed,
williamr@2: 		 * then returns a TPtrC8 of the finalised hash of all the previously
williamr@2: 		 * appended messages.
williamr@2: 		 * 
williamr@2: 		 * @param aMessage	Data to be included in the hash.
williamr@2: 		 * @return			A descriptor pointer to the buffer containing the
williamr@2: 		 *					resulting hash.
williamr@2: 		 */
williamr@2: 		IMPORT_C virtual TPtrC8 Hash(const TDesC8& aMessage)=0;
williamr@2: 
williamr@2: 		/** 
williamr@2: 		 * Creates a new CMessageDigest object with the exact same state as
williamr@2: 		 * the current object.  
williamr@2: 		 *
williamr@2: 		 * This function copies all internal state of the message digest.
williamr@2: 		 * To create a new CMessageDigest object without the state of
williamr@2: 		 * the current object, see ReplicateL().
williamr@2: 		 *
williamr@2: 		 * @return A pointer to the new CMessageDigest object
williamr@2: 		 */
williamr@2: 		IMPORT_C virtual CMessageDigest* CopyL(void)=0;
williamr@2: 		
williamr@2: 		/** 
williamr@2: 		 * Gets the internal block size of the message digest.
williamr@2: 		 * 
williamr@2: 		 * @return	Internal block size of message digest in bytes.
williamr@2: 		 */
williamr@2: 		IMPORT_C virtual TInt BlockSize(void)=0;
williamr@2: 		
williamr@2: 		/** 
williamr@2: 		 * Gets the size of the message digest output.
williamr@2: 		 *
williamr@2: 		 * @return	Output size of the message digest in bytes.
williamr@2: 		 */
williamr@2: 		IMPORT_C virtual TInt HashSize(void)=0;
williamr@2: 		
williamr@2: 		/** 
williamr@2: 		 * Resets the internal state of the message digest.  
williamr@2: 		 *
williamr@2: 		 * A reset hash object loses all internal state representing the hashed
williamr@2: 		 * data. A reset message digest is suitable to begin a new, distinct hash
williamr@2: 		 * of different data.  Any previously returned TPtrC8 from a call to
williamr@2: 		 * Final() remains valid until any subsequent call to Update() or
williamr@2: 		 * Final().
williamr@2: 		 */
williamr@2: 		IMPORT_C virtual void Reset(void)=0;
williamr@2: 		
williamr@2: 		/**
williamr@2: 		 * Destructor.
williamr@2: 		 */		
williamr@2: 		IMPORT_C ~CMessageDigest(void);
williamr@2: 	public:
williamr@2: 		/** 
williamr@2: 		 * Adds data to the internal representation of messages to be hashed.
williamr@2: 		 *
williamr@2: 		 * @param aMessage	Data to be included in the hash.
williamr@2: 		 * @since v8.0
williamr@2: 		 */
williamr@2: 		IMPORT_C virtual void Update(const TDesC8& aMessage)=0;
williamr@2: 		
williamr@2: 		/** 
williamr@2: 		 * Adds aMessage to the internal representation of data to be hashed,
williamr@2: 		 * returns a TPtrC8 of the finalised hash of all the previously
williamr@2: 		 * appended messages, and calls Reset().
williamr@2: 		 * 
williamr@2: 		 * @param aMessage	Data to be included in the hash 
williamr@2: 		 * @return			A descriptor pointer to the buffer containing the
williamr@2: 		 *					resulting hash.
williamr@2: 		 * @since v8.0
williamr@2: 		 */
williamr@2: 		IMPORT_C virtual TPtrC8 Final(const TDesC8& aMessage)=0;
williamr@2: 		
williamr@2: 		/** 
williamr@2: 		 * Gets a TPtrC8 of the finalised hash of all the previously
williamr@2: 		 * appended messages and then calls Reset().
williamr@2: 		 * 
williamr@2: 		 * @return	A descriptor pointer to the buffer containing the
williamr@2: 		 * 			resulting hash.
williamr@2: 		 * @since v8.0
williamr@2: 		 */
williamr@2: 		IMPORT_C virtual TPtrC8 Final(void)=0;
williamr@2: 	public:
williamr@2: 		/**
williamr@2: 		 * Restores the internal state of the message digest
williamr@2: 		 * to a previously stored state.
williamr@2: 		 *
williamr@2: 		 * @see StoreState()
williamr@2: 		 */
williamr@2: 		virtual void RestoreState() = 0;
williamr@2: 
williamr@2: 		/**
williamr@2: 		 * Stores the internal state of the message digest. 
williamr@2: 		 */
williamr@2: 		virtual void StoreState() = 0;
williamr@4: 
williamr@4: 		/**
williamr@4: 		@internalComponent
williamr@4: 		Used to retrieve the extended interfaces extension
williamr@4: 		*/		
williamr@4: 		TInt GetExtension(TUint aExtensionId, TAny*& a0, TAny* a1);		
williamr@4: 
williamr@2: 	protected:
williamr@2: 		/**
williamr@2: 		 * Constructor
williamr@2: 		 */
williamr@2: 		IMPORT_C CMessageDigest(void);
williamr@2: 
williamr@2: 		/**
williamr@2: 		 * Copy constructor
williamr@2: 		 *
williamr@2: 		 * @param aMD	A CMessageDigest object
williamr@2: 		 */
williamr@2: 		IMPORT_C CMessageDigest(const CMessageDigest& aMD);
williamr@2: 	};
williamr@2: 
williamr@2: /** 
williamr@4: The MD2 block size (in bytes) 
williamr@4: */
williamr@2: const TInt MD2_BLOCK=16;
williamr@2: 
williamr@4: /** 
williamr@4: The size (in bytes) of the MD2 message digest 
williamr@4: */
williamr@2: const TInt MD2_HASH=16;
williamr@2: 
williamr@2: /**
williamr@2:  * An MD2 message digest
williamr@2:  */
williamr@2: class CMD2:public CMessageDigest
williamr@2: 
williamr@2: 	{
williamr@2: 	public:
williamr@2: 		/**
williamr@2: 		 * Creates a new MD2 object.
williamr@2: 		 *
williamr@2: 		 * @return	A pointer to the new CMD2 object
williamr@2: 		 */
williamr@2: 		IMPORT_C static CMD2* NewL(void);
williamr@2: 		IMPORT_C CMessageDigest* ReplicateL(void);
williamr@2: 		IMPORT_C TPtrC8 Hash(const TDesC8& aMessage);
williamr@2: 		/** Destructor */
williamr@2: 		IMPORT_C ~CMD2(void);
williamr@2: 		IMPORT_C CMessageDigest* CopyL(void);
williamr@2: 		IMPORT_C TInt BlockSize(void);
williamr@2: 		IMPORT_C TInt HashSize(void);
williamr@2: 		IMPORT_C void Reset(void);
williamr@2: 		IMPORT_C void Update(const TDesC8& aMessage);
williamr@2: 		IMPORT_C TPtrC8 Final(const TDesC8& aMessage);
williamr@2: 		IMPORT_C TPtrC8 Final();
williamr@2: 	public:
williamr@2: 		void RestoreState();
williamr@2: 		void StoreState();
williamr@4: 	protected:	
williamr@4: 		/** @internalComponent */
williamr@2: 		CMD2(void);
williamr@2: 	};
williamr@2: 
williamr@2: /** 
williamr@4: The MD5 block size (in bytes)
williamr@4: */
williamr@2: const TUint MD5_LBLOCK=16;
williamr@2: 
williamr@4: /** 
williamr@4: The size (in bytes) of the MD5 message digest 
williamr@4: */
williamr@2: const TUint MD5_HASH=16;
williamr@2: 
williamr@2: /**
williamr@2:  * An MD5 message digest
williamr@2:  *
williamr@2:  * Takes a message of arbitrary length as input and produces a 128-bit message digest. 
williamr@4:  * 
williamr@4:  * The total input length of data should not be longer than 2^32 in bits(2^31 in bytes)
williamr@2:  * which is roughly half a gig.
williamr@2:  *
williamr@2:  */
williamr@2: class CMD5:public CMessageDigest
williamr@2: 	{
williamr@2: 	public:
williamr@2: 		/**
williamr@2: 		 * Creates a new MD5 object.
williamr@2: 		 *
williamr@2: 		 * @return	A pointer to the new CMD5 object
williamr@2: 		 */
williamr@2: 		IMPORT_C static CMD5* NewL(void);
williamr@2: 		IMPORT_C CMessageDigest* ReplicateL(void);
williamr@2: 		IMPORT_C TPtrC8 Hash(const TDesC8& aMessage);
williamr@2: 		/** Destructor */
williamr@2: 		IMPORT_C ~CMD5(void);
williamr@2: 		IMPORT_C CMessageDigest* CopyL(void);
williamr@2: 		IMPORT_C TInt BlockSize(void);
williamr@2: 		IMPORT_C TInt HashSize(void);
williamr@2: 		IMPORT_C void Reset(void);
williamr@2: 		IMPORT_C void Update(const TDesC8& aMessage);
williamr@2: 		IMPORT_C TPtrC8 Final(const TDesC8& aMessage);
williamr@2: 		IMPORT_C TPtrC8 Final();
williamr@2: 	public:
williamr@2: 		void RestoreState();
williamr@2: 		void StoreState();
williamr@4: 	protected:
williamr@4: 		/** @internalComponent */
williamr@2: 		CMD5(void);
williamr@2: 	};
williamr@2: 
williamr@4: 
williamr@2: /** 
williamr@4: The SHA-1 block size (in bytes) 
williamr@4: */
williamr@2: const TUint SHA1_LBLOCK=16;
williamr@2: 
williamr@4: /** 
williamr@4: The size (in bytes) of the SHA-1 message digest 
williamr@4: */
williamr@2: const TUint SHA1_HASH=20;
williamr@2: 
williamr@4: /** 
williamr@4: The size (in bytes) of the SHA message digest 
williamr@4: */
williamr@2: const TUint SHA_HASH=SHA1_HASH;
williamr@2: 
williamr@2: /**
williamr@2:  * A SHA-1 message digest
williamr@2:  */
williamr@2: class CSHA1:public CMessageDigest
williamr@2: 	{
williamr@2: 	public:
williamr@2: 		/**
williamr@2: 		 * Creates a new SHA-1 object.
williamr@2: 		 *
williamr@2: 		 * @return	A pointer to the new SHA-1 object
williamr@2: 		 */
williamr@2: 		IMPORT_C static CSHA1* NewL(void);
williamr@2: 		IMPORT_C CMessageDigest* ReplicateL(void);
williamr@2: 		IMPORT_C TPtrC8 Hash(const TDesC8& aMessage);
williamr@2: 		/** Destructor */
williamr@2: 		IMPORT_C ~CSHA1(void);
williamr@2: 		IMPORT_C CMessageDigest* CopyL(void);
williamr@2: 		IMPORT_C TInt BlockSize(void);
williamr@2: 		IMPORT_C TInt HashSize(void);
williamr@2: 		IMPORT_C void Reset(void);
williamr@2: 		IMPORT_C void Update(const TDesC8& aMessage);
williamr@2: 		IMPORT_C TPtrC8 Final(const TDesC8& aMessage);
williamr@2: 		IMPORT_C TPtrC8 Final();
williamr@2: 	public:
williamr@2: 		void RestoreState();
williamr@2: 		void StoreState();
williamr@4: 	protected:
williamr@4: 		/** @internalComponent */
williamr@2: 		CSHA1(void);
williamr@2: 	};
williamr@2: 
williamr@2: enum TSH2Algo
williamr@2: 	{
williamr@2: 	E224Bit,
williamr@2: 	E256Bit,
williamr@2: 	E384Bit,
williamr@2: 	E512Bit
williamr@2: 	};
williamr@2: 	
williamr@2: /**
williamr@2:  * A SHA-2 message digest
williamr@2:  * 
williamr@4:  * SHA-2 is comprised of SHA-224, SHA256, SHA384 and SHA512
williamr@2:  */
williamr@2: class CSHA2 : public CMessageDigest
williamr@2: 	{
williamr@4: 	public:
williamr@4: 		/**
williamr@4: 		 * Creates a new SHA-1 object.
williamr@4: 		 *
williamr@4: 		 * @return	A pointer to the new SHA-1 object
williamr@4: 		 */
williamr@4: 		IMPORT_C static CSHA2* NewL(TSH2Algo aAlgorithmId);
williamr@4: 		IMPORT_C static CSHA2* NewLC(TSH2Algo aAlgorithmId);
williamr@4: 		/** Destructor */
williamr@4: 		IMPORT_C ~CSHA2(void);
williamr@4: 	public:
williamr@4: 		void RestoreState();
williamr@4: 		void StoreState();		
williamr@4: 	protected:
williamr@4: 		/** @internalComponent */
williamr@4: 		CSHA2(void);
williamr@4: 	};	
williamr@2: 
williamr@4: 
williamr@2: /**
williamr@2:  * A SHA message digest
williamr@2:  *
williamr@2:  * @deprecated Replaced by CSHA1
williamr@2:  */
williamr@2: class CSHA:public CMessageDigest
williamr@2: 	{
williamr@2: 	public:
williamr@2: 		/**
williamr@2: 		 * Creates a new SHA object.
williamr@2: 		 *
williamr@2: 		 * @return	A pointer to the new SHA object
williamr@2: 		 */
williamr@2: 		IMPORT_C static CSHA* NewL(void);
williamr@2: 		IMPORT_C CMessageDigest* ReplicateL(void);
williamr@2: 		IMPORT_C TPtrC8 Hash(const TDesC8& aMessage);
williamr@2: 		/** Destructor */
williamr@2: 		IMPORT_C ~CSHA(void);
williamr@2: 		IMPORT_C CMessageDigest* CopyL(void);
williamr@2: 		IMPORT_C TInt BlockSize(void);
williamr@2: 		IMPORT_C TInt HashSize(void);
williamr@2: 		IMPORT_C void Reset(void);
williamr@2: 		IMPORT_C void Update(const TDesC8& aMessage);
williamr@2: 		IMPORT_C TPtrC8 Final(const TDesC8& aMessage);
williamr@2: 		IMPORT_C TPtrC8 Final();
williamr@2: 	public:
williamr@2: 		void RestoreState();
williamr@2: 		void StoreState();
williamr@2: 	};
williamr@2: 
williamr@2: /**
williamr@2:  * This is the maximum block size currently supported by HMAC implementation.
williamr@2:  */ 
williamr@4: const TUint KMaxBlockSize=128;
williamr@2: 
williamr@2: /**
williamr@2:  * An HMAC (Hashed Message Authentication Code)
williamr@2:  */
williamr@4: class CHMAC:public CMessageDigest
williamr@2: 
williamr@2: 	{
williamr@2: 	public:
williamr@2: 		/**
williamr@2: 		 * Creates a new HMAC object from a specified type of message digest 
williamr@2: 		 * and authentication key.
williamr@2: 		 * 
williamr@2: 		 * @param aKey		Authentication key.
williamr@2: 		 * @param aDigest	A message digest to construct the HMAC from.
williamr@2: 		 * @return			A pointer to the new CHMAC object. 
williamr@2: 		 *					The resulting HMAC object takes ownership of aDigest
williamr@2: 		 *					and is responsible for its deletion.
williamr@2: 		 */
williamr@2: 		IMPORT_C static CHMAC* NewL(const TDesC8& aKey,CMessageDigest* aDigest);
williamr@2: 		IMPORT_C CMessageDigest* ReplicateL(void);
williamr@2: 		IMPORT_C TPtrC8 Hash(const TDesC8& aMessage);
williamr@2: 		/** Destructor */
williamr@2: 		IMPORT_C ~CHMAC(void);
williamr@2: 		IMPORT_C CMessageDigest* CopyL(void);
williamr@2: 		IMPORT_C TInt BlockSize(void);
williamr@2: 		IMPORT_C TInt HashSize(void);
williamr@2: 		IMPORT_C void Reset(void);
williamr@2: 		IMPORT_C void Update(const TDesC8& aMessage);
williamr@2: 		IMPORT_C TPtrC8 Final(const TDesC8& aMessage);
williamr@2: 		IMPORT_C TPtrC8 Final();
williamr@2: 	public:
williamr@2: 		void RestoreState();
williamr@2: 		void StoreState();
williamr@4: 	protected:
williamr@4: 		/** @internalComponent */
williamr@4: 		CHMAC(void);
williamr@4: 		/** @internalComponent */
williamr@4: 		CHMAC(CMessageDigest* aDigest);
williamr@4: 		/** @internalComponent */
williamr@4: 		CHMAC(const CHMAC& aHMAC);
williamr@4: 		/** @internalComponent */
williamr@4: 		void InitialiseL(const TDesC8& aKey);
williamr@4: 		
williamr@2: 	private:
williamr@2: 		void InitBlockSizeL();
williamr@4: 
williamr@2: 	private:
williamr@2: 		CMessageDigest* iDigest;
williamr@2: 		TBuf8<KMaxBlockSize> iInnerPad;
williamr@2: 		TBuf8<KMaxBlockSize> iOuterPad;
williamr@2: 		TBuf8<KMaxBlockSize> iInnerPadCopy;
williamr@2: 		TBuf8<KMaxBlockSize> iOuterPadCopy;		
williamr@2: 		TInt iBlockSize;
williamr@4: 
williamr@2: 	};
williamr@4: 
williamr@2: /** 
williamr@4: The MD4 block size (in bytes)
williamr@4: */
williamr@4: const TUint MD4_LBLOCK=16;
williamr@2: 
williamr@4: /** 
williamr@4: The size (in bytes) of the MD4 message digest 
williamr@4: */
williamr@4: const TUint MD4_HASH=16;
williamr@2: 
williamr@2: /**
williamr@2:  * An MD4 message digest Algorithm.
williamr@2:  * Takes a message of arbitrary length as input and produces a 128-bit message digest. 
williamr@4:  * 
williamr@2:  * The total input length of data should not be longer than 2^32 in bits(2^31 in bytes)
williamr@2:  * which is roughly half a gig.
williamr@2:  *
williamr@2:  */
williamr@2: class CMD4:public CMessageDigest
williamr@2: 	{
williamr@2: 	public:
williamr@2: 		/**
williamr@2: 		 * Creates a new MD4 object.
williamr@2: 		 *
williamr@2: 		 * @return	A pointer to the new CMD4 object
williamr@2: 		 */
williamr@2: 		IMPORT_C static CMD4* NewL(void);
williamr@2: 		IMPORT_C CMessageDigest* ReplicateL(void);
williamr@2: 		IMPORT_C TPtrC8 Hash(const TDesC8& aMessage);
williamr@2: 		/** Destructor */
williamr@2: 		IMPORT_C ~CMD4(void);
williamr@2: 		IMPORT_C CMessageDigest* CopyL(void);
williamr@2: 		IMPORT_C TInt BlockSize(void);
williamr@2: 		IMPORT_C TInt HashSize(void);
williamr@2: 		IMPORT_C void Reset(void);
williamr@2: 		IMPORT_C void Update(const TDesC8& aMessage);
williamr@2: 		IMPORT_C TPtrC8 Final(const TDesC8& aMessage);
williamr@2: 		IMPORT_C TPtrC8 Final();
williamr@2: 	public:
williamr@2: 		virtual void RestoreState();
williamr@2: 		virtual void StoreState();
williamr@4: 	protected:
williamr@4: 		/** @internalComponent */
williamr@2: 		CMD4(void);
williamr@2: 	};
williamr@2: 
williamr@2: 
williamr@2: /**
williamr@2:  *	Factory to create a CMessageDigest derived object according to the identity of the hash algorithm.
williamr@2:  */
williamr@2: class CMessageDigestFactory : public CBase
williamr@2: {
williamr@2: public:
williamr@2: 	/**
williamr@4: 	 *Creates a CMessageDigest derived object according to the specified type of hash algorithm.
williamr@2: 	 *
williamr@2: 	 * @param aHashId	The identity of the hash algorithm
williamr@2: 	 * @return			A pointer to a CMessageDigest object
williamr@2: 	 */
williamr@2: 	IMPORT_C static CMessageDigest* NewDigestL(CMessageDigest::THashId aHashId);
williamr@2: 
williamr@2: 	/**
williamr@2: 	 * Creates a CMessageDigest derived object according to the specified type of hash algorithm.
williamr@2: 	 * 
williamr@2: 	 * The returned pointer is put onto the cleanup stack.
williamr@2: 	 *
williamr@2: 	 * @param aHashId	The identity of the hash algorithm
williamr@2: 	 * @return			A pointer to a CMessageDigest object
williamr@2: 	 */
williamr@2: 	IMPORT_C static CMessageDigest* NewDigestLC(CMessageDigest::THashId aHashId);
williamr@2: 
williamr@2: 	/**
williamr@2: 	 * Creates a CMessageDigest derived object according to the specified type of hash algorithm
williamr@2: 	 * and authentication key.
williamr@2: 	 *
williamr@2: 	 * @param aHashId	The identity of the hash algorithm
williamr@2: 	 * @param aKey		The authentication key 
williamr@2: 	 * @return			A pointer to a CMessageDigest object
williamr@2: 	 */
williamr@2: 	IMPORT_C static CMessageDigest* NewHMACL(CMessageDigest::THashId aHashId, const TDesC8& aKey);
williamr@2: 
williamr@2: 	/**
williamr@2: 	 * Creates a CMessageDigest derived object according to the specified type of hash algorithm
williamr@2: 	 * and authentication key.
williamr@2: 	 * 
williamr@2: 	 * The returned pointer is put onto the cleanup stack.
williamr@2: 	 *
williamr@2: 	 * @param aHashId	The identity of the hash algorithm
williamr@2: 	 * @param aKey		The authentication key 
williamr@2: 	 * @return			A pointer to a CMessageDigest object
williamr@2: 	 */
williamr@2: 	IMPORT_C static CMessageDigest* NewHMACLC(CMessageDigest::THashId aHashId, const TDesC8& aKey);
williamr@2: };
williamr@2: 
williamr@2: #endif // __HASH_H__