os/security/crypto/weakcrypto/test/tasymmetric/trsaparams.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) 1998-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
* tdsasignfb.cpp
sl@0
    16
*
sl@0
    17
*/
sl@0
    18
sl@0
    19
sl@0
    20
#include "t_input.h"
sl@0
    21
#include "t_output.h"
sl@0
    22
#include <asymmetric.h>
sl@0
    23
#include "tvectorutils.h"
sl@0
    24
#include "trsaparams.h"
sl@0
    25
sl@0
    26
_LIT8(KModStart, "<modulus>");
sl@0
    27
_LIT8(KModEnd, "</modulus>");
sl@0
    28
_LIT8(KPubExpStart, "<publicExponent>");
sl@0
    29
_LIT8(KPubExpEnd, "</publicExponent>");
sl@0
    30
_LIT8(KPrivExpStart, "<privateExponent>");
sl@0
    31
_LIT8(KPrivExpEnd, "</privateExponent>");
sl@0
    32
_LIT8(KPStart, "<P>");
sl@0
    33
_LIT8(KPEnd, "</P>");
sl@0
    34
_LIT8(KQStart, "<Q>");
sl@0
    35
_LIT8(KQEnd, "</Q>");
sl@0
    36
_LIT8(KdPStart, "<dP>");
sl@0
    37
_LIT8(KdPEnd, "</dP>");
sl@0
    38
_LIT8(KdQStart, "<dQ>");
sl@0
    39
_LIT8(KdQEnd, "</dQ>");
sl@0
    40
_LIT8(KqInvStart, "<qInv>");
sl@0
    41
_LIT8(KqInvEnd, "</qInv>");
sl@0
    42
_LIT8(KReturnCodeStart, "<return>");
sl@0
    43
_LIT8(KReturnCodeEnd, "</return>");
sl@0
    44
_LIT8(KErrArgumentString, "KErrArgument");
sl@0
    45
sl@0
    46
CTestAction* CRSATestPublicKey::NewL(RFs& aFs, CConsoleBase& aConsole, Output& aOut, 
sl@0
    47
	const TTestActionSpec& aTestActionSpec)
sl@0
    48
	{
sl@0
    49
	CTestAction* self = CRSATestPublicKey::NewLC(aFs, aConsole,
sl@0
    50
		aOut, aTestActionSpec);
sl@0
    51
	CleanupStack::Pop();
sl@0
    52
	return self;
sl@0
    53
	}
sl@0
    54
sl@0
    55
CTestAction* CRSATestPublicKey::NewLC(RFs& aFs, CConsoleBase& aConsole, Output& aOut, 
sl@0
    56
	const TTestActionSpec& aTestActionSpec)
sl@0
    57
	{
sl@0
    58
	CRSATestPublicKey* self = new(ELeave) CRSATestPublicKey(aFs, aConsole, aOut);
sl@0
    59
	CleanupStack::PushL(self);
sl@0
    60
	self->ConstructL(aTestActionSpec);
sl@0
    61
	return self;
sl@0
    62
	}
sl@0
    63
sl@0
    64
CRSATestPublicKey::~CRSATestPublicKey()
sl@0
    65
	{
sl@0
    66
	delete iBody;
sl@0
    67
	}
sl@0
    68
sl@0
    69
CRSATestPublicKey::CRSATestPublicKey(RFs& aFs, CConsoleBase& aConsole, Output& aOut)
sl@0
    70
	: CTestAction(aConsole, aOut), iFs(aFs)
sl@0
    71
	{
sl@0
    72
	}
sl@0
    73
sl@0
    74
void CRSATestPublicKey::ConstructL(const TTestActionSpec& aTestActionSpec)
sl@0
    75
	{
sl@0
    76
	CTestAction::ConstructL(aTestActionSpec);
sl@0
    77
	iBody = HBufC8::NewL(aTestActionSpec.iActionBody.Length());
sl@0
    78
	iBody->Des().Copy(aTestActionSpec.iActionBody);
sl@0
    79
sl@0
    80
	iExpectedReturnValue = KErrNone;
sl@0
    81
	TPtrC8 returnValue = Input::ParseElement(aTestActionSpec.iActionResult, KReturnCodeStart, KReturnCodeEnd);
sl@0
    82
	if(returnValue.Compare(KErrArgumentString) == 0)
sl@0
    83
		{
sl@0
    84
		iExpectedReturnValue = KErrArgument;
sl@0
    85
		}
sl@0
    86
sl@0
    87
	}
