crypto/weakcrypto/source/hash/sha2.cpp
author hgs
Thu, 12 Aug 2010 21:07:10 +0530
changeset 90 8c545fea2798
parent 72 de46a57f75fb
permissions -rw-r--r--
201031_01
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
72
de46a57f75fb 201023_02
hgs
parents:
diff changeset
     1
/*
de46a57f75fb 201023_02
hgs
parents:
diff changeset
     2
* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
de46a57f75fb 201023_02
hgs
parents:
diff changeset
     3
* All rights reserved.
de46a57f75fb 201023_02
hgs
parents:
diff changeset
     4
* This component and the accompanying materials are made available
de46a57f75fb 201023_02
hgs
parents:
diff changeset
     5
* under the terms of the License "Eclipse Public License v1.0"
de46a57f75fb 201023_02
hgs
parents:
diff changeset
     6
* which accompanies this distribution, and is available
de46a57f75fb 201023_02
hgs
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
de46a57f75fb 201023_02
hgs
parents:
diff changeset
     8
*
de46a57f75fb 201023_02
hgs
parents:
diff changeset
     9
* Initial Contributors:
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    11
*
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    12
* Contributors:
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    13
*
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    14
* Description: 
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    15
* software SHA2 implementation
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    16
* RFC 4634 (US Secure Hash Algorithms (SHA and HMAC-SHA))
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    17
* FIPS 180-2 (With change notice)
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    18
*
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    19
*/
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    20
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    21
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    22
/**
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    23
 @file
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    24
*/
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    25
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    26
#include <hash.h>
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    27
#include "sha224and256.h"
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    28
#include "sha384and512.h"
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    29
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    30
// Initial Hash Values of SHA2 algorithms
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    31
/**
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    32
 * Initial Hash Value for SHA-224
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    33
 * 
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    34
 * These words were obtained by taking the first thirty-two bits 
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    35
 * of the fractional parts of the square roots of the first eight
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    36
 * prime numbers.
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    37
 * 
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    38
 * FIPS 180-2 Appendix
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    39
 * FIPS 180-3 Section 5.3.2
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    40
 */
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    41
const TUint SHA224InitVals[] = 
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    42
    			{
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    43
    			0xc1059ed8, // A
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    44
    			0x367cd507, // B
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    45
    			0x3070dd17, // C
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    46
    			0xf70e5939, // D
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    47
    			0xffc00b31, // E
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    48
    			0x68581511, // F
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    49
    			0x64f98fa7, // G
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    50
    			0xbefa4fa4  // H
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    51
    			};
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    52
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    53
/**
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    54
 * Initial Hash Value for SHA-256
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    55
 * 
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    56
 * These words were obtained by taking the first thirty-two bits 
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    57
 * of the fractional parts of the square roots of the first eight
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    58
 * prime numbers.
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    59
 * 
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    60
 * FIPS 180-2 Section 5.3.2
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    61
 */
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    62
const TUint SHA256InitVals[] = 
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    63
    			{
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    64
    			0x6a09e667, // A
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    65
    			0xbb67ae85, // B
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    66
    			0x3c6ef372, // C
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    67
    			0xa54ff53a, // D
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    68
    			0x510e527f, // E
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    69
    			0x9b05688c, // F
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    70
    			0x1f83d9ab, // G
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    71
    			0x5be0cd19  // H
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    72
    			};
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    73
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    74
/**
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    75
 * Initial Hash Value for SHA-384
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    76
 * 
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    77
 *  These words were obtained by taking the first sixty-four bits 
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    78
 * of the fractional parts of the square roots of the first eight
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    79
 * prime numbers.
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    80
 * 
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    81
 * FIPS 180-2 Section 5.3.3
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    82
 */
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    83
const TUint64 SHA384InitVals[] = 
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    84
    			{
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    85
    			UI64LIT(0xcbbb9d5dc1059ed8), // A
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    86
    			UI64LIT(0x629a292a367cd507), // B
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    87
    			UI64LIT(0x9159015a3070dd17), // C
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    88
    			UI64LIT(0x152fecd8f70e5939), // D
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    89
    			UI64LIT(0x67332667ffc00b31), // E
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    90
    			UI64LIT(0x8eb44a8768581511), // F
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    91
    			UI64LIT(0xdb0c2e0d64f98fa7), // G
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    92
    			UI64LIT(0x47b5481dbefa4fa4)  // H
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    93
    			};
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    94
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    95
/**
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    96
 * Initial Hash Value for SHA-512
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    97
 * 
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    98
 * These words were obtained by taking the first sixty-four bits 
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    99
 * of the fractional parts of the square roots of the first eight
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   100
 * prime numbers.
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   101
 * 
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   102
 * FIPS 180-2 Section 5.3.4
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   103
 */
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   104
const TUint64 SHA512InitVals[] = 
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   105
    			{
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   106
    			UI64LIT(0x6a09e667f3bcc908), // A
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   107
    			UI64LIT(0xbb67ae8584caa73b), // B
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   108
    			UI64LIT(0x3c6ef372fe94f82b), // C
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   109
    			UI64LIT(0xa54ff53a5f1d36f1), // D
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   110
    			UI64LIT(0x510e527fade682d1), // E
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   111
    			UI64LIT(0x9b05688c2b3e6c1f), // F
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   112
    			UI64LIT(0x1f83d9abfb41bd6b), // G
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   113
    			UI64LIT(0x5be0cd19137e2179)  // H
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   114
    			};
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   115
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   116
	
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   117
EXPORT_C CSHA2* CSHA2::NewL(TSH2Algo aAlgorithmId)
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   118
	{
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   119
	CSHA2* self = CSHA2::NewLC(aAlgorithmId);
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   120
	CleanupStack::Pop(self);
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   121
	return self;						
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   122
	}
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   123
														
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   124
EXPORT_C CSHA2* CSHA2::NewLC(TSH2Algo aAlgorithmId)
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   125
	{
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   126
	CSHA2* self = new (ELeave) CSHA2();
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   127
	CleanupStack::PushL(self);
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   128
	self->ConstructL(aAlgorithmId);
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   129
	return self;						
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   130
	}
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   131
														
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   132
void CSHA2::ConstructL(const CSHA2& aSHA2)
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   133
	{
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   134
	iAlgorithmType = aSHA2.iAlgorithmType;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   135
	iInitValues = aSHA2.iInitValues;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   136
	iHashSize = aSHA2.iHashSize;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   137
    switch(iAlgorithmType)
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   138
		{
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   139
		case E224Bit:
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   140
		case E256Bit:
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   141
			{
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   142
			const CSHA224And256* const impl = static_cast<CSHA224And256*>(aSHA2.iImplementation);
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   143
			iImplementation = new (ELeave) CSHA224And256(*impl);
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   144
			break;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   145
			}
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   146
		case E384Bit:
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   147
		case E512Bit:
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   148
			{
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   149
			const CSHA384And512* const impl = static_cast<CSHA384And512*>(aSHA2.iImplementation);
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   150
			iImplementation = new (ELeave) CSHA384And512(*impl);
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   151
			break;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   152
			}
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   153
		default:
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   154
			{
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   155
			User::Leave(KErrNotSupported);
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   156
			}
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   157
		}
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   158
	}
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   159
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   160
void CSHA2::ConstructL(TSH2Algo aAlgorithmId)
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   161
    {
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   162
    switch(aAlgorithmId)
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   163
    	{
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   164
    	case E224Bit:
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   165
    		{
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   166
    		iImplementation = CSHA224And256::NewL();
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   167
    		iInitValues = SHA224InitVals;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   168
    		iAlgorithmType = E224Bit;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   169
    		iHashSize = KSHA224HashSize;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   170
    		break;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   171
    		}
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   172
    	case E256Bit:
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   173
    		{
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   174
    		iImplementation = CSHA224And256::NewL();
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   175
    		iInitValues = SHA256InitVals;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   176
    		iAlgorithmType = E256Bit;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   177
    		iHashSize = KSHA256HashSize;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   178
    		break;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   179
    		}
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   180
    	case E384Bit:
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   181
    		{
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   182
    		iImplementation = CSHA384And512::NewL();
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   183
    		iInitValues = SHA384InitVals;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   184
    		iAlgorithmType = E384Bit;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   185
    		iHashSize = KSHA384HashSize;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   186
    		break;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   187
    		}
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   188
    	case E512Bit:
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   189
    		{
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   190
    		iImplementation = CSHA384And512::NewL();
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   191
    		iInitValues = SHA512InitVals;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   192
    		iAlgorithmType = E512Bit;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   193
    		iHashSize = KSHA512HashSize;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   194
    		break;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   195
    		}
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   196
    	default:
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   197
    		{
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   198
    		User::Leave(KErrNotSupported);
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   199
    		}
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   200
    	}
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   201
    
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   202
    Reset();
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   203
    }
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   204
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   205
EXPORT_C CSHA2::~CSHA2()
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   206
	{
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   207
	delete iImplementation;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   208
	}
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   209
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   210
EXPORT_C CMessageDigest* CSHA2::ReplicateL()
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   211
	{	 
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   212
	return CSHA2::NewL(iAlgorithmType);
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   213
	}
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   214
	
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   215
EXPORT_C TPtrC8 CSHA2::Hash(const TDesC8& aMessage)
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   216
	{
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   217
	TPtrC8 ptr(KNullDesC8());
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   218
	iImplementation->Update(aMessage.Ptr(),aMessage.Size());
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   219
	iImplementation->StoreState();
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   220
	ptr.Set(iImplementation->Final().Ptr(), iHashSize);
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   221
	iImplementation->RestoreState();
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   222
	return ptr;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   223
	}
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   224
	
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   225
EXPORT_C CMessageDigest* CSHA2::CopyL()
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   226
	{
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   227
	CSHA2* hash = new(ELeave) CSHA2();
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   228
	CleanupStack::PushL(hash);
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   229
	hash->ConstructL(*this);
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   230
	CleanupStack::Pop(hash);
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   231
	return hash;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   232
	}
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   233
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   234
EXPORT_C TInt CSHA2::BlockSize(void)
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   235
	{
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   236
	TInt blockSize = KSHA256BlockSize;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   237
	if(E384Bit == iAlgorithmType || E512Bit == iAlgorithmType)
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   238
		{
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   239
		blockSize = KSHA512BlockSize;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   240
		}
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   241
	return blockSize;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   242
	}
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   243
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   244
EXPORT_C TInt CSHA2::HashSize(void)
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   245
	{
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   246
	return iHashSize;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   247
	}
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   248
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   249
EXPORT_C void CSHA2::Reset()
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   250
	{
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   251
	iImplementation->Reset(iInitValues);
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   252
	}
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   253
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   254
EXPORT_C void CSHA2::Update(const TDesC8& aMessage)
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   255
	{
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   256
	iImplementation->Update(aMessage.Ptr(),aMessage.Size());	
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   257
	}
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   258
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   259
EXPORT_C TPtrC8 CSHA2::Final(void)
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   260
	{
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   261
	TPtrC8 ptr(KNullDesC8());
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   262
	ptr.Set(iImplementation->Final().Ptr(), iHashSize);
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   263
	Reset();
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   264
	return ptr;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   265
	}
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   266
	
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   267
EXPORT_C TPtrC8 CSHA2::Final(const TDesC8& aMessage)
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   268
	{
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   269
	iImplementation->Update(aMessage.Ptr(),aMessage.Size());			
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   270
	TPtrC8 ptr(KNullDesC8());
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   271
	ptr.Set(iImplementation->Final().Ptr(), iHashSize);
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   272
	Reset();
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   273
	return ptr;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   274
	}
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   275
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   276
void CSHA2::RestoreState()
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   277
	{
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   278
	iImplementation->RestoreState();
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   279
	}
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   280
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   281
void CSHA2::StoreState()
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   282
	{
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   283
	iImplementation->StoreState();
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   284
	}
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   285
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   286
// Implemented in hmacimpl.cpp or softwarehashbase.cpp
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   287
// but required as derived from MHash. No coverage here.
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   288
#ifdef _BullseyeCoverage
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   289
#pragma suppress_warnings on
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   290
#pragma BullseyeCoverage off
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   291
#pragma suppress_warnings off
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   292
#endif
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   293