Update contrib.
2 * Copyright (c) 2006-2010 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.
21 #include <cryptospi/cryptoparams.h>
22 #include <cryptospi/cryptosymmetriccipherapi.h>
23 #include <cryptospi/cryptospidef.h>
24 #include <cryptospi/plugincharacteristics.h>
25 #include <cryptospi/keys.h>
26 #include <cryptostrength.h>
28 #include "../common/inlines.h"
30 using namespace CryptoSpi;
32 // CRC2EncryptorShim ////////////////////////////////////////////////////////
33 CRC2EncryptorShim* CRC2EncryptorShim::NewL(const TDesC8& aKey, TInt aEffectiveKeyLenBits)
35 CRC2EncryptorShim* self = CRC2EncryptorShim::NewLC(aKey, aEffectiveKeyLenBits);
36 CleanupStack::Pop(self);
40 CRC2EncryptorShim* CRC2EncryptorShim::NewLC(const TDesC8& aKey, TInt aEffectiveKeyLenBits)
42 CRC2EncryptorShim* self = new (ELeave) CRC2EncryptorShim();
43 CleanupStack::PushL(self);
44 self->ConstructL(aKey, aEffectiveKeyLenBits);
45 // weak enough if either aKey or aEffectiveKeyLenBits is weak
46 TInt minKeySize = Min(aEffectiveKeyLenBits, BytesToBits(aKey.Size()));
47 TCrypto::IsSymmetricWeakEnoughL(minKeySize);
51 CRC2EncryptorShim::CRC2EncryptorShim()
55 CRC2EncryptorShim::~CRC2EncryptorShim()
57 delete iSymmetricCipherImpl;
59 delete iAlgorithmParams;
62 void CRC2EncryptorShim::ConstructL(const TDesC8& aKey, TInt aEffectiveKeyLenBits)
64 TKeyProperty keyProperty = {KRc2Uid, KNullUid, KSymmetricKeyUid, KNonEmbeddedKeyUid};
65 CCryptoParams* keyParam =CCryptoParams::NewLC();
66 keyParam->AddL(aKey, KSymmetricKeyParameterUid);
67 iKey=CKey::NewL(keyProperty, *keyParam);
68 CleanupStack::PopAndDestroy(keyParam);
70 iAlgorithmParams = CCryptoParams::NewL();
71 iAlgorithmParams->AddL(aEffectiveKeyLenBits, KRC2EffectiveKeyLenBits);
73 CSymmetricCipherFactory::CreateSymmetricCipherL(
77 KCryptoModeEncryptUid,
83 TInt CRC2EncryptorShim::BlockSize() const
85 // SPI returns block size in BITS
86 return BitsToBytes(iSymmetricCipherImpl->BlockSize());
89 TInt CRC2EncryptorShim::KeySize() const
91 return iSymmetricCipherImpl->KeySize();
94 void CRC2EncryptorShim::Transform(TDes8& aBlock)
97 TRAP_IGNORE(iSymmetricCipherImpl->ProcessL(aBlock, iOutputBlock);)
98 aBlock = iOutputBlock;
101 void CRC2EncryptorShim::Reset()
103 iSymmetricCipherImpl->Reset();
106 TInt CRC2EncryptorShim::Extension_(TUint aExtensionId, TAny*& a0, TAny* /*a1*/)
108 TInt ret(KErrExtensionNotSupported);
110 if (KSymmetricCipherInterface == aExtensionId && iSymmetricCipherImpl)
112 a0=iSymmetricCipherImpl;
118 // CRC2DecryptorShim ////////////////////////////////////////////////////////
119 CRC2DecryptorShim* CRC2DecryptorShim::NewL(const TDesC8& aKey, TInt aEffectiveKeyLenBits)
121 CRC2DecryptorShim* self = CRC2DecryptorShim::NewLC(aKey, aEffectiveKeyLenBits);
122 CleanupStack::Pop(self);
127 CRC2DecryptorShim* CRC2DecryptorShim::NewLC(const TDesC8& aKey, TInt aEffectiveKeyLenBits)
129 CRC2DecryptorShim* self = new (ELeave) CRC2DecryptorShim();
130 CleanupStack::PushL(self);
131 self->ConstructL(aKey, aEffectiveKeyLenBits);
132 // weak enough if either aKey or aEffectiveKeyLenBits is weak
133 TInt minKeySize = Min(aEffectiveKeyLenBits, BytesToBits(aKey.Size()));
134 TCrypto::IsSymmetricWeakEnoughL(minKeySize);
138 CRC2DecryptorShim::CRC2DecryptorShim()
142 CRC2DecryptorShim::~CRC2DecryptorShim()
144 delete iSymmetricCipherImpl;
146 delete iAlgorithmParams;
150 void CRC2DecryptorShim::ConstructL(const TDesC8& aKey, TInt aEffectiveKeyLenBits)
152 TKeyProperty keyProperty = {KRc2Uid, KNullUid, KSymmetricKeyUid, KNonEmbeddedKeyUid};
153 CCryptoParams* keyParam =CCryptoParams::NewLC();
154 keyParam->AddL(aKey, KSymmetricKeyParameterUid);
155 iKey=CKey::NewL(keyProperty, *keyParam);
156 CleanupStack::PopAndDestroy(keyParam);
158 iAlgorithmParams = CCryptoParams::NewL();
159 iAlgorithmParams->AddL(aEffectiveKeyLenBits, KRC2EffectiveKeyLenBits);
161 CSymmetricCipherFactory::CreateSymmetricCipherL(
162 iSymmetricCipherImpl,
165 KCryptoModeDecryptUid,
166 KOperationModeECBUid,
171 TInt CRC2DecryptorShim::BlockSize() const
173 // SPI returns block size in BITS
174 return BitsToBytes(iSymmetricCipherImpl->BlockSize());
177 TInt CRC2DecryptorShim::KeySize() const
179 return iSymmetricCipherImpl->KeySize();
182 void CRC2DecryptorShim::Transform(TDes8& aBlock)
185 TRAP_IGNORE(iSymmetricCipherImpl->ProcessL(aBlock, iOutputBlock);)
186 aBlock = iOutputBlock;
189 void CRC2DecryptorShim::Reset()
191 iSymmetricCipherImpl->Reset();
194 TInt CRC2DecryptorShim::Extension_(TUint aExtensionId, TAny*& a0, TAny* /*a1*/)
196 TInt ret(KErrExtensionNotSupported);
198 if (CryptoSpi::KSymmetricCipherInterface == aExtensionId && iSymmetricCipherImpl)
200 a0=iSymmetricCipherImpl;