1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/security/crypto/weakcryptospi/source/hash/hashshim.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,856 @@
1.4 +/*
1.5 +* Copyright (c) 2006-2010 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of the License "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +* hash shim implementation
1.19 +* hash shim implementation
1.20 +*
1.21 +*/
1.22 +
1.23 +
1.24 +/**
1.25 + @file
1.26 +*/
1.27 +
1.28 +#include "hashshim.h"
1.29 +#include <cryptospi/cryptospidef.h>
1.30 +#include <cryptospi/plugincharacteristics.h>
1.31 +#include <cryptospi/keys.h>
1.32 +
1.33 +
1.34 +using namespace CryptoSpi;
1.35 +
1.36 +//
1.37 +// MD2 shim implementation
1.38 +//
1.39 +CMD2Shim* CMD2Shim::NewL()
1.40 + {
1.41 + CMD2Shim* self=CMD2Shim::NewLC();
1.42 + CleanupStack::Pop();
1.43 + return self;
1.44 + }
1.45 +
1.46 +CMD2Shim* CMD2Shim::NewLC()
1.47 + {
1.48 + CMD2Shim* self=new(ELeave) CMD2Shim();
1.49 + CleanupStack::PushL(self);
1.50 + self->ConstructL();
1.51 + return self;
1.52 + }
1.53 +
1.54 +TInt CMD2Shim::Extension_(TUint aExtensionId, TAny*& a0, TAny* /*a1*/)
1.55 + {
1.56 + TInt ret(KErrNotSupported);
1.57 +
1.58 + if (KHashInterfaceUid.iUid==aExtensionId && iHashImpl)
1.59 + {
1.60 + a0=iHashImpl;
1.61 + ret=KErrNone;
1.62 + }
1.63 +
1.64 + return ret;
1.65 + }
1.66 +
1.67 +CMD2Shim::CMD2Shim()
1.68 + {
1.69 + }
1.70 +
1.71 +CMD2Shim::~CMD2Shim()
1.72 + {
1.73 + delete iHashImpl;
1.74 + }
1.75 +
1.76 +
1.77 +void CMD2Shim::ConstructL()
1.78 + {
1.79 + CHashFactory::CreateHashL(iHashImpl,
1.80 + KMd2Uid,
1.81 + KHashModeUid,
1.82 + NULL, NULL);
1.83 + }
1.84 +
1.85 +CMessageDigest* CMD2Shim::CopyL()
1.86 + {
1.87 + CMD2Shim* copy=new(ELeave) CMD2Shim();
1.88 + CleanupStack::PushL(copy);
1.89 + copy->iHashImpl=iHashImpl->CopyL();
1.90 + CleanupStack::Pop();
1.91 + return copy;
1.92 + }
1.93 +
1.94 +CMessageDigest* CMD2Shim::ReplicateL()
1.95 + {
1.96 + CMD2Shim* copy=new(ELeave) CMD2Shim();
1.97 + CleanupStack::PushL(copy);
1.98 + copy->iHashImpl=iHashImpl->ReplicateL();
1.99 + CleanupStack::Pop();
1.100 + return copy;
1.101 + }
1.102 +
1.103 +
1.104 +TInt CMD2Shim::BlockSize()
1.105 + {
1.106 + const TCharacteristics* ptr(NULL);
1.107 + TRAPD(err, iHashImpl->GetCharacteristicsL(ptr);)
1.108 +
1.109 + if (err)
1.110 + {
1.111 + return ((err>0)? KErrGeneral : err);
1.112 + }
1.113 + const THashCharacteristics* hashPtr=static_cast<const THashCharacteristics*>(ptr);
1.114 + return hashPtr->iBlockSize/8;
1.115 + }
1.116 +
1.117 +TInt CMD2Shim::HashSize()
1.118 + {
1.119 + const TCharacteristics* ptr(NULL);
1.120 + TRAPD(err, iHashImpl->GetCharacteristicsL(ptr);)
1.121 + if (err)
1.122 + {
1.123 + return ((err>0)? KErrGeneral : err);
1.124 + }
1.125 + const THashCharacteristics* hashPtr=static_cast<const THashCharacteristics*>(ptr);
1.126 + return hashPtr->iOutputSize/8;
1.127 + }
1.128 +
1.129 +void CMD2Shim::Update(const TDesC8& aMessage)
1.130 + {
1.131 + iHashImpl->Update(aMessage);
1.132 + }
1.133 +
1.134 +
1.135 +TPtrC8 CMD2Shim::Final(const TDesC8& aMessage)
1.136 + {
1.137 + return iHashImpl->Final(aMessage);
1.138 + }
1.139 +
1.140 +TPtrC8 CMD2Shim::Final()
1.141 + {
1.142 + TPtrC8 ptr(KNullDesC8());
1.143 + return iHashImpl->Final(ptr);
1.144 + }
1.145 +
1.146 +void CMD2Shim::Reset()
1.147 + {
1.148 + iHashImpl->Reset();
1.149 + }
1.150 +
1.151 +
1.152 +TPtrC8 CMD2Shim::Hash(const TDesC8& aMessage)
1.153 + {
1.154 + return iHashImpl->Hash(aMessage);
1.155 + }
1.156 +
1.157 +//
1.158 +// Implementation of MD5 shim
1.159 +//
1.160 +CMD5Shim* CMD5Shim::NewL()
1.161 + {
1.162 + CMD5Shim* self=CMD5Shim::NewLC();
1.163 + CleanupStack::Pop();
1.164 + return self;
1.165 + }
1.166 +
1.167 +CMD5Shim* CMD5Shim::NewLC()
1.168 + {
1.169 +
1.170 + CMD5Shim* self=new(ELeave) CMD5Shim();
1.171 + CleanupStack::PushL(self);
1.172 + self->ConstructL();
1.173 + return self;
1.174 +
1.175 + }
1.176 +
1.177 +CMD5Shim::CMD5Shim()
1.178 + {
1.179 + }
1.180 +
1.181 +TInt CMD5Shim::Extension_(TUint aExtensionId, TAny*& a0, TAny* /*a1*/)
1.182 + {
1.183 + TInt ret(KErrNotSupported);
1.184 +
1.185 + if (KHashInterfaceUid.iUid==aExtensionId && iHashImpl)
1.186 + {
1.187 + a0=iHashImpl;
1.188 + ret=KErrNone;
1.189 + }
1.190 +
1.191 + return ret;
1.192 + }
1.193 +
1.194 +CMD5Shim::~CMD5Shim()
1.195 + {
1.196 + delete iHashImpl;
1.197 + }
1.198 +
1.199 +
1.200 +void CMD5Shim::ConstructL()
1.201 + {
1.202 + CHashFactory::CreateHashL(iHashImpl,
1.203 + KMd5Uid,
1.204 + KHashModeUid,
1.205 + NULL,
1.206 + NULL);
1.207 + }
1.208 +
1.209 +CMessageDigest* CMD5Shim::CopyL()
1.210 + {
1.211 + CMD5Shim* copy=new(ELeave) CMD5Shim();
1.212 + CleanupStack::PushL(copy);
1.213 + copy->iHashImpl=iHashImpl->CopyL();
1.214 + CleanupStack::Pop();
1.215 + return copy;
1.216 + }
1.217 +
1.218 +CMessageDigest* CMD5Shim::ReplicateL()
1.219 + {
1.220 + CMD5Shim* copy=new(ELeave) CMD5Shim();
1.221 + CleanupStack::PushL(copy);
1.222 + copy->iHashImpl=iHashImpl->ReplicateL();
1.223 + CleanupStack::Pop();
1.224 + return copy;
1.225 + }
1.226 +
1.227 +TInt CMD5Shim::BlockSize()
1.228 + {
1.229 + const TCharacteristics* ptr(NULL);
1.230 + TRAPD(err, iHashImpl->GetCharacteristicsL(ptr);)
1.231 + if (err)
1.232 + {
1.233 + return ((err>0)? KErrGeneral : err);
1.234 + }
1.235 + const THashCharacteristics* hashPtr=static_cast<const THashCharacteristics*>(ptr);
1.236 + return hashPtr->iBlockSize/8;
1.237 + }
1.238 +
1.239 +TInt CMD5Shim::HashSize()
1.240 + {
1.241 + const TCharacteristics* ptr(NULL);
1.242 + TRAPD(err, iHashImpl->GetCharacteristicsL(ptr);)
1.243 + if (err)
1.244 + {
1.245 + return ((err>0)? KErrGeneral : err);
1.246 + }
1.247 + const THashCharacteristics* hashPtr=static_cast<const THashCharacteristics*>(ptr);
1.248 + return hashPtr->iOutputSize/8;
1.249 + }
1.250 +
1.251 +void CMD5Shim::Update(const TDesC8& aMessage)
1.252 + {
1.253 + iHashImpl->Update(aMessage);
1.254 + }
1.255 +
1.256 +TPtrC8 CMD5Shim::Final(const TDesC8& aMessage)
1.257 + {
1.258 + return iHashImpl->Final(aMessage);
1.259 + }
1.260 +
1.261 +TPtrC8 CMD5Shim::Final()
1.262 + {
1.263 + TPtrC8 ptr(KNullDesC8());
1.264 + return iHashImpl->Final(ptr);
1.265 + }
1.266 +
1.267 +void CMD5Shim::Reset()
1.268 + {
1.269 + iHashImpl->Reset();
1.270 + }
1.271 +
1.272 +
1.273 +TPtrC8 CMD5Shim::Hash(const TDesC8& aMessage)
1.274 + {
1.275 + return iHashImpl->Hash(aMessage);
1.276 + }
1.277 +
1.278 +//
1.279 +// Implementation of SHA1 shim
1.280 +//
1.281 +
1.282 +CSHA1Shim* CSHA1Shim::NewL()
1.283 + {
1.284 + CSHA1Shim* self=CSHA1Shim::NewLC();
1.285 + CleanupStack::Pop();
1.286 + return self;
1.287 + }
1.288 +
1.289 +CSHA1Shim* CSHA1Shim::NewLC()
1.290 + {
1.291 +
1.292 + CSHA1Shim* self=new(ELeave) CSHA1Shim();
1.293 + CleanupStack::PushL(self);
1.294 + self->ConstructL();
1.295 + return self;
1.296 +
1.297 + }
1.298 +
1.299 +CSHA1Shim::CSHA1Shim()
1.300 + {
1.301 + }
1.302 +
1.303 +
1.304 +TInt CSHA1Shim::Extension_(TUint aExtensionId, TAny*& a0, TAny* /*a1*/)
1.305 + {
1.306 + TInt ret(KErrNotSupported);
1.307 +
1.308 + if (KHashInterfaceUid.iUid==aExtensionId && iHashImpl)
1.309 + {
1.310 + a0=iHashImpl;
1.311 + ret=KErrNone;
1.312 + }
1.313 +
1.314 + return ret;
1.315 + }
1.316 +
1.317 +CSHA1Shim::~CSHA1Shim()
1.318 + {
1.319 + delete iHashImpl;
1.320 + }
1.321 +
1.322 +
1.323 +void CSHA1Shim::ConstructL()
1.324 + {
1.325 + CHashFactory::CreateHashL(iHashImpl,
1.326 + KSha1Uid,
1.327 + KHashModeUid,
1.328 + NULL,
1.329 + NULL);
1.330 + }
1.331 +
1.332 +CMessageDigest* CSHA1Shim::CopyL()
1.333 + {
1.334 + CSHA1Shim* copy=new(ELeave) CSHA1Shim();
1.335 + CleanupStack::PushL(copy);
1.336 + copy->iHashImpl=iHashImpl->CopyL();
1.337 + CleanupStack::Pop();
1.338 + return copy;
1.339 + }
1.340 +
1.341 +CMessageDigest* CSHA1Shim::ReplicateL()
1.342 + {
1.343 + CSHA1Shim* copy=new(ELeave) CSHA1Shim();
1.344 + CleanupStack::PushL(copy);
1.345 + copy->iHashImpl=iHashImpl->ReplicateL();
1.346 + CleanupStack::Pop();
1.347 + return copy;
1.348 + }
1.349 +
1.350 +TInt CSHA1Shim::BlockSize()
1.351 + {
1.352 + const TCharacteristics* ptr(NULL);
1.353 + TRAPD(err, iHashImpl->GetCharacteristicsL(ptr);)
1.354 + if (err)
1.355 + {
1.356 + return ((err>0)? KErrGeneral : err);
1.357 + }
1.358 + const THashCharacteristics* hashPtr=static_cast<const THashCharacteristics*>(ptr);
1.359 + return hashPtr->iBlockSize/8;
1.360 + }
1.361 +
1.362 +TInt CSHA1Shim::HashSize()
1.363 + {
1.364 + const TCharacteristics* ptr(NULL);
1.365 + TRAPD(err, iHashImpl->GetCharacteristicsL(ptr);)
1.366 + if (err)
1.367 + {
1.368 + return ((err>0)? KErrGeneral : err);
1.369 + }
1.370 + const THashCharacteristics* hashPtr=static_cast<const THashCharacteristics*>(ptr);
1.371 + return hashPtr->iOutputSize/8;
1.372 + }
1.373 +
1.374 +void CSHA1Shim::Update(const TDesC8& aMessage)
1.375 + {
1.376 + iHashImpl->Update(aMessage);
1.377 + }
1.378 +
1.379 +TPtrC8 CSHA1Shim::Final(const TDesC8& aMessage)
1.380 + {
1.381 + return iHashImpl->Final(aMessage);
1.382 + }
1.383 +
1.384 +TPtrC8 CSHA1Shim::Final()
1.385 + {
1.386 + TPtrC8 ptr(KNullDesC8());
1.387 + return iHashImpl->Final(ptr);
1.388 + }
1.389 +
1.390 +void CSHA1Shim::Reset()
1.391 + {
1.392 + iHashImpl->Reset();
1.393 + }
1.394 +
1.395 +TPtrC8 CSHA1Shim::Hash(const TDesC8& aMessage)
1.396 + {
1.397 + return iHashImpl->Hash(aMessage);
1.398 + }
1.399 +
1.400 +
1.401 +//
1.402 +// Implementation of SHA2 shim
1.403 +//
1.404 +
1.405 +CSHA2Shim* CSHA2Shim::NewL(TSH2Algo aAlgorithmId)
1.406 + {
1.407 + CSHA2Shim* self=CSHA2Shim::NewLC(aAlgorithmId);
1.408 + CleanupStack::Pop();
1.409 + return self;
1.410 + }
1.411 +
1.412 +CSHA2Shim* CSHA2Shim::NewLC(TSH2Algo aAlgorithmId)
1.413 + {
1.414 +
1.415 + CSHA2Shim* self=new(ELeave) CSHA2Shim();
1.416 + CleanupStack::PushL(self);
1.417 + self->ConstructL(aAlgorithmId);
1.418 + return self;
1.419 + }
1.420 +
1.421 +CSHA2Shim::CSHA2Shim()
1.422 + {
1.423 + }
1.424 +
1.425 +TInt CSHA2Shim::Extension_(TUint aExtensionId, TAny*& a0, TAny* /*a1*/)
1.426 + {
1.427 + TInt ret(KErrNotSupported);
1.428 +
1.429 + if (KHashInterfaceUid.iUid==aExtensionId && iHashImpl)
1.430 + {
1.431 + a0=iHashImpl;
1.432 + ret=KErrNone;
1.433 + }
1.434 + return ret;
1.435 + }
1.436 +
1.437 +CSHA2Shim::~CSHA2Shim()
1.438 + {
1.439 + delete iHashImpl;
1.440 + }
1.441 +
1.442 +void CSHA2Shim::ConstructL(TSH2Algo aAlgorithmId)
1.443 + {
1.444 + TUid algoId = {0};
1.445 + switch(aAlgorithmId)
1.446 + {
1.447 + case E224Bit:
1.448 + {
1.449 + algoId = KSha224Uid;
1.450 + break;
1.451 + }
1.452 + case E256Bit:
1.453 + {
1.454 + algoId = KSha256Uid;
1.455 + break;
1.456 + }
1.457 + case E384Bit:
1.458 + {
1.459 + algoId = KSha384Uid;
1.460 + break;
1.461 + }
1.462 + case E512Bit:
1.463 + {
1.464 + algoId = KSha512Uid;
1.465 + break;
1.466 + }
1.467 + default:
1.468 + User::Leave(KErrNotSupported);
1.469 + }
1.470 +
1.471 + CHashFactory::CreateHashL(iHashImpl,
1.472 + algoId,
1.473 + KHashModeUid,
1.474 + NULL,
1.475 + NULL);
1.476 + }
1.477 +
1.478 +CMessageDigest* CSHA2Shim::CopyL()
1.479 + {
1.480 + CSHA2Shim* copy=new(ELeave) CSHA2Shim();
1.481 + CleanupStack::PushL(copy);
1.482 + copy->iHashImpl=iHashImpl->CopyL();
1.483 + CleanupStack::Pop();
1.484 + return copy;
1.485 + }
1.486 +
1.487 +CMessageDigest* CSHA2Shim::ReplicateL()
1.488 + {
1.489 + CSHA2Shim* copy=new(ELeave) CSHA2Shim();
1.490 + CleanupStack::PushL(copy);
1.491 + copy->iHashImpl=iHashImpl->ReplicateL();
1.492 + CleanupStack::Pop();
1.493 + return copy;
1.494 + }
1.495 +
1.496 +TInt CSHA2Shim::BlockSize()
1.497 + {
1.498 + const TCharacteristics* ptr(NULL);
1.499 + TRAPD(err, iHashImpl->GetCharacteristicsL(ptr);)
1.500 + if (err)
1.501 + {
1.502 + return ((err>0)? KErrGeneral : err);
1.503 + }
1.504 + const THashCharacteristics* hashPtr=static_cast<const THashCharacteristics*>(ptr);
1.505 + return hashPtr->iBlockSize/8;
1.506 + }
1.507 +
1.508 +TInt CSHA2Shim::HashSize()
1.509 + {
1.510 + const TCharacteristics* ptr(NULL);
1.511 + TRAPD(err, iHashImpl->GetCharacteristicsL(ptr);)
1.512 + if (err)
1.513 + {
1.514 + return ((err>0)? KErrGeneral : err);
1.515 + }
1.516 + const THashCharacteristics* hashPtr=static_cast<const THashCharacteristics*>(ptr);
1.517 + return hashPtr->iOutputSize/8;
1.518 + }
1.519 +
1.520 +void CSHA2Shim::Update(const TDesC8& aMessage)
1.521 + {
1.522 + iHashImpl->Update(aMessage);
1.523 + }
1.524 +
1.525 +TPtrC8 CSHA2Shim::Final(const TDesC8& aMessage)
1.526 + {
1.527 + return iHashImpl->Final(aMessage);
1.528 + }
1.529 +
1.530 +TPtrC8 CSHA2Shim::Final()
1.531 + {
1.532 + TPtrC8 ptr(KNullDesC8());
1.533 + return iHashImpl->Final(ptr);
1.534 + }
1.535 +
1.536 +void CSHA2Shim::Reset()
1.537 + {
1.538 + iHashImpl->Reset();
1.539 + }
1.540 +
1.541 +TPtrC8 CSHA2Shim::Hash(const TDesC8& aMessage)
1.542 + {
1.543 + return iHashImpl->Hash(aMessage);
1.544 + }
1.545 +
1.546 +//
1.547 +// Implementation of HMAC shim
1.548 +//
1.549 +
1.550 +CHMACShim* CHMACShim::NewL(const TDesC8& aKey, CMessageDigest* aDigest)
1.551 + {
1.552 + CHMACShim* self(0);
1.553 +
1.554 + // Check whether the hash contains an SPI plug-in
1.555 + TAny* implPtr(0);
1.556 + TInt err = aDigest->GetExtension(CryptoSpi::KHashInterface, implPtr, NULL);
1.557 + if (err == KErrNone && implPtr)
1.558 + {
1.559 + CryptoSpi::CHash* impl(static_cast<CryptoSpi::CHash*>(implPtr));
1.560 + const CryptoSpi::TCharacteristics* c(0);
1.561 + impl->GetCharacteristicsL(c);
1.562 + const CryptoSpi::THashCharacteristics* hashCharacteristics(static_cast<const CryptoSpi::THashCharacteristics*>(c));
1.563 +
1.564 +
1.565 + // Verify that the plug-in supports Hmac mode
1.566 + if (hashCharacteristics->IsOperationModeSupported(CryptoSpi::KHmacModeUid))
1.567 + {
1.568 +
1.569 + #ifndef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT
1.570 + // Make an own copy
1.571 + CHash* myHash=impl->ReplicateL();
1.572 + CleanupStack::PushL(myHash);
1.573 + #endif
1.574 + // Set the key
1.575 + TKeyProperty keyProperty = {KHmacModeUid, KNullUid, KSymmetricKey, KNonEmbeddedKeyUid};
1.576 + CCryptoParams* keyParam =CCryptoParams::NewLC();
1.577 + keyParam->AddL(aKey, KHmacKeyParameterUid);
1.578 + CKey* uniKey= CKey::NewLC(keyProperty, *keyParam);
1.579 + #ifndef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT
1.580 + myHash->SetKeyL(*uniKey);
1.581 + CleanupStack::PopAndDestroy(2, keyParam);
1.582 + // Set hash to Hmac mode
1.583 + myHash->SetOperationModeL(CryptoSpi::KHmacModeUid);
1.584 + self = new(ELeave) CHMACShim(myHash, aDigest);
1.585 + CleanupStack::Pop(myHash);
1.586 + #else
1.587 + TUid algorithmUID = algorithmUID.Uid(hashCharacteristics->cmn.iAlgorithmUID);
1.588 + //Create a pointer for the Mac Implementation Object
1.589 + CMac* macImpl = NULL;
1.590 + CMacFactory::CreateMacL(macImpl,algorithmUID,*uniKey, NULL);
1.591 + CleanupStack::PushL(macImpl);
1.592 + self = new(ELeave) CHMACShim(macImpl, aDigest,uniKey, algorithmUID);
1.593 + CleanupStack::Pop(macImpl);
1.594 + CleanupStack::Pop(uniKey);
1.595 + CleanupStack::PopAndDestroy(keyParam);
1.596 + #endif
1.597 + }
1.598 + }
1.599 + return self;
1.600 + }
1.601 +
1.602 +#ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT
1.603 +
1.604 +CHMACShim::CHMACShim(CryptoSpi::CMac* aImpl, CMessageDigest* aDigest, CryptoSpi::CKey* aKey, TUid aAlgorithmUid)
1.605 + : CHMAC(aDigest), iMacImpl(aImpl), iKey(aKey), iAlgorithmUid(aAlgorithmUid)
1.606 + {
1.607 + }
1.608 +
1.609 +#else
1.610 +
1.611 +CHMACShim::CHMACShim(CryptoSpi::CHash* aImpl, CMessageDigest* aDigest)
1.612 + : CHMAC(aDigest), iMacImpl(aImpl)
1.613 + {
1.614 + }
1.615 +
1.616 +#endif
1.617 +
1.618 +CHMACShim::CHMACShim()
1.619 + {
1.620 + }
1.621 +
1.622 +CHMACShim::~CHMACShim()
1.623 + {
1.624 + delete iMacImpl;
1.625 +#ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT
1.626 + delete iKey;
1.627 +#endif
1.628 + }
1.629 +
1.630 +TInt CHMACShim::BlockSize()
1.631 + {
1.632 + const TCharacteristics* ptr(NULL);
1.633 + TRAPD(err, iMacImpl->GetCharacteristicsL(ptr));
1.634 +
1.635 + if (err)
1.636 + {
1.637 + return ((err>0)? KErrGeneral : err);
1.638 + }
1.639 +
1.640 +#ifndef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT
1.641 + const THashCharacteristics* hashPtr=static_cast<const THashCharacteristics*>(ptr);
1.642 + return hashPtr->iBlockSize/8;
1.643 +#else
1.644 + const TMacCharacteristics* macPtr=static_cast<const TMacCharacteristics*>(ptr);
1.645 + return macPtr->iHashAlgorithmChar->iBlockSize/8;
1.646 +#endif
1.647 + }
1.648 +
1.649 +TInt CHMACShim::HashSize()
1.650 + {
1.651 + const TCharacteristics* ptr(NULL);
1.652 + TRAPD(err, iMacImpl->GetCharacteristicsL(ptr));
1.653 + if (err)
1.654 + {
1.655 + return ((err>0)? KErrGeneral : err);
1.656 + }
1.657 +
1.658 +#ifndef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT
1.659 + const THashCharacteristics* hashPtr=static_cast<const THashCharacteristics*>(ptr);
1.660 + return hashPtr->iOutputSize/8;
1.661 +#else
1.662 + const TMacCharacteristics* macPtr=static_cast<const TMacCharacteristics*>(ptr);
1.663 + return macPtr->iHashAlgorithmChar->iOutputSize/8;
1.664 +#endif
1.665 + }
1.666 +
1.667 +void CHMACShim::Update(const TDesC8& aMessage)
1.668 + {
1.669 +#ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT
1.670 + // The error is ignored as the legacy code methods are non-leaving and they call
1.671 + // the new MAC interfaces which uses leaving methods for processing MAC value.
1.672 + // This call always call the non-leaving legacy method.
1.673 + TRAP_IGNORE(iMacImpl->UpdateL(aMessage));
1.674 +#else
1.675 + iMacImpl->Update(aMessage);
1.676 +#endif
1.677 + }
1.678 +
1.679 +TPtrC8 CHMACShim::Final(const TDesC8& aMessage)
1.680 + {
1.681 +#ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT
1.682 + TPtrC8 macPtr(KNullDesC8());
1.683 + // The error is ignored as the legacy code methods are non-leaving and they call
1.684 + // the new MAC interfaces which uses leaving methods for processing MAC value.
1.685 + // This call always call the non-leaving legacy method.
1.686 + TRAP_IGNORE(macPtr.Set(iMacImpl->FinalL(aMessage)));
1.687 + return macPtr;
1.688 +#else
1.689 + return iMacImpl->Final(aMessage);
1.690 +#endif
1.691 + }
1.692 +
1.693 +TPtrC8 CHMACShim::Final()
1.694 + {
1.695 + TPtrC8 ptr(KNullDesC8());
1.696 +#ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT
1.697 + TPtrC8 macPtr(KNullDesC8());
1.698 + // The error is ignored as the legacy code methods are non-leaving and they call
1.699 + // the new MAC interfaces which uses leaving methods for processing MAC value.
1.700 + // This call always call the non-leaving legacy method.
1.701 + TRAP_IGNORE(macPtr.Set(iMacImpl->FinalL(ptr)));
1.702 + return macPtr;
1.703 +#else
1.704 + return iMacImpl->Final(ptr);
1.705 +#endif
1.706 + }
1.707 +
1.708 +void CHMACShim::Reset()
1.709 + {
1.710 + iMacImpl->Reset();
1.711 + }
1.712 +
1.713 +TPtrC8 CHMACShim::Hash(const TDesC8& aMessage)
1.714 + {
1.715 +#ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT
1.716 + TPtrC8 macPtr(KNullDesC8());
1.717 + // The error is ignored as the legacy code methods are non-leaving and they call
1.718 + // the new MAC interfaces which uses leaving methods for processing MAC value.
1.719 + // This call always call the non-leaving legacy method.
1.720 + TRAP_IGNORE(macPtr.Set(iMacImpl->MacL(aMessage)));
1.721 + return macPtr;
1.722 +#else
1.723 + return iMacImpl->Hash(aMessage);
1.724 +#endif
1.725 + }
1.726 +
1.727 +CMessageDigest* CHMACShim::ReplicateL()
1.728 + {
1.729 + CHMACShim* copy=new(ELeave) CHMACShim();
1.730 + CleanupStack::PushL(copy);
1.731 + copy->iMacImpl=iMacImpl->ReplicateL();
1.732 + CleanupStack::Pop(copy);
1.733 + return copy;
1.734 + }
1.735 +
1.736 +CMessageDigest* CHMACShim::CopyL()
1.737 + {
1.738 + CHMACShim* copy=new(ELeave) CHMACShim();
1.739 + CleanupStack::PushL(copy);
1.740 + copy->iMacImpl=iMacImpl->CopyL();
1.741 + CleanupStack::Pop(copy);
1.742 + return copy;
1.743 + }
1.744 +
1.745 +//
1.746 +// Implemetation of MD4 shim
1.747 +//
1.748 +CMD4Shim* CMD4Shim::NewL()
1.749 + {
1.750 + CMD4Shim* self=CMD4Shim::NewLC();
1.751 + CleanupStack::Pop();
1.752 + return self;
1.753 + }
1.754 +
1.755 +CMD4Shim* CMD4Shim::NewLC()
1.756 + {
1.757 + CMD4Shim* self=new(ELeave) CMD4Shim();
1.758 + CleanupStack::PushL(self);
1.759 + self->ConstructL();
1.760 + return self;
1.761 + }
1.762 +
1.763 +CMD4Shim::CMD4Shim()
1.764 + {
1.765 + }
1.766 +
1.767 +TInt CMD4Shim::Extension_(TUint aExtensionId, TAny*& a0, TAny* /*a1*/)
1.768 + {
1.769 + TInt ret(KErrNotSupported);
1.770 +
1.771 + if (KHashInterfaceUid.iUid==aExtensionId && iHashImpl)
1.772 + {
1.773 + a0=iHashImpl;
1.774 + ret=KErrNone;
1.775 + }
1.776 +
1.777 + return ret;
1.778 + }
1.779 +
1.780 +CMD4Shim::~CMD4Shim()
1.781 + {
1.782 + delete iHashImpl;
1.783 + }
1.784 +
1.785 +
1.786 +void CMD4Shim::ConstructL()
1.787 + {
1.788 + CHashFactory::CreateHashL(iHashImpl,KMd4Uid,KHashModeUid,NULL,NULL);
1.789 + }
1.790 +
1.791 +CMessageDigest* CMD4Shim::CopyL()
1.792 + {
1.793 + CMD4Shim* copy=new(ELeave) CMD4Shim();
1.794 + CleanupStack::PushL(copy);
1.795 + copy->iHashImpl=iHashImpl->CopyL();
1.796 + CleanupStack::Pop();
1.797 + return copy;
1.798 + }
1.799 +
1.800 +CMessageDigest* CMD4Shim::ReplicateL()
1.801 + {
1.802 + CMD4Shim* copy=new(ELeave) CMD4Shim();
1.803 + CleanupStack::PushL(copy);
1.804 + copy->iHashImpl=iHashImpl->ReplicateL();
1.805 + CleanupStack::Pop();
1.806 + return copy;
1.807 + }
1.808 +
1.809 +TInt CMD4Shim::BlockSize()
1.810 + {
1.811 + const TCharacteristics* ptr(NULL);
1.812 + TRAPD(err, iHashImpl->GetCharacteristicsL(ptr);)
1.813 + if (err)
1.814 + {
1.815 + return ((err>0)? KErrGeneral : err);
1.816 + }
1.817 + const THashCharacteristics* hashPtr=static_cast<const THashCharacteristics*>(ptr);
1.818 + return hashPtr->iBlockSize/8;
1.819 + }
1.820 +
1.821 +TInt CMD4Shim::HashSize()
1.822 + {
1.823 + const TCharacteristics* ptr(NULL);
1.824 + TRAPD(err, iHashImpl->GetCharacteristicsL(ptr);)
1.825 + if (err)
1.826 + {
1.827 + return ((err>0)? KErrGeneral : err);
1.828 + }
1.829 + const THashCharacteristics* hashPtr=static_cast<const THashCharacteristics*>(ptr);
1.830 + return hashPtr->iOutputSize/8;
1.831 + }
1.832 +
1.833 +void CMD4Shim::Update(const TDesC8& aMessage)
1.834 + {
1.835 + iHashImpl->Update(aMessage);
1.836 + }
1.837 +
1.838 +TPtrC8 CMD4Shim::Final(const TDesC8& aMessage)
1.839 + {
1.840 + return iHashImpl->Final(aMessage);
1.841 + }
1.842 +
1.843 +TPtrC8 CMD4Shim::Final()
1.844 + {
1.845 + TPtrC8 ptr(KNullDesC8());
1.846 + return iHashImpl->Final(ptr);
1.847 + }
1.848 +
1.849 +void CMD4Shim::Reset()
1.850 + {
1.851 + iHashImpl->Reset();
1.852 + }
1.853 +
1.854 +
1.855 +TPtrC8 CMD4Shim::Hash(const TDesC8& aMessage)
1.856 + {
1.857 + return iHashImpl->Hash(aMessage);
1.858 + }
1.859 +