crypto/weakcryptospi/source/spi/cryptosymmetriccipherapi.cpp
changeset 8 35751d3474b7
child 43 2f10d260163b
equal deleted inserted replaced
2:675a964f4eb5 8:35751d3474b7
       
     1 /*
       
     2 * Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     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".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 * crypto symmetric cipher API implementation
       
    16 * crypto symmetric cipher API implementation
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 /**
       
    22  @file
       
    23 */
       
    24 
       
    25 #include "cryptosymmetriccipherapi.h"
       
    26 #include "legacyselector.h"
       
    27 #include "symmetriccipherplugin.h"
       
    28 
       
    29 using namespace CryptoSpi; 
       
    30 
       
    31 //
       
    32 // Implementation of Symmetric Cipher Base Class
       
    33 //
       
    34 CSymmetricCipherBase::CSymmetricCipherBase(MSymmetricCipherBase* aSymmetricCipher, TInt aHandle)
       
    35 : CCryptoBase(aSymmetricCipher, aHandle)
       
    36 	{
       
    37 	}
       
    38 
       
    39 CSymmetricCipherBase::~CSymmetricCipherBase()
       
    40 	{
       
    41 	}
       
    42 
       
    43 EXPORT_C void CSymmetricCipherBase::SetKeyL(const CKey& aKey)
       
    44 	{
       
    45 	MSymmetricCipherBase* ptr=static_cast<MSymmetricCipherBase*>(iPlugin);
       
    46 	ptr->SetKeyL(aKey);
       
    47 	}
       
    48 
       
    49 EXPORT_C void CSymmetricCipherBase::SetOperationModeL(TUid aOperationMode)
       
    50 	{
       
    51 	MSymmetricCipherBase* ptr=static_cast<MSymmetricCipherBase*>(iPlugin);
       
    52 	ptr->SetOperationModeL(aOperationMode);
       
    53 	}
       
    54 
       
    55 EXPORT_C void CSymmetricCipherBase::SetCryptoModeL(TUid aCryptoMode)
       
    56 	{
       
    57 	MSymmetricCipherBase* ptr=static_cast<MSymmetricCipherBase*>(iPlugin);
       
    58 	ptr->SetCryptoModeL(aCryptoMode);
       
    59 	}
       
    60 
       
    61 EXPORT_C void CSymmetricCipherBase::SetPaddingModeL(TUid aPaddingMode)
       
    62 	{
       
    63 	MSymmetricCipherBase* ptr=static_cast<MSymmetricCipherBase*>(iPlugin);
       
    64 	ptr->SetPaddingModeL(aPaddingMode);
       
    65 	}
       
    66 
       
    67 EXPORT_C void CSymmetricCipherBase::SetIvL(const TDesC8& aIv)
       
    68 	{
       
    69 	MSymmetricCipherBase* ptr=static_cast<MSymmetricCipherBase*>(iPlugin);
       
    70 	ptr->SetIvL(aIv);
       
    71 	}
       
    72 
       
    73 EXPORT_C TInt CSymmetricCipherBase::BlockSize()
       
    74 	{
       
    75 	MSymmetricCipherBase* ptr=static_cast<MSymmetricCipherBase*>(iPlugin);
       
    76 	return ptr->BlockSize();
       
    77 	}
       
    78 
       
    79 EXPORT_C TInt CSymmetricCipherBase::KeySize()
       
    80 	{
       
    81 	MSymmetricCipherBase* ptr=static_cast<MSymmetricCipherBase*>(iPlugin);
       
    82 	return ptr->KeySize();
       
    83 	}	
       
    84 
       
    85 EXPORT_C TInt CSymmetricCipherBase::MaxOutputLength(TInt aInputLength)
       
    86 	{
       
    87 	MSymmetricCipherBase* ptr=static_cast<MSymmetricCipherBase*>(iPlugin);
       
    88 	return ptr->MaxOutputLength(aInputLength);
       
    89 	}
       
    90 	
       
    91 EXPORT_C TInt CSymmetricCipherBase::MaxFinalOutputLength(TInt aInputLength)
       
    92 	{
       
    93 	MSymmetricCipherBase* ptr=static_cast<MSymmetricCipherBase*>(iPlugin);
       
    94 	return ptr->MaxFinalOutputLength(aInputLength);
       
    95 	}	
       
    96 
       
    97 //
       
    98 // Implementation of Symmetric Cipher
       
    99 //
       
   100 CSymmetricCipher* CSymmetricCipher::NewL(MSymmetricCipher* aSymmetricCipher, TInt aHandle)
       
   101 	{
       
   102 	CSymmetricCipher* self=new(ELeave) CSymmetricCipher(aSymmetricCipher, aHandle);
       
   103 	return self;		
       
   104 	}
       
   105 
       
   106 CSymmetricCipher::CSymmetricCipher(MSymmetricCipher* aSymmetricCipher, TInt aHandle)
       
   107 : CSymmetricCipherBase(aSymmetricCipher, aHandle)
       
   108 	{	
       
   109 	}
       
   110 
       
   111 EXPORT_C CSymmetricCipher::~CSymmetricCipher()
       
   112 	{
       
   113 	}
       
   114 
       
   115 EXPORT_C void CSymmetricCipher::ProcessL(const TDesC8& aInput, TDes8& aOutput)
       
   116 	{
       
   117 	MSymmetricCipher* ptr=static_cast<MSymmetricCipher*>(iPlugin);
       
   118 	ptr->ProcessL(aInput, aOutput);
       
   119 	}
       
   120 
       
   121 
       
   122 EXPORT_C void CSymmetricCipher::ProcessFinalL(const TDesC8& aInput, TDes8& aOutput)
       
   123 	{
       
   124 	MSymmetricCipher* ptr=static_cast<MSymmetricCipher*>(iPlugin);
       
   125 	ptr->ProcessFinalL(aInput, aOutput);		
       
   126 	}
       
   127 
       
   128 
       
   129 //
       
   130 // Implementation of Symmetric Cipher Factory
       
   131 //
       
   132 EXPORT_C void CSymmetricCipherFactory::CreateSymmetricCipherL(CSymmetricCipher*& aCipher,
       
   133 															TUid aAlgorithmUid,
       
   134 															const CKey& aKey,
       
   135 															TUid aCryptoMode,
       
   136 															TUid aOperationMode,
       
   137 															TUid aPaddingMode,
       
   138 															const CCryptoParams* aAlgorithmParams)
       
   139 	{
       
   140 	MPluginSelector* selector=reinterpret_cast<MPluginSelector *>(Dll::Tls());
       
   141 	if (selector)
       
   142 		{
       
   143 		selector->CreateSymmetricCipherL(aCipher, aAlgorithmUid, aKey, aCryptoMode, aOperationMode, aPaddingMode, aAlgorithmParams);
       
   144 		}
       
   145 	else
       
   146 		{
       
   147 		CLegacySelector* legacySelector=CLegacySelector::NewLC();
       
   148 		legacySelector->CreateSymmetricCipherL(aCipher, aAlgorithmUid, aKey, aCryptoMode, aOperationMode, aPaddingMode, aAlgorithmParams);
       
   149 		CleanupStack::PopAndDestroy(legacySelector); //selector	
       
   150 		}
       
   151 	}
       
   152 
       
   153 
       
   154 //
       
   155 // Implementation of Asynchronous Symmetric Cipher
       
   156 // (async methods not implemented, so no coverage)
       
   157 //
       
   158 
       
   159 #ifdef _BullseyeCoverage
       
   160 #pragma suppress_warnings on
       
   161 #pragma BullseyeCoverage off
       
   162 #pragma suppress_warnings off
       
   163 #endif
       
   164 
       
   165 CAsyncSymmetricCipher* CAsyncSymmetricCipher::NewL(MAsyncSymmetricCipher* aAsyncSymmetricCipher, TInt aHandle)
       
   166 	{
       
   167 	CAsyncSymmetricCipher* self=new(ELeave) CAsyncSymmetricCipher(aAsyncSymmetricCipher, aHandle);
       
   168 	return self;		
       
   169 	}
       
   170 
       
   171 CAsyncSymmetricCipher::CAsyncSymmetricCipher(MAsyncSymmetricCipher* aAsyncSymmetricCipher, TInt aHandle)
       
   172 : CSymmetricCipherBase(aAsyncSymmetricCipher, aHandle)
       
   173 	{
       
   174 	}
       
   175 
       
   176 EXPORT_C CAsyncSymmetricCipher::~CAsyncSymmetricCipher()
       
   177 	{
       
   178 		
       
   179 	}
       
   180 	
       
   181 EXPORT_C void CAsyncSymmetricCipher::ProcessL(const TDesC8& aInput, TDes8& aOutput, TRequestStatus& aRequestStatus)
       
   182 	{
       
   183 	MAsyncSymmetricCipher* ptr=static_cast<MAsyncSymmetricCipher*>(iPlugin);
       
   184 	ptr->ProcessL(aInput, aOutput, aRequestStatus);		
       
   185 	}
       
   186 
       
   187 EXPORT_C void CAsyncSymmetricCipher::ProcessFinalL(const TDesC8& aInput, TDes8& aOutput, TRequestStatus& aRequestStatus)
       
   188 	{
       
   189 	MAsyncSymmetricCipher* ptr=static_cast<MAsyncSymmetricCipher*>(iPlugin);
       
   190 	ptr->ProcessFinalL(aInput, aOutput, aRequestStatus);
       
   191 	}
       
   192 
       
   193 EXPORT_C void CAsyncSymmetricCipher::Cancel()
       
   194 	{
       
   195 	MAsyncSymmetricCipher* ptr=static_cast<MAsyncSymmetricCipher*>(iPlugin);
       
   196 	ptr->Cancel();		
       
   197 	}
       
   198 
       
   199 //
       
   200 // Implementation of Symmetric Cipher Factory
       
   201 //
       
   202 EXPORT_C void CSymmetricCipherFactory::CreateAsyncSymmetricCipherL(CAsyncSymmetricCipher*& aCipher,
       
   203 														TUid aAlgorithmUid,
       
   204 														const CKey& aKey,
       
   205 														TUid aCryptoMode,
       
   206 														TUid aOperationMode,
       
   207 														TUid aPaddingMode,
       
   208 														const CCryptoParams* aAlgorithmParams)
       
   209 	{
       
   210 	MPluginSelector* selector=reinterpret_cast<MPluginSelector *>(Dll::Tls());
       
   211 	if (selector)
       
   212 		{
       
   213 		selector->CreateAsyncSymmetricCipherL(aCipher, aAlgorithmUid, aKey, aCryptoMode, aOperationMode, aPaddingMode, aAlgorithmParams);
       
   214 		}
       
   215 	else
       
   216 		{
       
   217 		CLegacySelector* legacySelector=CLegacySelector::NewLC();
       
   218 		legacySelector->CreateAsyncSymmetricCipherL(aCipher, aAlgorithmUid, aKey, aCryptoMode, aOperationMode, aPaddingMode, aAlgorithmParams);
       
   219 		CleanupStack::PopAndDestroy(legacySelector); //selector	
       
   220 		}	
       
   221 	}
       
   222