os/security/crypto/weakcryptospi/test/tcryptospi/src/symmetriccipherprocessbeforeivsetstep.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     3
* All rights reserved.
sl@0
     4
* This component and the accompanying materials are made available
sl@0
     5
* under the terms of the License "Eclipse Public License v1.0"
sl@0
     6
* which accompanies this distribution, and is available
sl@0
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
*
sl@0
     9
* Initial Contributors:
sl@0
    10
* Nokia Corporation - initial contribution.
sl@0
    11
*
sl@0
    12
* Contributors:
sl@0
    13
*
sl@0
    14
* Description: 
sl@0
    15
*
sl@0
    16
*/
sl@0
    17
sl@0
    18
sl@0
    19
/**
sl@0
    20
 @file
sl@0
    21
 @internalTechnology
sl@0
    22
*/
sl@0
    23
sl@0
    24
#include "symmetriccipherprocessbeforeivsetstep.h"
sl@0
    25
sl@0
    26
using namespace CryptoSpi;
sl@0
    27
sl@0
    28
CSymmetricCipherProcessBeforeIvSetStep::CSymmetricCipherProcessBeforeIvSetStep()
sl@0
    29
	{
sl@0
    30
	SetTestStepName(KSymmetricCipherProcessBeforeIvSetStep);
sl@0
    31
	}
sl@0
    32
sl@0
    33
sl@0
    34
TVerdict CSymmetricCipherProcessBeforeIvSetStep::doTestStepPreambleL()
sl@0
    35
	{
sl@0
    36
	SetTestStepResult(EPass);
sl@0
    37
	return TestStepResult();
sl@0
    38
	}
sl@0
    39
sl@0
    40
sl@0
    41
TVerdict CSymmetricCipherProcessBeforeIvSetStep::doTestStepL()
sl@0
    42
	{
sl@0
    43
	INFO_PRINTF1(_L("*** Symmetric Cipher - Calling the Process methods without first setting the IV ***"));
sl@0
    44
	INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
sl@0
    45
	
sl@0
    46
  	if (TestStepResult()!=EPass)
sl@0
    47
  		{
sl@0
    48
  		return TestStepResult(); 
sl@0
    49
  		}
sl@0
    50
		
sl@0
    51
	//Assume failure, unless all is successful
sl@0
    52
	SetTestStepResult(EFail);
sl@0
    53
		
sl@0
    54
	TVariantPtrC operationMode;
sl@0
    55
		
sl@0
    56
	CSymmetricCipher* impl = NULL;
sl@0
    57
	CKey* key = NULL;
sl@0
    58
	SetupCipherL(EFalse, EFalse, operationMode, impl, key);
sl@0
    59
sl@0
    60
	INFO_PRINTF1(_L("Plugin loaded."));
sl@0
    61
	
sl@0
    62
	CleanupStack::PushL(key);
sl@0
    63
	CleanupStack::PushL(impl);
sl@0
    64
sl@0
    65
	HBufC8* plaintext = ReadInPlaintextL();
sl@0
    66
	CleanupStack::PushL(plaintext);
sl@0
    67
				
sl@0
    68
	//Create buffer for encrypted data
sl@0
    69
	TInt maxOutputLength = impl->MaxFinalOutputLength(plaintext->Length());
sl@0
    70
	HBufC8* encrypted =	HBufC8::NewLC(maxOutputLength);
sl@0
    71
	TPtr8 encryptedPtr = encrypted->Des();
sl@0
    72
sl@0
    73
	INFO_PRINTF1(_L("Calling ProcessL()..."));
sl@0
    74
sl@0
    75
	//Perform the encryption operation
sl@0
    76
	TRAPD(err, impl->ProcessL((*plaintext), encryptedPtr));
sl@0
    77
					
sl@0
    78
	if (err == KErrNotSupported)
sl@0
    79
		{
sl@0
    80
		INFO_PRINTF1(_L("ProcessL() errored with KErrNotSupported as expected"));
sl@0
    81
		SetTestStepResult(EPass);
sl@0
    82
		}
sl@0
    83
	else if (err == KErrNone)
sl@0
    84
		{
sl@0
    85
		ERR_PRINTF1(_L("*** FAIL: ProcessL() did not error ***"));
sl@0
    86
		SetTestStepResult(EFail);						
sl@0
    87
		}
sl@0
    88
	else
sl@0
    89
		{
sl@0
    90
		ERR_PRINTF2(_L("*** FAIL: ProcessL() errored with unexpected error code - %d ***"), err);
sl@0
    91
		SetTestStepResult(EFail);				
sl@0
    92
		}
sl@0
    93
				
sl@0
    94
	if (encryptedPtr.Length() != 0)
sl@0
    95
		{
sl@0
    96
		ERR_PRINTF1(_L("*** FAIL: encryptedPtr had been modified by ProcessL() ***"));
sl@0
    97
		SetTestStepResult(EFail);					
sl@0
    98
		}
sl@0
    99
					
sl@0
   100
	if (TestStepResult() == EFail)
sl@0
   101
		{
sl@0
   102
		CleanupStack::PopAndDestroy(4, key);
sl@0
   103
		INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
sl@0
   104
		return TestStepResult();	
sl@0
   105
		}	
sl@0
   106
				
sl@0
   107
	INFO_PRINTF1(_L("Calling ProcessFinalL()..."));
sl@0
   108
sl@0
   109
	//Perform the encryption operation
sl@0
   110
	TRAP(err, impl->ProcessFinalL((*plaintext), encryptedPtr));
sl@0
   111
				
sl@0
   112
	if (err == KErrNotSupported)
sl@0
   113
		{
sl@0
   114
		INFO_PRINTF1(_L("ProcessFinalL() errored with KErrNotSupported as expected"));
sl@0
   115
		}
sl@0
   116
	else if (err == KErrNone)
sl@0
   117
		{
sl@0
   118
		ERR_PRINTF1(_L("*** FAIL: ProcessFinalL() did not error ***"));
sl@0
   119
		SetTestStepResult(EFail);						
sl@0
   120
		}
sl@0
   121
	else
sl@0
   122
		{
sl@0
   123
		ERR_PRINTF2(_L("*** FAIL: ProcessFinalL() errored with unexpected error code - %d ***"), err);
sl@0
   124
		SetTestStepResult(EFail);				
sl@0
   125
		}
sl@0
   126
				
sl@0
   127
	if (encryptedPtr.Length() != 0)
sl@0
   128
		{
sl@0
   129
		ERR_PRINTF1(_L("*** FAIL: encryptedPtr had been modified by ProcessFinalL() ***"));
sl@0
   130
		SetTestStepResult(EFail);					
sl@0
   131
		}
sl@0
   132
	
sl@0
   133
	CleanupStack::PopAndDestroy(encrypted);
sl@0
   134
	CleanupStack::PopAndDestroy(plaintext);
sl@0
   135
	CleanupStack::PopAndDestroy(impl);
sl@0
   136
	CleanupStack::PopAndDestroy(key);				
sl@0
   137
	
sl@0
   138
	INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
sl@0
   139
	return TestStepResult();		
sl@0
   140
	}
sl@0
   141
sl@0
   142
sl@0
   143
TVerdict CSymmetricCipherProcessBeforeIvSetStep::doTestStepPostambleL()
sl@0
   144
	{
sl@0
   145
	return TestStepResult();
sl@0
   146
	}