epoc32/include/hash.h
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:33:34 +0100
branchSymbian3
changeset 4 837f303aceeb
parent 2 2fe1408b6811
permissions -rw-r--r--
Current Symbian^3 public API header files (from PDK 3.0.h)
This is the epoc32/include tree with the "platform" subtrees removed, and
all but a selected few mbg and rsg files removed.
williamr@2
     1
/*
williamr@2
     2
* Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
williamr@2
     3
* All rights reserved.
williamr@2
     4
* This component and the accompanying materials are made available
williamr@2
     5
* under the terms of the License "Eclipse Public License v1.0"
williamr@2
     6
* which accompanies this distribution, and is available
williamr@2
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
williamr@2
     8
*
williamr@2
     9
* Initial Contributors:
williamr@2
    10
* Nokia Corporation - initial contribution.
williamr@2
    11
*
williamr@2
    12
* Contributors:
williamr@2
    13
*
williamr@2
    14
* Description: 
williamr@2
    15
* ** IMPORTANT ** PublishedPartner API's in this file are published to 3rd party developers via the 
williamr@2
    16
* Symbian website. Changes to these API's should be treated as PublishedAll API changes and the Security TA should be consulted.
williamr@2
    17
* This header contains the definition of the message digest classes
williamr@2
    18
*
williamr@2
    19
*/
williamr@2
    20
williamr@2
    21
williamr@2
    22
/**
williamr@2
    23
 @file 
williamr@2
    24
 @publishedAll
williamr@2
    25
 @released
williamr@2
    26
*/
williamr@2
    27
williamr@2
    28
#ifndef __HASH_H__
williamr@2
    29
#define __HASH_H__
williamr@2
    30
williamr@2
    31
#include <e32base.h>
williamr@2
    32
williamr@2
    33
/**
williamr@2
    34
 * Base class for message digests.
williamr@2
    35
 */
williamr@2
    36
