os/security/crypto/weakcryptospi/source/symmetric/bufferedtransformationshim.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 2006-2010 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     3
* All rights reserved.
sl@0
     4
* This component and the accompanying materials are made available
sl@0
     5
* under the terms of the License "Eclipse Public License v1.0"
sl@0
     6
* which accompanies this distribution, and is available
sl@0
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
*
sl@0
     9
* Initial Contributors:
sl@0
    10
* Nokia Corporation - initial contribution.
sl@0
    11
*
sl@0
    12
* Contributors:
sl@0
    13
*
sl@0
    14
* Description: 
sl@0
    15
* blocktransformationshim.cpp
sl@0
    16
*
sl@0
    17
*/
sl@0
    18
sl@0
    19
sl@0
    20
#include "bufferedtransformationshim.h"
sl@0
    21
sl@0
    22
#include <cryptospi/cryptospidef.h>
sl@0
    23
#include <padding.h>
sl@0
    24
#include <cryptospi/cryptosymmetriccipherapi.h>
sl@0
    25
#include <cryptospi/plugincharacteristics.h>
sl@0
    26
#include "../common/inlines.h"
sl@0
    27
sl@0
    28
// CBufferedEncryptorShim
sl@0
    29
CBufferedEncryptorShim::CBufferedEncryptorShim(CryptoSpi::CSymmetricCipher* aSymmetricCipherImpl) :
sl@0
    30
	iSymmetricCipherImpl(aSymmetricCipherImpl)
sl@0
    31
	{
sl@0
    32
	}
sl@0
    33
sl@0
    34
CBufferedEncryptorShim* CBufferedEncryptorShim::NewL(CBlockTransformation* aBT, CPadding* aPadding)
sl@0
    35
	{
sl@0
    36
	CBufferedEncryptorShim* self(0);
sl@0
    37
	
sl@0
    38
	// Check whether the block transform contains an SPI plug-in
sl@0
    39
	TAny* implPtr(0);
sl@0
    40
	TInt err = aBT->GetExtension(CryptoSpi::KSymmetricCipherInterface, implPtr, NULL);	
sl@0
    41
	if (err == KErrNone && implPtr)
sl@0
    42
		{
sl@0
    43
		CryptoSpi::CSymmetricCipher* impl(static_cast<CryptoSpi::CSymmetricCipher*>(implPtr));
sl@0
    44
		
sl@0
    45
		const CryptoSpi::TCharacteristics* c(0);
sl@0
    46
		impl->GetCharacteristicsL(c);
sl@0
    47
	
sl@0
    48
		const CryptoSpi::TSymmetricCipherCharacteristics* cipherCharacteristics(
sl@0
    49
			static_cast<const CryptoSpi::TSymmetricCipherCharacteristics*>(c));
sl@0
    50
			
sl@0
    51
		// See if the padding mode is recognised by CryptoSpi and if so, check
sl@0
    52
		// whether the plug-in supports that padding mode.
sl@0
    53
		TUid paddingMode;
sl@0
    54
		TAny* paddingPtr = &paddingMode;		
sl@0
    55
		err = aPadding->GetExtension(CryptoSpi::KPaddingInterface, paddingPtr, 0);		
sl@0
    56
		if (err == KErrNone && cipherCharacteristics->IsPaddingModeSupported(paddingMode))
sl@0
    57
			{
sl@0
    58
			impl->SetCryptoModeL(CryptoSpi::KCryptoModeEncryptUid);
sl@0
    59
			impl->SetPaddingModeL(paddingMode);		
sl@0
    60
			self = new(ELeave) CBufferedEncryptorShim(impl);
sl@0
    61
			CleanupStack::PushL(self);
sl@0
    62
			self->ConstructL(aBT, aPadding);
sl@0
    63
			CleanupStack::Pop(self);
sl@0
    64
			}
sl@0
    65
		}				
sl@0
    66
	return self;
sl@0
    67
	}
sl@0
    68
sl@0
    69
void CBufferedEncryptorShim::ConstructL(CBlockTransformation* aBT, CPadding* aPadding)
sl@0
    70
	{
sl@0
    71
	CBufferedEncryptor::ConstructL(aBT, aPadding);
sl@0
    72
	}
sl@0
    73
sl@0
    74
void CBufferedEncryptorShim::Process(const TDesC8& aInput, TDes8& aOutput)
sl@0
    75
	{
sl@0
    76
	TRAP_IGNORE(iSymmetricCipherImpl->ProcessL(aInput, aOutput);)
sl@0
    77
	}
sl@0
    78
	
sl@0
    79
TInt CBufferedEncryptorShim::MaxOutputLength(TInt aInputLength) const
sl@0
    80
	{
sl@0
    81
	return iSymmetricCipherImpl->MaxOutputLength(aInputLength);
sl@0
    82
	}
sl@0
    83
	
sl@0
    84
void CBufferedEncryptorShim::Reset()
sl@0
    85
	{
sl@0
    86
	iSymmetricCipherImpl->Reset();
sl@0
    87
	}
sl@0
    88
	
sl@0
    89
TInt CBufferedEncryptorShim::BlockSize() const
sl@0
    90
	{
sl@0
    91
	return BitsToBytes(iSymmetricCipherImpl->BlockSize());
sl@0
    92
	}
sl@0
    93
	
sl@0
    94
TInt CBufferedEncryptorShim::KeySize() const
sl@0
    95
	{
sl@0
    96
	return iSymmetricCipherImpl->KeySize();
sl@0
    97
	}
sl@0
    98
	
sl@0
    99
