sl@0: /* sl@0: * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of the License "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: sl@0: /** sl@0: @file sl@0: @internalComponent sl@0: @released sl@0: */ sl@0: #include "rijndaelimpl.h" sl@0: #include "keys.h" sl@0: #include "pluginconfig.h" sl@0: sl@0: using namespace HwCrypto; sl@0: sl@0: const TUint KAESKeyBytes128 = 16; sl@0: const TUint KAESKeyBytes192 = 24; sl@0: const TUint KAESKeyBytes256 = 32; sl@0: const TUint KAESBlockBytes = 16; sl@0: sl@0: _LIT(KLddFileName,"cryptoldd.ldd"); sl@0: _LIT(KPddFileName,"crypto.h4.pdd"); sl@0: sl@0: sl@0: /* CRijndaelmpl*/ sl@0: CH4RijndaelImpl::CH4RijndaelImpl( sl@0: TUid aCryptoMode, sl@0: TUid aOperationMode, sl@0: TUid aPadding) : sl@0: CH4CipherImpl(KAESBlockBytes, aCryptoMode, aOperationMode, aPadding) sl@0: { sl@0: } sl@0: sl@0: CH4RijndaelImpl* CH4RijndaelImpl::NewL(const CKey& aKey, TUid aCryptoMode, TUid aOperationMode, TUid aPadding) sl@0: { sl@0: CH4RijndaelImpl* self = CH4RijndaelImpl::NewLC(aKey, aCryptoMode, aOperationMode, aPadding); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: CH4RijndaelImpl* CH4RijndaelImpl::NewLC(const CKey& aKey, TUid aCryptoMode, TUid aOperationMode, TUid aPadding) sl@0: { sl@0: CH4RijndaelImpl* self = new(ELeave) CH4RijndaelImpl(aCryptoMode, aOperationMode, aPadding); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(aKey); sl@0: return self; sl@0: } sl@0: sl@0: CH4RijndaelImpl::~CH4RijndaelImpl() sl@0: { sl@0: iDriver.Close(); sl@0: } sl@0: sl@0: void CH4RijndaelImpl::ConstructL(const CKey& aKey) sl@0: { sl@0: // Load PDD sl@0: TInt r = User::LoadPhysicalDevice(KPddFileName); sl@0: if((r != KErrNone) && (r != KErrAlreadyExists)) User::Leave(r); sl@0: sl@0: // Load LDD sl@0: r = User::LoadLogicalDevice(KLddFileName); sl@0: if((r != KErrNone) && (r != KErrAlreadyExists)) User::Leave(r); sl@0: sl@0: sl@0: CH4CipherImpl::ConstructL(aKey); sl@0: } sl@0: sl@0: TUid CH4RijndaelImpl::ImplementationUid() const sl@0: { sl@0: return KCryptoPluginAesUid; sl@0: } sl@0: sl@0: const CExtendedCharacteristics* CH4RijndaelImpl::GetExtendedCharacteristicsL() sl@0: { sl@0: return StaticGetExtendedCharacteristicsL(); sl@0: } sl@0: sl@0: CExtendedCharacteristics* CH4RijndaelImpl::StaticGetExtendedCharacteristicsL() sl@0: { sl@0: // All Symbian software plug-ins have unlimited concurrency, cannot be reserved sl@0: // for exclusive use and are not CERTIFIED to be standards compliant. sl@0: return CExtendedCharacteristics::NewL(KMaxTInt, EFalse); sl@0: } sl@0: sl@0: sl@0: TBool CH4RijndaelImpl::IsValidKeyLength(TInt aKeyBytes) const sl@0: { sl@0: switch(aKeyBytes) sl@0: { sl@0: case KAESKeyBytes128: sl@0: case KAESKeyBytes192: sl@0: case KAESKeyBytes256: sl@0: return ETrue; sl@0: default: sl@0: return EFalse; sl@0: } sl@0: } sl@0: sl@0: void CH4RijndaelImpl::DoSetupL() sl@0: { sl@0: iDriver.Close(); sl@0: User::LeaveIfError(iDriver.Open()); sl@0: sl@0: TBool encrypt = (iCryptoMode.iUid == KCryptoModeEncrypt); sl@0: RCryptoDriver::TChainingMode chainingMode = (iOperationMode.iUid == KOperationModeCBC) ? (RCryptoDriver::ECbcMode) : (RCryptoDriver::EEcbMode); sl@0: User::LeaveIfError(iDriver.SetAesConfig(encrypt, chainingMode, iKey->Des(), iIv)); sl@0: } sl@0: sl@0: void CH4RijndaelImpl::DoWriteL(const TUint8* aBuffer, TUint aNumBytes) sl@0: { sl@0: TPtrC8 ptr(aBuffer, aNumBytes); sl@0: sl@0: TRequestStatus status; sl@0: iDriver.AesWrite(status, ptr); sl@0: User::WaitForRequest(status); sl@0: User::LeaveIfError(status.Int()); sl@0: } sl@0: sl@0: void CH4RijndaelImpl::DoReadL(TDes8 &aBuffer, TUint32 aLength) sl@0: { sl@0: TRequestStatus status; sl@0: iDriver.AesRead(status, aBuffer, aLength); sl@0: User::WaitForRequest(status); sl@0: User::LeaveIfError(status.Int()); sl@0: } sl@0: sl@0: sl@0: sl@0: // End of file