os/security/crypto/weakcryptospi/test/tcryptospi/src/plugincharschecker.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/security/crypto/weakcryptospi/test/tcryptospi/src/plugincharschecker.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,379 @@
     1.4 +/*
     1.5 +* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of the License "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description: 
    1.18 +*
    1.19 +*/
    1.20 +
    1.21 +
    1.22 +/**
    1.23 + @file
    1.24 + @internalTechnology
    1.25 +*/
    1.26 + 
    1.27 +#include "plugincharschecker.h"
    1.28 +
    1.29 +using namespace CryptoSpi;
    1.30 +
    1.31 +CPluginCharsChecker::~CPluginCharsChecker()
    1.32 +	{
    1.33 +	}
    1.34 +
    1.35 +CPluginCharsChecker::CPluginCharsChecker()
    1.36 +	{
    1.37 +	}
    1.38 +	
    1.39 +CPluginCharsChecker* CPluginCharsChecker::NewL()
    1.40 +	{
    1.41 +	CPluginCharsChecker* me = CPluginCharsChecker::NewLC();
    1.42 +	CleanupStack::Pop(me);
    1.43 +	return me;
    1.44 +	}
    1.45 +	
    1.46 +CPluginCharsChecker* CPluginCharsChecker::NewLC()
    1.47 +	{
    1.48 +	CPluginCharsChecker* me = new(ELeave) CPluginCharsChecker();
    1.49 +	CleanupStack::PushL(me);
    1.50 +	return me;
    1.51 +	}
    1.52 +	
    1.53 +	
    1.54 +TBool CPluginCharsChecker::checkCommonCharacteristics(const TCommonCharacteristics* aCharacteristics,
    1.55 +												TVariantPtrC aInterfaceUid,
    1.56 +												TVariantPtrC aAlgorithmUid,
    1.57 +												TVariantPtrC aImplementationUid,
    1.58 +												TVariantPtrC aCreatorName,
    1.59 +												TBool aFIPSApproved,
    1.60 +												TBool aHardwareSupported,
    1.61 +												TInt aMaxConcurrencySupported,
    1.62 +												TVariantPtrC aAlgorithmName,
    1.63 +												TInt aLatency,
    1.64 +												TInt aThroughput,
    1.65 +												TPtrC& aErrorMessage)
    1.66 +	{
    1.67 +	TBool result = ETrue;
    1.68 +	
    1.69 +	TRomLitC16 creatorName = *(aCharacteristics->iCreatorName);
    1.70 +	TRomLitC16 algorithmName = *(aCharacteristics->iAlgorithmName);
    1.71 +	
    1.72 +	if(!(aCharacteristics->iInterfaceUID == aInterfaceUid))
    1.73 +		{
    1.74 +		aErrorMessage.Set(_L("COMMON_INTERFACE_ID"));
    1.75 +		result = EFalse;
    1.76 +		}
    1.77 +		
    1.78 +	if(!(aCharacteristics->iAlgorithmUID == aAlgorithmUid))
    1.79 +		{
    1.80 +		aErrorMessage.Set(_L("COMMON_ALGORITHM_ID"));
    1.81 +		result = EFalse;
    1.82 +		}
    1.83 +		
    1.84 +	if(!(aCharacteristics->iImplementationUID == aImplementationUid))
    1.85 +		{
    1.86 +		aErrorMessage.Set(_L("COMMON_IMPLEMENTATION_ID"));
    1.87 +		result = EFalse;
    1.88 +		}
    1.89 +		
    1.90 +	if(!(*creatorName == *(static_cast<TRomLitC16>(aCreatorName))))
    1.91 +		{
    1.92 +		aErrorMessage.Set(_L("COMMON_CREATOR_NAME"));
    1.93 +		result = EFalse;
    1.94 +		}
    1.95 +		
    1.96 +	if(!(aCharacteristics->iIsFIPSApproved == aFIPSApproved)) 
    1.97 +		{
    1.98 +		aErrorMessage.Set(_L("COMMON_FIPS_APPROVED"));
    1.99 +		result = EFalse;
   1.100 +		}
   1.101 +		
   1.102 +	if(!(aCharacteristics->iIsHardwareSupported == aHardwareSupported))
   1.103 +		{
   1.104 +		aErrorMessage.Set(_L("COMMON_HARDWARE_SUPPORTED"));
   1.105 +		result = EFalse;
   1.106 +		}
   1.107 +	
   1.108 +	if(!(aCharacteristics->iMaxConcurrencySupported == aMaxConcurrencySupported))
   1.109 +		{
   1.110 +		aErrorMessage.Set(_L("COMMON_MAXIMUM_CONCURRENCY"));
   1.111 +		result = EFalse;	
   1.112 +		}
   1.113 +	
   1.114 +	if(!(*algorithmName == *(static_cast<TRomLitC16>(aAlgorithmName))))
   1.115 +		{
   1.116 +		aErrorMessage.Set(_L("COMMON_ALGORITHM_NAME"));
   1.117 +		result = EFalse;
   1.118 +		}
   1.119 +	
   1.120 +	if(!(aCharacteristics->iLatency == aLatency))
   1.121 +		{
   1.122 +		aErrorMessage.Set(_L("COMMON_LATENCY"));
   1.123 +		result = EFalse;
   1.124 +		}
   1.125 +		
   1.126 +	if(!(aCharacteristics->iThroughput == aThroughput))
   1.127 +		{	
   1.128 +		aErrorMessage.Set(_L("COMMON_THROUGHPUT"));
   1.129 +		result = EFalse;
   1.130 +		}
   1.131 +										
   1.132 +	return result;	
   1.133 +	}
   1.134 +	
   1.135 +	
   1.136 +TBool CPluginCharsChecker::checkSymmetricCharacteristics(const TSymmetricCipherCharacteristics* aCharacteristics,
   1.137 +												TInt aSymmetricMaxKeyLength,
   1.138 +												TInt aSymmetricBlockSize,
   1.139 +												TVariantPtrC aSymmetricPaddingModes,
   1.140 +												TInt aSymmetricPaddingModeNum,
   1.141 +												TVariantPtrC aSymmetricOperationModes,
   1.142 +												TInt aSymmetricOperationModeNum,
   1.143 +												TInt aSymmetricKeySupportMode,
   1.144 +												TPtrC& aErrorMessage)
   1.145 +	{
   1.146 +	TBool result = ETrue;
   1.147 +	
   1.148 +	TInt32 supportedPaddingModes = *(aCharacteristics->iSupportedPaddingModes);
   1.149 +	TInt32 supportedOperationModes = *(aCharacteristics->iSupportedOperationModes);
   1.150 +	
   1.151 +	if(!(aCharacteristics->iMaximumKeyLength == aSymmetricMaxKeyLength)) 
   1.152 +		{
   1.153 +		aErrorMessage.Set(_L("SYMMETRIC_MAXIMUM_KEY_LENGTH"));
   1.154 +		result = EFalse;
   1.155 +		}
   1.156 +		
   1.157 +	if(!(aCharacteristics->iBlockSize == aSymmetricBlockSize))
   1.158 +		{
   1.159 +		aErrorMessage.Set(_L("SYMMETRIC_BLOCK_SIZE"));
   1.160 +		result = EFalse;
   1.161 +		}
   1.162 +	
   1.163 +	if(!(supportedPaddingModes == *(static_cast<const TInt32*>(aSymmetricPaddingModes))))
   1.164 +		{
   1.165 +		aErrorMessage.Set(_L("SYMMETRIC_SUPPORTED_PADDING_MODES"));
   1.166 +		result = EFalse;
   1.167 +		}
   1.168 +		
   1.169 +	if(!(aCharacteristics->iPaddingModeNum == aSymmetricPaddingModeNum))
   1.170 +		{
   1.171 +		aErrorMessage.Set(_L("SYMMETRIC_PADDING_MODE_NUM"));
   1.172 +		result = EFalse;
   1.173 +		}
   1.174 +		
   1.175 +	if(!(supportedOperationModes == *(static_cast<const TInt32*>(aSymmetricOperationModes)))) 
   1.176 +		{
   1.177 +		aErrorMessage.Set(_L("SYMMETRIC_OPERATION_MODES"));
   1.178 +		result = EFalse;
   1.179 +		}
   1.180 +						
   1.181 +	if(!(aCharacteristics->iOperationModeNum == aSymmetricOperationModeNum))
   1.182 +		{
   1.183 +		aErrorMessage.Set(_L("SYMMETRIC_OPERATION_MODE_NUM"));
   1.184 +		result = EFalse;
   1.185 +		}
   1.186 +	
   1.187 +	if(!(aCharacteristics->iKeySupportMode == aSymmetricKeySupportMode))
   1.188 +		{
   1.189 +		aErrorMessage.Set(_L("SYMMETRIC_KEY_SUPPORT_MODE"));
   1.190 +		result = EFalse;
   1.191 +		}
   1.192 +		
   1.193 +	return result;	
   1.194 +	}
   1.195 +
   1.196 +	
   1.197 +TBool CPluginCharsChecker::checkAsymmetricCharacteristics(const TAsymmetricCipherCharacteristics* aCharacteristics,
   1.198 +													TInt aAsymmetricMaxKeyLength,
   1.199 +													TVariantPtrC aAsymmetricPaddingModes,
   1.200 +													TInt aAsymmetricPaddingModeNum,
   1.201 +													TInt aAsymmetricKeySupportMode,
   1.202 +													TPtrC& aErrorMessage)
   1.203 +	{
   1.204 +	TBool result = ETrue;
   1.205 +	
   1.206 +	TInt32 supportedPaddingModes = *(aCharacteristics->iSupportedPaddingModes);
   1.207 +	
   1.208 +	if(!(aCharacteristics->iMaximumKeyLength == aAsymmetricMaxKeyLength)) 
   1.209 +		{
   1.210 +		aErrorMessage.Set(_L("ASYMMETRIC_MAXIMUM_KEY_LENGTH"));
   1.211 +		result = EFalse;
   1.212 +		}
   1.213 +		
   1.214 +	if(!(supportedPaddingModes == *(static_cast<const TInt32*>(aAsymmetricPaddingModes))))
   1.215 +		{
   1.216 +		aErrorMessage.Set(_L("ASYMMETRIC_SUPPORTED_PADDING_MODES"));
   1.217 +		result = EFalse;
   1.218 +		}
   1.219 +		
   1.220 +	if(!(aCharacteristics->iPaddingModeNum == aAsymmetricPaddingModeNum))
   1.221 +		{
   1.222 +		aErrorMessage.Set(_L("ASYMMETRIC_PADDING_MODE_NUM"));
   1.223 +		result = EFalse;
   1.224 +		}
   1.225 +		
   1.226 +	if(!(aCharacteristics->iKeySupportMode == aAsymmetricKeySupportMode))
   1.227 +		{	
   1.228 +		aErrorMessage.Set(_L("ASYMMETRIC_KEY_SUPPORT_MODE"));
   1.229 +		result = EFalse;
   1.230 +		}
   1.231 +	
   1.232 +	return result;	
   1.233 +	}
   1.234 +	
   1.235 +	
   1.236 +TBool CPluginCharsChecker::checkHashCharacteristics(const THashCharacteristics* aCharacteristics,
   1.237 +													TInt aBlockSize,
   1.238 +													TInt aOutputSize,
   1.239 +													TVariantPtrC aHashOperationModes,
   1.240 +													TInt aHashOperationModeNum,
   1.241 +													TPtrC& aErrorMessage)
   1.242 +	{
   1.243 +	TBool result = ETrue;
   1.244 +	
   1.245 +	TInt32 supportedOperationModes = *(aCharacteristics->iSupportedOperationModes);
   1.246 +
   1.247 +	if(!(aCharacteristics->iBlockSize == aBlockSize)) 
   1.248 +		{
   1.249 +		aErrorMessage.Set(_L("HASH_BLOCK_SIZE"));
   1.250 +		result = EFalse;
   1.251 +		}
   1.252 +		
   1.253 +	if(!(aCharacteristics->iOutputSize == aOutputSize))
   1.254 +		{
   1.255 +		aErrorMessage.Set(_L("HASH_OUTPUT_SIZE"));
   1.256 +		result = EFalse;
   1.257 +		}
   1.258 +		
   1.259 +	if(!(supportedOperationModes == *(static_cast<const TInt32*>(aHashOperationModes)))) 
   1.260 +		{
   1.261 +		aErrorMessage.Set(_L("HASH_SUPPORTED_OPERATION_MODES"));
   1.262 +		result = EFalse;	
   1.263 +		}
   1.264 +		
   1.265 +	if(!(aCharacteristics->iOperationModeNum == aHashOperationModeNum))
   1.266 +		{
   1.267 +		aErrorMessage.Set(_L("HASH_OPERATION_MODE_NUM"));
   1.268 +		result = EFalse;	
   1.269 +		}
   1.270 +	
   1.271 +	return result;
   1.272 +	}
   1.273 +	
   1.274 +#ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT
   1.275 +TBool CPluginCharsChecker::checkMacCharacteristics(const TMacCharacteristics* aCharacteristics,
   1.276 +													TVariantPtrC aMacMode,
   1.277 +													TPtrC& aErrorMessage)
   1.278 +	{
   1.279 +	TBool result = ETrue;
   1.280 +
   1.281 +	if(!(aCharacteristics->iMacMode == aMacMode)) 
   1.282 +		{
   1.283 +		aErrorMessage.Set(_L("MAC_MODE"));
   1.284 +		result = EFalse;
   1.285 +		}
   1.286 +		
   1.287 +	return result;
   1.288 +	}
   1.289 +#endif
   1.290 +
   1.291 +TBool CPluginCharsChecker::checkRandomCharacteristics(const TRandomCharacteristics* aCharacteristics,
   1.292 +														TInt aRandomBlockingMode,
   1.293 +														TPtrC& aErrorMessage)
   1.294 +	{
   1.295 +	TBool result = ETrue;
   1.296 +	
   1.297 +	if(!(aCharacteristics->iBlockingMode == aRandomBlockingMode)) 
   1.298 +		{
   1.299 +		aErrorMessage.Set(_L("RANDOM_BLOCKING_MODE"));
   1.300 +		result = EFalse;
   1.301 +		}
   1.302 +		
   1.303 +	return result;	
   1.304 +	}
   1.305 +	
   1.306 +
   1.307 +TBool CPluginCharsChecker::checkAsymSignatureCharacteristics(const TAsymmetricSignatureCharacteristics* aCharacteristics,
   1.308 +															TInt aAsymSignMaxKeyLength,
   1.309 +															TVariantPtrC aAsymSignPaddingModes,
   1.310 +															TInt aAsymSignPaddingModeNum,
   1.311 +															TInt aAsymSignKeySupportMode,
   1.312 +															TPtrC& aErrorMessage)
   1.313 +	{
   1.314 +	TBool result = ETrue;
   1.315 +	
   1.316 +	TInt32 supportedPaddingModes = *(aCharacteristics->iSupportedPaddingModes);
   1.317 +	
   1.318 +	if(!(aCharacteristics->iMaximumKeyLength == aAsymSignMaxKeyLength)) 
   1.319 +		{
   1.320 +		aErrorMessage.Set(_L("ASYMSIGN_MAXIMUM_KEY_LENGTH"));
   1.321 +		result = EFalse;
   1.322 +		}
   1.323 +		
   1.324 +	if(!(supportedPaddingModes == *(static_cast<const TInt32*>(aAsymSignPaddingModes))))
   1.325 +		{
   1.326 +		aErrorMessage.Set(_L("ASYMSIGN_SUPPORTED_PADDING_MODES"));
   1.327 +		result = EFalse;
   1.328 +		}
   1.329 +		
   1.330 +	if(!(aCharacteristics->iPaddingModeNum == aAsymSignPaddingModeNum))
   1.331 +		{
   1.332 +		aErrorMessage.Set(_L("ASYMSIGN_PADDING_MODE_NUM"));
   1.333 +		result = EFalse;
   1.334 +		}
   1.335 +
   1.336 +	if(!(aCharacteristics->iKeySupportMode == aAsymSignKeySupportMode))
   1.337 +		{
   1.338 +		aErrorMessage.Set(_L("ASYMSIGN_KEY_SUPPORT_MODE"));
   1.339 +		result = EFalse;
   1.340 +		}
   1.341 +		
   1.342 +	return result;	
   1.343 +	}
   1.344 +	
   1.345 +TBool CPluginCharsChecker::checkAsymKeypairGenCharacteristics(const CryptoSpi::TAsymmetricKeypairGeneratorCharacteristics* aCharacteristics,
   1.346 +																TInt aAsymKeypairGenMaxKeyLength,
   1.347 +																TPtrC& aErrorMessage)
   1.348 +	{
   1.349 +	TBool result = ETrue;
   1.350 +	
   1.351 +	if(!(aCharacteristics->iMaximumKeyLength == aAsymKeypairGenMaxKeyLength)) 
   1.352 +		{
   1.353 +		aErrorMessage.Set(_L("ASYMKEYPAIRGEN_MAX_KEY_LENGTH"));
   1.354 +		result = EFalse;
   1.355 +		}
   1.356 +		
   1.357 +	return result;
   1.358 +	}	
   1.359 +
   1.360 +TBool CPluginCharsChecker::checkSelectedPlugin(const TCharacteristics* aCharacteristics,
   1.361 +												TVariantPtrC aAlgorithmUid,
   1.362 +												TVariantPtrC aImplementationUid,
   1.363 +												TPtrC& aErrorMessage)
   1.364 +	{
   1.365 +	TBool result = ETrue;
   1.366 +	
   1.367 +	const TCommonCharacteristics* commonChars = static_cast<const TCommonCharacteristics*>(aCharacteristics);
   1.368 +	
   1.369 +	if(!(commonChars->iAlgorithmUID == aAlgorithmUid))   
   1.370 +		{
   1.371 +		aErrorMessage.Set(_L("COMMON_ALGORITHM_ID"));
   1.372 +		result = EFalse;
   1.373 +		}
   1.374 +		
   1.375 +	if(!(commonChars->iImplementationUID == aImplementationUid))
   1.376 +		{
   1.377 +		aErrorMessage.Set(_L("COMMON_IMPLEMENTATION_ID"));
   1.378 +		result = EFalse;	
   1.379 +		}	
   1.380 +	
   1.381 +	return result;	
   1.382 +	}