sl@0
    88
sl@0
    89
void CRSATestPublicKey::DoPerformPrerequisite(TRequestStatus& aStatus)
sl@0
    90
	{
sl@0
    91
	TRequestStatus* status = &aStatus;
sl@0
    92
	User::RequestComplete(status, KErrNone);
sl@0
    93
	iActionState = CTestAction::EAction;
sl@0
    94
	}
sl@0
    95
sl@0
    96
void CRSATestPublicKey::DoPerformPostrequisite(TRequestStatus& aStatus)
sl@0
    97
	{
sl@0
    98
	TRequestStatus* status = &aStatus;
sl@0
    99
sl@0
   100
	iFinished = ETrue;
sl@0
   101
	User::RequestComplete(status, KErrNone);
sl@0
   102
	}
sl@0
   103
sl@0
   104
void CRSATestPublicKey::DoReportAction(void)
sl@0
   105
	{
sl@0
   106
	}
sl@0
   107
sl@0
   108
void CRSATestPublicKey::DoCheckResult(TInt)
sl@0
   109
	{
sl@0
   110
	if (iResult)
sl@0
   111
		iConsole.Printf(_L("."));
sl@0
   112
	else
sl@0
   113
		iConsole.Printf(_L("X"));
sl@0
   114
	}
sl@0
   115
sl@0
   116
void CRSATestPublicKey::PerformAction(TRequestStatus& aStatus)
sl@0
   117
	{
sl@0
   118
	__UHEAP_MARK;
sl@0
   119
	TRequestStatus* status = &aStatus;
sl@0
   120
	iResult = EFalse;
sl@0
   121
sl@0
   122
	TPtrC8 modIn = Input::ParseElement(*iBody, KModStart, KModEnd);
sl@0
   123
    RInteger mod = VectorUtils::ParseIntegerL(modIn);
sl@0
   124
	CleanupStack::PushL(mod);
sl@0
   125
sl@0
   126
	TPtrC8 expIn = Input::ParseElement(*iBody, KPubExpStart, KPubExpEnd);
sl@0
   127
    RInteger exp = VectorUtils::ParseIntegerL(expIn);
sl@0
   128
	CleanupStack::PushL(exp);
sl@0
   129
sl@0
   130
sl@0
   131
	CRSAPublicKey* key = NULL;
sl@0
   132
	TRAPD(err, key = CRSAPublicKey::NewL(mod, exp));
sl@0
   133
	if(err == iExpectedReturnValue)
sl@0
   134
		{
sl@0
   135
		iResult=ETrue;
sl@0
   136
		}
sl@0
   137
	else
sl@0
   138
		{
sl@0
   139
		iOut.writeString(_L("CRSAPublicKey construction did not return expected result\n"));
sl@0
   140
		}
sl@0
   141
	if(err != KErrNone)
sl@0
   142
		{
sl@0
   143
		CleanupStack::PopAndDestroy(2);
sl@0
   144
		}
sl@0
   145
	else
sl@0
   146
		{
sl@0
   147
		CleanupStack::PushL(key);
sl@0
   148
		CleanupStack::PopAndDestroy(3);	
sl@0
   149
		}
sl@0
   150
		
sl@0
   151
	User::RequestComplete(status, KErrNone);
sl@0
   152
	iActionState = CTestAction::EPostrequisite;
sl@0
   153
	__UHEAP_MARKEND;
sl@0
   154
	}
sl@0
   155
sl@0
   156
sl@0
   157
CTestAction* CRSATestPrivateKey::NewL(RFs& aFs, CConsoleBase& aConsole, Output& aOut, 
sl@0
   158
	const TTestActionSpec& aTestActionSpec)
sl@0
   159
	{
sl@0
   160
	CTestAction* self = CRSATestPrivateKey::NewLC(aFs, aConsole,
sl@0
   161
		aOut, aTestActionSpec);
sl@0
   162
	CleanupStack::Pop();
sl@0
   163
	return self;
sl@0
   164
	}
sl@0
   165
sl@0
   166