class CMessageDigest:public CBase
williamr@2
    37
	{
williamr@2
    38
	public:
williamr@2
    39
	/**
williamr@2
    40
	 *	Enumeration to identify hash functions (aka message-digest algorithms).
williamr@2
    41
	 */
williamr@2
    42
	enum THashId
williamr@2
    43
	{
williamr@2
    44
		/** 
williamr@2
    45
		 * Message Digest algorithm developed by Rivest for digital signature
williamr@2
    46
		 * applications (and optimized for 8-bit machines). 
williamr@2
    47
		 * 
williamr@2
    48
		 * Takes a message of arbitrary length and produces a 128-bit message digest. 
williamr@2
    49
		 *
williamr@2
    50
		 * See RFC 1319
williamr@2
    51
		 */
williamr@2
    52
		EMD2,
williamr@2
    53
		/** 
williamr@2
    54
		 * Message Digest algorithm developed by Rivest for digital signature
williamr@2
    55
		 * applications (and optimized for 32-bit machines). 
williamr@2
    56
		 * 
williamr@2
    57
		 * Takes a message of arbitrary length and produces a 128-bit message digest. 
williamr@2
    58
		 * 
williamr@2
    59
		 * See RFC 1321
williamr@2
    60
		 */
williamr@2
    61
		EMD5,
williamr@2
    62
		/** 
williamr@2
    63
		 * Secure Hash Algorithm (version 1) is a message digest algorithm developed by 
williamr@2
    64
		 * NIST, along with the NSA, for use with the Digital Signature Standard (DSS).
williamr@2
    65
		 * 
williamr@2
    66
		 * It takes a message of less than 2^64 bits in length and produces
williamr@2
    67
		 * a 160-bit message digest.
williamr@2
    68
		 *
williamr@2
    69
		 * See FIPS 180-1 and RFC 3174
williamr@2
    70
		 */
williamr@2
    71
		ESHA1,
williamr@2
    72
		/** 
williamr@2
    73
		 * HMAC - Hash function based Message Authentication Code is a mechanism
williamr@2
    74
		 * for message authentication using cryptographic hash functions. (A checksum.)
williamr@2
    75
		 * 
williamr@2
    76
		 * It can be used with any iterative cryptographic hash function,
williamr@2
    77
   		 * e.g., MD5, SHA-1, in combination with a secret shared key
williamr@2
    78
   		 * to produce a checksum that is appended to the message.
williamr@2
    79
   		 * The cryptographic strength of HMAC depends on the properties
williamr@2
    80
   		 * of the underlying hash function.
williamr@2
    81
		 *
williamr@2
    82
		 * See RFC 2104 
williamr@2
    83
		 */
williamr@2
    84
		HMAC,
williamr@2
    85
		/** 
williamr@2
    86
		 * Message Digest algorithm developed by Rivest for digital signature
williamr@2
    87
		 * applications (and optimized for 32-bit machines). 
williamr@2
    88
		 * 
williamr@2
    89
		 * Takes a message of arbitrary length and produces a 128-bit message digest. 
williamr@2
    90
		 * 
williamr@2
    91
		 * See RFC 1320
williamr@2
    92
		 */
williamr@2
    93
		EMD4,
williamr@2
    94
		/** 
williamr@2
    95
		 * Secure Hash Algorithm - 224 (version 2) is a message digest algorithm developed by 
williamr@2
    96
		 * NIST, along with the NSA, for use with the Digital Signature Standard (DSS).
williamr@2
    97
		 * 
williamr@2
    98
		 * It takes a message of less than 2^64 bits in length and produces
williamr@2
    99
		 * a 224-bit message digest.
williamr@2
   100
		 *
williamr@2
   101
		 * See FIPS 180-2 (with change notice), RFC3874 and FIPS 180-3
williamr@2
   102
		 */
williamr@2
   103
		ESHA224,
williamr@2
   104
		/** 
williamr@2
   105
		 * Secure Hash Algorithm - 256 (version 2) is a message digest algorithm developed by 
williamr@2
   106
		 * NIST, along with the NSA, for use with the Digital Signature Standard (DSS).
williamr@2
   107
		 * 
williamr@2
   108
		 * It takes a message of less than 2^64 bits in length and produces
williamr@2
   109
		 * a 256-bit message digest.
williamr@2
   110
		 *
williamr@2
   111
		 * See FIPS 180-2 and RFC 4634
williamr@2
   112
		 */
williamr@2
   113
		ESHA256,
williamr@2
   114
		/** 
williamr@2
   115
		 * Secure Hash Algorithm - 384 (version 2) is a message digest algorithm developed by 
williamr@2
   116
		 * NIST, along with the NSA, for use with the Digital Signature Standard (DSS).
williamr@2
   117
		 * 
williamr@2
   118
		 * It takes a message of less than 2^128 bits in length and produces
williamr@2
   119
		 * a 384-bit message digest.
williamr@2
   120
		 *
williamr@2
   121
		 * See FIPS 180-2 and RFC 4634
williamr@2
   122
		 */
williamr@2
   123
		ESHA384,
williamr@2
   124
		/** 
williamr@2
   125
		 * Secure Hash Algorithm - 512 (version 2) is a message digest algorithm developed by 
williamr@2
   126
		 * NIST, along with the NSA, for use with the Digital Signature Standard (DSS).
williamr@2
   127
		 * 
williamr@2
   128
		 * It takes a message of less than 2^128 bits in length and produces
williamr@2
   129
		 * a 512-bit message digest.
williamr@2
   130
		 *
williamr@2
   131
		 * See FIPS 180-2 and RFC 4634
williamr@2
   132
		 */
williamr@2
   133
		ESHA512
williamr@2
   134
	};
williamr@2
   135
	
williamr@2
   136
	public:
williamr@2
   137
		/** 
williamr@2
   138
		 * Creates a brand new reset CMessageDigest object containing no state
williamr@2
   139
		 * information from the current object.  
williamr@2
   140
		 * 
williamr@2
   141
		 * To make a copy of a message digest with its internal state intact,
williamr@2
   142
		 * see CopyL().
williamr@2
   143
		 *
williamr@2
   144
		 * @return A pointer to the new reset CMessageDigest object
williamr@2
   145
		 */
williamr@2
   146
		IMPORT_C virtual CMessageDigest* ReplicateL(void)=0;		
williamr@2
   147
williamr@2
   148
		/** 
williamr@2
   149
		 * Adds aMessage to the internal representation of data to be hashed,
williamr@2
   150
		 * then returns a TPtrC8 of the finalised hash of all the previously
williamr@2
   151
		 * appended messages.
williamr@2
   152
		 * 
williamr@2
   153
		 * @param aMessage	Data to be included in the hash.
williamr@2
   154
		 * @return			A descriptor pointer to the buffer containing the
williamr@2
   155
		 *					resulting hash.
williamr@2
   156
		 */
williamr@2
   157
		IMPORT_C virtual TPtrC8 Hash(const TDesC8& aMessage)=0;
williamr@2
   158
williamr@2
   159
		/** 
williamr@2
   160
		 * Creates a new CMessageDigest object with the exact same state as
williamr@2
   161
		 * the current object.  
williamr@2
   162
		 *
williamr@2
   163
		 * This function copies all internal state of the message digest.
williamr@2
   164
		 * To create a new CMessageDigest object without the state of
williamr@2
   165
		 * the current object, see ReplicateL().
williamr@2
   166
		 *
williamr@2
   167
		 * @return A pointer to the new CMessageDigest object
williamr@2
   168
		 */
williamr@2
   169
		IMPORT_C virtual CMessageDigest* CopyL(void)=0;
williamr@2
   170
		
williamr@2
   171
		/** 
williamr@2
   172
		 * Gets the internal block size of the message digest.
williamr@2
   173
		 * 
williamr@2
   174
		 * @return	Internal block size of message digest in bytes.
williamr@2
   175
		 */
williamr@2
   176
		IMPORT_C virtual TInt BlockSize(void)=0;
williamr@2
   177
		
williamr@2
   178
		/** 
williamr@2
   179
		 * Gets the size of the message digest output.
williamr@2
   180
		 *
williamr@2
   181
		 * @return	Output size of the message digest in bytes.
williamr@2
   182
		 */
williamr@2
   183
		IMPORT_C virtual TInt HashSize(void)=0;
williamr@2
   184
		
williamr@2
   185
		/** 
williamr@2
   186
		 * Resets the internal state of the message digest.  
williamr@2
   187
		 *
williamr@2
   188
		 * A reset hash object loses all internal state representing the hashed
williamr@2
   189
		 * data. A reset message digest is suitable to begin a new, distinct hash
williamr@2
   190
		 * of different data.  Any previously returned TPtrC8 from a call to
williamr@2
   191
		 * Final() remains valid until any subsequent call to Update() or
williamr@2
   192
		 * Final().
williamr@2
   193
		 */
williamr@2
   194
		IMPORT_C virtual void Reset(void)=0;
williamr@2
   195
		
williamr@2
   196
		/**
williamr@2
   197
		 * Destructor.
williamr@2
   198
		 */		
williamr@2
   199
		IMPORT_C ~CMessageDigest(void);
williamr@2
   200
	public:
williamr@2
   201
		/** 
williamr@2
   202
		 * Adds data to the internal representation of messages to be hashed.
williamr@2
   203
		 *
williamr@2
   204
		 * @param aMessage	Data to be included in the hash.
williamr@2
   205
		 * @since v8.0
williamr@2
   206
		 */
williamr@2
   207
		IMPORT_C virtual void Update(const TDesC8& aMessage)=0;
williamr@2
   208
		
williamr@2
   209
		/** 
williamr@2
   210
		 * Adds aMessage to the internal representation of data to be hashed,
williamr@2
   211
		 * returns a TPtrC8 of the finalised hash of all the previously
williamr@2
   212
		 * appended messages, and calls Reset().
williamr@2
   213
		 * 
williamr@2
   214
		 * @param aMessage	Data to be included in the hash 
williamr@2
   215
		 * @return			A descriptor pointer to the buffer containing the
williamr@2
   216
		 *					resulting hash.
williamr@2
   217
		 * @since v8.0
williamr@2
   218
		 */
williamr@2
   219
		IMPORT_C virtual TPtrC8 Final(const TDesC8& aMessage)=0;
williamr@2
   220
		
williamr@2
   221
		/** 
williamr@2
   222
		 * Gets a TPtrC8 of the finalised hash of all the previously
williamr@2
   223
		 * appended messages and then calls Reset().
williamr@2
   224
		 * 
williamr@2
   225
		 * @return	A descriptor pointer to the buffer containing the
williamr@2
   226
		 * 			resulting hash.
williamr@2
   227
		 * @since v8.0
williamr@2
   228
		 */
williamr@2
   229
		IMPORT_C virtual TPtrC8 Final(void)=0;
williamr@2
   230
	public:
williamr@2
   231
		/**
williamr@2
   232
		 * Restores the internal state of the message digest
williamr@2
   233
		 * to a previously stored state.
williamr@2
   234
		 *
williamr@2
   235
		 * @see StoreState()
williamr@2
   236
		 */
williamr@2
   237
		virtual void RestoreState() = 0;
williamr@2
   238
williamr@2
   239
		/**
williamr@2
   240
		 * Stores the internal state of the message digest. 
williamr@2
   241
		 */
williamr@2
   242
		virtual void StoreState() = 0;
williamr@4
   243
williamr@4
   244
		/**
williamr@4
   245
		@internalComponent
williamr@4
   246
		Used to retrieve the extended interfaces extension
williamr@4
   247
		*/		
williamr@4
   248
		TInt GetExtension(TUint aExtensionId, TAny*& a0, TAny* a1);		
williamr@4
   249
williamr@2
   250
	protected:
williamr@2
   251
		/**
williamr@2
   252
		 * Constructor
williamr@2
   253
		 */
williamr@2
   254
		IMPORT_C CMessageDigest(void);
williamr@2
   255
williamr@2
   256
		/**
williamr@2
   257
		 * Copy constructor
williamr@2
   258
		 *
williamr@2
   259
		 * @param aMD	A CMessageDigest object
williamr@2
   260
		 */
williamr@2
   261
		IMPORT_C CMessageDigest(const CMessageDigest& aMD);
williamr@2
   262
	};
