sl@0: /* sl@0: * Copyright (c) 2006-2010 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: #include "arc4shim.h" sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include "../common/inlines.h" sl@0: #include sl@0: sl@0: using namespace CryptoSpi; sl@0: sl@0: CArc4Shim* CArc4Shim::NewL(const TDesC8& aKey, TUint aDiscardBytes) sl@0: { sl@0: CArc4Shim* self = NewLC(aKey, aDiscardBytes); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: CArc4Shim* CArc4Shim::NewLC(const TDesC8& aKey, TUint aDiscardBytes) sl@0: { sl@0: CArc4Shim* self = new (ELeave) CArc4Shim(); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(aKey, aDiscardBytes); sl@0: TCrypto::IsSymmetricWeakEnoughL(BytesToBits(aKey.Size())); sl@0: return self; sl@0: } sl@0: sl@0: void CArc4Shim::ConstructL(const TDesC8& aKey, TUint aDiscardBytes) sl@0: { sl@0: TKeyProperty keyProperty = {KArc4Uid, KNullUid, KSymmetricKey, KNonEmbeddedKeyUid}; sl@0: CCryptoParams* keyParam =CCryptoParams::NewLC(); sl@0: keyParam->AddL(aKey, KSymmetricKeyParameterUid); sl@0: iKey=CKey::NewL(keyProperty, *keyParam); sl@0: CleanupStack::PopAndDestroy(keyParam); sl@0: sl@0: iAlgorithmParams = CCryptoParams::NewL(); sl@0: iAlgorithmParams->AddL(aDiscardBytes, KARC4DiscardBytes); sl@0: sl@0: CSymmetricCipherFactory::CreateSymmetricCipherL( sl@0: iSymmetricCipherImpl, sl@0: KArc4Uid, sl@0: *iKey, sl@0: KCryptoModeNoneUid, sl@0: KOperationModeNoneUid, sl@0: KPaddingModeNoneUid, sl@0: iAlgorithmParams); sl@0: } sl@0: sl@0: CArc4Shim::~CArc4Shim() sl@0: { sl@0: delete iSymmetricCipherImpl; sl@0: delete iKey; sl@0: delete iAlgorithmParams; sl@0: } sl@0: sl@0: void CArc4Shim::Reset() sl@0: { sl@0: iSymmetricCipherImpl->Reset(); sl@0: } sl@0: sl@0: TInt CArc4Shim::BlockSize() const sl@0: { sl@0: return iSymmetricCipherImpl->BlockSize() >> 3; // Convert to bits sl@0: } sl@0: sl@0: TInt CArc4Shim::KeySize() const sl@0: { sl@0: return iSymmetricCipherImpl->KeySize(); sl@0: } sl@0: sl@0: void CArc4Shim::Process(const TDesC8& aInput, TDes8& aOutput) sl@0: { sl@0: TRAP_IGNORE(iSymmetricCipherImpl->ProcessL(aInput, aOutput);) sl@0: } sl@0: sl@0: void CArc4Shim::ProcessFinalL(const TDesC8& aInput, TDes8& aOutput) sl@0: { sl@0: iSymmetricCipherImpl->ProcessFinalL(aInput, aOutput); sl@0: } sl@0: sl@0: TInt CArc4Shim::MaxOutputLength(TInt aInputLength) const sl@0: { sl@0: return iSymmetricCipherImpl->MaxOutputLength(aInputLength); sl@0: } sl@0: sl@0: TInt CArc4Shim::MaxFinalOutputLength(TInt aInputLength) const sl@0: { sl@0: return iSymmetricCipherImpl->MaxFinalOutputLength(aInputLength); sl@0: } sl@0: sl@0: CArc4Shim::CArc4Shim() sl@0: { sl@0: } sl@0: