os/security/cryptoplugins/cryptospiplugins/test/h4drv/crypto_h4_plugin/rijndaelimpl.cpp
First public contribution.
2 * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
24 #include "rijndaelimpl.h"
26 #include "pluginconfig.h"
28 using namespace HwCrypto;
30 const TUint KAESKeyBytes128 = 16;
31 const TUint KAESKeyBytes192 = 24;
32 const TUint KAESKeyBytes256 = 32;
33 const TUint KAESBlockBytes = 16;
35 _LIT(KLddFileName,"cryptoldd.ldd");
36 _LIT(KPddFileName,"crypto.h4.pdd");
40 CH4RijndaelImpl::CH4RijndaelImpl(
44 CH4CipherImpl(KAESBlockBytes, aCryptoMode, aOperationMode, aPadding)
48 CH4RijndaelImpl* CH4RijndaelImpl::NewL(const CKey& aKey, TUid aCryptoMode, TUid aOperationMode, TUid aPadding)
50 CH4RijndaelImpl* self = CH4RijndaelImpl::NewLC(aKey, aCryptoMode, aOperationMode, aPadding);
51 CleanupStack::Pop(self);
55 CH4RijndaelImpl* CH4RijndaelImpl::NewLC(const CKey& aKey, TUid aCryptoMode, TUid aOperationMode, TUid aPadding)
57 CH4RijndaelImpl* self = new(ELeave) CH4RijndaelImpl(aCryptoMode, aOperationMode, aPadding);
58 CleanupStack::PushL(self);
59 self->ConstructL(aKey);
63 CH4RijndaelImpl::~CH4RijndaelImpl()
68 void CH4RijndaelImpl::ConstructL(const CKey& aKey)
71 TInt r = User::LoadPhysicalDevice(KPddFileName);
72 if((r != KErrNone) && (r != KErrAlreadyExists)) User::Leave(r);
75 r = User::LoadLogicalDevice(KLddFileName);
76 if((r != KErrNone) && (r != KErrAlreadyExists)) User::Leave(r);
79 CH4CipherImpl::ConstructL(aKey);
82 TUid CH4RijndaelImpl::ImplementationUid() const
84 return KCryptoPluginAesUid;
87 const CExtendedCharacteristics* CH4RijndaelImpl::GetExtendedCharacteristicsL()
89 return StaticGetExtendedCharacteristicsL();
92 CExtendedCharacteristics* CH4RijndaelImpl::StaticGetExtendedCharacteristicsL()
94 // All Symbian software plug-ins have unlimited concurrency, cannot be reserved
95 // for exclusive use and are not CERTIFIED to be standards compliant.
96 return CExtendedCharacteristics::NewL(KMaxTInt, EFalse);
100 TBool CH4RijndaelImpl::IsValidKeyLength(TInt aKeyBytes) const
104 case KAESKeyBytes128:
105 case KAESKeyBytes192:
106 case KAESKeyBytes256:
113 void CH4RijndaelImpl::DoSetupL()
116 User::LeaveIfError(iDriver.Open());
118 TBool encrypt = (iCryptoMode.iUid == KCryptoModeEncrypt);
119 RCryptoDriver::TChainingMode chainingMode = (iOperationMode.iUid == KOperationModeCBC) ? (RCryptoDriver::ECbcMode) : (RCryptoDriver::EEcbMode);
120 User::LeaveIfError(iDriver.SetAesConfig(encrypt, chainingMode, iKey->Des(), iIv));
123 void CH4RijndaelImpl::DoWriteL(const TUint8* aBuffer, TUint aNumBytes)
125 TPtrC8 ptr(aBuffer, aNumBytes);
127 TRequestStatus status;
128 iDriver.AesWrite(status, ptr);
129 User::WaitForRequest(status);
130 User::LeaveIfError(status.Int());
133 void CH4RijndaelImpl::DoReadL(TDes8 &aBuffer, TUint32 aLength)
135 TRequestStatus status;
136 iDriver.AesRead(status, aBuffer, aLength);
137 User::WaitForRequest(status);
138 User::LeaveIfError(status.Int());