williamr@2
   263
williamr@2
   264
/** 
williamr@4
   265
The MD2 block size (in bytes) 
williamr@4
   266
*/
williamr@2
   267
const TInt MD2_BLOCK=16;
williamr@2
   268
williamr@4
   269
/** 
williamr@4
   270
The size (in bytes) of the MD2 message digest 
williamr@4
   271
*/
williamr@2
   272
const TInt MD2_HASH=16;
williamr@2
   273
williamr@2
   274
/**
williamr@2
   275
 * An MD2 message digest
williamr@2
   276
 */
williamr@2
   277
class CMD2:public CMessageDigest
williamr@2
   278
williamr@2
   279
	{
williamr@2
   280
	public:
williamr@2
   281
		/**
williamr@2
   282
		 * Creates a new MD2 object.
williamr@2
   283
		 *
williamr@2
   284
		 * @return	A pointer to the new CMD2 object
williamr@2
   285
		 */
williamr@2
   286
		IMPORT_C static CMD2* NewL(void);
williamr@2
   287
		IMPORT_C CMessageDigest* ReplicateL(void);
williamr@2
   288
		IMPORT_C TPtrC8 Hash(const TDesC8& aMessage);
williamr@2
   289
		/** Destructor */
williamr@2
   290
		IMPORT_C ~CMD2(void);
williamr@2
   291
		IMPORT_C CMessageDigest* CopyL(void);
williamr@2
   292
		IMPORT_C TInt BlockSize(void);
williamr@2
   293
		IMPORT_C TInt HashSize(void);
williamr@2
   294
		IMPORT_C void Reset(void);
williamr@2
   295
		IMPORT_C void Update(const TDesC8& aMessage);
williamr@2
   296
		IMPORT_C TPtrC8 Final(const TDesC8& aMessage);
williamr@2
   297
		IMPORT_C TPtrC8 Final();
williamr@2
   298
	public:
williamr@2
   299
		void RestoreState();
williamr@2
   300
		void StoreState();
williamr@4
   301
	protected:	
williamr@4
   302
		/** @internalComponent */
williamr@2
   303
		CMD2(void);
williamr@2
   304
	};
