os/security/crypto/weakcryptospi/test/tcryptospi/src/symmetriccipherbadivlengthstep.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/symmetriccipherbadivlengthstep.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,123 @@
     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 "symmetriccipherbadivlengthstep.h"
    1.28 +
    1.29 +using namespace CryptoSpi;
    1.30 +
    1.31 +CSymmetricCipherBadIvLengthStep::CSymmetricCipherBadIvLengthStep()
    1.32 +	{
    1.33 +	SetTestStepName(KSymmetricCipherBadIvLengthStep);
    1.34 +	}
    1.35 +
    1.36 +
    1.37 +TVerdict CSymmetricCipherBadIvLengthStep::doTestStepPreambleL()
    1.38 +	{
    1.39 +	SetTestStepResult(EPass);
    1.40 +	return TestStepResult();
    1.41 +	}
    1.42 +
    1.43 +
    1.44 +TVerdict CSymmetricCipherBadIvLengthStep::doTestStepL()
    1.45 +	{
    1.46 +	INFO_PRINTF1(_L("*** Symmetric Cipher - Trying to set the IV to a descriptor of the wrong length ***"));
    1.47 +	INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
    1.48 +	
    1.49 +  	if (TestStepResult()!=EPass)
    1.50 +  		{
    1.51 +  		return TestStepResult(); 
    1.52 +  		}
    1.53 +		
    1.54 +	// Assume failure, unless all is successful
    1.55 +	SetTestStepResult(EFail);
    1.56 +	
    1.57 +	TVariantPtrC operationMode;
    1.58 +	CSymmetricCipher* impl = NULL;
    1.59 +	CKey* key = NULL;
    1.60 +	SetupCipherL(EFalse, EFalse, operationMode, impl, key);
    1.61 +	
    1.62 +	INFO_PRINTF1(_L("Plugin loaded."));
    1.63 +	
    1.64 +	CleanupStack::PushL(key);
    1.65 +	CleanupStack::PushL(impl);
    1.66 +			
    1.67 +	if((TUid(operationMode) == KOperationModeCBCUid) || (TUid(operationMode) == KOperationModeCTRUid))
    1.68 +		{
    1.69 +		TInt blockSize(0);
    1.70 +				
    1.71 +		if (TUid(operationMode) == KOperationModeCTRUid)
    1.72 +			{
    1.73 +			blockSize = CtrModeCalcBlockSizeL(*impl) * 2;
    1.74 +			}
    1.75 +		else
    1.76 +			{
    1.77 +			blockSize = impl->BlockSize() * 2;
    1.78 +			}
    1.79 +		
    1.80 +		// blocksize is in bits so to allocate the correct number of bytes devide by 8
    1.81 +		HBufC8* iv = HBufC8::NewLC(blockSize/8);
    1.82 +		
    1.83 +		// blocksize is in bits so to allocate the correct number of 8 byte chunks divide by 64
    1.84 +		for(TInt i = 0 ; i <blockSize/64 ; i++)
    1.85 +			{
    1.86 +			iv->Des().Append(_L8("12345678"));
    1.87 +			}
    1.88 +									
    1.89 +		TRAPD(err,impl->SetIvL(iv->Des()));
    1.90 +				
    1.91 +		if(err == KErrArgument)
    1.92 +			{
    1.93 +			INFO_PRINTF1(_L("PASS : SetIvL() errored with KErrArgument as expected"));
    1.94 +			SetTestStepResult(EPass);
    1.95 +			}
    1.96 +		else if (err == KErrNone)
    1.97 +			{
    1.98 +			ERR_PRINTF1(_L("*** FAIL: SetIvL() did not error ***"));
    1.99 +			SetTestStepResult(EFail);						
   1.100 +			}
   1.101 +		else
   1.102 +			{
   1.103 +			ERR_PRINTF2(_L("*** FAIL: SetIvL() errored with unexpected error code - %d ***"), err);
   1.104 +			SetTestStepResult(EFail);				
   1.105 +			}
   1.106 +		CleanupStack::PopAndDestroy(iv);					
   1.107 +		}
   1.108 +	else
   1.109 +		{
   1.110 +		ERR_PRINTF2(_L("*** FAIL: This test requires an operation mode that supports an initialisation vector and does not support operation id: %d ***"), (TUid(operationMode)).iUid);
   1.111 +		SetTestStepResult(EFail);					
   1.112 +		}
   1.113 +
   1.114 +	CleanupStack::PopAndDestroy(impl);
   1.115 +	CleanupStack::PopAndDestroy(key);
   1.116 +			
   1.117 +	INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
   1.118 +
   1.119 +	return TestStepResult();
   1.120 +	}
   1.121 +
   1.122 +
   1.123 +TVerdict CSymmetricCipherBadIvLengthStep::doTestStepPostambleL()
   1.124 +	{
   1.125 +	return TestStepResult();
   1.126 +	}