First public contribution.
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/cryptosymmetriccipherapi.h>
22 #include <cryptospi/cryptospidef.h>
23 #include <cryptospi/plugincharacteristics.h>
24 #include <cryptospi/keys.h>
25 #include <cryptostrength.h>
26 #include "../common/inlines.h"
28 using namespace CryptoSpi;
30 // C3DESEncryptorShim ////////////////////////////////////////////////////////
31 C3DESEncryptorShim* C3DESEncryptorShim::NewL(const TDesC8& aKey)
33 C3DESEncryptorShim* self = C3DESEncryptorShim::NewLC(aKey);
34 CleanupStack::Pop(self);
38 C3DESEncryptorShim* C3DESEncryptorShim::NewLC(const TDesC8& aKey)
40 C3DESEncryptorShim* self = new (ELeave) C3DESEncryptorShim();
41 CleanupStack::PushL(self);
42 self->ConstructL(aKey);
43 // DES only used 7 bits out of every key byte
44 TCrypto::IsSymmetricWeakEnoughL(BytesToBits(aKey.Size()) - aKey.Size());
48 C3DESEncryptorShim::C3DESEncryptorShim()
52 C3DESEncryptorShim::~C3DESEncryptorShim()
54 delete iSymmetricCipherImpl;
58 void C3DESEncryptorShim::ConstructL(const TDesC8& aKey)
60 TKeyProperty keyProperty = {K3DesUid, KNullUid, KSymmetricKey, KNonEmbeddedKeyUid};
61 CCryptoParams* keyParam =CCryptoParams::NewLC();
62 keyParam->AddL(aKey, KSymmetricKeyParameterUid);
63 iKey=CKey::NewL(keyProperty, *keyParam);
64 CleanupStack::PopAndDestroy(keyParam);
66 CSymmetricCipherFactory::CreateSymmetricCipherL(
70 KCryptoModeEncryptUid,
76 TInt C3DESEncryptorShim::BlockSize() const
78 // SPI returns block size in BITS
79 return iSymmetricCipherImpl->BlockSize() >> 3;
82 TInt C3DESEncryptorShim::KeySize() const
84 return iSymmetricCipherImpl->KeySize();
87 void C3DESEncryptorShim::Transform(TDes8& aBlock)
90 TRAP_IGNORE(iSymmetricCipherImpl->ProcessL(aBlock, iOutputBlock);)
91 aBlock = iOutputBlock;
94 void C3DESEncryptorShim::Reset()
96 iSymmetricCipherImpl->Reset();
99 TInt C3DESEncryptorShim::Extension_(TUint aExtensionId, TAny*& a0, TAny* /*a1*/)
101 TInt ret(KErrExtensionNotSupported);
103 if (CryptoSpi::KSymmetricCipherInterface == aExtensionId && iSymmetricCipherImpl)
105 a0=iSymmetricCipherImpl;
111 // C3DESDecryptorShim ////////////////////////////////////////////////////////
112 C3DESDecryptorShim* C3DESDecryptorShim::NewL(const TDesC8& aKey)
114 C3DESDecryptorShim* self = C3DESDecryptorShim::NewLC(aKey);
115 CleanupStack::Pop(self);
120 C3DESDecryptorShim* C3DESDecryptorShim::NewLC(const TDesC8& aKey)
122 C3DESDecryptorShim* self = new (ELeave) C3DESDecryptorShim();
123 CleanupStack::PushL(self);
124 self->ConstructL(aKey);
125 // DES only used 7 bits out of every key byte
126 TCrypto::IsSymmetricWeakEnoughL(BytesToBits(aKey.Size()) - aKey.Size());
130 C3DESDecryptorShim::C3DESDecryptorShim()
134 C3DESDecryptorShim::~C3DESDecryptorShim()
136 delete iSymmetricCipherImpl;
141 void C3DESDecryptorShim::ConstructL(const TDesC8& aKey)
143 TKeyProperty keyProperty = {K3DesUid, KNullUid, KSymmetricKey, KNonEmbeddedKeyUid};
144 CCryptoParams* keyParam =CCryptoParams::NewLC();
145 keyParam->AddL(aKey, KSymmetricKeyParameterUid);
146 iKey=CKey::NewL(keyProperty, *keyParam);
147 CleanupStack::PopAndDestroy(keyParam);
148 CSymmetricCipherFactory::CreateSymmetricCipherL(
149 iSymmetricCipherImpl,
152 KCryptoModeDecryptUid,
153 KOperationModeECBUid,
158 TInt C3DESDecryptorShim::BlockSize() const
160 // SPI returns block size in BITS
161 return BitsToBytes(iSymmetricCipherImpl->BlockSize());
164 TInt C3DESDecryptorShim::KeySize() const
166 return iSymmetricCipherImpl->KeySize();
169 void C3DESDecryptorShim::Transform(TDes8& aBlock)
172 TRAP_IGNORE(iSymmetricCipherImpl->ProcessL(aBlock, iOutputBlock);)
173 aBlock = iOutputBlock;
176 void C3DESDecryptorShim::Reset()
178 iSymmetricCipherImpl->Reset();
181 TInt C3DESDecryptorShim::Extension_(TUint aExtensionId, TAny*& a0, TAny* /*a1*/)
183 TInt ret(KErrExtensionNotSupported);
185 if (CryptoSpi::KSymmetricCipherInterface == aExtensionId && iSymmetricCipherImpl)
187 a0=iSymmetricCipherImpl;