williamr@2
   305
williamr@2
   306
/** 
williamr@4
   307
The MD5 block size (in bytes)
williamr@4
   308
*/
williamr@2
   309
const TUint MD5_LBLOCK=16;
williamr@2
   310
williamr@4
   311
/** 
williamr@4
   312
The size (in bytes) of the MD5 message digest 
williamr@4
   313
*/
williamr@2
   314
const TUint MD5_HASH=16;
williamr@2
   315
williamr@2
   316
/**
williamr@2
   317
 * An MD5 message digest
williamr@2
   318
 *
williamr@2
   319
 * Takes a message of arbitrary length as input and produces a 128-bit message digest. 
williamr@4
   320
 * 
williamr@4
   321
 * The total input length of data should not be longer than 2^32 in bits(2^31 in bytes)
williamr@2
   322
 * which is roughly half a gig.
williamr@2
   323
 *
williamr@2
   324
 */
williamr@2
   325
class CMD5:public CMessageDigest
williamr@2
   326
	{
williamr@2
   327
	public:
williamr@2
   328
		/**
williamr@2
   329
		 * Creates a new MD5 object.
williamr@2
   330
		 *
williamr@2
   331
		 * @return	A pointer to the new CMD5 object
williamr@2
   332
		 */
williamr@2
   333
		IMPORT_C static CMD5* NewL(void);
williamr@2
   334
		IMPORT_C CMessageDigest* ReplicateL(void);
williamr@2
   335
		IMPORT_C TPtrC8 Hash(const TDesC8& aMessage);
williamr@2
   336
		/** Destructor */
williamr@2
   337
		IMPORT_C ~CMD5(void);
williamr@2
   338
		IMPORT_C CMessageDigest* CopyL(void);
williamr@2
   339
		IMPORT_C TInt BlockSize(void);
williamr@2
   340
		IMPORT_C TInt HashSize(void);
williamr@2
   341
		IMPORT_C void Reset(void);
williamr@2
   342
		IMPORT_C void Update(const TDesC8& aMessage);
williamr@2
   343
		IMPORT_C TPtrC8 Final(const TDesC8& aMessage);
williamr@2
   344
		IMPORT_C TPtrC8 Final();
williamr@2
   345
	public:
williamr@2
   346
		void RestoreState();
williamr@2
   347
		void StoreState();
williamr@4
   348
	protected:
williamr@4
   349
		/** @internalComponent */
williamr@2
   350
		CMD5(void);
williamr@2
   351
	};
