1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/security/crypto/weakcryptospi/source/symmetric/rijndaelshim.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,187 @@
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 +#include "rijndaelshim.h"
1.23 +
1.24 +#include <cryptospi/cryptosymmetriccipherapi.h>
1.25 +#include <cryptospi/cryptospidef.h>
1.26 +#include <cryptospi/plugincharacteristics.h>
1.27 +#include <cryptospi/keys.h>
1.28 +#include <cryptostrength.h>
1.29 +
1.30 +#include "../common/inlines.h"
1.31 +
1.32 +using namespace CryptoSpi;
1.33 +
1.34 +// CAESEncryptorShim ////////////////////////////////////////////////////////
1.35 +CAESEncryptorShim* CAESEncryptorShim::NewL(const TDesC8& aKey)
1.36 + {
1.37 + CAESEncryptorShim* self = CAESEncryptorShim::NewLC(aKey);
1.38 + CleanupStack::Pop(self);
1.39 + return self;
1.40 + }
1.41 +
1.42 +CAESEncryptorShim* CAESEncryptorShim::NewLC(const TDesC8& aKey)
1.43 + {
1.44 + CAESEncryptorShim* self = new (ELeave) CAESEncryptorShim();
1.45 + CleanupStack::PushL(self);
1.46 + self->ConstructL(aKey);
1.47 + TCrypto::IsSymmetricWeakEnoughL(BytesToBits(aKey.Size()));
1.48 + return self;
1.49 + }
1.50 +
1.51 +CAESEncryptorShim::CAESEncryptorShim()
1.52 + {
1.53 + }
1.54 +
1.55 +CAESEncryptorShim::~CAESEncryptorShim()
1.56 + {
1.57 + delete iSymmetricCipherImpl;
1.58 + delete iKey;
1.59 + }
1.60 +
1.61 +void CAESEncryptorShim::ConstructL(const TDesC8& aKey)
1.62 + {
1.63 + TKeyProperty keyProperty = {KAesUid, KNullUid, KSymmetricKeyUid, KNonEmbeddedKeyUid};
1.64 + CCryptoParams* keyParam =CCryptoParams::NewLC();
1.65 + keyParam->AddL(aKey, KSymmetricKeyParameterUid);
1.66 + iKey=CKey::NewL(keyProperty, *keyParam);
1.67 + CleanupStack::PopAndDestroy(keyParam);
1.68 + CSymmetricCipherFactory::CreateSymmetricCipherL(
1.69 + iSymmetricCipherImpl,
1.70 + KAesUid,
1.71 + *iKey,
1.72 + KCryptoModeEncryptUid,
1.73 + KOperationModeECBUid,
1.74 + KPaddingModeNoneUid,
1.75 + NULL);
1.76 + }
1.77 +
1.78 +TInt CAESEncryptorShim::BlockSize() const
1.79 + {
1.80 + return BitsToBytes(iSymmetricCipherImpl->BlockSize());
1.81 + }
1.82 +
1.83 +TInt CAESEncryptorShim::KeySize() const
1.84 + {
1.85 + return iSymmetricCipherImpl->KeySize();
1.86 + }
1.87 +
1.88 +void CAESEncryptorShim::Transform(TDes8& aBlock)
1.89 + {
1.90 + iOutputBlock.Zero();
1.91 + TRAP_IGNORE(iSymmetricCipherImpl->ProcessL(aBlock, iOutputBlock);)
1.92 + aBlock = iOutputBlock;
1.93 + }
1.94 +
1.95 +void CAESEncryptorShim::Reset()
1.96 + {
1.97 + iSymmetricCipherImpl->Reset();
1.98 + }
1.99 +
1.100 +TInt CAESEncryptorShim::Extension_(TUint aExtensionId, TAny*& a0, TAny* /*a1*/)
1.101 + {
1.102 + TInt ret(KErrExtensionNotSupported);
1.103 +
1.104 + if (CryptoSpi::KSymmetricCipherInterface == aExtensionId && iSymmetricCipherImpl)
1.105 + {
1.106 + a0=iSymmetricCipherImpl;
1.107 + ret=KErrNone;
1.108 + }
1.109 + return ret;
1.110 + }
1.111 +
1.112 +// CAESDecryptorShim ////////////////////////////////////////////////////////
1.113 +
1.114 +CAESDecryptorShim* CAESDecryptorShim::NewL(const TDesC8& aKey)
1.115 + {
1.116 + CAESDecryptorShim* self = CAESDecryptorShim::NewLC(aKey);
1.117 + CleanupStack::Pop(self);
1.118 + return self;
1.119 + }
1.120 +
1.121 +
1.122 +CAESDecryptorShim* CAESDecryptorShim::NewLC(const TDesC8& aKey)
1.123 + {
1.124 + CAESDecryptorShim* self = new (ELeave) CAESDecryptorShim();
1.125 + CleanupStack::PushL(self);
1.126 + self->ConstructL(aKey);
1.127 + TCrypto::IsSymmetricWeakEnoughL(BytesToBits(aKey.Size()));
1.128 + return self;
1.129 + }
1.130 +
1.131 +CAESDecryptorShim::CAESDecryptorShim()
1.132 + {
1.133 + }
1.134 +
1.135 +CAESDecryptorShim::~CAESDecryptorShim()
1.136 + {
1.137 + delete iSymmetricCipherImpl;
1.138 + delete iKey;
1.139 + }
1.140 +
1.141 +void CAESDecryptorShim::ConstructL(const TDesC8& aKey)
1.142 + {
1.143 + TKeyProperty keyProperty = {KAesUid, KNullUid, KSymmetricKeyUid, KNonEmbeddedKeyUid};
1.144 + CCryptoParams* keyParam =CCryptoParams::NewLC();
1.145 + keyParam->AddL(aKey, KSymmetricKeyParameterUid);
1.146 + iKey=CKey::NewL(keyProperty, *keyParam);
1.147 + CleanupStack::PopAndDestroy(keyParam);
1.148 + CSymmetricCipherFactory::CreateSymmetricCipherL(
1.149 + iSymmetricCipherImpl,
1.150 + KAesUid,
1.151 + *iKey,
1.152 + KCryptoModeDecryptUid,
1.153 + KOperationModeECBUid,
1.154 + KPaddingModeNoneUid,
1.155 + NULL);
1.156 + }
1.157 +
1.158 +TInt CAESDecryptorShim::BlockSize() const
1.159 + {
1.160 + return BitsToBytes(iSymmetricCipherImpl->BlockSize());
1.161 + }
1.162 +
1.163 +TInt CAESDecryptorShim::KeySize() const
1.164 + {
1.165 + return iSymmetricCipherImpl->KeySize();
1.166 + }
1.167 +
1.168 +void CAESDecryptorShim::Transform(TDes8& aBlock)
1.169 + {
1.170 + iOutputBlock.Zero();
1.171 + TRAP_IGNORE(iSymmetricCipherImpl->ProcessL(aBlock, iOutputBlock);)
1.172 + aBlock = iOutputBlock;
1.173 + }
1.174 +
1.175 +void CAESDecryptorShim::Reset()
1.176 + {
1.177 + iSymmetricCipherImpl->Reset();
1.178 + }
1.179 +
1.180 +TInt CAESDecryptorShim::Extension_(TUint aExtensionId, TAny*& a0, TAny* /*a1*/)
1.181 + {
1.182 + TInt ret(KErrExtensionNotSupported);
1.183 +
1.184 + if (CryptoSpi::KSymmetricCipherInterface == aExtensionId && iSymmetricCipherImpl)
1.185 + {
1.186 + a0=iSymmetricCipherImpl;
1.187 + ret=KErrNone;
1.188 + }
1.189 + return ret;
1.190 + }