CTestAction* CRSATestPrivateKey::NewLC(RFs& aFs, CConsoleBase& aConsole, Output& aOut, 
sl@0
   167
	const TTestActionSpec& aTestActionSpec)
sl@0
   168
	{
sl@0
   169
	CRSATestPrivateKey* self = new(ELeave) CRSATestPrivateKey(aFs, aConsole, aOut);
sl@0
   170
	CleanupStack::PushL(self);
sl@0
   171
	self->ConstructL(aTestActionSpec);
sl@0
   172
	return self;
sl@0
   173
	}
sl@0
   174
sl@0
   175
CRSATestPrivateKey::~CRSATestPrivateKey()
sl@0
   176
	{
sl@0
   177
	delete iBody;
sl@0
   178
	}
sl@0
   179
sl@0
   180
CRSATestPrivateKey::CRSATestPrivateKey(RFs& aFs, CConsoleBase& aConsole, Output& aOut)
sl@0
   181
	: CTestAction(aConsole, aOut), iFs(aFs)
sl@0
   182
	{
sl@0
   183
	}
sl@0
   184
sl@0
   185
void CRSATestPrivateKey::ConstructL(const TTestActionSpec& aTestActionSpec)
sl@0
   186
	{
sl@0
   187
	CTestAction::ConstructL(aTestActionSpec);
sl@0
   188
	iBody = HBufC8::NewL(aTestActionSpec.iActionBody.Length());
sl@0
   189
	iBody->Des().Copy(aTestActionSpec.iActionBody);
sl@0
   190
sl@0
   191
	iExpectedReturnValue = KErrNone;
sl@0
   192
	TPtrC8 returnValue = Input::ParseElement(aTestActionSpec.iActionResult, KReturnCodeStart, KReturnCodeEnd);
sl@0
   193
	if(returnValue.Compare(KErrArgumentString) == 0)
sl@0
   194
		{
sl@0
   195
		iExpectedReturnValue = KErrArgument;
sl@0
   196
		}
sl@0
   197
sl@0
   198
	}
sl@0
   199
sl@0
   200
void CRSATestPrivateKey::DoPerformPrerequisite(TRequestStatus& aStatus)
sl@0
   201
	{
sl@0
   202
	TRequestStatus* status = &aStatus;
sl@0
   203
	User::RequestComplete(status, KErrNone);
sl@0
   204
	iActionState = CTestAction::EAction;
sl@0
   205
	}
sl@0
   206
sl@0
   207
void CRSATestPrivateKey::DoPerformPostrequisite(TRequestStatus& aStatus)
sl@0
   208
	{
sl@0
   209
	TRequestStatus* status = &aStatus;
sl@0
   210
sl@0
   211
	iFinished = ETrue;
sl@0
   212
	User::RequestComplete(status, KErrNone);
sl@0
   213
	}
sl@0
   214
sl@0
   215
void CRSATestPrivateKey::DoReportAction(void)
sl@0
   216
	{
sl@0
   217
	}
sl@0
   218
sl@0
   219
void CRSATestPrivateKey::DoCheckResult(TInt)
sl@0
   220
	{
sl@0
   221
	if (iResult)
sl@0
   222
		iConsole.Printf(_L("."));
sl@0
   223
	else
sl@0
   224
		iConsole.Printf(_L("X"));
sl@0
   225
	}
sl@0
   226
sl@0
   227