williamr@2
   352
williamr@4
   353
williamr@2
   354
/** 
williamr@4
   355
The SHA-1 block size (in bytes) 
williamr@4
   356
*/
williamr@2
   357
const TUint SHA1_LBLOCK=16;
williamr@2
   358
williamr@4
   359
/** 
williamr@4
   360
The size (in bytes) of the SHA-1 message digest 
williamr@4
   361
*/
williamr@2
   362
const TUint SHA1_HASH=20;
williamr@2
   363
williamr@4
   364
/** 
williamr@4
   365
The size (in bytes) of the SHA message digest 
williamr@4
   366
*/
williamr@2
   367
const TUint SHA_HASH=SHA1_HASH;
williamr@2
   368
williamr@2
   369
/**
williamr@2
   370
 * A SHA-1 message digest
williamr@2
   371
 */
williamr@2
   372
class CSHA1:public CMessageDigest
williamr@2
   373
	{
williamr@2
   374
	public:
williamr@2
   375
		/**
williamr@2
   376
		 * Creates a new SHA-1 object.
williamr@2
   377
		 *
williamr@2
   378
		 * @return	A pointer to the new SHA-1 object
williamr@2
   379
		 */
williamr@2
   380
		IMPORT_C static CSHA1* NewL(void);
williamr@2
   381
		IMPORT_C CMessageDigest* ReplicateL(void);
williamr@2
   382
		IMPORT_C TPtrC8 Hash(const TDesC8& aMessage);
williamr@2
   383
		/** Destructor */
williamr@2
   384
		IMPORT_C ~CSHA1(void);
williamr@2
   385
		IMPORT_C CMessageDigest* CopyL(void);
williamr@2
   386
		IMPORT_C TInt BlockSize(void);
williamr@2
   387
		IMPORT_C TInt HashSize(void);
williamr@2
   388
		IMPORT_C void Reset(void);
williamr@2
   389
		IMPORT_C void Update(const TDesC8& aMessage);
williamr@2
   390
		IMPORT_C TPtrC8 Final(const TDesC8& aMessage);
williamr@2
   391
		IMPORT_C TPtrC8 Final();
williamr@2
   392
	public:
williamr@2
   393
		void RestoreState();
williamr@2
   394
		void StoreState();
williamr@4
   395
	protected:
williamr@4
   396
		/** @internalComponent */
williamr@2
   397
		CSHA1(void);
williamr@2
   398
	};
