os/security/crypto/weakcryptospi/source/hash/hashshim.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 2006-2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     5 * under the terms of the License "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description: 
    15 * hash shim implementation
    16 * hash shim implementation
    17 *
    18 */
    19 
    20 
    21 /**
    22  @file
    23 */
    24 
    25 #include "hashshim.h"
    26 #include <cryptospi/cryptospidef.h>
    27 #include <cryptospi/plugincharacteristics.h>
    28 #include <cryptospi/keys.h>
    29 
    30 
    31 using namespace CryptoSpi;
    32 
    33 //
    34 // MD2 shim implementation
    35 //
    36 CMD2Shim* CMD2Shim::NewL()
    37 	{
    38 	CMD2Shim* self=CMD2Shim::NewLC();
    39 	CleanupStack::Pop();
    40 	return self;	
    41 	}
    42 
    43 CMD2Shim* CMD2Shim::NewLC()
    44 	{
    45 	CMD2Shim* self=new(ELeave) CMD2Shim();
    46 	CleanupStack::PushL(self);
    47 	self->ConstructL();
    48 	return self;	
    49 	}
    50 
    51 TInt CMD2Shim::Extension_(TUint aExtensionId, TAny*& a0, TAny* /*a1*/)
    52 	{
    53 	TInt ret(KErrNotSupported);
    54 	
    55 	if (KHashInterfaceUid.iUid==aExtensionId && iHashImpl)
    56 		{
    57 		a0=iHashImpl;
    58 		ret=KErrNone;	
    59 		}
    60 		
    61 	return ret;
    62 	}
    63 
    64 CMD2Shim::CMD2Shim()
    65 	{		
    66 	}
    67 
    68 CMD2Shim::~CMD2Shim()
    69 	{
    70 	delete iHashImpl;				
    71 	}
    72 
    73 
    74 void CMD2Shim::ConstructL()
    75 	{	
    76 	CHashFactory::CreateHashL(iHashImpl,
    77 							KMd2Uid,
    78 							KHashModeUid,
    79 							NULL, NULL);
    80 	}
    81 
    82 CMessageDigest* CMD2Shim::CopyL()
    83 	{
    84 	CMD2Shim* copy=new(ELeave) CMD2Shim();
    85 	CleanupStack::PushL(copy);
    86 	copy->iHashImpl=iHashImpl->CopyL();
    87 	CleanupStack::Pop();
    88 	return copy;
    89 	}
    90 	
    91 CMessageDigest* CMD2Shim::ReplicateL()
    92 	{
    93 	CMD2Shim* copy=new(ELeave) CMD2Shim();
    94 	CleanupStack::PushL(copy);
    95 	copy->iHashImpl=iHashImpl->ReplicateL();
    96 	CleanupStack::Pop();
    97 	return copy;
    98 	}
    99 
   100 
   101 TInt CMD2Shim::BlockSize()
   102 	{
   103 	const TCharacteristics* ptr(NULL);
   104 	TRAPD(err, iHashImpl->GetCharacteristicsL(ptr);)
   105 	
   106 	if (err)
   107 		{
   108 		return ((err>0)? KErrGeneral : err);
   109 		}
   110 	const THashCharacteristics* hashPtr=static_cast<const THashCharacteristics*>(ptr);
   111 	return hashPtr->iBlockSize/8;
   112 	}
   113 
   114 TInt CMD2Shim::HashSize()
   115 	{
   116 	const TCharacteristics* ptr(NULL);
   117 	TRAPD(err, iHashImpl->GetCharacteristicsL(ptr);)
   118 	if (err)
   119 		{
   120 		return ((err>0)? KErrGeneral : err);
   121 		}	
   122 	const THashCharacteristics* hashPtr=static_cast<const THashCharacteristics*>(ptr);
   123 	return hashPtr->iOutputSize/8;
   124 	}
   125 
   126 void CMD2Shim::Update(const TDesC8& aMessage)
   127 	{
   128 	iHashImpl->Update(aMessage);	
   129 	}
   130 	
   131 	
   132 TPtrC8 CMD2Shim::Final(const TDesC8& aMessage)
   133 	{
   134 	return iHashImpl->Final(aMessage);
   135 	}
   136 
   137 TPtrC8 CMD2Shim::Final()
   138 	{
   139 	TPtrC8 ptr(KNullDesC8());
   140 	return iHashImpl->Final(ptr);
   141 	}
   142 		
   143 void CMD2Shim::Reset()
   144 	{
   145 	iHashImpl->Reset();
   146 	}
   147 	
   148 
   149 TPtrC8 CMD2Shim::Hash(const TDesC8& aMessage)
   150 	{
   151 	return iHashImpl->Hash(aMessage);
   152 	}
   153 
   154 //
   155 // Implementation of MD5 shim
   156 //
   157 CMD5Shim* CMD5Shim::NewL()
   158 	{
   159 	CMD5Shim* self=CMD5Shim::NewLC();
   160 	CleanupStack::Pop();
   161 	return self;	
   162 	}
   163 
   164 CMD5Shim* CMD5Shim::NewLC()
   165 	{
   166 	
   167 	CMD5Shim* self=new(ELeave) CMD5Shim();
   168 	CleanupStack::PushL(self);
   169 	self->ConstructL();
   170 	return self;	
   171 	
   172 	}
   173 
   174 CMD5Shim::CMD5Shim()
   175 	{		
   176 	}
   177 	
   178 TInt CMD5Shim::Extension_(TUint aExtensionId, TAny*& a0, TAny* /*a1*/)
   179 	{
   180 	TInt ret(KErrNotSupported);
   181 	
   182 	if (KHashInterfaceUid.iUid==aExtensionId && iHashImpl)
   183 		{
   184 		a0=iHashImpl;
   185 		ret=KErrNone;	
   186 		}
   187 		
   188 	return ret;
   189 	}
   190 
   191 CMD5Shim::~CMD5Shim()
   192 	{
   193 	delete iHashImpl;				
   194 	}
   195 
   196 
   197 void CMD5Shim::ConstructL()
   198 	{	
   199 	CHashFactory::CreateHashL(iHashImpl,
   200 							KMd5Uid,
   201 							KHashModeUid,
   202 							NULL,
   203 							NULL);
   204 	}
   205 
   206 CMessageDigest* CMD5Shim::CopyL()
   207 	{
   208 	CMD5Shim* copy=new(ELeave) CMD5Shim();
   209 	CleanupStack::PushL(copy);
   210 	copy->iHashImpl=iHashImpl->CopyL();
   211 	CleanupStack::Pop();
   212 	return copy;
   213 	}
   214 
   215 CMessageDigest* CMD5Shim::ReplicateL()
   216 	{
   217 	CMD5Shim* copy=new(ELeave) CMD5Shim();
   218 	CleanupStack::PushL(copy);
   219 	copy->iHashImpl=iHashImpl->ReplicateL();
   220 	CleanupStack::Pop();
   221 	return copy;
   222 	}
   223 
   224 TInt CMD5Shim::BlockSize()
   225 	{
   226 	const TCharacteristics* ptr(NULL);
   227 	TRAPD(err, iHashImpl->GetCharacteristicsL(ptr);)
   228 	if (err)
   229 		{
   230 		return ((err>0)? KErrGeneral : err);
   231 		}		
   232 	const THashCharacteristics* hashPtr=static_cast<const THashCharacteristics*>(ptr);
   233 	return hashPtr->iBlockSize/8;
   234 	}
   235 
   236 TInt CMD5Shim::HashSize()
   237 	{
   238 	const TCharacteristics* ptr(NULL);
   239 	TRAPD(err, iHashImpl->GetCharacteristicsL(ptr);)
   240 	if (err)
   241 		{
   242 		return ((err>0)? KErrGeneral : err);
   243 		}		
   244 	const THashCharacteristics* hashPtr=static_cast<const THashCharacteristics*>(ptr);
   245 	return hashPtr->iOutputSize/8;
   246 	}
   247 
   248 void CMD5Shim::Update(const TDesC8& aMessage)
   249 	{
   250 	iHashImpl->Update(aMessage);	
   251 	}
   252 	
   253 TPtrC8 CMD5Shim::Final(const TDesC8& aMessage)
   254 	{
   255 	return iHashImpl->Final(aMessage);
   256 	}
   257 
   258 TPtrC8 CMD5Shim::Final()
   259 	{
   260 	TPtrC8 ptr(KNullDesC8());
   261 	return iHashImpl->Final(ptr);
   262 	}
   263 		
   264 void CMD5Shim::Reset()
   265 	{
   266 	iHashImpl->Reset();
   267 	}
   268 	
   269 
   270 TPtrC8 CMD5Shim::Hash(const TDesC8& aMessage)
   271 	{
   272 	return iHashImpl->Hash(aMessage);
   273 	}
   274 	
   275 //
   276 // Implementation of SHA1 shim
   277 //	
   278 	
   279 CSHA1Shim* CSHA1Shim::NewL()
   280 	{
   281 	CSHA1Shim* self=CSHA1Shim::NewLC();
   282 	CleanupStack::Pop();
   283 	return self;	
   284 	}
   285 
   286 CSHA1Shim* CSHA1Shim::NewLC()
   287 	{
   288 	
   289 	CSHA1Shim* self=new(ELeave) CSHA1Shim();
   290 	CleanupStack::PushL(self);
   291 	self->ConstructL();
   292 	return self;	
   293 	
   294 	}
   295 
   296 CSHA1Shim::CSHA1Shim()
   297 	{		
   298 	}
   299 	
   300 	
   301 TInt CSHA1Shim::Extension_(TUint aExtensionId, TAny*& a0, TAny* /*a1*/)
   302 	{
   303 	TInt ret(KErrNotSupported);
   304 	
   305 	if (KHashInterfaceUid.iUid==aExtensionId && iHashImpl)
   306 		{
   307 		a0=iHashImpl;
   308 		ret=KErrNone;	
   309 		}
   310 		
   311 	return ret;
   312 	}
   313 
   314 CSHA1Shim::~CSHA1Shim()
   315 	{
   316 	delete iHashImpl;			
   317 	}
   318 
   319 
   320 void CSHA1Shim::ConstructL()
   321 	{
   322 	CHashFactory::CreateHashL(iHashImpl,
   323 							KSha1Uid,
   324 							KHashModeUid,
   325 							NULL,
   326 							NULL);
   327 	}
   328 
   329 CMessageDigest* CSHA1Shim::CopyL()
   330 	{
   331 	CSHA1Shim* copy=new(ELeave) CSHA1Shim();
   332 	CleanupStack::PushL(copy);
   333 	copy->iHashImpl=iHashImpl->CopyL();
   334 	CleanupStack::Pop();
   335 	return copy;
   336 	}
   337 	
   338 CMessageDigest* CSHA1Shim::ReplicateL()
   339 	{
   340 	CSHA1Shim* copy=new(ELeave) CSHA1Shim();
   341 	CleanupStack::PushL(copy);
   342 	copy->iHashImpl=iHashImpl->ReplicateL();
   343 	CleanupStack::Pop();
   344 	return copy;
   345 	}
   346 
   347 TInt CSHA1Shim::BlockSize()
   348 	{
   349 	const TCharacteristics* ptr(NULL);
   350 	TRAPD(err, iHashImpl->GetCharacteristicsL(ptr);)
   351 	if (err)
   352 		{
   353 		return ((err>0)? KErrGeneral : err);
   354 		}	
   355 	const THashCharacteristics* hashPtr=static_cast<const THashCharacteristics*>(ptr);
   356 	return hashPtr->iBlockSize/8;
   357 	}
   358 
   359 TInt CSHA1Shim::HashSize()
   360 	{
   361 	const TCharacteristics* ptr(NULL);
   362 	TRAPD(err, iHashImpl->GetCharacteristicsL(ptr);)
   363 	if (err)
   364 		{
   365 		return ((err>0)? KErrGeneral : err);
   366 		}
   367 	const THashCharacteristics* hashPtr=static_cast<const THashCharacteristics*>(ptr);
   368 	return hashPtr->iOutputSize/8;
   369 	}
   370 
   371 void CSHA1Shim::Update(const TDesC8& aMessage)
   372 	{
   373 	iHashImpl->Update(aMessage);	
   374 	}
   375 	
   376 TPtrC8 CSHA1Shim::Final(const TDesC8& aMessage)
   377 	{
   378 	return iHashImpl->Final(aMessage);
   379 	}
   380 
   381 TPtrC8 CSHA1Shim::Final()
   382 	{
   383 	TPtrC8 ptr(KNullDesC8());
   384 	return iHashImpl->Final(ptr);
   385 	}
   386 		
   387 void CSHA1Shim::Reset()
   388 	{
   389 	iHashImpl->Reset();
   390 	}
   391 
   392 TPtrC8 CSHA1Shim::Hash(const TDesC8& aMessage)
   393 	{
   394 	return iHashImpl->Hash(aMessage);
   395 	}
   396 	
   397 
   398 //
   399 // Implementation of SHA2 shim
   400 //	
   401 	
   402 CSHA2Shim* CSHA2Shim::NewL(TSH2Algo aAlgorithmId)
   403 	{
   404 	CSHA2Shim* self=CSHA2Shim::NewLC(aAlgorithmId);
   405 	CleanupStack::Pop();
   406 	return self;	
   407 	}
   408 
   409 CSHA2Shim* CSHA2Shim::NewLC(TSH2Algo aAlgorithmId)
   410 	{
   411 	
   412 	CSHA2Shim* self=new(ELeave) CSHA2Shim();
   413 	CleanupStack::PushL(self);
   414 	self->ConstructL(aAlgorithmId);
   415 	return self;
   416 	}
   417 
   418 CSHA2Shim::CSHA2Shim()
   419 	{		
   420 	}
   421 	
   422 TInt CSHA2Shim::Extension_(TUint aExtensionId, TAny*& a0, TAny* /*a1*/)
   423 	{
   424 	TInt ret(KErrNotSupported);
   425 	
   426 	if (KHashInterfaceUid.iUid==aExtensionId && iHashImpl)
   427 		{
   428 		a0=iHashImpl;
   429 		ret=KErrNone;	
   430 		}
   431 	return ret;
   432 	}
   433 
   434 CSHA2Shim::~CSHA2Shim()
   435 	{
   436 	delete iHashImpl;			
   437 	}
   438 
   439 void CSHA2Shim::ConstructL(TSH2Algo aAlgorithmId)
   440 	{
   441 	TUid algoId = {0};
   442 	switch(aAlgorithmId)
   443 		{
   444 		case E224Bit:
   445 			{
   446 			algoId = KSha224Uid;
   447 			break;
   448 			}
   449 		case E256Bit:
   450 			{
   451 			algoId = KSha256Uid;
   452 			break;
   453 			}
   454 		case E384Bit:
   455 			{
   456 			algoId = KSha384Uid;
   457 			break;
   458 			}
   459 		case E512Bit:
   460 			{
   461 			algoId = KSha512Uid;
   462 			break;
   463 			}
   464 		default:
   465 			User::Leave(KErrNotSupported);
   466 		}
   467 	
   468 	CHashFactory::CreateHashL(iHashImpl,
   469 							  algoId,
   470 							  KHashModeUid,
   471 							  NULL,
   472 							  NULL);				
   473 	}
   474 
   475 CMessageDigest* CSHA2Shim::CopyL()
   476 	{
   477 	CSHA2Shim* copy=new(ELeave) CSHA2Shim();
   478 	CleanupStack::PushL(copy);
   479 	copy->iHashImpl=iHashImpl->CopyL();
   480 	CleanupStack::Pop();
   481 	return copy;
   482 	}
   483 	
   484 CMessageDigest* CSHA2Shim::ReplicateL()
   485 	{
   486 	CSHA2Shim* copy=new(ELeave) CSHA2Shim();
   487 	CleanupStack::PushL(copy);
   488 	copy->iHashImpl=iHashImpl->ReplicateL();
   489 	CleanupStack::Pop();
   490 	return copy;
   491 	}
   492 
   493 TInt CSHA2Shim::BlockSize()
   494 	{
   495 	const TCharacteristics* ptr(NULL);
   496 	TRAPD(err, iHashImpl->GetCharacteristicsL(ptr);)
   497 	if (err)
   498 		{
   499 		return ((err>0)? KErrGeneral : err);
   500 		}	
   501 	const THashCharacteristics* hashPtr=static_cast<const THashCharacteristics*>(ptr);
   502 	return hashPtr->iBlockSize/8;
   503 	}
   504 
   505 TInt CSHA2Shim::HashSize()
   506 	{
   507 	const TCharacteristics* ptr(NULL);
   508 	TRAPD(err, iHashImpl->GetCharacteristicsL(ptr);)
   509 	if (err)
   510 		{
   511 		return ((err>0)? KErrGeneral : err);
   512 		}
   513 	const THashCharacteristics* hashPtr=static_cast<const THashCharacteristics*>(ptr);
   514 	return hashPtr->iOutputSize/8;
   515 	}
   516 
   517 void CSHA2Shim::Update(const TDesC8& aMessage)
   518 	{
   519 	iHashImpl->Update(aMessage);	
   520 	}
   521 	
   522 TPtrC8 CSHA2Shim::Final(const TDesC8& aMessage)
   523 	{
   524 	return iHashImpl->Final(aMessage);
   525 	}
   526 
   527 TPtrC8 CSHA2Shim::Final()
   528 	{
   529 	TPtrC8 ptr(KNullDesC8());
   530 	return iHashImpl->Final(ptr);
   531 	}
   532 		
   533 void CSHA2Shim::Reset()
   534 	{
   535 	iHashImpl->Reset();
   536 	}
   537 
   538 TPtrC8 CSHA2Shim::Hash(const TDesC8& aMessage)
   539 	{
   540 	return iHashImpl->Hash(aMessage);
   541 	}
   542 
   543 //
   544 // Implementation of HMAC shim
   545 //	
   546 
   547 CHMACShim* CHMACShim::NewL(const TDesC8& aKey, CMessageDigest* aDigest)
   548 	{
   549 	CHMACShim* self(0);
   550 	
   551 	// Check whether the hash contains an SPI plug-in
   552 	TAny* implPtr(0);
   553 	TInt err = aDigest->GetExtension(CryptoSpi::KHashInterface, implPtr, NULL);	
   554 	if (err == KErrNone && implPtr)
   555 		{
   556 		CryptoSpi::CHash* impl(static_cast<CryptoSpi::CHash*>(implPtr));
   557 		const CryptoSpi::TCharacteristics* c(0);
   558 		impl->GetCharacteristicsL(c);
   559 		const CryptoSpi::THashCharacteristics* hashCharacteristics(static_cast<const CryptoSpi::THashCharacteristics*>(c));
   560 			
   561 		
   562 		// Verify that the plug-in supports Hmac mode
   563 		if (hashCharacteristics->IsOperationModeSupported(CryptoSpi::KHmacModeUid))
   564 			{
   565 			
   566 	#ifndef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT				
   567 			// Make an own copy
   568 			CHash* myHash=impl->ReplicateL();
   569 			CleanupStack::PushL(myHash);	
   570 	#endif	
   571 			// Set the key
   572 			TKeyProperty keyProperty = {KHmacModeUid, KNullUid, KSymmetricKey, KNonEmbeddedKeyUid};
   573 		 	CCryptoParams* keyParam =CCryptoParams::NewLC();
   574 		 	keyParam->AddL(aKey, KHmacKeyParameterUid);
   575 		 	CKey* uniKey= CKey::NewLC(keyProperty, *keyParam);
   576 	#ifndef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT		
   577 		 	myHash->SetKeyL(*uniKey);		 			 	
   578 		 	CleanupStack::PopAndDestroy(2, keyParam);
   579 			// Set hash to Hmac mode			
   580 			myHash->SetOperationModeL(CryptoSpi::KHmacModeUid);
   581 			self = new(ELeave) CHMACShim(myHash, aDigest);
   582 			CleanupStack::Pop(myHash);
   583 	#else 	
   584 		 	TUid algorithmUID = algorithmUID.Uid(hashCharacteristics->cmn.iAlgorithmUID);
   585 			//Create a pointer for the Mac Implementation Object
   586 			CMac* macImpl = NULL;
   587 			CMacFactory::CreateMacL(macImpl,algorithmUID,*uniKey, NULL);
   588 			CleanupStack::PushL(macImpl);
   589 		 	self = new(ELeave) CHMACShim(macImpl, aDigest,uniKey, algorithmUID);
   590 		 	CleanupStack::Pop(macImpl);
   591 		 	CleanupStack::Pop(uniKey);			
   592 		 	CleanupStack::PopAndDestroy(keyParam);
   593 	#endif		 	
   594 			}
   595 		}				
   596 	return self;
   597 	}
   598 	
   599 #ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT	
   600 
   601 CHMACShim::CHMACShim(CryptoSpi::CMac* aImpl, CMessageDigest* aDigest, CryptoSpi::CKey* aKey, TUid aAlgorithmUid)
   602 	: CHMAC(aDigest), iMacImpl(aImpl), iKey(aKey), iAlgorithmUid(aAlgorithmUid)
   603 	{		
   604 	}
   605 
   606 #else
   607 
   608 CHMACShim::CHMACShim(CryptoSpi::CHash* aImpl, CMessageDigest* aDigest)
   609 	: CHMAC(aDigest), iMacImpl(aImpl)
   610 	{		
   611 	}
   612 
   613 #endif
   614 
   615 CHMACShim::CHMACShim()
   616 	{		
   617 	}
   618 
   619 CHMACShim::~CHMACShim()
   620 	{
   621 	delete iMacImpl;
   622 #ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT		
   623 	delete iKey;
   624 #endif
   625 	}
   626 
   627 TInt CHMACShim::BlockSize()
   628 	{
   629 	const TCharacteristics* ptr(NULL);
   630 	TRAPD(err, iMacImpl->GetCharacteristicsL(ptr));
   631 
   632 	if (err)
   633 		{
   634 		return ((err>0)? KErrGeneral : err);
   635 		}
   636 
   637 #ifndef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT			
   638 	const THashCharacteristics* hashPtr=static_cast<const THashCharacteristics*>(ptr);
   639 	return hashPtr->iBlockSize/8;
   640 #else		
   641 	const TMacCharacteristics* macPtr=static_cast<const TMacCharacteristics*>(ptr);
   642 	return macPtr->iHashAlgorithmChar->iBlockSize/8;
   643 #endif	
   644 	}
   645 
   646 TInt CHMACShim::HashSize()
   647 	{
   648 	const TCharacteristics* ptr(NULL);
   649 	TRAPD(err, iMacImpl->GetCharacteristicsL(ptr));
   650 	if (err)
   651 		{
   652 		return ((err>0)? KErrGeneral : err);
   653 		}
   654 
   655 #ifndef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT			
   656 	const THashCharacteristics* hashPtr=static_cast<const THashCharacteristics*>(ptr);
   657 	return hashPtr->iOutputSize/8;
   658 #else			
   659 	const TMacCharacteristics* macPtr=static_cast<const TMacCharacteristics*>(ptr);
   660 	return macPtr->iHashAlgorithmChar->iOutputSize/8;
   661 #endif	
   662 	}
   663 
   664 void CHMACShim::Update(const TDesC8& aMessage)
   665 	{
   666 #ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT
   667 	// The error is ignored as the legacy code methods are non-leaving and they call 
   668 	// the new MAC interfaces which uses leaving methods for processing MAC value. 	
   669 	// This call always call the non-leaving legacy method.	
   670 	TRAP_IGNORE(iMacImpl->UpdateL(aMessage));
   671 #else
   672 	iMacImpl->Update(aMessage);
   673 #endif	
   674 	}
   675 	
   676 TPtrC8 CHMACShim::Final(const TDesC8& aMessage)
   677 	{
   678 #ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT
   679 	TPtrC8 macPtr(KNullDesC8());
   680 	// The error is ignored as the legacy code methods are non-leaving and they call 
   681 	// the new MAC interfaces which uses leaving methods for processing MAC value. 	
   682 	// This call always call the non-leaving legacy method.	
   683 	TRAP_IGNORE(macPtr.Set(iMacImpl->FinalL(aMessage)));	
   684 	return macPtr;
   685 #else
   686 	return iMacImpl->Final(aMessage);
   687 #endif	
   688 	}
   689 
   690 TPtrC8 CHMACShim::Final()
   691 	{
   692 	TPtrC8 ptr(KNullDesC8());
   693 #ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT
   694 	TPtrC8 macPtr(KNullDesC8());
   695 	// The error is ignored as the legacy code methods are non-leaving and they call 
   696 	// the new MAC interfaces which uses leaving methods for processing MAC value. 	
   697 	// This call always call the non-leaving legacy method.	
   698 	TRAP_IGNORE(macPtr.Set(iMacImpl->FinalL(ptr)));	
   699 	return macPtr;
   700 #else
   701 	return iMacImpl->Final(ptr);
   702 #endif	
   703 	}
   704 		
   705 void CHMACShim::Reset()
   706 	{
   707 	iMacImpl->Reset();
   708 	}
   709 	
   710 TPtrC8 CHMACShim::Hash(const TDesC8& aMessage)
   711 	{
   712 #ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT	
   713 	TPtrC8 macPtr(KNullDesC8());
   714 	// The error is ignored as the legacy code methods are non-leaving and they call 
   715 	// the new MAC interfaces which uses leaving methods for processing MAC value. 	
   716 	// This call always call the non-leaving legacy method.	
   717 	TRAP_IGNORE(macPtr.Set(iMacImpl->MacL(aMessage)));	
   718 	return macPtr;
   719 #else
   720 	return iMacImpl->Hash(aMessage);
   721 #endif	
   722 	}
   723 	
   724 CMessageDigest* CHMACShim::ReplicateL()
   725 	{
   726 	CHMACShim* copy=new(ELeave) CHMACShim();
   727 	CleanupStack::PushL(copy);
   728 	copy->iMacImpl=iMacImpl->ReplicateL();
   729 	CleanupStack::Pop(copy);
   730 	return copy;	
   731 	}
   732 	
   733 CMessageDigest* CHMACShim::CopyL()
   734 	{
   735 	CHMACShim* copy=new(ELeave) CHMACShim();
   736 	CleanupStack::PushL(copy);
   737 	copy->iMacImpl=iMacImpl->CopyL();
   738 	CleanupStack::Pop(copy);
   739 	return copy;	
   740 	}
   741 
   742 //
   743 // Implemetation of MD4 shim
   744 //
   745 CMD4Shim* CMD4Shim::NewL()
   746 	{
   747 	CMD4Shim* self=CMD4Shim::NewLC();
   748 	CleanupStack::Pop();
   749 	return self;	
   750 	}
   751 
   752 CMD4Shim* CMD4Shim::NewLC()
   753 	{
   754 	CMD4Shim* self=new(ELeave) CMD4Shim();
   755 	CleanupStack::PushL(self);
   756 	self->ConstructL();
   757 	return self;	
   758 	}
   759 
   760 CMD4Shim::CMD4Shim()
   761 	{		
   762 	}
   763 	
   764 TInt CMD4Shim::Extension_(TUint aExtensionId, TAny*& a0, TAny* /*a1*/)
   765 	{
   766 	TInt ret(KErrNotSupported);
   767 	
   768 	if (KHashInterfaceUid.iUid==aExtensionId && iHashImpl)
   769 		{
   770 		a0=iHashImpl;
   771 		ret=KErrNone;	
   772 		}
   773 		
   774 	return ret;
   775 	}
   776 
   777 CMD4Shim::~CMD4Shim()
   778 	{
   779 	delete iHashImpl;				
   780 	}
   781 
   782 
   783 void CMD4Shim::ConstructL()
   784 	{	
   785 	CHashFactory::CreateHashL(iHashImpl,KMd4Uid,KHashModeUid,NULL,NULL);
   786 	}
   787 
   788 CMessageDigest* CMD4Shim::CopyL()
   789 	{
   790 	CMD4Shim* copy=new(ELeave) CMD4Shim();
   791 	CleanupStack::PushL(copy);
   792 	copy->iHashImpl=iHashImpl->CopyL();
   793 	CleanupStack::Pop();
   794 	return copy;
   795 	}
   796 
   797 CMessageDigest* CMD4Shim::ReplicateL()
   798 	{
   799 	CMD4Shim* copy=new(ELeave) CMD4Shim();
   800 	CleanupStack::PushL(copy);
   801 	copy->iHashImpl=iHashImpl->ReplicateL();
   802 	CleanupStack::Pop();
   803 	return copy;
   804 	}
   805 
   806 TInt CMD4Shim::BlockSize()
   807 	{
   808 	const TCharacteristics* ptr(NULL);
   809 	TRAPD(err, iHashImpl->GetCharacteristicsL(ptr);)
   810 	if (err)
   811 		{
   812 		return ((err>0)? KErrGeneral : err);
   813 		}		
   814 	const THashCharacteristics* hashPtr=static_cast<const THashCharacteristics*>(ptr);
   815 	return hashPtr->iBlockSize/8;
   816 	}
   817 
   818 TInt CMD4Shim::HashSize()
   819 	{
   820 	const TCharacteristics* ptr(NULL);
   821 	TRAPD(err, iHashImpl->GetCharacteristicsL(ptr);)
   822 	if (err)
   823 		{
   824 		return ((err>0)? KErrGeneral : err);
   825 		}		
   826 	const THashCharacteristics* hashPtr=static_cast<const THashCharacteristics*>(ptr);
   827 	return hashPtr->iOutputSize/8;
   828 	}
   829 
   830 void CMD4Shim::Update(const TDesC8& aMessage)
   831 	{
   832 	iHashImpl->Update(aMessage);	
   833 	}
   834 	
   835 TPtrC8 CMD4Shim::Final(const TDesC8& aMessage)
   836 	{
   837 	return iHashImpl->Final(aMessage);
   838 	}
   839 
   840 TPtrC8 CMD4Shim::Final()
   841 	{
   842 	TPtrC8 ptr(KNullDesC8());
   843 	return iHashImpl->Final(ptr);
   844 	}
   845 		
   846 void CMD4Shim::Reset()
   847 	{
   848 	iHashImpl->Reset();
   849 	}
   850 	
   851 
   852 TPtrC8 CMD4Shim::Hash(const TDesC8& aMessage)
   853 	{
   854 	return iHashImpl->Hash(aMessage);
   855 	}
   856