epoc32/include/hash.h
branchSymbian3
changeset 4 837f303aceeb
parent 2 2fe1408b6811
     1.1 --- a/epoc32/include/hash.h	Wed Mar 31 12:27:01 2010 +0100
     1.2 +++ b/epoc32/include/hash.h	Wed Mar 31 12:33:34 2010 +0100
     1.3 @@ -19,8 +19,6 @@
     1.4  */
     1.5  
     1.6  
     1.7 -
     1.8 -
     1.9  /**
    1.10   @file 
    1.11   @publishedAll
    1.12 @@ -32,10 +30,6 @@
    1.13  
    1.14  #include <e32base.h>
    1.15  
    1.16 -
    1.17 -//Forward Declarations
    1.18 -class MSHA2Impl;
    1.19 -
    1.20  /**
    1.21   * Base class for message digests.
    1.22   */
    1.23 @@ -246,6 +240,13 @@
    1.24  		 * Stores the internal state of the message digest. 
    1.25  		 */
    1.26  		virtual void StoreState() = 0;
    1.27 +
    1.28 +		/**
    1.29 +		@internalComponent
    1.30 +		Used to retrieve the extended interfaces extension
    1.31 +		*/		
    1.32 +		TInt GetExtension(TUint aExtensionId, TAny*& a0, TAny* a1);		
    1.33 +
    1.34  	protected:
    1.35  		/**
    1.36  		 * Constructor
    1.37 @@ -261,13 +262,13 @@
    1.38  	};
    1.39  
    1.40  /** 
    1.41 - * The MD2 block size (in bytes) 
    1.42 - * 
    1.43 - * @internalTechnology 
    1.44 - */
    1.45 +The MD2 block size (in bytes) 
    1.46 +*/
    1.47  const TInt MD2_BLOCK=16;
    1.48  
    1.49 -/** The size (in bytes) of the MD2 message digest */
    1.50 +/** 
    1.51 +The size (in bytes) of the MD2 message digest 
    1.52 +*/
    1.53  const TInt MD2_HASH=16;
    1.54  
    1.55  /**
    1.56 @@ -297,42 +298,27 @@
    1.57  	public:
    1.58  		void RestoreState();
    1.59  		void StoreState();
    1.60 -	private:
    1.61 -		void DoUpdate(const TUint8* aData,TUint aLength);
    1.62 -		void DoFinal(void);
    1.63 -		void Block(const TUint8* aData);
    1.64 -	private:
    1.65 +	protected:	
    1.66 +		/** @internalComponent */
    1.67  		CMD2(void);
    1.68 -		CMD2(const CMD2& aMD2);
    1.69 -	private:
    1.70 -		TBuf8<MD2_HASH> iHash;
    1.71 -		TInt iNum;
    1.72 -		TUint8 iData[MD2_BLOCK];
    1.73 -		TUint iChecksum[MD2_BLOCK];
    1.74 -		TUint iState[MD2_BLOCK];
    1.75 -	private:
    1.76 -		TBuf8<MD2_HASH> iHashBuf;
    1.77 -		TUint8 iDataTemp[MD2_BLOCK];
    1.78 -		TUint iChecksumTemp[MD2_BLOCK];
    1.79 -		TUint iStateTemp[MD2_BLOCK];
    1.80  	};
    1.81  
    1.82  /** 
    1.83 - * The MD5 block size (in bytes)
    1.84 - * 
    1.85 - * @internalTechnology 
    1.86 - */
    1.87 +The MD5 block size (in bytes)
    1.88 +*/
    1.89  const TUint MD5_LBLOCK=16;
    1.90  
    1.91 -/** The size (in bytes) of the MD5 message digest */
    1.92 +/** 
    1.93 +The size (in bytes) of the MD5 message digest 
    1.94 +*/
    1.95  const TUint MD5_HASH=16;
    1.96  
    1.97  /**
    1.98   * An MD5 message digest
    1.99   *
   1.100   * Takes a message of arbitrary length as input and produces a 128-bit message digest. 
   1.101 - *
   1.102 - * The length of input data should not be longer than 2^32 in bits(2^31 in bytes)
   1.103 + * 
   1.104 + * The total input length of data should not be longer than 2^32 in bits(2^31 in bytes)
   1.105   * which is roughly half a gig.
   1.106   *
   1.107   */
   1.108 @@ -359,44 +345,25 @@
   1.109  	public:
   1.110  		void RestoreState();
   1.111  		void StoreState();
   1.112 -	private:
   1.113 +	protected:
   1.114 +		/** @internalComponent */
   1.115  		CMD5(void);
   1.116 -		CMD5(const CMD5& aMD5);
   1.117 -	private:
   1.118 -		void DoUpdate(const TUint8* aData,TUint aLength);
   1.119 -		void DoFinal(void);
   1.120 -		void Block();
   1.121 -	private:
   1.122 -		TBuf8<MD5_HASH> iHash;
   1.123 -	private:
   1.124 -		TUint iA;
   1.125 -		TUint iB;
   1.126 -		TUint iC;
   1.127 -		TUint iD;
   1.128 -		TUint iNl;
   1.129 -		TUint iNh;
   1.130 -		TUint iData[MD5_LBLOCK];
   1.131 -	private:
   1.132 -		TUint iACopy;
   1.133 -		TUint iBCopy;
   1.134 -		TUint iCCopy;
   1.135 -		TUint iDCopy;
   1.136 -		TUint iNlCopy;
   1.137 -		TUint iNhCopy;
   1.138 -		TUint iDataCopy[MD5_LBLOCK];
   1.139  	};
   1.140  
   1.141 +
   1.142  /** 
   1.143 - * The SHA-1 block size (in bytes) 
   1.144 - * 
   1.145 - * @internalTechnology 
   1.146 - */
   1.147 +The SHA-1 block size (in bytes) 
   1.148 +*/
   1.149  const TUint SHA1_LBLOCK=16;
   1.150  
   1.151 -/** The size (in bytes) of the SHA-1 message digest */
   1.152 +/** 
   1.153 +The size (in bytes) of the SHA-1 message digest 
   1.154 +*/
   1.155  const TUint SHA1_HASH=20;
   1.156  
   1.157 -/** The size (in bytes) of the SHA message digest */
   1.158 +/** 
   1.159 +The size (in bytes) of the SHA message digest 
   1.160 +*/
   1.161  const TUint SHA_HASH=SHA1_HASH;
   1.162  
   1.163  /**
   1.164 @@ -425,33 +392,9 @@
   1.165  	public:
   1.166  		void RestoreState();
   1.167  		void StoreState();
   1.168 -	private:
   1.169 +	protected:
   1.170 +		/** @internalComponent */
   1.171  		CSHA1(void);
   1.172 -		CSHA1(const CSHA1& aSHA1);
   1.173 -		void ConstructL(void);
   1.174 -	private:
   1.175 -		void DoUpdate(const TUint8* aData,TUint aLength);
   1.176 -		void DoFinal(void);
   1.177 -		void Block();
   1.178 -	private:
   1.179 -		TBuf8<SHA1_HASH> iHash;
   1.180 -		TUint iA;
   1.181 -		TUint iB;
   1.182 -		TUint iC;
   1.183 -		TUint iD;
   1.184 -		TUint iE;
   1.185 -		TUint iNl;
   1.186 -		TUint iNh;
   1.187 -		TUint iData[SHA1_LBLOCK*5];
   1.188 -	private:
   1.189 -		TUint iACopy;
   1.190 -		TUint iBCopy;
   1.191 -		TUint iCCopy;
   1.192 -		TUint iDCopy;
   1.193 -		TUint iECopy;
   1.194 -		TUint iNlCopy;
   1.195 -		TUint iNhCopy;	
   1.196 -		TUint iDataCopy[SHA1_LBLOCK*5];
   1.197  	};
   1.198  
   1.199  enum TSH2Algo
   1.200 @@ -465,45 +408,29 @@
   1.201  /**
   1.202   * A SHA-2 message digest
   1.203   * 
   1.204 - * SHA-2 comprises of SHA-224, SHA256, SHA384 and SHA512
   1.205 + * SHA-2 is comprised of SHA-224, SHA256, SHA384 and SHA512
   1.206   */
   1.207  class CSHA2 : public CMessageDigest
   1.208  	{
   1.209 -public:
   1.210 -	//NewL & NewLC	
   1.211 -	IMPORT_C static CSHA2* NewL(TSH2Algo aAlgorithmId);
   1.212 -	IMPORT_C static CSHA2* NewLC(TSH2Algo aAlgorithmId);
   1.213 -	
   1.214 -	/** Destructor */
   1.215 -	IMPORT_C ~CSHA2(void);
   1.216 -	
   1.217 -	//From CMessageDigest
   1.218 -	IMPORT_C CMessageDigest* ReplicateL(void);
   1.219 -	IMPORT_C TPtrC8 Hash(const TDesC8& aMessage);
   1.220 -	IMPORT_C CMessageDigest* CopyL(void);
   1.221 -	IMPORT_C TInt BlockSize(void);
   1.222 -	IMPORT_C TInt HashSize(void);
   1.223 -	IMPORT_C void Reset(void);
   1.224 -	IMPORT_C void Update(const TDesC8& aMessage);
   1.225 -	IMPORT_C TPtrC8 Final(const TDesC8& aMessage);
   1.226 -	IMPORT_C TPtrC8 Final();
   1.227 +	public:
   1.228 +		/**
   1.229 +		 * Creates a new SHA-1 object.
   1.230 +		 *
   1.231 +		 * @return	A pointer to the new SHA-1 object
   1.232 +		 */
   1.233 +		IMPORT_C static CSHA2* NewL(TSH2Algo aAlgorithmId);
   1.234 +		IMPORT_C static CSHA2* NewLC(TSH2Algo aAlgorithmId);
   1.235 +		/** Destructor */
   1.236 +		IMPORT_C ~CSHA2(void);
   1.237 +	public:
   1.238 +		void RestoreState();
   1.239 +		void StoreState();		
   1.240 +	protected:
   1.241 +		/** @internalComponent */
   1.242 +		CSHA2(void);
   1.243 +	};	
   1.244  
   1.245 -public:
   1.246 -	void RestoreState();
   1.247 -	void StoreState();
   1.248 -	
   1.249 -private:
   1.250 -	//Constructors
   1.251 -	void ConstructL(TSH2Algo aAlgorithmId);
   1.252 -	void ConstructL(const CSHA2& aSHA512);
   1.253 -	
   1.254 -private:
   1.255 -	MSHA2Impl*	iImplementation;
   1.256 -	const TAny*	iInitValues;
   1.257 -	TSH2Algo	iAlgorithmType;
   1.258 -	TUint		iHashSize;
   1.259 -	};	
   1.260 -	
   1.261 +
   1.262  /**
   1.263   * A SHA message digest
   1.264   *
   1.265 @@ -537,12 +464,12 @@
   1.266  /**
   1.267   * This is the maximum block size currently supported by HMAC implementation.
   1.268   */ 
   1.269 -	const TUint KMaxBlockSize=128;
   1.270 +const TUint KMaxBlockSize=128;
   1.271  
   1.272  /**
   1.273   * An HMAC (Hashed Message Authentication Code)
   1.274   */
   1.275 -	class CHMAC:public CMessageDigest
   1.276 +class CHMAC:public CMessageDigest
   1.277  
   1.278  	{
   1.279  	public:
   1.280 @@ -571,13 +498,19 @@
   1.281  	public:
   1.282  		void RestoreState();
   1.283  		void StoreState();
   1.284 +	protected:
   1.285 +		/** @internalComponent */
   1.286 +		CHMAC(void);
   1.287 +		/** @internalComponent */
   1.288 +		CHMAC(CMessageDigest* aDigest);
   1.289 +		/** @internalComponent */
   1.290 +		CHMAC(const CHMAC& aHMAC);
   1.291 +		/** @internalComponent */
   1.292 +		void InitialiseL(const TDesC8& aKey);
   1.293 +		
   1.294  	private:
   1.295 -		CHMAC(void);
   1.296 -		CHMAC(CMessageDigest* aDigest);
   1.297 -		CHMAC(const CHMAC& aHMAC);
   1.298 -		void InitialiseL(const TDesC8& aKey);
   1.299  		void InitBlockSizeL();
   1.300 -		
   1.301 +
   1.302  	private:
   1.303  		CMessageDigest* iDigest;
   1.304  		TBuf8<KMaxBlockSize> iInnerPad;
   1.305 @@ -585,23 +518,23 @@
   1.306  		TBuf8<KMaxBlockSize> iInnerPadCopy;
   1.307  		TBuf8<KMaxBlockSize> iOuterPadCopy;		
   1.308  		TInt iBlockSize;
   1.309 +
   1.310  	};
   1.311 -	
   1.312 +
   1.313  /** 
   1.314 - * The MD4 block size 
   1.315 - * @internalTechnology 
   1.316 - */
   1.317 - const TUint MD4_LBLOCK=16;
   1.318 +The MD4 block size (in bytes)
   1.319 +*/
   1.320 +const TUint MD4_LBLOCK=16;
   1.321  
   1.322 -/** The size (in bytes) of the MD4 message digest */
   1.323 - const TUint MD4_HASH=16;
   1.324 -
   1.325 +/** 
   1.326 +The size (in bytes) of the MD4 message digest 
   1.327 +*/
   1.328 +const TUint MD4_HASH=16;
   1.329  
   1.330  /**
   1.331   * An MD4 message digest Algorithm.
   1.332 - *
   1.333   * Takes a message of arbitrary length as input and produces a 128-bit message digest. 
   1.334 - *
   1.335 + * 
   1.336   * The total input length of data should not be longer than 2^32 in bits(2^31 in bytes)
   1.337   * which is roughly half a gig.
   1.338   *
   1.339 @@ -629,45 +562,9 @@
   1.340  	public:
   1.341  		virtual void RestoreState();
   1.342  		virtual void StoreState();
   1.343 -	private:
   1.344 +	protected:
   1.345 +		/** @internalComponent */
   1.346  		CMD4(void);
   1.347 -		CMD4(const CMD4& aMD4);
   1.348 -	private:
   1.349 -	   /**
   1.350 -		* Divides the message into blocks of 512 bits and performs the
   1.351 -		* Block operation on them.
   1.352 -		*/
   1.353 -		void DoUpdate(const TUint8* aData,TUint aLength);
   1.354 -	   /**
   1.355 -		* Performs the Block operation on the last 512 bit block.
   1.356 -		* This function does the padding on the last 512 bit block
   1.357 -		* and also appends the length of the message to the last 64-bits
   1.358 -		* of the block.
   1.359 -		*/
   1.360 -		void DoFinal(void);
   1.361 -	   /**
   1.362 -		* Performs the Block operation on the 512 bit blocks
   1.363 -		*/
   1.364 -		void Block();
   1.365 -	private:
   1.366 -		/*Holds the generated 128-bit Message Digest*/
   1.367 -		TBuf8<MD4_HASH> iHash;
   1.368 -	private:
   1.369 -		TUint iA;
   1.370 -		TUint iB;
   1.371 -		TUint iC;
   1.372 -		TUint iD;
   1.373 -		TUint iNl;
   1.374 -		TUint iNh;
   1.375 -		TUint iData[MD4_LBLOCK];
   1.376 -	private:
   1.377 -		TUint iACopy;
   1.378 -		TUint iBCopy;
   1.379 -		TUint iCCopy;
   1.380 -		TUint iDCopy;
   1.381 -		TUint iNlCopy;
   1.382 -		TUint iNhCopy;
   1.383 -		TUint iDataCopy[MD4_LBLOCK];
   1.384  	};
   1.385  
   1.386  
   1.387 @@ -678,7 +575,7 @@
   1.388  {
   1.389  public:
   1.390  	/**
   1.391 -	 * Creates a CMessageDigest derived object according to the specified type of hash algorithm.
   1.392 +	 *Creates a CMessageDigest derived object according to the specified type of hash algorithm.
   1.393  	 *
   1.394  	 * @param aHashId	The identity of the hash algorithm
   1.395  	 * @return			A pointer to a CMessageDigest object