williamr@2
   399
williamr@2
   400
enum TSH2Algo
williamr@2
   401
	{
williamr@2
   402
	E224Bit,
williamr@2
   403
	E256Bit,
williamr@2
   404
	E384Bit,
williamr@2
   405
	E512Bit
williamr@2
   406
	};
williamr@2
   407
	
williamr@2
   408
/**
williamr@2
   409
 * A SHA-2 message digest
williamr@2
   410
 * 
williamr@4
   411
 * SHA-2 is comprised of SHA-224, SHA256, SHA384 and SHA512
williamr@2
   412
 */
williamr@2
   413
class CSHA2 : public CMessageDigest
williamr@2
   414
	{
williamr@4
   415
	public:
williamr@4
   416
		/**
williamr@4
   417
		 * Creates a new SHA-1 object.
williamr@4
   418
		 *
williamr@4
   419
		 * @return	A pointer to the new SHA-1 object
williamr@4
   420
		 */
williamr@4
   421
		IMPORT_C static CSHA2* NewL(TSH2Algo aAlgorithmId);
williamr@4
   422
		IMPORT_C static CSHA2* NewLC(TSH2Algo aAlgorithmId);
williamr@4
   423
		/** Destructor */
williamr@4
   424
		IMPORT_C ~CSHA2(void);
williamr@4
   425
	public:
williamr@4
   426
		void RestoreState();
williamr@4
   427
		void StoreState();		
williamr@4
   428
	protected:
williamr@4
   429
		/** @internalComponent */
williamr@4
   430
		CSHA2(void);
williamr@4
   431
	};	
williamr@2
   432
williamr@4
   433
williamr@2
   434
/**
williamr@2
   435
 * A SHA message digest
williamr@2
   436
 *
williamr@2
   437
 * @deprecated Replaced by CSHA1
williamr@2
   438
 */
williamr@2
   439
class CSHA:public CMessageDigest
williamr@2
   440
	{
williamr@2
   441
	public:
williamr@2
   442
		/**
williamr@2
   443
		 * Creates a new SHA object.
williamr@2
   444
		 *
williamr@2
   445
		 * @return	A pointer to the new SHA object
williamr@2
   446
		 */
williamr@2
   447
		IMPORT_C static CSHA* NewL(void);
williamr@2
   448
		IMPORT_C CMessageDigest* ReplicateL(void);
williamr@2
   449
		IMPORT_C TPtrC8 Hash(const TDesC8& aMessage);
williamr@2
   450
		/** Destructor */
williamr@2
   451
		IMPORT_C ~CSHA(void);
williamr@2
   452
		IMPORT_C CMessageDigest* CopyL(void);
williamr@2
   453
		IMPORT_C TInt BlockSize(void);
williamr@2
   454
		IMPORT_C TInt HashSize(void);
williamr@2
   455
		IMPORT_C void Reset(void);
williamr@2
   456
		IMPORT_C void Update(const TDesC8& aMessage);
williamr@2
   457
		IMPORT_C TPtrC8 Final(const TDesC8& aMessage);
williamr@2
   458
		IMPORT_C TPtrC8 Final();
williamr@2
   459
	public:
williamr@2
   460
		void RestoreState();
williamr@2
   461
		void StoreState();
williamr@2
   462
	};
williamr@2
   463
williamr@2
   464
/**
williamr@2
   465
 * This is the maximum block size currently supported by HMAC implementation.
williamr@2
   466
 */ 
williamr@4
   467
const TUint KMaxBlockSize=128;
williamr@2
   468
williamr@2
   469
/**
williamr@2
   470
 * An HMAC (Hashed Message Authentication Code)
williamr@2
   471
 */
williamr@4
   472
class CHMAC:public CMessageDigest
williamr@2
   473