void CRSATestPrivateKey::PerformAction(TRequestStatus& aStatus)
sl@0
   228
	{
sl@0
   229
	__UHEAP_MARK;
sl@0
   230
	TRequestStatus* status = &aStatus;
sl@0
   231
	iResult = EFalse;
sl@0
   232
sl@0
   233
	TPtrC8 modIn = Input::ParseElement(*iBody, KModStart, KModEnd);
sl@0
   234
    RInteger mod = VectorUtils::ParseIntegerL(modIn);
sl@0
   235
	CleanupStack::PushL(mod);
sl@0
   236
sl@0
   237
	TPtrC8 expIn = Input::ParseElement(*iBody, KPrivExpStart, KPrivExpEnd);
sl@0
   238
    RInteger exp = VectorUtils::ParseIntegerL(expIn);
sl@0
   239
	CleanupStack::PushL(exp);
sl@0
   240
sl@0
   241
sl@0
   242
	CRSAPrivateKeyStandard* key = NULL;
sl@0
   243
	TRAPD(err, key = CRSAPrivateKeyStandard::NewL(mod, exp));
sl@0
   244
	if(err == iExpectedReturnValue)
sl@0
   245
		{
sl@0
   246
		iResult=ETrue;
sl@0
   247
		}
sl@0
   248
	else
sl@0
   249
		{
sl@0
   250
		iOut.writeString(_L("CRSAPrivateKey construction did not return expected result\n"));
sl@0
   251
		}
sl@0
   252
	if(err != KErrNone)
sl@0
   253
		{
sl@0
   254
		CleanupStack::PopAndDestroy(2);
sl@0
   255
		}
sl@0
   256
	else
sl@0
   257
		{
sl@0
   258
		CleanupStack::PushL(key);
sl@0
   259
		CleanupStack::PopAndDestroy(3);	
sl@0
   260
		}
sl@0
   261
		
sl@0
   262
	User::RequestComplete(status, KErrNone);
sl@0
   263
	iActionState = CTestAction::EPostrequisite;
sl@0
   264
	__UHEAP_MARKEND;
sl@0
   265
	}
sl@0
   266
sl@0
   267
CTestAction* CRSATestPrivateKeyCRT::NewL(RFs& aFs, CConsoleBase& aConsole, Output& aOut, 
sl@0
   268
	const TTestActionSpec& aTestActionSpec)
sl@0
   269
	{
sl@0
   270
	CTestAction* self = CRSATestPrivateKeyCRT::NewLC(aFs, aConsole,
sl@0
   271
		aOut, aTestActionSpec);
sl@0
   272
	CleanupStack::Pop();
sl@0
   273
	return self;
sl@0
   274
	}
sl@0
   275
sl@0
   276
CTestAction* CRSATestPrivateKeyCRT::NewLC(RFs& aFs, CConsoleBase& aConsole, Output& aOut, 
sl@0
   277
	const TTestActionSpec& aTestActionSpec)
sl@0
   278
	{
sl@0
   279
	CRSATestPrivateKeyCRT* self = new(ELeave) CRSATestPrivateKeyCRT(aFs, aConsole, aOut);
sl@0
   280
	CleanupStack::PushL(self);
sl@0
   281
	self->ConstructL(aTestActionSpec);
sl@0
   282
	return self;
sl@0
   283
	}
sl@0
   284
sl@0
   285
CRSATestPrivateKeyCRT::~CRSATestPrivateKeyCRT()
sl@0
   286
	{
sl@0
   287
	delete iBody;
sl@0
   288
	}
sl@0
   289
sl@0
   290
CRSATestPrivateKeyCRT::CRSATestPrivateKeyCRT(RFs& aFs, CConsoleBase& aConsole, Output& aOut)
sl@0
   291
	: CTestAction(aConsole, aOut), iFs(aFs)
sl@0
   292
	{
sl@0
   293
	}
sl@0
   294
sl@0
   295
void CRSATestPrivateKeyCRT::ConstructL(const TTestActionSpec& aTestActionSpec)
sl@0
   296
	{
sl@0
   297
	CTestAction::ConstructL(aTestActionSpec);
sl@0
   298
	iBody = HBufC8::NewL(aTestActionSpec.iActionBody.Length());
sl@0
   299
	iBody->Des().Copy(aTestActionSpec.iActionBody);
sl@0
   300
sl@0
   301
	iExpectedReturnValue = KErrNone;
sl@0
   302
	TPtrC8 returnValue = Input::ParseElement(aTestActionSpec.iActionResult, KReturnCodeStart, KReturnCodeEnd);
sl@0
   303
	if(returnValue.Compare(KErrArgumentString) == 0)
sl@0
   304
		{
sl@0
   305
		iExpectedReturnValue = KErrArgument;
sl@0
   306
		}
sl@0
   307
sl@0
   308
	}
sl@0
   309
sl@0
   310
void CRSATestPrivateKeyCRT::DoPerformPrerequisite(TRequestStatus& aStatus)
sl@0
   311
	{
sl@0
   312
	TRequestStatus* status = &aStatus;
sl@0
   313
	User::RequestComplete(status, KErrNone);
sl@0
   314
	iActionState = CTestAction::EAction;
sl@0
   315
	}
sl@0
   316
sl@0
   317
