crypto/weakcrypto/source/hash/md2.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) 2005-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
* (c) 2003 Symbian Ltd.  All rights reserved.
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    16
*
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    17
*/
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
 @file
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    22
*/
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    23
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    24
#include <e32std.h>
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    25
#include <hash.h>
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    26
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    27
#define EXPANDLOOP
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    28
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    29
//
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    30
// 32bit endianness independent MD2 implementation
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    31
//
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    32
CMD2::CMD2(void)
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    33
: CMessageDigest(),iHash(MD2_HASH)
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    34
	{
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    35
	}
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    36
CMD2::CMD2(const CMD2& aMD)
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    37
: CMessageDigest(aMD),iHash(aMD.iHash),iNum(aMD.iNum)
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    38
	{
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    39
	(void)Mem::Copy(iData,aMD.iData,sizeof(iData));
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    40
	(void)Mem::Copy(iChecksum,aMD.iChecksum,sizeof(iChecksum));
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    41
	(void)Mem::Copy(iState,aMD.iState,sizeof(iState));
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    42
	}
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    43
EXPORT_C CMD2* CMD2::NewL(void)
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    44
	{
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    45
	return (new(ELeave) CMD2);
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    46
	}
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    47
EXPORT_C CMessageDigest* CMD2::ReplicateL(void)
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    48
	{
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    49
	return NewL();
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    50
	}
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    51
EXPORT_C CMD2::~CMD2(void)
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    52
	{
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    53
	}
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    54
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    55
EXPORT_C TPtrC8 CMD2::Hash(const TDesC8& aMessage)
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    56
	{
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    57
	TPtrC8 ptr(KNullDesC8());
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    58
	DoUpdate(aMessage.Ptr(),aMessage.Size());
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    59
	StoreState();	
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    60
	DoFinal();
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    61
	ptr.Set(iHash);
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    62
	RestoreState();	
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    63
	return ptr;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    64
	}
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    65
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    66
EXPORT_C CMessageDigest* CMD2::CopyL(void)
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    67
	{
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    68
	return new(ELeave) CMD2(*this);
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    69
	}
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    70
EXPORT_C TInt CMD2::BlockSize(void)
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    71
	{
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    72
	return sizeof(iData);
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    73
	}
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    74
EXPORT_C TInt CMD2::HashSize(void)
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    75
	{
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    76
	return MD2_HASH;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    77
	}
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    78
EXPORT_C void CMD2::Reset(void)
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    79
	{
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    80
	Mem::FillZ(iData,sizeof(iData));
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    81
	Mem::FillZ(iChecksum,sizeof(iChecksum));
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    82
	Mem::FillZ(iState,sizeof(iState));
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    83
	iNum=0;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    84
	}
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    85
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    86
EXPORT_C void CMD2::Update(const TDesC8& aMessage)
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    87
	{
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    88
	DoUpdate(aMessage.Ptr(),aMessage.Size());
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    89
	}
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    90
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    91
EXPORT_C TPtrC8 CMD2::Final(const TDesC8& aMessage)
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    92
	{
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    93
	TPtrC8 ptr(KNullDesC8());
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    94
	DoUpdate(aMessage.Ptr(),aMessage.Size());
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    95
	DoFinal();
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    96
	ptr.Set(iHash);
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    97
	Reset();
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    98
	return ptr;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    99
	}
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   100
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   101
EXPORT_C TPtrC8 CMD2::Final()
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   102
	{
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   103
	TPtrC8 ptr(KNullDesC8());
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   104
	DoFinal();
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   105
	ptr.Set(iHash);
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   106
	Reset();
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   107
	return ptr;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   108
	}
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   109
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   110
void CMD2::DoUpdate(const TUint8* aData,TUint aLength)
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   111
	{
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   112
	TBool carryOn=ETrue;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   113
	if (iNum)
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   114
		{
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   115
		if (iNum+aLength>=(TUint)MD2_BLOCK)
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   116
			{
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   117
			const TUint temp=MD2_BLOCK-iNum;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   118
			(void)Mem::Copy(iData+iNum,aData,temp);
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   119
			Block(iData);
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   120
			aData+=temp;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   121
			aLength-=temp;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   122
			iNum=0;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   123
			}
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   124
		else
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   125
			{
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   126
			(void)Mem::Copy(iData+iNum,aData,aLength);
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   127
			iNum+=aLength;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   128
			carryOn=EFalse;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   129
			}
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   130
		}
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   131
	// processing by block of MD2_BLOCK
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   132
	if (carryOn)
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   133
		{
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   134
		while (aLength>=(TUint)MD2_BLOCK)
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   135
			{
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   136
			Block(aData);
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   137
			aData+=MD2_BLOCK;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   138
			aLength-=MD2_BLOCK;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   139
			}
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   140
		(void)Mem::Copy(iData,aData,aLength);
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   141
		iNum=aLength;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   142
		}
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   143
	}
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   144
static inline TUint CMD2_S(TUint& elt,TUint8 val)
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   145
	{
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   146
	return elt^=val;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   147
	}
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   148
// 
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   149
// data must be MD2_BLOCK bytes long
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   150
//
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   151
void CMD2::Block(const TUint8* data)
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   152
	{
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   153
	static const TUint8 S[256]={
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   154
		0x29, 0x2E, 0x43, 0xC9, 0xA2, 0xD8, 0x7C, 0x01,
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   155
		0x3D, 0x36, 0x54, 0xA1, 0xEC, 0xF0, 0x06, 0x13,
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   156
		0x62, 0xA7, 0x05, 0xF3, 0xC0, 0xC7, 0x73, 0x8C,
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   157
		0x98, 0x93, 0x2B, 0xD9, 0xBC, 0x4C, 0x82, 0xCA,
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   158
		0x1E, 0x9B, 0x57, 0x3C, 0xFD, 0xD4, 0xE0, 0x16,
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   159
		0x67, 0x42, 0x6F, 0x18, 0x8A, 0x17, 0xE5, 0x12,
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   160
		0xBE, 0x4E, 0xC4, 0xD6, 0xDA, 0x9E, 0xDE, 0x49,
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   161
		0xA0, 0xFB, 0xF5, 0x8E, 0xBB, 0x2F, 0xEE, 0x7A,
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   162
		0xA9, 0x68, 0x79, 0x91, 0x15, 0xB2, 0x07, 0x3F,
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   163
		0x94, 0xC2, 0x10, 0x89, 0x0B, 0x22, 0x5F, 0x21,
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   164
		0x80, 0x7F, 0x5D, 0x9A, 0x5A, 0x90, 0x32, 0x27,
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   165
		0x35, 0x3E, 0xCC, 0xE7, 0xBF, 0xF7, 0x97, 0x03,
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   166
		0xFF, 0x19, 0x30, 0xB3, 0x48, 0xA5, 0xB5, 0xD1,
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   167
		0xD7, 0x5E, 0x92, 0x2A, 0xAC, 0x56, 0xAA, 0xC6,
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   168
		0x4F, 0xB8, 0x38, 0xD2, 0x96, 0xA4, 0x7D, 0xB6,
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   169
		0x76, 0xFC, 0x6B, 0xE2, 0x9C, 0x74, 0x04, 0xF1,
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   170
		0x45, 0x9D, 0x70, 0x59, 0x64, 0x71, 0x87, 0x20,
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   171
		0x86, 0x5B, 0xCF, 0x65, 0xE6, 0x2D, 0xA8, 0x02,
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   172
		0x1B, 0x60, 0x25, 0xAD, 0xAE, 0xB0, 0xB9, 0xF6,
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   173
		0x1C, 0x46, 0x61, 0x69, 0x34, 0x40, 0x7E, 0x0F,
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   174
		0x55, 0x47, 0xA3, 0x23, 0xDD, 0x51, 0xAF, 0x3A,
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   175
		0xC3, 0x5C, 0xF9, 0xCE, 0xBA, 0xC5, 0xEA, 0x26,
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   176
		0x2C, 0x53, 0x0D, 0x6E, 0x85, 0x28, 0x84, 0x09,
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   177
		0xD3, 0xDF, 0xCD, 0xF4, 0x41, 0x81, 0x4D, 0x52,
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   178
		0x6A, 0xDC, 0x37, 0xC8, 0x6C, 0xC1, 0xAB, 0xFA,
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   179
		0x24, 0xE1, 0x7B, 0x08, 0x0C, 0xBD, 0xB1, 0x4A,
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   180
		0x78, 0x88, 0x95, 0x8B, 0xE3, 0x63, 0xE8, 0x6D,
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   181
		0xE9, 0xCB, 0xD5, 0xFE, 0x3B, 0x00, 0x1D, 0x39,
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   182
		0xF2, 0xEF, 0xB7, 0x0E, 0x66, 0x58, 0xD0, 0xE4,
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   183
		0xA6, 0x77, 0x72, 0xF8, 0xEB, 0x75, 0x4B, 0x0A,
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   184
		0x31, 0x44, 0x50, 0xB4, 0x8F, 0xED, 0x1F, 0x1A,
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   185
		0xDB, 0x99, 0x8D, 0x33, 0x9F, 0x11, 0x83, 0x14,
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   186
		};
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   187
	TUint state[MD2_BLOCK*3];
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   188
	TUint j=iChecksum[MD2_BLOCK-1];
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   189
	TUint i=0,temp=0;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   190
	while (i<(TUint)MD2_BLOCK)
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   191
		{
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   192
		const TUint tempState=iState[i];
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   193
		temp=data[i];
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   194
		state[i]=tempState;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   195
		state[i+16]=temp;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   196
		state[i+32]=temp^tempState;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   197
		j=CMD2_S(iChecksum[i++],S[temp^j]);
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   198
		}
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   199
	temp=0;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   200
	TUint* pstate=state;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   201
	const TUint *pend=state+(MD2_BLOCK*3);
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   202
	for (i=0; i<18; i++)
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   203
		{
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   204
		while (pstate<pend)
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   205
			{
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   206
			temp=CMD2_S(*pstate,S[temp]);pstate++;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   207
			temp=CMD2_S(*pstate,S[temp]);pstate++;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   208
			temp=CMD2_S(*pstate,S[temp]);pstate++;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   209
			temp=CMD2_S(*pstate,S[temp]);pstate++;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   210
			temp=CMD2_S(*pstate,S[temp]);pstate++;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   211
			temp=CMD2_S(*pstate,S[temp]);pstate++;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   212
			temp=CMD2_S(*pstate,S[temp]);pstate++;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   213
			temp=CMD2_S(*pstate,S[temp]);pstate++;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   214
			}
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   215
		pstate=state;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   216
		temp=(temp+i)&0xff;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   217
		}
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   218
	(void)Mem::Copy(iState,state,MD2_BLOCK*sizeof(TUint));
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   219
	}
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   220
void CMD2::DoFinal()
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   221
	{
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   222
	const TUint pad=MD2_BLOCK-iNum;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   223
	if (pad>0)
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   224
		Mem::Fill(iData+iNum,(TUint8)pad,pad);
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   225
	Block(iData);
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   226
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   227
	TUint8* pData=iData;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   228
	const TUint8* pEnd=iData+MD2_BLOCK;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   229
	const TUint* pChecksum=iChecksum;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   230
	while (pData<pEnd)
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   231
		{
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   232
		*pData=(TUint8)*pChecksum;//checksum is always less than 255 
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   233
		pData++;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   234
		pChecksum++;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   235
		}
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   236
	Block(iData);
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   237
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   238
	TUint* pState=iState;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   239
	for (TUint i=0;i<(TUint)MD2_BLOCK;i++,pState++) //safe: iState and iHash have got same size
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   240
		iHash[i]=(TUint8)(*pState&0xff);
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   241
	}
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   242
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   243
void CMD2::RestoreState()
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   244
{
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   245
	Mem::Copy(&iData[0], &iDataTemp[0], MD2_BLOCK);
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   246
	Mem::Copy(&iChecksum[0], &iChecksumTemp[0], MD2_BLOCK*sizeof(TUint));
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   247
	Mem::Copy(&iState[0], &iStateTemp[0], MD2_BLOCK*sizeof(TUint));
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   248
}
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   249
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   250
void CMD2::StoreState()
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   251
{
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   252
	Mem::Copy(&iDataTemp[0], &iData[0], MD2_BLOCK);
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   253
	Mem::Copy(&iChecksumTemp[0], &iChecksum[0], MD2_BLOCK*sizeof(TUint));
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   254
	Mem::Copy(&iStateTemp[0], &iState[0], MD2_BLOCK*sizeof(TUint));
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   255
}
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   256