crypto/weakcryptospi/source/spi/cryptomacapi.cpp
changeset 8 35751d3474b7
equal deleted inserted replaced
2:675a964f4eb5 8:35751d3474b7
       
     1 /*
       
     2 * Copyright (c) 2008-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 Mac API implementation
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 /**
       
    21  @file
       
    22 */
       
    23 
       
    24 #include <cryptospi/cryptomacapi.h>
       
    25 #include <cryptospi/macplugin.h>
       
    26 #include "legacyselector.h"
       
    27 
       
    28 using namespace CryptoSpi;
       
    29 
       
    30 
       
    31 EXPORT_C void CMacFactory::CreateMacL(CMac*& aMac,
       
    32 									  const TUid aAlgorithmUid,
       
    33 									  const CKey& aKey,
       
    34 		                              const CCryptoParams* aAlgorithmParams)
       
    35 	{
       
    36 	MPluginSelector* selector=reinterpret_cast<MPluginSelector *>(Dll::Tls());
       
    37 	if (selector)
       
    38 		{
       
    39 		selector->CreateMacL(aMac, aAlgorithmUid, aKey, aAlgorithmParams);
       
    40 		}
       
    41 	else
       
    42 		{
       
    43 		CLegacySelector* legacySelector=CLegacySelector::NewLC();
       
    44 		legacySelector->CreateMacL(aMac, aAlgorithmUid, aKey, aAlgorithmParams);
       
    45 		CleanupStack::PopAndDestroy(legacySelector); //selector	
       
    46 		}
       
    47 	}									
       
    48 
       
    49 CMac* CMac::NewL(MMac* aMac, TInt aHandle)
       
    50 	{
       
    51 	CMac* self = new (ELeave) CMac(aMac, aHandle); 		
       
    52 	return self;
       
    53 	}
       
    54 		
       
    55 CMac::CMac(MMac* aMac, TInt aHandle)
       
    56 : CCryptoBase(aMac, aHandle)
       
    57 	{
       
    58 	}
       
    59 
       
    60 EXPORT_C CMac::~CMac()
       
    61 	{
       
    62 	}
       
    63 
       
    64 /**
       
    65  * Following working methods delegate calls to the plug-in implementation 
       
    66  * of the requested MAC algorithm.
       
    67  */
       
    68 EXPORT_C TPtrC8 CMac::MacL(const TDesC8& aMessage)
       
    69 	{
       
    70 	return ((MMac*)iPlugin)->MacL(aMessage); 
       
    71 	}
       
    72 
       
    73 
       
    74 EXPORT_C void CMac::UpdateL(const TDesC8& aMessage)
       
    75 	{
       
    76 	((MMac*)iPlugin)->UpdateL(aMessage);
       
    77 	}
       
    78 
       
    79 EXPORT_C TPtrC8 CMac::FinalL(const TDesC8& aMessage)
       
    80 	{
       
    81 	return ((MMac*)iPlugin)->FinalL(aMessage);
       
    82 	}
       
    83 
       
    84 EXPORT_C void CMac::ReInitialiseAndSetKeyL(const CKey& aKey)
       
    85 	{
       
    86 	((MMac*)iPlugin)->ReInitialiseAndSetKeyL(aKey);	
       
    87 	}
       
    88 
       
    89 EXPORT_C CMac* CMac::ReplicateL()
       
    90 	{
       
    91 	MMac* plugin=((MMac*)iPlugin)->ReplicateL();
       
    92 	CleanupClosePushL(*plugin);
       
    93 	RLibrary lib;
       
    94 	lib.SetHandle(iLibHandle);
       
    95 	RLibrary duplib=lib;
       
    96 	User::LeaveIfError(duplib.Duplicate(RThread(), EOwnerProcess));
       
    97 	CleanupClosePushL(duplib);
       
    98 	CMac* self=new(ELeave) CMac(plugin, duplib.Handle());
       
    99 	CleanupStack::Pop(2, plugin); //duplib, plugin
       
   100 	return self;		
       
   101 	}
       
   102 
       
   103 EXPORT_C CMac* CMac::CopyL()
       
   104 	{
       
   105 	MMac* plugin=((MMac*)iPlugin)->CopyL();
       
   106 	CleanupClosePushL(*plugin);
       
   107 	RLibrary lib;
       
   108 	lib.SetHandle(iLibHandle);
       
   109 	RLibrary duplib=lib;
       
   110 	User::LeaveIfError(duplib.Duplicate(RThread(), EOwnerProcess));
       
   111 	CleanupClosePushL(duplib);
       
   112 	CMac* self=new(ELeave) CMac(plugin, duplib.Handle());
       
   113 	CleanupStack::Pop(2, plugin); //duplib, plugin
       
   114 	return self;			
       
   115 	}
       
   116 
       
   117 //
       
   118 // Asynchronous MAC interface implementation
       
   119 // (async not implemented, so no coverage)
       
   120 // Once we have a dedicated hardware plugin-dll
       
   121 // the following pre-processor conditions must be removed.
       
   122 //
       
   123 #ifdef _BullseyeCoverage
       
   124 #pragma suppress_warnings on
       
   125 #pragma BullseyeCoverage off
       
   126 #pragma suppress_warnings off
       
   127 #endif
       
   128 
       
   129 
       
   130 EXPORT_C void CMacFactory::CreateAsyncMacL(CAsyncMac*& aMac,
       
   131 									  const TUid aAlgorithmUid,
       
   132 									  const CKey& aKey,
       
   133 		                              const CCryptoParams* aAlgorithmParams)
       
   134 	{
       
   135 	MPluginSelector* selector=reinterpret_cast<MPluginSelector *>(Dll::Tls());
       
   136 	if (selector)
       
   137 		{
       
   138 		selector->CreateAsyncMacL(aMac, aAlgorithmUid, aKey, aAlgorithmParams);
       
   139 		}
       
   140 	else
       
   141 		{
       
   142 		CLegacySelector* legacySelector=CLegacySelector::NewLC();
       
   143 		legacySelector->CreateAsyncMacL(aMac, aAlgorithmUid, aKey, aAlgorithmParams);
       
   144 		CleanupStack::PopAndDestroy(legacySelector); //selector	
       
   145 		}
       
   146 	}									
       
   147 
       
   148 CAsyncMac* CAsyncMac::NewL(MAsyncMac* aMac, TInt aHandle)
       
   149 	{
       
   150 	CAsyncMac* self = new (ELeave) CAsyncMac(aMac, aHandle); 		
       
   151 	return self;
       
   152 	}
       
   153 		
       
   154 CAsyncMac::CAsyncMac(MAsyncMac* aMac, TInt aHandle)
       
   155 : CCryptoBase(aMac, aHandle)
       
   156 	{
       
   157 	}
       
   158 
       
   159 EXPORT_C CAsyncMac::~CAsyncMac()
       
   160 	{
       
   161 	}
       
   162 
       
   163 /**
       
   164  * Following asynchronous working methods delegate calls to the plug-in implementation 
       
   165  * of the requested MAC algorithm.
       
   166  */
       
   167 EXPORT_C TPtrC8 CAsyncMac::MacL(const TDesC8& aMessage, TRequestStatus& aStatus)
       
   168 	{
       
   169 	return ((MAsyncMac*)iPlugin)->MacL(aMessage, aStatus); 
       
   170 	}
       
   171 
       
   172 EXPORT_C void CAsyncMac::UpdateL(const TDesC8& aMessage, TRequestStatus& aStatus)
       
   173 	{
       
   174 	((MAsyncMac*)iPlugin)->UpdateL(aMessage, aStatus);
       
   175 	}
       
   176 
       
   177 EXPORT_C TPtrC8 CAsyncMac::FinalL(const TDesC8& aMessage, TRequestStatus& aStatus)
       
   178 	{
       
   179 	return ((MAsyncMac*)iPlugin)->FinalL(aMessage, aStatus);
       
   180 	}
       
   181 
       
   182 EXPORT_C void CAsyncMac::ReInitialiseAndSetKeyL(const CKey& aKey)
       
   183 	{
       
   184 	((MAsyncMac*)iPlugin)->ReInitialiseAndSetKeyL(aKey);	
       
   185 	}
       
   186 
       
   187 EXPORT_C CAsyncMac* CAsyncMac::ReplicateL()
       
   188 	{
       
   189 	MAsyncMac* plugin=((MAsyncMac*)iPlugin)->ReplicateL();
       
   190 	CleanupClosePushL(*plugin);
       
   191 	RLibrary lib;
       
   192 	lib.SetHandle(iLibHandle);
       
   193 	RLibrary duplib=lib;
       
   194 	User::LeaveIfError(duplib.Duplicate(RThread(), EOwnerProcess));
       
   195 	CleanupClosePushL(duplib);
       
   196 	CAsyncMac* self=new(ELeave) CAsyncMac(plugin, duplib.Handle());
       
   197 	CleanupStack::Pop(2, plugin); //duplib, plugin
       
   198 	return self;		
       
   199 	}
       
   200 
       
   201 EXPORT_C CAsyncMac* CAsyncMac::CopyL()
       
   202 	{
       
   203 	MAsyncMac* plugin=((MAsyncMac*)iPlugin)->CopyL();
       
   204 	CleanupClosePushL(*plugin);
       
   205 	RLibrary lib;
       
   206 	lib.SetHandle(iLibHandle);
       
   207 	RLibrary duplib=lib;
       
   208 	User::LeaveIfError(duplib.Duplicate(RThread(), EOwnerProcess));
       
   209 	CleanupClosePushL(duplib);
       
   210 	CAsyncMac* self=new(ELeave) CAsyncMac(plugin, duplib.Handle());
       
   211 	CleanupStack::Pop(2, plugin); //duplib, plugin
       
   212 	return self;			
       
   213 	}
       
   214 
       
   215 
       
   216 EXPORT_C void CAsyncMac::Cancel()
       
   217 	{
       
   218 	((MAsyncMac*)iPlugin)->Cancel();	
       
   219 	}