os/security/cryptoplugins/cryptospiplugins/test/h4drv/crypto_h4_plugin/rijndaelimpl.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/security/cryptoplugins/cryptospiplugins/test/h4drv/crypto_h4_plugin/rijndaelimpl.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,143 @@
1.4 +/*
1.5 +* Copyright (c) 2007-2009 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 +*
1.19 +*/
1.20 +
1.21 +
1.22 +/**
1.23 + @file
1.24 + @internalComponent
1.25 + @released
1.26 +*/
1.27 +#include "rijndaelimpl.h"
1.28 +#include "keys.h"
1.29 +#include "pluginconfig.h"
1.30 +
1.31 +using namespace HwCrypto;
1.32 +
1.33 +const TUint KAESKeyBytes128 = 16;
1.34 +const TUint KAESKeyBytes192 = 24;
1.35 +const TUint KAESKeyBytes256 = 32;
1.36 +const TUint KAESBlockBytes = 16;
1.37 +
1.38 +_LIT(KLddFileName,"cryptoldd.ldd");
1.39 +_LIT(KPddFileName,"crypto.h4.pdd");
1.40 +
1.41 +
1.42 +/* CRijndaelmpl*/
1.43 +CH4RijndaelImpl::CH4RijndaelImpl(
1.44 + TUid aCryptoMode,
1.45 + TUid aOperationMode,
1.46 + TUid aPadding) :
1.47 + CH4CipherImpl(KAESBlockBytes, aCryptoMode, aOperationMode, aPadding)
1.48 + {
1.49 + }
1.50 +
1.51 +CH4RijndaelImpl* CH4RijndaelImpl::NewL(const CKey& aKey, TUid aCryptoMode, TUid aOperationMode, TUid aPadding)
1.52 + {
1.53 + CH4RijndaelImpl* self = CH4RijndaelImpl::NewLC(aKey, aCryptoMode, aOperationMode, aPadding);
1.54 + CleanupStack::Pop(self);
1.55 + return self;
1.56 + }
1.57 +
1.58 +CH4RijndaelImpl* CH4RijndaelImpl::NewLC(const CKey& aKey, TUid aCryptoMode, TUid aOperationMode, TUid aPadding)
1.59 + {
1.60 + CH4RijndaelImpl* self = new(ELeave) CH4RijndaelImpl(aCryptoMode, aOperationMode, aPadding);
1.61 + CleanupStack::PushL(self);
1.62 + self->ConstructL(aKey);
1.63 + return self;
1.64 + }
1.65 +
1.66 +CH4RijndaelImpl::~CH4RijndaelImpl()
1.67 + {
1.68 + iDriver.Close();
1.69 + }
1.70 +
1.71 +void CH4RijndaelImpl::ConstructL(const CKey& aKey)
1.72 + {
1.73 + // Load PDD
1.74 + TInt r = User::LoadPhysicalDevice(KPddFileName);
1.75 + if((r != KErrNone) && (r != KErrAlreadyExists)) User::Leave(r);
1.76 +
1.77 + // Load LDD
1.78 + r = User::LoadLogicalDevice(KLddFileName);
1.79 + if((r != KErrNone) && (r != KErrAlreadyExists)) User::Leave(r);
1.80 +
1.81 +
1.82 + CH4CipherImpl::ConstructL(aKey);
1.83 + }
1.84 +
1.85 +TUid CH4RijndaelImpl::ImplementationUid() const
1.86 + {
1.87 + return KCryptoPluginAesUid;
1.88 + }
1.89 +
1.90 +const CExtendedCharacteristics* CH4RijndaelImpl::GetExtendedCharacteristicsL()
1.91 + {
1.92 + return StaticGetExtendedCharacteristicsL();
1.93 + }
1.94 +
1.95 +CExtendedCharacteristics* CH4RijndaelImpl::StaticGetExtendedCharacteristicsL()
1.96 + {
1.97 + // All Symbian software plug-ins have unlimited concurrency, cannot be reserved
1.98 + // for exclusive use and are not CERTIFIED to be standards compliant.
1.99 + return CExtendedCharacteristics::NewL(KMaxTInt, EFalse);
1.100 + }
1.101 +
1.102 +
1.103 +TBool CH4RijndaelImpl::IsValidKeyLength(TInt aKeyBytes) const
1.104 + {
1.105 + switch(aKeyBytes)
1.106 + {
1.107 + case KAESKeyBytes128:
1.108 + case KAESKeyBytes192:
1.109 + case KAESKeyBytes256:
1.110 + return ETrue;
1.111 + default:
1.112 + return EFalse;
1.113 + }
1.114 + }
1.115 +
1.116 +void CH4RijndaelImpl::DoSetupL()
1.117 + {
1.118 + iDriver.Close();
1.119 + User::LeaveIfError(iDriver.Open());
1.120 +
1.121 + TBool encrypt = (iCryptoMode.iUid == KCryptoModeEncrypt);
1.122 + RCryptoDriver::TChainingMode chainingMode = (iOperationMode.iUid == KOperationModeCBC) ? (RCryptoDriver::ECbcMode) : (RCryptoDriver::EEcbMode);
1.123 + User::LeaveIfError(iDriver.SetAesConfig(encrypt, chainingMode, iKey->Des(), iIv));
1.124 + }
1.125 +
1.126 +void CH4RijndaelImpl::DoWriteL(const TUint8* aBuffer, TUint aNumBytes)
1.127 + {
1.128 + TPtrC8 ptr(aBuffer, aNumBytes);
1.129 +
1.130 + TRequestStatus status;
1.131 + iDriver.AesWrite(status, ptr);
1.132 + User::WaitForRequest(status);
1.133 + User::LeaveIfError(status.Int());
1.134 + }
1.135 +
1.136 +void CH4RijndaelImpl::DoReadL(TDes8 &aBuffer, TUint32 aLength)
1.137 + {
1.138 + TRequestStatus status;
1.139 + iDriver.AesRead(status, aBuffer, aLength);
1.140 + User::WaitForRequest(status);
1.141 + User::LeaveIfError(status.Int());
1.142 + }
1.143 +
1.144 +
1.145 +
1.146 +// End of file