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