crypto/weakcryptospi/source/spi/cryptohashapi.cpp
changeset 8 35751d3474b7
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 hash API implementation
       
    16 * crypto hash API implementation
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 /**
       
    22  @file
       
    23 */
       
    24 
       
    25 #include <cryptospi/cryptohashapi.h>
       
    26 #include "legacyselector.h"
       
    27 #include <cryptospi/hashplugin.h>
       
    28 
       
    29 
       
    30 using namespace CryptoSpi;
       
    31 
       
    32 //
       
    33 // Hash Factory Implementation
       
    34 //
       
    35 EXPORT_C void CHashFactory::CreateHashL(CHash*& aHash,
       
    36 									TUid aAlgorithmUid,
       
    37 									TUid aOperationMode,
       
    38 									const CKey* aKey,
       
    39 									const CCryptoParams* aAlgorithmParams)
       
    40 	{
       
    41 	MPluginSelector* selector=reinterpret_cast<MPluginSelector *>(Dll::Tls());
       
    42 	if (selector)
       
    43 		{
       
    44 		selector->CreateHashL(aHash, aAlgorithmUid, aOperationMode, aKey, aAlgorithmParams);
       
    45 		}
       
    46 	else
       
    47 		{
       
    48 		CLegacySelector* legacySelector=CLegacySelector::NewLC();
       
    49 		legacySelector->CreateHashL(aHash, aAlgorithmUid, aOperationMode, aKey, aAlgorithmParams);
       
    50 		CleanupStack::PopAndDestroy(legacySelector); //selector	
       
    51 		}
       
    52 	}							
       
    53 
       
    54 #ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT		
       
    55 
       
    56 EXPORT_C void CHashFactory::CreateHashL(CHash*& aHash,
       
    57 								 TUid aAlgorithmUid,
       
    58 								 const CCryptoParams* aAlgorithmParams)
       
    59 	{
       
    60 	MPluginSelector* selector=reinterpret_cast<MPluginSelector *>(Dll::Tls());
       
    61 	if (selector)
       
    62 		{
       
    63 		selector->CreateHashL(aHash, aAlgorithmUid, aAlgorithmParams);
       
    64 		}
       
    65 	else
       
    66 		{
       
    67 		CLegacySelector* legacySelector=CLegacySelector::NewLC();
       
    68 		legacySelector->CreateHashL(aHash, aAlgorithmUid, aAlgorithmParams);
       
    69 		CleanupStack::PopAndDestroy(legacySelector); //selector	
       
    70 		}
       
    71 	}
       
    72 #endif
       
    73 
       
    74 //
       
    75 // Hash implementation
       
    76 //
       
    77 CHash* CHash::NewL(MHash* aHash, TInt aHandle)
       
    78 	{
       
    79 	CHash* self=new(ELeave) CHash(aHash, aHandle);
       
    80 	return self;		
       
    81 	}
       
    82 					
       
    83 EXPORT_C CHash::~CHash()
       
    84 	{
       
    85 	}
       
    86 
       
    87 EXPORT_C TPtrC8 CHash::Hash(const TDesC8& aMessage)
       
    88 	{
       
    89 	return ((MHash*)iPlugin)->Hash(aMessage);
       
    90 	}
       
    91 	
       
    92 EXPORT_C void CHash::Update(const TDesC8& aMessage)
       
    93 	{
       
    94 	((MHash*)iPlugin)->Update(aMessage);	
       
    95 	}
       
    96 
       
    97 EXPORT_C TPtrC8 CHash::Final(const TDesC8& aMessage)
       
    98 	{
       
    99 	MHash* hash=(MHash*)iPlugin;
       
   100 	TPtrC8 hashValue=hash->Final(aMessage);
       
   101 	hash->Reset();
       
   102 	return hashValue;
       
   103 	}
       
   104 	
       
   105 EXPORT_C CHash* CHash::ReplicateL()
       
   106 	{
       
   107 	MHash* plugin=((MHash*)iPlugin)->ReplicateL();
       
   108 	CleanupClosePushL(*plugin);
       
   109 	RLibrary lib;
       
   110 	lib.SetHandle(iLibHandle);
       
   111 	RLibrary duplib=lib;
       
   112 	User::LeaveIfError(duplib.Duplicate(RThread(), EOwnerProcess));
       
   113 	CleanupClosePushL(duplib);
       
   114 	CHash* self=new(ELeave) CHash(plugin, duplib.Handle());
       
   115 	CleanupStack::Pop(2, plugin); //duplib, plugin
       
   116 	return self;		
       
   117 	}
       
   118 	
       
   119 EXPORT_C void CHash::SetKeyL(const CKey& aKey)
       
   120 	{
       
   121 	((MHash*)iPlugin)->SetKeyL(aKey);
       
   122 	}
       
   123 			
       
   124 EXPORT_C void CHash::SetOperationModeL(TUid aOperationMode)
       
   125 	{
       
   126 	((MHash*)iPlugin)->SetOperationModeL(aOperationMode);
       
   127 	}
       
   128 
       
   129 EXPORT_C CHash* CHash::CopyL()
       
   130 	{
       
   131 	MHash* plugin=((MHash*)iPlugin)->CopyL();
       
   132 	CleanupClosePushL(*plugin);
       
   133 	RLibrary lib;
       
   134 	lib.SetHandle(iLibHandle);
       
   135 	RLibrary duplib=lib;
       
   136 	User::LeaveIfError(duplib.Duplicate(RThread(), EOwnerProcess));
       
   137 	CleanupClosePushL(duplib);
       
   138 	CHash* self=new(ELeave) CHash(plugin, duplib.Handle());
       
   139 	CleanupStack::Pop(2, plugin); //duplib, plugin
       
   140 	return self;			
       
   141 	}
       
   142 
       
   143 CHash::CHash(MHash* aHash, TInt aHandle)
       
   144 : CCryptoBase(aHash, aHandle)
       
   145 	{
       
   146 	}
       
   147 
       
   148 //
       
   149 // Asynchronous hash implementation
       
   150 // (async not implemented, so no coverage)
       
   151 //
       
   152 //
       
   153 #ifdef _BullseyeCoverage
       
   154 #pragma suppress_warnings on
       
   155 #pragma BullseyeCoverage off
       
   156 #pragma suppress_warnings off
       
   157 #endif
       
   158 
       
   159 EXPORT_C void CHashFactory::CreateAsyncHashL(CAsyncHash*& aHash, 
       
   160 											TUid aAlgorithmUid,
       
   161 											TUid aOperationMode,
       
   162 											const CKey* aKey,
       
   163 											const CCryptoParams* aAlgorithmParams)
       
   164 	{
       
   165 	MPluginSelector* selector=reinterpret_cast<MPluginSelector *>(Dll::Tls());
       
   166 	if (selector)
       
   167 		{
       
   168 		selector->CreateAsyncHashL(aHash, aAlgorithmUid, aOperationMode, aKey, aAlgorithmParams);
       
   169 		}
       
   170 	else
       
   171 		{
       
   172 		CLegacySelector* legacySelector=CLegacySelector::NewLC();
       
   173 		legacySelector->CreateAsyncHashL(aHash, aAlgorithmUid, aOperationMode, aKey, aAlgorithmParams);
       
   174 		CleanupStack::PopAndDestroy(legacySelector); //selector
       
   175 		}
       
   176 	}
       
   177 
       
   178 #ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT		
       
   179 EXPORT_C void CHashFactory::CreateAsyncHashL(CAsyncHash*& aHash, 
       
   180 								      TUid aAlgorithmUid,
       
   181 								      const CCryptoParams* aAlgorithmParams)
       
   182 	{
       
   183 	MPluginSelector* selector=reinterpret_cast<MPluginSelector *>(Dll::Tls());
       
   184 	if (selector)
       
   185 		{
       
   186 		selector->CreateAsyncHashL(aHash, aAlgorithmUid, aAlgorithmParams);
       
   187 		}
       
   188 	else
       
   189 		{
       
   190 		CLegacySelector* legacySelector=CLegacySelector::NewLC();
       
   191 		legacySelector->CreateAsyncHashL(aHash, aAlgorithmUid, aAlgorithmParams);
       
   192 		CleanupStack::PopAndDestroy(legacySelector); //selector
       
   193 		}
       
   194 	
       
   195 	}
       
   196 #endif
       
   197 
       
   198 CAsyncHash* CAsyncHash::NewL(MAsyncHash* aHash, TInt aHandle)
       
   199 	{
       
   200 	CAsyncHash* self=new(ELeave) CAsyncHash(aHash, aHandle);
       
   201 	return self;
       
   202 	}
       
   203 
       
   204 EXPORT_C CAsyncHash::~CAsyncHash()
       
   205 	{
       
   206 	}
       
   207 
       
   208 EXPORT_C void CAsyncHash::Hash(const TDesC8& aMessage, TPtrC8& aHash, TRequestStatus& aStatus)
       
   209 	{
       
   210 	((MAsyncHash*)iPlugin)->Hash(aMessage, aHash, aStatus);
       
   211 	}
       
   212 	
       
   213 EXPORT_C void CAsyncHash::Update(const TDesC8& aMessage, TRequestStatus& aStatus)
       
   214 	{
       
   215 	((MAsyncHash*)iPlugin)->Update(aMessage, aStatus);	
       
   216 	}
       
   217 
       
   218 EXPORT_C void CAsyncHash::Final(const TDesC8& aMessage, TPtrC8& aFinal, TRequestStatus& aStatus)
       
   219 	{
       
   220 	((MAsyncHash*)iPlugin)->Final(aMessage, aFinal, aStatus);
       
   221 	}
       
   222 
       
   223 EXPORT_C void CAsyncHash::Cancel()
       
   224 	{
       
   225 	((MAsyncHash*)iPlugin)->Cancel();	
       
   226 	}
       
   227 
       
   228 EXPORT_C CAsyncHash* CAsyncHash::ReplicateL()
       
   229 	{
       
   230 	MAsyncHash* plugin=((MAsyncHash*)iPlugin)->ReplicateL();
       
   231 	CleanupClosePushL(*plugin);
       
   232 	RLibrary lib;
       
   233 	lib.SetHandle(iLibHandle);
       
   234 	RLibrary duplib=lib;
       
   235 	User::LeaveIfError(duplib.Duplicate(RThread(), EOwnerProcess));
       
   236 	CleanupClosePushL(duplib);
       
   237 	CAsyncHash* self=new(ELeave) CAsyncHash(plugin, duplib.Handle());
       
   238 	CleanupStack::Pop(2, plugin); //duplib, plugin
       
   239 	return self;		
       
   240 	}
       
   241 
       
   242 EXPORT_C CAsyncHash* CAsyncHash::CopyL()
       
   243 	{
       
   244 	MAsyncHash* plugin=((MAsyncHash*)iPlugin)->CopyL();
       
   245 	CleanupClosePushL(*plugin);
       
   246 	RLibrary lib;
       
   247 	lib.SetHandle(iLibHandle);
       
   248 	RLibrary duplib=lib;
       
   249 	User::LeaveIfError(duplib.Duplicate(RThread(), EOwnerProcess));
       
   250 	CleanupClosePushL(duplib);
       
   251 	CAsyncHash* self=new(ELeave) CAsyncHash(plugin, duplib.Handle());
       
   252 	CleanupStack::Pop(2, plugin); //duplib, plugin
       
   253 	return self;	
       
   254 	}
       
   255 
       
   256 EXPORT_C void CAsyncHash::SetKeyL(const CKey& aKey)
       
   257 	{
       
   258 	((MAsyncHash*)iPlugin)->SetKeyL(aKey);
       
   259 	}
       
   260 			
       
   261 EXPORT_C void CAsyncHash::SetOperationModeL(TUid aOperationMode)
       
   262 	{
       
   263 	((MAsyncHash*)iPlugin)->SetOperationModeL(aOperationMode);
       
   264 	}
       
   265 	
       
   266 CAsyncHash::CAsyncHash(MAsyncHash* aAsyncHash, TInt aHandle)
       
   267 : CCryptoBase(aAsyncHash, aHandle)
       
   268 	{		
       
   269 	}
       
   270 
       
   271