1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/security/crypto/weakcryptospi/source/symmetric/arc4shim.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,113 @@
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 +*
1.19 +*/
1.20 +
1.21 +
1.22 +
1.23 +#include "arc4shim.h"
1.24 +
1.25 +#include <cryptospi/cryptosymmetriccipherapi.h>
1.26 +#include <cryptospi/cryptospidef.h>
1.27 +#include <cryptospi/plugincharacteristics.h>
1.28 +#include <cryptostrength.h>
1.29 +#include "../common/inlines.h"
1.30 +#include <cryptospi/keys.h>
1.31 +
1.32 +using namespace CryptoSpi;
1.33 +
1.34 +CArc4Shim* CArc4Shim::NewL(const TDesC8& aKey, TUint aDiscardBytes)
1.35 + {
1.36 + CArc4Shim* self = NewLC(aKey, aDiscardBytes);
1.37 + CleanupStack::Pop(self);
1.38 + return self;
1.39 + }
1.40 +
1.41 +CArc4Shim* CArc4Shim::NewLC(const TDesC8& aKey, TUint aDiscardBytes)
1.42 + {
1.43 + CArc4Shim* self = new (ELeave) CArc4Shim();
1.44 + CleanupStack::PushL(self);
1.45 + self->ConstructL(aKey, aDiscardBytes);
1.46 + TCrypto::IsSymmetricWeakEnoughL(BytesToBits(aKey.Size()));
1.47 + return self;
1.48 + }
1.49 +
1.50 +void CArc4Shim::ConstructL(const TDesC8& aKey, TUint aDiscardBytes)
1.51 + {
1.52 + TKeyProperty keyProperty = {KArc4Uid, KNullUid, KSymmetricKey, KNonEmbeddedKeyUid};
1.53 + CCryptoParams* keyParam =CCryptoParams::NewLC();
1.54 + keyParam->AddL(aKey, KSymmetricKeyParameterUid);
1.55 + iKey=CKey::NewL(keyProperty, *keyParam);
1.56 + CleanupStack::PopAndDestroy(keyParam);
1.57 +
1.58 + iAlgorithmParams = CCryptoParams::NewL();
1.59 + iAlgorithmParams->AddL(aDiscardBytes, KARC4DiscardBytes);
1.60 +
1.61 + CSymmetricCipherFactory::CreateSymmetricCipherL(
1.62 + iSymmetricCipherImpl,
1.63 + KArc4Uid,
1.64 + *iKey,
1.65 + KCryptoModeNoneUid,
1.66 + KOperationModeNoneUid,
1.67 + KPaddingModeNoneUid,
1.68 + iAlgorithmParams);
1.69 + }
1.70 +
1.71 +CArc4Shim::~CArc4Shim()
1.72 + {
1.73 + delete iSymmetricCipherImpl;
1.74 + delete iKey;
1.75 + delete iAlgorithmParams;
1.76 + }
1.77 +
1.78 +void CArc4Shim::Reset()
1.79 + {
1.80 + iSymmetricCipherImpl->Reset();
1.81 + }
1.82 +
1.83 +TInt CArc4Shim::BlockSize() const
1.84 + {
1.85 + return iSymmetricCipherImpl->BlockSize() >> 3; // Convert to bits
1.86 + }
1.87 +
1.88 +TInt CArc4Shim::KeySize() const
1.89 + {
1.90 + return iSymmetricCipherImpl->KeySize();
1.91 + }
1.92 +
1.93 +void CArc4Shim::Process(const TDesC8& aInput, TDes8& aOutput)
1.94 + {
1.95 + TRAP_IGNORE(iSymmetricCipherImpl->ProcessL(aInput, aOutput);)
1.96 + }
1.97 +
1.98 +void CArc4Shim::ProcessFinalL(const TDesC8& aInput, TDes8& aOutput)
1.99 + {
1.100 + iSymmetricCipherImpl->ProcessFinalL(aInput, aOutput);
1.101 + }
1.102 +
1.103 +TInt CArc4Shim::MaxOutputLength(TInt aInputLength) const
1.104 + {
1.105 + return iSymmetricCipherImpl->MaxOutputLength(aInputLength);
1.106 + }
1.107 +
1.108 +TInt CArc4Shim::MaxFinalOutputLength(TInt aInputLength) const
1.109 + {
1.110 + return iSymmetricCipherImpl->MaxFinalOutputLength(aInputLength);
1.111 + }
1.112 +
1.113 +CArc4Shim::CArc4Shim()
1.114 + {
1.115 + }
1.116 +