williamr@2
   474
	{
williamr@2
   475
	public:
williamr@2
   476
		/**
williamr@2
   477
		 * Creates a new HMAC object from a specified type of message digest 
williamr@2
   478
		 * and authentication key.
williamr@2
   479
		 * 
williamr@2
   480
		 * @param aKey		Authentication key.
williamr@2
   481
		 * @param aDigest	A message digest to construct the HMAC from.
williamr@2
   482
		 * @return			A pointer to the new CHMAC object. 
williamr@2
   483
		 *					The resulting HMAC object takes ownership of aDigest
williamr@2
   484
		 *					and is responsible for its deletion.
williamr@2
   485
		 */
williamr@2
   486
		IMPORT_C static CHMAC* NewL(const TDesC8& aKey,CMessageDigest* aDigest);
williamr@2
   487
		IMPORT_C CMessageDigest* ReplicateL(void);
williamr@2
   488
		IMPORT_C TPtrC8 Hash(const TDesC8& aMessage);
williamr@2
   489
		/** Destructor */
williamr@2
   490
		IMPORT_C ~CHMAC(void);
williamr@2
   491
		IMPORT_C CMessageDigest* CopyL(void);
williamr@2
   492
		IMPORT_C TInt BlockSize(void);
williamr@2
   493
		IMPORT_C TInt HashSize(void);
williamr@2
   494
		IMPORT_C void Reset(void);
williamr@2
   495
		IMPORT_C void Update(const TDesC8& aMessage);
williamr@2
   496
		IMPORT_C TPtrC8 Final(const TDesC8& aMessage);
williamr@2
   497
		IMPORT_C TPtrC8 Final();
williamr@2
   498
	public:
williamr@2
   499
		void RestoreState();
williamr@2
   500
		void StoreState();
williamr@4
   501
	protected:
williamr@4
   502
		/** @internalComponent */
williamr@4
   503
		CHMAC(void);
williamr@4
   504
		/** @internalComponent */
williamr@4
   505
		CHMAC(CMessageDigest* aDigest);
williamr@4
   506
		/** @internalComponent */
williamr@4
   507
		CHMAC(const CHMAC& aHMAC);
williamr@4
   508
		/** @internalComponent */
williamr@4
   509
		void InitialiseL(const TDesC8& aKey);
williamr@4
   510
		
williamr@2
   511
	private:
williamr@2
   512
		void InitBlockSizeL();
williamr@4
   513
williamr@2
   514
	private:
williamr@2
   515
		CMessageDigest* iDigest;
williamr@2
   516
		TBuf8<KMaxBlockSize> iInnerPad;
williamr@2
   517
		TBuf8<KMaxBlockSize> iOuterPad;
williamr@2
   518
		TBuf8<KMaxBlockSize> iInnerPadCopy;
williamr@2
   519
		TBuf8<KMaxBlockSize> iOuterPadCopy;		
williamr@2
   520
		TInt iBlockSize;
williamr@4
   521
williamr@2
   522
	};
williamr@4
   523
williamr@2
   524
/** 
williamr@4
   525
The MD4 block size (in bytes)
williamr@4
   526
*/
williamr@4
   527
const TUint MD4_LBLOCK=16;
williamr@2
   528
williamr@4
   529
/** 
williamr@4
   530
The size (in bytes) of the MD4 message digest 
williamr@4
   531
*/
williamr@4
   532
const TUint MD4_HASH=16;
williamr@2
   533
williamr@2
   534
/**
williamr@2
   535
 * An MD4 message digest Algorithm.
williamr@2
   536
 * Takes a message of arbitrary length as input and produces a 128-bit message digest. 
williamr@4
   537
 * 
williamr@2
   538
 * The total input length of data should not be longer than 2^32 in bits(2^31 in bytes)
williamr@2
   539
 * which is roughly half a gig.
williamr@2
   540
 *
williamr@2
   541
 */
williamr@2
   542
class CMD4:public CMessageDigest
williamr@2
   543
	{
williamr@2
   544
	public:
williamr@2
   545
		/**
williamr@2
   546
		 * Creates a new MD4 object.
williamr@2
   547
		 *
williamr@2
   548
		 * @return	A pointer to the new CMD4 object
williamr@2
   549
		 */
williamr@2
   550
		IMPORT_C static CMD4* NewL(void);
williamr@2
   551
		IMPORT_C CMessageDigest* ReplicateL(void);
williamr@2
   552
		IMPORT_C TPtrC8 Hash(const TDesC8& aMessage);
williamr@2
   553
		/** Destructor */
williamr@2
   554
		IMPORT_C ~CMD4(void);
williamr@2
   555
		IMPORT_C CMessageDigest* CopyL(void);
williamr@2
   556
		IMPORT_C TInt BlockSize(void);
williamr@2
   557
		IMPORT_C TInt HashSize(void);
williamr@2
   558
		IMPORT_C void Reset(void);
williamr@2
   559
		IMPORT_C void Update(const TDesC8& aMessage);
williamr@2
   560
		IMPORT_C TPtrC8 Final(const TDesC8& aMessage);
williamr@2
   561
		IMPORT_C TPtrC8 Final();
williamr@2
   562
	public:
williamr@2
   563
		virtual void RestoreState();
williamr@2
   564
		virtual void StoreState();
williamr@4
   565
	protected:
williamr@4
   566
		/** @internalComponent */
williamr@2
   567
		CMD4(void);
williamr@2
   568
	};
williamr@2
   569
williamr@2
   570
williamr@2
   571
/**
williamr@2
   572
 *	Factory to create a CMessageDigest derived object according to the identity of the hash algorithm.
williamr@2
   573
 */
williamr@2
   574
class CMessageDigestFactory : public CBase
williamr@2
   575
{
williamr@2
   576
public:
williamr@2
   577
	/**
williamr@4
   578
	 *Creates a CMessageDigest derived object according to the specified type of hash algorithm.
williamr@2
   579
	 *
williamr@2
   580
	 * @param aHashId	The identity of the hash algorithm
williamr@2
   581
	 * @return			A pointer to a CMessageDigest object
williamr@2
   582
	 */
williamr@2
   583
	IMPORT_C static CMessageDigest* NewDigestL(CMessageDigest::THashId aHashId);
williamr@2
   584
williamr@2
   585
	/**
williamr@2
   586
	 * Creates a CMessageDigest derived object according to the specified type of hash algorithm.
williamr@2
   587
	 * 
williamr@2
   588
	 * The returned pointer is put onto the cleanup stack.
williamr@2
   589
	 *
williamr@2
   590
	 * @param aHashId	The identity of the hash algorithm
williamr@2
   591
	 * @return			A pointer to a CMessageDigest object
williamr@2
   592
	 */
williamr@2
   593
	IMPORT_C static CMessageDigest* NewDigestLC(CMessageDigest::THashId aHashId);
williamr@2
   594
williamr@2
   595
	/**
williamr@2
   596
	 * Creates a CMessageDigest derived object according to the specified type of hash algorithm
williamr@2
   597
	 * and authentication key.
williamr@2
   598
	 *
williamr@2
   599
	 * @param aHashId	The identity of the hash algorithm
williamr@2
   600
	 * @param aKey		The authentication key 
williamr@2
   601
	 * @return			A pointer to a CMessageDigest object
williamr@2
   602
	 */
williamr@2
   603
	IMPORT_C static CMessageDigest* NewHMACL(CMessageDigest::THashId aHashId, const TDesC8& aKey);
williamr@2
   604
williamr@2
   605
	/**
williamr@2
   606
	 * Creates a CMessageDigest derived object according to the specified type of hash algorithm
williamr@2
   607
	 * and authentication key.
williamr@2
   608
	 * 
williamr@2
   609
	 * The returned pointer is put onto the cleanup stack.
williamr@2
   610
	 *
williamr@2
   611
	 * @param aHashId	The identity of the hash algorithm
williamr@2
   612
	 * @param aKey		The authentication key 
williamr@2
   613
	 * @return			A pointer to a CMessageDigest object
williamr@2
   614
	 */
williamr@2
   615
	IMPORT_C static CMessageDigest* NewHMACLC(CMessageDigest::THashId aHashId, const TDesC8& aKey);
williamr@2
   616
};
williamr@2
   617
williamr@2
   618
#endif // __HASH_H__