os/security/crypto/weakcryptospi/test/tasymmetric/tasymmetricmisc.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 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
#include "tasymmetricmisc.h"
sl@0
    20
#include "t_input.h"
sl@0
    21
#include <asymmetric.h>
sl@0
    22
#include <random.h>
sl@0
    23
#include <padding.h>
sl@0
    24
#include <bigint.h>
sl@0
    25
#include "tbrokenrandom.h"
sl@0
    26
sl@0
    27
enum TActionMode {EDHKeyPair = 1, EDHPrivateKey =2, EDHPublicKey =3};
sl@0
    28
sl@0
    29
CTestAction* CAsymmetricMiscellaneous::NewL(RFs& aFs, CConsoleBase& aConsole, Output& aOut, 
sl@0
    30
	const TTestActionSpec& aTestActionSpec)
sl@0
    31
	{
sl@0
    32
	CTestAction* self = CAsymmetricMiscellaneous::NewLC(aFs, aConsole,
sl@0
    33
		aOut, aTestActionSpec);
sl@0
    34
	CleanupStack::Pop();
sl@0
    35
	return self;
sl@0
    36
	}
sl@0
    37
sl@0
    38
CTestAction* CAsymmetricMiscellaneous::NewLC(RFs& aFs, CConsoleBase& aConsole, Output& aOut, 
sl@0
    39
	const TTestActionSpec& aTestActionSpec)
sl@0
    40
	{
sl@0
    41
	CAsymmetricMiscellaneous* self = new(ELeave) CAsymmetricMiscellaneous(aFs, aConsole, aOut);
sl@0
    42
	CleanupStack::PushL(self);
sl@0
    43
	self->ConstructL(aTestActionSpec);
sl@0
    44
	return self;
sl@0
    45
	}
sl@0
    46
sl@0
    47
CAsymmetricMiscellaneous::~CAsymmetricMiscellaneous()
sl@0
    48
	{	
sl@0
    49
	delete iBody;	
sl@0
    50
	}
sl@0
    51
sl@0
    52
CAsymmetricMiscellaneous::CAsymmetricMiscellaneous(RFs& aFs, CConsoleBase& aConsole, Output& aOut)
sl@0
    53
	: CTestAction(aConsole, aOut), iFs(aFs)
sl@0
    54
	{
sl@0
    55
	}
sl@0
    56
sl@0
    57
void CAsymmetricMiscellaneous::ConstructL(const TTestActionSpec& aTestActionSpec)
sl@0
    58
	{
sl@0
    59
	CTestAction::ConstructL(aTestActionSpec);
sl@0
    60
	iBody = HBufC8::NewL(aTestActionSpec.iActionBody.Length());
sl@0
    61
	iBody->Des().Copy(aTestActionSpec.iActionBody);
sl@0
    62
sl@0
    63
	iActionMode = Input::ParseIntElement(*iBody, _L8("<actionmode>"), _L8("</actionmode>"));
sl@0
    64
	
sl@0
    65
	HBufC8* g = Input::ParseElementHexL(*iBody, _L8("<g>"));
sl@0
    66
	CleanupStack::PushL(g);
sl@0
    67
	iG = RInteger::NewL(*g);
sl@0
    68
	CleanupStack::PopAndDestroy(g);
sl@0
    69
	
sl@0
    70
	HBufC8* n = Input::ParseElementHexL(*iBody, _L8("<n>"));
sl@0
    71
	CleanupStack::PushL(n);
sl@0
    72
	iN = RInteger::NewL(*n);
sl@0
    73
	CleanupStack::PopAndDestroy(n);
sl@0
    74
sl@0
    75
	HBufC8* x = Input::ParseElementHexL(*iBody, _L8("<x>"));
sl@0
    76
	CleanupStack::PushL(x);
sl@0
    77
	iX = RInteger::NewL(*x);
sl@0
    78
	CleanupStack::PopAndDestroy(x);
sl@0
    79
	}
sl@0
    80
sl@0
    81
void CAsymmetricMiscellaneous::DoPerformPrerequisite(TRequestStatus& aStatus)
sl@0
    82
	{
sl@0
    83
	TRequestStatus* status = &aStatus;
sl@0
    84
	User::RequestComplete(status, KErrNone);
sl@0
    85
	iActionState = CTestAction::EAction;
sl@0
    86
	}
sl@0
    87
sl@0
    88
void CAsymmetricMiscellaneous::DoPerformPostrequisite(TRequestStatus& aStatus)
sl@0
    89
	{
sl@0
    90
	TRequestStatus* status = &aStatus;
sl@0
    91
sl@0
    92
	iFinished = ETrue;
sl@0
    93
	User::RequestComplete(status, KErrNone);
sl@0
    94
	}
sl@0
    95
sl@0
    96
void CAsymmetricMiscellaneous::DoReportAction(void)
sl@0
    97
	{
sl@0
    98
	}
sl@0
    99
sl@0
   100
void CAsymmetricMiscellaneous::DoCheckResult(TInt)
sl@0
   101
	{
sl@0
   102
	if (iResult)
sl@0
   103
		iConsole.Printf(_L("."));
sl@0
   104
	else
sl@0
   105
		iConsole.Printf(_L("X"));
sl@0
   106
	}
sl@0
   107
sl@0
   108
void CAsymmetricMiscellaneous::PerformAction(TRequestStatus& aStatus)
sl@0
   109
	{
sl@0
   110
	__UHEAP_MARK;	
sl@0
   111
	TRequestStatus* status = &aStatus;
sl@0
   112
	iResult = ETrue;
sl@0
   113
	
sl@0
   114
	// Construction of dummy objects just to cover the left over methods.
sl@0
   115
	switch (iActionMode)
sl@0
   116
		{
sl@0
   117
		case EDHKeyPair:
sl@0
   118
			{
sl@0
   119
			CDHKeyPair* dhKeyPair = CDHKeyPair::NewLC(iN, iG, iX);
sl@0
   120
			if (dhKeyPair == NULL)
sl@0
   121
				{
sl@0
   122
				iResult = EFalse;
sl@0
   123
				}
sl@0
   124
			CleanupStack::PopAndDestroy(dhKeyPair);
sl@0
   125
			}
sl@0
   126
			break;
sl@0
   127
			
sl@0
   128
		case EDHPrivateKey:
sl@0
   129
			{			
sl@0
   130
			CDHPrivateKey* dhPrivateKey = CDHPrivateKey::NewLC(iN, iG, iX);
sl@0
   131
			if (dhPrivateKey == NULL)
sl@0
   132
				{
sl@0
   133
				iResult = EFalse;
sl@0
   134
				}
sl@0
   135
			CleanupStack::PopAndDestroy(dhPrivateKey);
sl@0
   136
			}
sl@0
   137
			break;
sl@0
   138
	
sl@0
   139
		case EDHPublicKey:
sl@0
   140
			{
sl@0
   141
			CDHPublicKey* dhPublicKeyPtr = CDHPublicKey::NewLC(iN, iG, iX);
sl@0
   142
			if (dhPublicKeyPtr == NULL)
sl@0
   143
				{
sl@0
   144
				iResult = EFalse;
sl@0
   145
				}
sl@0
   146
			CleanupStack::PopAndDestroy(dhPublicKeyPtr);
sl@0
   147
			}
sl@0
   148
			break;
sl@0
   149
		
sl@0
   150
		default:
sl@0
   151
			break;
sl@0
   152
		}
sl@0
   153
	User::RequestComplete(status, KErrNone);
sl@0
   154
	iActionState = CTestAction::EPostrequisite;
sl@0
   155
	__UHEAP_MARKEND;
sl@0
   156
	}