void CRSATestPrivateKeyCRT::DoPerformPostrequisite(TRequestStatus& aStatus)
sl@0
   318
	{
sl@0
   319
	TRequestStatus* status = &aStatus;
sl@0
   320
sl@0
   321
	iFinished = ETrue;
sl@0
   322
	User::RequestComplete(status, KErrNone);
sl@0
   323
	}
sl@0
   324
sl@0
   325
void CRSATestPrivateKeyCRT::DoReportAction(void)
sl@0
   326
	{
sl@0
   327
	}
sl@0
   328
sl@0
   329
void CRSATestPrivateKeyCRT::DoCheckResult(TInt)
sl@0
   330
	{
sl@0
   331
	if (iResult)
sl@0
   332
		iConsole.Printf(_L("."));
sl@0
   333
	else
sl@0
   334
		iConsole.Printf(_L("X"));
sl@0
   335
	}
sl@0
   336
sl@0
   337
void CRSATestPrivateKeyCRT::PerformAction(TRequestStatus& aStatus)
sl@0
   338
	{
sl@0
   339
	__UHEAP_MARK;
sl@0
   340
	TRequestStatus* status = &aStatus;
sl@0
   341
	iResult = EFalse;
sl@0
   342
sl@0
   343
	TPtrC8 modIn = Input::ParseElement(*iBody, KModStart, KModEnd);
sl@0
   344
    RInteger mod = VectorUtils::ParseIntegerL(modIn);
sl@0
   345
	CleanupStack::PushL(mod);
sl@0
   346
sl@0
   347
	TPtrC8 PIn = Input::ParseElement(*iBody, KPStart, KPEnd);
sl@0
   348
    RInteger P = VectorUtils::ParseIntegerL(PIn);
sl@0
   349
	CleanupStack::PushL(P);
sl@0
   350
sl@0
   351
	TPtrC8 QIn = Input::ParseElement(*iBody, KQStart, KQEnd);
sl@0
   352
    RInteger Q = VectorUtils::ParseIntegerL(QIn);
sl@0
   353
	CleanupStack::PushL(Q);
sl@0
   354
sl@0
   355
	TPtrC8 dPIn = Input::ParseElement(*iBody, KdPStart, KdPEnd);
sl@0
   356
    RInteger dP = VectorUtils::ParseIntegerL(dPIn);
sl@0
   357
	CleanupStack::PushL(dP);
sl@0
   358
sl@0
   359
	TPtrC8 dQIn = Input::ParseElement(*iBody, KdQStart, KdQEnd);
sl@0
   360
    RInteger dQ = VectorUtils::ParseIntegerL(dQIn);
sl@0
   361
	CleanupStack::PushL(dQ);
sl@0
   362
sl@0
   363
	TPtrC8 QInvIn = Input::ParseElement(*iBody, KqInvStart, KqInvEnd);
sl@0
   364
    RInteger QInv = VectorUtils::ParseIntegerL(QInvIn);
sl@0
   365
	CleanupStack::PushL(QInv);
sl@0
   366
sl@0
   367
sl@0
   368
	CRSAPrivateKeyCRT* key = NULL;
sl@0
   369
	TRAPD(err, key = CRSAPrivateKeyCRT::NewL(mod, P, Q, dP, dQ, QInv));
sl@0
   370
	if(err == iExpectedReturnValue)
sl@0
   371
		{
sl@0
   372
		iResult=ETrue;
sl@0
   373
		}
sl@0
   374
	else
sl@0
   375
		{
sl@0
   376
		iOut.writeString(_L("CRSAPrivateKeyCRT construction did not return expected result\n"));
sl@0
   377
		}
sl@0
   378
	if(err != KErrNone)
sl@0
   379
		{
sl@0
   380
		CleanupStack::PopAndDestroy(6);
sl@0
   381
		}
sl@0
   382
	else
sl@0
   383
		{
sl@0
   384
		CleanupStack::PushL(key);
sl@0
   385
		CleanupStack::PopAndDestroy(7);	
sl@0
   386
		}
sl@0
   387
		
sl@0
   388
	User::RequestComplete(status, KErrNone);
sl@0
   389
	iActionState = CTestAction::EPostrequisite;
sl@0
   390
	__UHEAP_MARKEND;
sl@0
   391
	}
sl@0
   392