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/cryptosymmetriccipherapi.h>
22 #include <cryptospi/cryptospidef.h>
23 #include <cryptospi/plugincharacteristics.h>
24 #include <cryptospi/keys.h>
25 #include <cryptostrength.h>
27 #include "../common/inlines.h"
29 using namespace CryptoSpi;
31 // CDESEncryptorShim ////////////////////////////////////////////////////////
32 CDESEncryptorShim* CDESEncryptorShim::NewL(const TDesC8& aKey)
34 CDESEncryptorShim* self = CDESEncryptorShim::NewLC(aKey);
35 CleanupStack::Pop(self);
39 CDESEncryptorShim* CDESEncryptorShim::NewLC(const TDesC8& aKey)
41 CDESEncryptorShim* self = new (ELeave) CDESEncryptorShim();
42 CleanupStack::PushL(self);
43 self->ConstructL(aKey);
44 // DES only used 7 bits out of every key byte
45 TCrypto::IsSymmetricWeakEnoughL(BytesToBits(aKey.Size()) - aKey.Size());
49 CDESEncryptorShim::CDESEncryptorShim()
53 CDESEncryptorShim::~CDESEncryptorShim()
55 delete iSymmetricCipherImpl;
59 void CDESEncryptorShim::ConstructL(const TDesC8& aKey)
61 TKeyProperty keyProperty = {KDesUid, KNullUid, KSymmetricKey, KNonEmbeddedKeyUid};
62 CCryptoParams* keyParam =CCryptoParams::NewLC();
63 keyParam->AddL(aKey, KSymmetricKeyParameterUid);
64 iKey=CKey::NewL(keyProperty, *keyParam);
65 CleanupStack::PopAndDestroy(keyParam);
66 CSymmetricCipherFactory::CreateSymmetricCipherL(
70 KCryptoModeEncryptUid,
76 TInt CDESEncryptorShim::BlockSize() const
78 // SPI returns block size in BITS
79 return BitsToBytes(iSymmetricCipherImpl->BlockSize());
82 TInt CDESEncryptorShim::KeySize() const
84 return iSymmetricCipherImpl->KeySize();
87 void CDESEncryptorShim::Transform(TDes8& aBlock)
90 TRAP_IGNORE(iSymmetricCipherImpl->ProcessL(aBlock, iOutputBlock);)
91 aBlock = iOutputBlock;
94 void CDESEncryptorShim::Reset()
96 iSymmetricCipherImpl->Reset();
99 TInt CDESEncryptorShim::Extension_(TUint aExtensionId, TAny*& a0, TAny* /*a1*/)
101 TInt ret(KErrNotSupported);
103 if (CryptoSpi::KSymmetricCipherInterface == aExtensionId && iSymmetricCipherImpl)
105 a0=iSymmetricCipherImpl;
111 // CDESDecryptorShim ////////////////////////////////////////////////////////
112 CDESDecryptorShim* CDESDecryptorShim::NewL(const TDesC8& aKey)
114 CDESDecryptorShim* self = CDESDecryptorShim::NewLC(aKey);
115 CleanupStack::Pop(self);
120 CDESDecryptorShim* CDESDecryptorShim::NewLC(const TDesC8& aKey)
122 CDESDecryptorShim* self = new (ELeave) CDESDecryptorShim();
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 CDESDecryptorShim::CDESDecryptorShim()
134 CDESDecryptorShim::~CDESDecryptorShim()
136 delete iSymmetricCipherImpl;
141 void CDESDecryptorShim::ConstructL(const TDesC8& aKey)
143 TKeyProperty keyProperty = {KDesUid, 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 CDESDecryptorShim::BlockSize() const
160 // SPI returns block size in BITS
161 return BitsToBytes(iSymmetricCipherImpl->BlockSize());
164 TInt CDESDecryptorShim::KeySize() const
166 return iSymmetricCipherImpl->KeySize();
169 void CDESDecryptorShim::Transform(TDes8& aBlock)
172 TRAP_IGNORE(iSymmetricCipherImpl->ProcessL(aBlock, iOutputBlock);)
173 aBlock = iOutputBlock;
176 void CDESDecryptorShim::Reset()
178 iSymmetricCipherImpl->Reset();
181 TInt CDESDecryptorShim::Extension_(TUint aExtensionId, TAny*& a0, TAny* /*a1*/)
183 TInt ret(KErrNotSupported);
185 if (CryptoSpi::KSymmetricCipherInterface == aExtensionId && iSymmetricCipherImpl)
187 a0=iSymmetricCipherImpl;