crypto/weakcryptospi/source/spi/plugincharacteristics.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 plugin characteristic implementation
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 #include <cryptospi/plugincharacteristics.h>
       
    22 #include <cryptospi/cryptospidef.h>
       
    23 #include <cryptospi/romlit.h>
       
    24 
       
    25 using namespace CryptoSpi;
       
    26 
       
    27 EXPORT_C TBool TSymmetricCipherCharacteristics::IsOperationModeSupported(TUid aOperationMode) const
       
    28 	{
       
    29 	// Sanity check to catch incorrect casts of characteristics classes
       
    30 	ASSERT(cmn.iInterfaceUID == KSymmetricCipherInterface);
       
    31 	
       
    32 	TBool supported(EFalse);
       
    33 	for (TUint i = 0; i < iOperationModeNum; ++i)
       
    34 		{
       
    35 		if (iSupportedOperationModes[i] == aOperationMode.iUid)
       
    36 			{
       
    37 			supported = ETrue;
       
    38 			break;
       
    39 			}
       
    40 		}
       
    41 	return supported;
       
    42 	}
       
    43 
       
    44 EXPORT_C TBool TSymmetricCipherCharacteristics::IsPaddingModeSupported(TUid aPaddingMode) const	
       
    45 	{
       
    46 	// Sanity check to catch incorrect casts of characteristics classes
       
    47 	ASSERT(cmn.iInterfaceUID == KSymmetricCipherInterface);
       
    48 	
       
    49 	TBool supported(EFalse);
       
    50 	for (TUint i = 0; i < iPaddingModeNum; ++i)
       
    51 		{
       
    52 		if (iSupportedPaddingModes[i] == aPaddingMode.iUid)
       
    53 			{
       
    54 			supported = ETrue;
       
    55 			break;
       
    56 			}
       
    57 		}
       
    58 	return supported;		
       
    59 	}
       
    60 
       
    61 EXPORT_C TBool TAsymmetricCipherCharacteristics::IsPaddingModeSupported(TUid aPaddingMode) const	
       
    62 	{
       
    63 	// Sanity check to catch incorrect casts of characteristics classes
       
    64 	ASSERT(cmn.iInterfaceUID == KAsymmetricCipherInterface);
       
    65 	
       
    66 	TBool supported(EFalse);
       
    67 	for (TInt i = 0; i < iPaddingModeNum; ++i)
       
    68 		{
       
    69 		if (iSupportedPaddingModes[i] == aPaddingMode.iUid)
       
    70 			{
       
    71 			supported = ETrue;
       
    72 			break;
       
    73 			}
       
    74 		}
       
    75 	return supported;
       
    76 	}
       
    77 
       
    78 EXPORT_C TBool TAsymmetricSignatureCharacteristics::IsPaddingModeSupported(TUid aPaddingMode) const	
       
    79 	{
       
    80 	// Sanity check to catch incorrect casts of characteristics classes
       
    81 	ASSERT(cmn.iInterfaceUID == KSignerInterface || cmn.iInterfaceUID == KVerifierInterface);
       
    82 	
       
    83 	TBool supported(EFalse);
       
    84 	for (TInt i = 0; i < iPaddingModeNum; ++i)
       
    85 		{
       
    86 		if (iSupportedPaddingModes[i] == aPaddingMode.iUid)
       
    87 			{
       
    88 			supported = ETrue;
       
    89 			break;
       
    90 			}
       
    91 		}
       
    92 	return supported;		
       
    93 	}
       
    94 	
       
    95 EXPORT_C TBool THashCharacteristics::IsOperationModeSupported(TUid aOperationMode) const	
       
    96 	{
       
    97 	// Sanity check to catch incorrect casts of characteristics classes
       
    98 	ASSERT(cmn.iInterfaceUID == KHashInterface);
       
    99 	
       
   100 	TBool supported(EFalse);
       
   101 	for (TUint i = 0; i < iOperationModeNum; ++i)
       
   102 		{
       
   103 		if (iSupportedOperationModes[i] == aOperationMode.iUid)
       
   104 			{
       
   105 			supported = ETrue;
       
   106 			break;
       
   107 			}
       
   108 		}
       
   109 	return supported;
       
   110 	}
       
   111 
       
   112 #ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT	
       
   113 
       
   114 void TMacCharacteristics::ExternalizeL(RWriteStream& aStream) const
       
   115 	{
       
   116 	iMacChar.ExternalizeL(aStream);
       
   117 	aStream.WriteInt32L(iMacMode);
       
   118 	if(iMacMode == KHmacMode)
       
   119 		{
       
   120 		//externalize THashCharacteristics object
       
   121 		iHashAlgorithmChar->ExternalizeL(aStream);
       
   122 		}
       
   123 	else if(iMacMode == KSymmetricCipherMode)
       
   124 		{
       
   125 		//externalize TSymmetricCipherCharacteristics object
       
   126 		iCipherAlgorithmChar->ExternalizeL(aStream);
       
   127 		}
       
   128 	}
       
   129 
       
   130 #endif
       
   131 
       
   132 void TCommonCharacteristics::ExternalizeL(RWriteStream& aStream) const
       
   133 	{
       
   134 	aStream.WriteInt32L(iInterfaceUID);
       
   135 	aStream.WriteInt32L(iAlgorithmUID);
       
   136 	aStream.WriteInt32L(iImplementationUID);	
       
   137 	aStream<<(*iCreatorName)();
       
   138 	aStream.WriteInt8L(iIsFIPSApproved);
       
   139 	aStream.WriteInt8L(iIsHardwareSupported);
       
   140 	aStream.WriteUint32L(iMaxConcurrencySupported);
       
   141 	aStream<<(*iAlgorithmName)();
       
   142 	aStream.WriteInt32L(iLatency);
       
   143 	aStream.WriteInt32L(iThroughput);
       
   144 	}
       
   145 
       
   146 void THashCharacteristics::ExternalizeL(RWriteStream& aStream) const
       
   147 	{
       
   148 	cmn.ExternalizeL(aStream);
       
   149 	aStream.WriteUint32L(iBlockSize);
       
   150 	aStream.WriteUint32L(iOutputSize);
       
   151 	aStream.WriteUint32L(iOperationModeNum);
       
   152 	for (TUint i=0;i<iOperationModeNum;i++)
       
   153 		{
       
   154 		aStream.WriteInt32L(iSupportedOperationModes[i]);
       
   155 		}
       
   156 	}
       
   157 	
       
   158 void TRandomCharacteristics::ExternalizeL(RWriteStream& aStream) const
       
   159 	{
       
   160 	cmn.ExternalizeL(aStream);
       
   161 	aStream.WriteUint32L(iBlockingMode);
       
   162 	}
       
   163 
       
   164 void TSymmetricCipherCharacteristics::ExternalizeL(RWriteStream& aStream) const
       
   165 	{
       
   166 	cmn.ExternalizeL(aStream);
       
   167 	aStream.WriteUint32L(iMaximumKeyLength);
       
   168 	aStream.WriteUint32L(iBlockSize);
       
   169 	aStream.WriteUint32L(iPaddingModeNum);
       
   170 	for (TUint i=0;i<iPaddingModeNum;i++)
       
   171 		{
       
   172 		aStream.WriteInt32L(iSupportedPaddingModes[i]);
       
   173 		}
       
   174 	aStream.WriteUint32L(iOperationModeNum);
       
   175 	for (TUint j=0;j<iOperationModeNum;j++)
       
   176 		{
       
   177 		aStream.WriteInt32L(iSupportedOperationModes[j]);
       
   178 		}
       
   179 	aStream.WriteInt32L(iKeySupportMode);
       
   180 	}
       
   181 
       
   182 void TAsymmetricCipherCharacteristics::ExternalizeL(RWriteStream& aStream) const
       
   183 	{
       
   184 	cmn.ExternalizeL(aStream);
       
   185 	aStream.WriteUint32L(iMaximumKeyLength);
       
   186 	aStream.WriteUint32L(iPaddingModeNum);
       
   187 	for (TInt i=0;i<iPaddingModeNum;i++)
       
   188 		{
       
   189 		aStream.WriteInt32L(iSupportedPaddingModes[i]);
       
   190 		}
       
   191 	aStream.WriteInt32L(iKeySupportMode);
       
   192 	}
       
   193 
       
   194 void TAsymmetricSignatureCharacteristics::ExternalizeL(RWriteStream& aStream) const
       
   195 	{
       
   196 	cmn.ExternalizeL(aStream);
       
   197 	aStream.WriteUint32L(iMaximumKeyLength);
       
   198 	aStream.WriteUint32L(iPaddingModeNum);
       
   199 	for (TInt i=0;i<iPaddingModeNum;i++)
       
   200 		{
       
   201 		aStream.WriteInt32L(iSupportedPaddingModes[i]);
       
   202 		}
       
   203 	aStream.WriteInt32L(iKeySupportMode);
       
   204 	}
       
   205 
       
   206 void TKeyAgreementCharacteristics::ExternalizeL(RWriteStream& aStream) const
       
   207 	{
       
   208 	cmn.ExternalizeL(aStream);
       
   209 	}
       
   210 	
       
   211 void TAsymmetricKeypairGeneratorCharacteristics::ExternalizeL(RWriteStream& aStream) const
       
   212 	{
       
   213 	cmn.ExternalizeL(aStream);
       
   214 	aStream.WriteUint32L(iMaximumKeyLength);	
       
   215 	}
       
   216