void CBufferedEncryptorShim::ProcessFinalL(const TDesC8& aInput, TDes8& aOutput)
sl@0
   100
	{
sl@0
   101
	iSymmetricCipherImpl->ProcessFinalL(aInput, aOutput);
sl@0
   102
	}
sl@0
   103
	
sl@0
   104
TInt CBufferedEncryptorShim::MaxFinalOutputLength(TInt aInputLength) const
sl@0
   105
	{
sl@0
   106
	return iSymmetricCipherImpl->MaxFinalOutputLength(aInputLength);
sl@0
   107
	}
sl@0
   108
sl@0
   109
// CBufferedDecryptorShim
sl@0
   110
CBufferedDecryptorShim::CBufferedDecryptorShim(CryptoSpi::CSymmetricCipher* aSymmetricCipherImpl) :
sl@0
   111
	iSymmetricCipherImpl(aSymmetricCipherImpl)
sl@0
   112
	{
sl@0
   113
	}
sl@0
   114
sl@0
   115
CBufferedDecryptorShim* CBufferedDecryptorShim::NewL(CBlockTransformation* aBT, CPadding* aPadding)
sl@0
   116
	{
sl@0
   117
	CBufferedDecryptorShim* self(0);
sl@0
   118
	
sl@0
   119
	// Check whether the block transform contains an SPI plug-in
sl@0
   120
	TAny* implPtr(0);
sl@0
   121
	TInt err = aBT->GetExtension(CryptoSpi::KSymmetricCipherInterface, implPtr, NULL);	
sl@0
   122
	if (err == KErrNone && implPtr)
sl@0
   123
		{
sl@0
   124
		CryptoSpi::CSymmetricCipher* impl(static_cast<CryptoSpi::CSymmetricCipher*>(implPtr));
sl@0
   125
		
sl@0
   126
		const CryptoSpi::TCharacteristics* c(0);
sl@0
   127
		impl->GetCharacteristicsL(c);
sl@0
   128
	
sl@0
   129
		const CryptoSpi::TSymmetricCipherCharacteristics* cipherCharacteristics(
sl@0
   130
			static_cast<const CryptoSpi::TSymmetricCipherCharacteristics*>(c));
sl@0
   131
			
sl@0
   132
		// See if the padding mode is recognised by CryptoSpi and if so, check
sl@0
   133
		// whether the plug-in supports that padding mode.
sl@0
   134
		TUid paddingMode;
sl@0
   135
		TAny* paddingPtr = &paddingMode;		
sl@0
   136
		err = aPadding->GetExtension(CryptoSpi::KPaddingInterface, paddingPtr, 0);		
sl@0
   137
		if (err == KErrNone && cipherCharacteristics->IsPaddingModeSupported(paddingMode))
sl@0
   138
			{
sl@0
   139
			impl->SetCryptoModeL(CryptoSpi::KCryptoModeDecryptUid);			
sl@0
   140
			impl->SetPaddingModeL(paddingMode);
sl@0
   141
			
sl@0
   142
			self = new(ELeave) CBufferedDecryptorShim(impl);
sl@0
   143
			CleanupStack::PushL(self);
sl@0
   144
			self->ConstructL(aBT, aPadding);
sl@0
   145
			CleanupStack::Pop(self);
sl@0
   146
			}
sl@0
   147
		}				
sl@0
   148
	return self;
sl@0
   149
	}
sl@0
   150
sl@0
   151
void CBufferedDecryptorShim::ConstructL(CBlockTransformation* aBT, CPadding* aPadding)
sl@0
   152
	{
sl@0
   153
	CBufferedDecryptor::ConstructL(aBT, aPadding);
sl@0
   154
	}
sl@0
   155
sl@0
   156
void CBufferedDecryptorShim::Process(const TDesC8& aInput, TDes8& aOutput)
sl@0
   157
	{
sl@0
   158
	TRAP_IGNORE(iSymmetricCipherImpl->ProcessL(aInput, aOutput);)
sl@0
   159
	}
sl@0
   160
	
sl@0
   161
TInt CBufferedDecryptorShim::MaxOutputLength(TInt aInputLength) const
sl@0
   162
	{
sl@0
   163
	return iSymmetricCipherImpl->MaxOutputLength(aInputLength);
sl@0
   164
	}
sl@0
   165
	
sl@0
   166
void CBufferedDecryptorShim::Reset()
sl@0
   167
	{
sl@0
   168
	iSymmetricCipherImpl->Reset();
sl@0
   169
	}
sl@0
   170
	
sl@0
   171
TInt CBufferedDecryptorShim::BlockSize() const
sl@0
   172
	{
sl@0
   173
	return BitsToBytes(iSymmetricCipherImpl->BlockSize());
sl@0
   174
	}
sl@0
   175
	
sl@0
   176
TInt CBufferedDecryptorShim::KeySize() const
sl@0
   177
	{
sl@0
   178
	return iSymmetricCipherImpl->KeySize();
sl@0
   179
	}
sl@0
   180
	
sl@0
   181
void CBufferedDecryptorShim::ProcessFinalL(const TDesC8& aInput, TDes8& aOutput)
sl@0
   182
	{
sl@0
   183
	iSymmetricCipherImpl->ProcessFinalL(aInput, aOutput);
sl@0
   184
	}
sl@0
   185
	
sl@0
   186
TInt CBufferedDecryptorShim::MaxFinalOutputLength(TInt aInputLength) const
sl@0
   187
	{
sl@0
   188
	return iSymmetricCipherImpl->MaxFinalOutputLength(aInputLength);
sl@0
   189
	}