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.
19 #include "rijndaelshim.h"
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 // CAESEncryptorShim ////////////////////////////////////////////////////////
32 CAESEncryptorShim* CAESEncryptorShim::NewL(const TDesC8& aKey)
34 CAESEncryptorShim* self = CAESEncryptorShim::NewLC(aKey);
35 CleanupStack::Pop(self);
39 CAESEncryptorShim* CAESEncryptorShim::NewLC(const TDesC8& aKey)
41 CAESEncryptorShim* self = new (ELeave) CAESEncryptorShim();
42 CleanupStack::PushL(self);
43 self->ConstructL(aKey);
44 TCrypto::IsSymmetricWeakEnoughL(BytesToBits(aKey.Size()));
48 CAESEncryptorShim::CAESEncryptorShim()
52 CAESEncryptorShim::~CAESEncryptorShim()
54 delete iSymmetricCipherImpl;
58 void CAESEncryptorShim::ConstructL(const TDesC8& aKey)
60 TKeyProperty keyProperty = {KAesUid, KNullUid, KSymmetricKeyUid, KNonEmbeddedKeyUid};
61 CCryptoParams* keyParam =CCryptoParams::NewLC();
62 keyParam->AddL(aKey, KSymmetricKeyParameterUid);
63 iKey=CKey::NewL(keyProperty, *keyParam);
64 CleanupStack::PopAndDestroy(keyParam);
65 CSymmetricCipherFactory::CreateSymmetricCipherL(
69 KCryptoModeEncryptUid,
75 TInt CAESEncryptorShim::BlockSize() const
77 return BitsToBytes(iSymmetricCipherImpl->BlockSize());
80 TInt CAESEncryptorShim::KeySize() const
82 return iSymmetricCipherImpl->KeySize();
85 void CAESEncryptorShim::Transform(TDes8& aBlock)
88 TRAP_IGNORE(iSymmetricCipherImpl->ProcessL(aBlock, iOutputBlock);)
89 aBlock = iOutputBlock;
92 void CAESEncryptorShim::Reset()
94 iSymmetricCipherImpl->Reset();
97 TInt CAESEncryptorShim::Extension_(TUint aExtensionId, TAny*& a0, TAny* /*a1*/)
99 TInt ret(KErrExtensionNotSupported);
101 if (CryptoSpi::KSymmetricCipherInterface == aExtensionId && iSymmetricCipherImpl)
103 a0=iSymmetricCipherImpl;
109 // CAESDecryptorShim ////////////////////////////////////////////////////////
111 CAESDecryptorShim* CAESDecryptorShim::NewL(const TDesC8& aKey)
113 CAESDecryptorShim* self = CAESDecryptorShim::NewLC(aKey);
114 CleanupStack::Pop(self);
119 CAESDecryptorShim* CAESDecryptorShim::NewLC(const TDesC8& aKey)
121 CAESDecryptorShim* self = new (ELeave) CAESDecryptorShim();
122 CleanupStack::PushL(self);
123 self->ConstructL(aKey);
124 TCrypto::IsSymmetricWeakEnoughL(BytesToBits(aKey.Size()));
128 CAESDecryptorShim::CAESDecryptorShim()
132 CAESDecryptorShim::~CAESDecryptorShim()
134 delete iSymmetricCipherImpl;
138 void CAESDecryptorShim::ConstructL(const TDesC8& aKey)
140 TKeyProperty keyProperty = {KAesUid, KNullUid, KSymmetricKeyUid, KNonEmbeddedKeyUid};
141 CCryptoParams* keyParam =CCryptoParams::NewLC();
142 keyParam->AddL(aKey, KSymmetricKeyParameterUid);
143 iKey=CKey::NewL(keyProperty, *keyParam);
144 CleanupStack::PopAndDestroy(keyParam);
145 CSymmetricCipherFactory::CreateSymmetricCipherL(
146 iSymmetricCipherImpl,
149 KCryptoModeDecryptUid,
150 KOperationModeECBUid,
155 TInt CAESDecryptorShim::BlockSize() const
157 return BitsToBytes(iSymmetricCipherImpl->BlockSize());
160 TInt CAESDecryptorShim::KeySize() const
162 return iSymmetricCipherImpl->KeySize();
165 void CAESDecryptorShim::Transform(TDes8& aBlock)
168 TRAP_IGNORE(iSymmetricCipherImpl->ProcessL(aBlock, iOutputBlock);)
169 aBlock = iOutputBlock;
172 void CAESDecryptorShim::Reset()
174 iSymmetricCipherImpl->Reset();
177 TInt CAESDecryptorShim::Extension_(TUint aExtensionId, TAny*& a0, TAny* /*a1*/)
179 TInt ret(KErrExtensionNotSupported);
181 if (CryptoSpi::KSymmetricCipherInterface == aExtensionId && iSymmetricCipherImpl)
183 a0=iSymmetricCipherImpl;