1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/security/crypto/weakcryptospi/source/symmetric/bufferedtransformationshim.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,189 @@
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 +* blocktransformationshim.cpp
1.19 +*
1.20 +*/
1.21 +
1.22 +
1.23 +#include "bufferedtransformationshim.h"
1.24 +
1.25 +#include <cryptospi/cryptospidef.h>
1.26 +#include <padding.h>
1.27 +#include <cryptospi/cryptosymmetriccipherapi.h>
1.28 +#include <cryptospi/plugincharacteristics.h>
1.29 +#include "../common/inlines.h"
1.30 +
1.31 +// CBufferedEncryptorShim
1.32 +CBufferedEncryptorShim::CBufferedEncryptorShim(CryptoSpi::CSymmetricCipher* aSymmetricCipherImpl) :
1.33 + iSymmetricCipherImpl(aSymmetricCipherImpl)
1.34 + {
1.35 + }
1.36 +
1.37 +CBufferedEncryptorShim* CBufferedEncryptorShim::NewL(CBlockTransformation* aBT, CPadding* aPadding)
1.38 + {
1.39 + CBufferedEncryptorShim* self(0);
1.40 +
1.41 + // Check whether the block transform contains an SPI plug-in
1.42 + TAny* implPtr(0);
1.43 + TInt err = aBT->GetExtension(CryptoSpi::KSymmetricCipherInterface, implPtr, NULL);
1.44 + if (err == KErrNone && implPtr)
1.45 + {
1.46 + CryptoSpi::CSymmetricCipher* impl(static_cast<CryptoSpi::CSymmetricCipher*>(implPtr));
1.47 +
1.48 + const CryptoSpi::TCharacteristics* c(0);
1.49 + impl->GetCharacteristicsL(c);
1.50 +
1.51 + const CryptoSpi::TSymmetricCipherCharacteristics* cipherCharacteristics(
1.52 + static_cast<const CryptoSpi::TSymmetricCipherCharacteristics*>(c));
1.53 +
1.54 + // See if the padding mode is recognised by CryptoSpi and if so, check
1.55 + // whether the plug-in supports that padding mode.
1.56 + TUid paddingMode;
1.57 + TAny* paddingPtr = &paddingMode;
1.58 + err = aPadding->GetExtension(CryptoSpi::KPaddingInterface, paddingPtr, 0);
1.59 + if (err == KErrNone && cipherCharacteristics->IsPaddingModeSupported(paddingMode))
1.60 + {
1.61 + impl->SetCryptoModeL(CryptoSpi::KCryptoModeEncryptUid);
1.62 + impl->SetPaddingModeL(paddingMode);
1.63 + self = new(ELeave) CBufferedEncryptorShim(impl);
1.64 + CleanupStack::PushL(self);
1.65 + self->ConstructL(aBT, aPadding);
1.66 + CleanupStack::Pop(self);
1.67 + }
1.68 + }
1.69 + return self;
1.70 + }
1.71 +
1.72 +void CBufferedEncryptorShim::ConstructL(CBlockTransformation* aBT, CPadding* aPadding)
1.73 + {
1.74 + CBufferedEncryptor::ConstructL(aBT, aPadding);
1.75 + }
1.76 +
1.77 +void CBufferedEncryptorShim::Process(const TDesC8& aInput, TDes8& aOutput)
1.78 + {
1.79 + TRAP_IGNORE(iSymmetricCipherImpl->ProcessL(aInput, aOutput);)
1.80 + }
1.81 +
1.82 +TInt CBufferedEncryptorShim::MaxOutputLength(TInt aInputLength) const
1.83 + {
1.84 + return iSymmetricCipherImpl->MaxOutputLength(aInputLength);
1.85 + }
1.86 +
1.87 +void CBufferedEncryptorShim::Reset()
1.88 + {
1.89 + iSymmetricCipherImpl->Reset();
1.90 + }
1.91 +
1.92 +TInt CBufferedEncryptorShim::BlockSize() const
1.93 + {
1.94 + return BitsToBytes(iSymmetricCipherImpl->BlockSize());
1.95 + }
1.96 +
1.97 +TInt CBufferedEncryptorShim::KeySize() const
1.98 + {
1.99 + return iSymmetricCipherImpl->KeySize();
1.100 + }
1.101 +
1.102 +void CBufferedEncryptorShim::ProcessFinalL(const TDesC8& aInput, TDes8& aOutput)
1.103 + {
1.104 + iSymmetricCipherImpl->ProcessFinalL(aInput, aOutput);
1.105 + }
1.106 +
1.107 +TInt CBufferedEncryptorShim::MaxFinalOutputLength(TInt aInputLength) const
1.108 + {
1.109 + return iSymmetricCipherImpl->MaxFinalOutputLength(aInputLength);
1.110 + }
1.111 +
1.112 +// CBufferedDecryptorShim
1.113 +CBufferedDecryptorShim::CBufferedDecryptorShim(CryptoSpi::CSymmetricCipher* aSymmetricCipherImpl) :
1.114 + iSymmetricCipherImpl(aSymmetricCipherImpl)
1.115 + {
1.116 + }
1.117 +
1.118 +CBufferedDecryptorShim* CBufferedDecryptorShim::NewL(CBlockTransformation* aBT, CPadding* aPadding)
1.119 + {
1.120 + CBufferedDecryptorShim* self(0);
1.121 +
1.122 + // Check whether the block transform contains an SPI plug-in
1.123 + TAny* implPtr(0);
1.124 + TInt err = aBT->GetExtension(CryptoSpi::KSymmetricCipherInterface, implPtr, NULL);
1.125 + if (err == KErrNone && implPtr)
1.126 + {
1.127 + CryptoSpi::CSymmetricCipher* impl(static_cast<CryptoSpi::CSymmetricCipher*>(implPtr));
1.128 +
1.129 + const CryptoSpi::TCharacteristics* c(0);
1.130 + impl->GetCharacteristicsL(c);
1.131 +
1.132 + const CryptoSpi::TSymmetricCipherCharacteristics* cipherCharacteristics(
1.133 + static_cast<const CryptoSpi::TSymmetricCipherCharacteristics*>(c));
1.134 +
1.135 + // See if the padding mode is recognised by CryptoSpi and if so, check
1.136 + // whether the plug-in supports that padding mode.
1.137 + TUid paddingMode;
1.138 + TAny* paddingPtr = &paddingMode;
1.139 + err = aPadding->GetExtension(CryptoSpi::KPaddingInterface, paddingPtr, 0);
1.140 + if (err == KErrNone && cipherCharacteristics->IsPaddingModeSupported(paddingMode))
1.141 + {
1.142 + impl->SetCryptoModeL(CryptoSpi::KCryptoModeDecryptUid);
1.143 + impl->SetPaddingModeL(paddingMode);
1.144 +
1.145 + self = new(ELeave) CBufferedDecryptorShim(impl);
1.146 + CleanupStack::PushL(self);
1.147 + self->ConstructL(aBT, aPadding);
1.148 + CleanupStack::Pop(self);
1.149 + }
1.150 + }
1.151 + return self;
1.152 + }
1.153 +
1.154 +void CBufferedDecryptorShim::ConstructL(CBlockTransformation* aBT, CPadding* aPadding)
1.155 + {
1.156 + CBufferedDecryptor::ConstructL(aBT, aPadding);
1.157 + }
1.158 +
1.159 +void CBufferedDecryptorShim::Process(const TDesC8& aInput, TDes8& aOutput)
1.160 + {
1.161 + TRAP_IGNORE(iSymmetricCipherImpl->ProcessL(aInput, aOutput);)
1.162 + }
1.163 +
1.164 +TInt CBufferedDecryptorShim::MaxOutputLength(TInt aInputLength) const
1.165 + {
1.166 + return iSymmetricCipherImpl->MaxOutputLength(aInputLength);
1.167 + }
1.168 +
1.169 +void CBufferedDecryptorShim::Reset()
1.170 + {
1.171 + iSymmetricCipherImpl->Reset();
1.172 + }
1.173 +
1.174 +TInt CBufferedDecryptorShim::BlockSize() const
1.175 + {
1.176 + return BitsToBytes(iSymmetricCipherImpl->BlockSize());
1.177 + }
1.178 +
1.179 +TInt CBufferedDecryptorShim::KeySize() const
1.180 + {
1.181 + return iSymmetricCipherImpl->KeySize();
1.182 + }
1.183 +
1.184 +void CBufferedDecryptorShim::ProcessFinalL(const TDesC8& aInput, TDes8& aOutput)
1.185 + {
1.186 + iSymmetricCipherImpl->ProcessFinalL(aInput, aOutput);
1.187 + }
1.188 +
1.189 +TInt CBufferedDecryptorShim::MaxFinalOutputLength(TInt aInputLength) const
1.190 + {
1.191 + return iSymmetricCipherImpl->MaxFinalOutputLength(aInputLength);
1.192 + }