os/security/crypto/weakcrypto/test/tasymmetric/trsaparams.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/security/crypto/weakcrypto/test/tasymmetric/trsaparams.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,392 @@
     1.4 +/*
     1.5 +* Copyright (c) 1998-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 +* tdsasignfb.cpp
    1.19 +*
    1.20 +*/
    1.21 +
    1.22 +
    1.23 +#include "t_input.h"
    1.24 +#include "t_output.h"
    1.25 +#include <asymmetric.h>
    1.26 +#include "tvectorutils.h"
    1.27 +#include "trsaparams.h"
    1.28 +
    1.29 +_LIT8(KModStart, "<modulus>");
    1.30 +_LIT8(KModEnd, "</modulus>");
    1.31 +_LIT8(KPubExpStart, "<publicExponent>");
    1.32 +_LIT8(KPubExpEnd, "</publicExponent>");
    1.33 +_LIT8(KPrivExpStart, "<privateExponent>");
    1.34 +_LIT8(KPrivExpEnd, "</privateExponent>");
    1.35 +_LIT8(KPStart, "<P>");
    1.36 +_LIT8(KPEnd, "</P>");
    1.37 +_LIT8(KQStart, "<Q>");
    1.38 +_LIT8(KQEnd, "</Q>");
    1.39 +_LIT8(KdPStart, "<dP>");
    1.40 +_LIT8(KdPEnd, "</dP>");
    1.41 +_LIT8(KdQStart, "<dQ>");
    1.42 +_LIT8(KdQEnd, "</dQ>");
    1.43 +_LIT8(KqInvStart, "<qInv>");
    1.44 +_LIT8(KqInvEnd, "</qInv>");
    1.45 +_LIT8(KReturnCodeStart, "<return>");
    1.46 +_LIT8(KReturnCodeEnd, "</return>");
    1.47 +_LIT8(KErrArgumentString, "KErrArgument");
    1.48 +
    1.49 +CTestAction* CRSATestPublicKey::NewL(RFs& aFs, CConsoleBase& aConsole, Output& aOut, 
    1.50 +	const TTestActionSpec& aTestActionSpec)
    1.51 +	{
    1.52 +	CTestAction* self = CRSATestPublicKey::NewLC(aFs, aConsole,
    1.53 +		aOut, aTestActionSpec);
    1.54 +	CleanupStack::Pop();
    1.55 +	return self;
    1.56 +	}
    1.57 +
    1.58 +CTestAction* CRSATestPublicKey::NewLC(RFs& aFs, CConsoleBase& aConsole, Output& aOut, 
    1.59 +	const TTestActionSpec& aTestActionSpec)
    1.60 +	{
    1.61 +	CRSATestPublicKey* self = new(ELeave) CRSATestPublicKey(aFs, aConsole, aOut);
    1.62 +	CleanupStack::PushL(self);
    1.63 +	self->ConstructL(aTestActionSpec);
    1.64 +	return self;
    1.65 +	}
    1.66 +
    1.67 +CRSATestPublicKey::~CRSATestPublicKey()
    1.68 +	{
    1.69 +	delete iBody;
    1.70 +	}
    1.71 +
    1.72 +CRSATestPublicKey::CRSATestPublicKey(RFs& aFs, CConsoleBase& aConsole, Output& aOut)
    1.73 +	: CTestAction(aConsole, aOut), iFs(aFs)
    1.74 +	{
    1.75 +	}
    1.76 +
    1.77 +void CRSATestPublicKey::ConstructL(const TTestActionSpec& aTestActionSpec)
    1.78 +	{
    1.79 +	CTestAction::ConstructL(aTestActionSpec);
    1.80 +	iBody = HBufC8::NewL(aTestActionSpec.iActionBody.Length());
    1.81 +	iBody->Des().Copy(aTestActionSpec.iActionBody);
    1.82 +
    1.83 +	iExpectedReturnValue = KErrNone;
    1.84 +	TPtrC8 returnValue = Input::ParseElement(aTestActionSpec.iActionResult, KReturnCodeStart, KReturnCodeEnd);
    1.85 +	if(returnValue.Compare(KErrArgumentString) == 0)
    1.86 +		{
    1.87 +		iExpectedReturnValue = KErrArgument;
    1.88 +		}
    1.89 +
    1.90 +	}
    1.91 +
    1.92 +void CRSATestPublicKey::DoPerformPrerequisite(TRequestStatus& aStatus)
    1.93 +	{
    1.94 +	TRequestStatus* status = &aStatus;
    1.95 +	User::RequestComplete(status, KErrNone);
    1.96 +	iActionState = CTestAction::EAction;
    1.97 +	}
    1.98 +
    1.99 +void CRSATestPublicKey::DoPerformPostrequisite(TRequestStatus& aStatus)
   1.100 +	{
   1.101 +	TRequestStatus* status = &aStatus;
   1.102 +
   1.103 +	iFinished = ETrue;
   1.104 +	User::RequestComplete(status, KErrNone);
   1.105 +	}
   1.106 +
   1.107 +void CRSATestPublicKey::DoReportAction(void)
   1.108 +	{
   1.109 +	}
   1.110 +
   1.111 +void CRSATestPublicKey::DoCheckResult(TInt)
   1.112 +	{
   1.113 +	if (iResult)
   1.114 +		iConsole.Printf(_L("."));
   1.115 +	else
   1.116 +		iConsole.Printf(_L("X"));
   1.117 +	}
   1.118 +
   1.119 +void CRSATestPublicKey::PerformAction(TRequestStatus& aStatus)
   1.120 +	{
   1.121 +	__UHEAP_MARK;
   1.122 +	TRequestStatus* status = &aStatus;
   1.123 +	iResult = EFalse;
   1.124 +
   1.125 +	TPtrC8 modIn = Input::ParseElement(*iBody, KModStart, KModEnd);
   1.126 +    RInteger mod = VectorUtils::ParseIntegerL(modIn);
   1.127 +	CleanupStack::PushL(mod);
   1.128 +
   1.129 +	TPtrC8 expIn = Input::ParseElement(*iBody, KPubExpStart, KPubExpEnd);
   1.130 +    RInteger exp = VectorUtils::ParseIntegerL(expIn);
   1.131 +	CleanupStack::PushL(exp);
   1.132 +
   1.133 +
   1.134 +	CRSAPublicKey* key = NULL;
   1.135 +	TRAPD(err, key = CRSAPublicKey::NewL(mod, exp));
   1.136 +	if(err == iExpectedReturnValue)
   1.137 +		{
   1.138 +		iResult=ETrue;
   1.139 +		}
   1.140 +	else
   1.141 +		{
   1.142 +		iOut.writeString(_L("CRSAPublicKey construction did not return expected result\n"));
   1.143 +		}
   1.144 +	if(err != KErrNone)
   1.145 +		{
   1.146 +		CleanupStack::PopAndDestroy(2);
   1.147 +		}
   1.148 +	else
   1.149 +		{
   1.150 +		CleanupStack::PushL(key);
   1.151 +		CleanupStack::PopAndDestroy(3);	
   1.152 +		}
   1.153 +		
   1.154 +	User::RequestComplete(status, KErrNone);
   1.155 +	iActionState = CTestAction::EPostrequisite;
   1.156 +	__UHEAP_MARKEND;
   1.157 +	}
   1.158 +
   1.159 +
   1.160 +CTestAction* CRSATestPrivateKey::NewL(RFs& aFs, CConsoleBase& aConsole, Output& aOut, 
   1.161 +	const TTestActionSpec& aTestActionSpec)
   1.162 +	{
   1.163 +	CTestAction* self = CRSATestPrivateKey::NewLC(aFs, aConsole,
   1.164 +		aOut, aTestActionSpec);
   1.165 +	CleanupStack::Pop();
   1.166 +	return self;
   1.167 +	}
   1.168 +
   1.169 +CTestAction* CRSATestPrivateKey::NewLC(RFs& aFs, CConsoleBase& aConsole, Output& aOut, 
   1.170 +	const TTestActionSpec& aTestActionSpec)
   1.171 +	{
   1.172 +	CRSATestPrivateKey* self = new(ELeave) CRSATestPrivateKey(aFs, aConsole, aOut);
   1.173 +	CleanupStack::PushL(self);
   1.174 +	self->ConstructL(aTestActionSpec);
   1.175 +	return self;
   1.176 +	}
   1.177 +
   1.178 +CRSATestPrivateKey::~CRSATestPrivateKey()
   1.179 +	{
   1.180 +	delete iBody;
   1.181 +	}
   1.182 +
   1.183 +CRSATestPrivateKey::CRSATestPrivateKey(RFs& aFs, CConsoleBase& aConsole, Output& aOut)
   1.184 +	: CTestAction(aConsole, aOut), iFs(aFs)
   1.185 +	{
   1.186 +	}
   1.187 +
   1.188 +void CRSATestPrivateKey::ConstructL(const TTestActionSpec& aTestActionSpec)
   1.189 +	{
   1.190 +	CTestAction::ConstructL(aTestActionSpec);
   1.191 +	iBody = HBufC8::NewL(aTestActionSpec.iActionBody.Length());
   1.192 +	iBody->Des().Copy(aTestActionSpec.iActionBody);
   1.193 +
   1.194 +	iExpectedReturnValue = KErrNone;
   1.195 +	TPtrC8 returnValue = Input::ParseElement(aTestActionSpec.iActionResult, KReturnCodeStart, KReturnCodeEnd);
   1.196 +	if(returnValue.Compare(KErrArgumentString) == 0)
   1.197 +		{
   1.198 +		iExpectedReturnValue = KErrArgument;
   1.199 +		}
   1.200 +
   1.201 +	}
   1.202 +
   1.203 +void CRSATestPrivateKey::DoPerformPrerequisite(TRequestStatus& aStatus)
   1.204 +	{
   1.205 +	TRequestStatus* status = &aStatus;
   1.206 +	User::RequestComplete(status, KErrNone);
   1.207 +	iActionState = CTestAction::EAction;
   1.208 +	}
   1.209 +
   1.210 +void CRSATestPrivateKey::DoPerformPostrequisite(TRequestStatus& aStatus)
   1.211 +	{
   1.212 +	TRequestStatus* status = &aStatus;
   1.213 +
   1.214 +	iFinished = ETrue;
   1.215 +	User::RequestComplete(status, KErrNone);
   1.216 +	}
   1.217 +
   1.218 +void CRSATestPrivateKey::DoReportAction(void)
   1.219 +	{
   1.220 +	}
   1.221 +
   1.222 +void CRSATestPrivateKey::DoCheckResult(TInt)
   1.223 +	{
   1.224 +	if (iResult)
   1.225 +		iConsole.Printf(_L("."));
   1.226 +	else
   1.227 +		iConsole.Printf(_L("X"));
   1.228 +	}
   1.229 +
   1.230 +void CRSATestPrivateKey::PerformAction(TRequestStatus& aStatus)
   1.231 +	{
   1.232 +	__UHEAP_MARK;
   1.233 +	TRequestStatus* status = &aStatus;
   1.234 +	iResult = EFalse;
   1.235 +
   1.236 +	TPtrC8 modIn = Input::ParseElement(*iBody, KModStart, KModEnd);
   1.237 +    RInteger mod = VectorUtils::ParseIntegerL(modIn);
   1.238 +	CleanupStack::PushL(mod);
   1.239 +
   1.240 +	TPtrC8 expIn = Input::ParseElement(*iBody, KPrivExpStart, KPrivExpEnd);
   1.241 +    RInteger exp = VectorUtils::ParseIntegerL(expIn);
   1.242 +	CleanupStack::PushL(exp);
   1.243 +
   1.244 +
   1.245 +	CRSAPrivateKeyStandard* key = NULL;
   1.246 +	TRAPD(err, key = CRSAPrivateKeyStandard::NewL(mod, exp));
   1.247 +	if(err == iExpectedReturnValue)
   1.248 +		{
   1.249 +		iResult=ETrue;
   1.250 +		}
   1.251 +	else
   1.252 +		{
   1.253 +		iOut.writeString(_L("CRSAPrivateKey construction did not return expected result\n"));
   1.254 +		}
   1.255 +	if(err != KErrNone)
   1.256 +		{
   1.257 +		CleanupStack::PopAndDestroy(2);
   1.258 +		}
   1.259 +	else
   1.260 +		{
   1.261 +		CleanupStack::PushL(key);
   1.262 +		CleanupStack::PopAndDestroy(3);	
   1.263 +		}
   1.264 +		
   1.265 +	User::RequestComplete(status, KErrNone);
   1.266 +	iActionState = CTestAction::EPostrequisite;
   1.267 +	__UHEAP_MARKEND;
   1.268 +	}
   1.269 +
   1.270 +CTestAction* CRSATestPrivateKeyCRT::NewL(RFs& aFs, CConsoleBase& aConsole, Output& aOut, 
   1.271 +	const TTestActionSpec& aTestActionSpec)
   1.272 +	{
   1.273 +	CTestAction* self = CRSATestPrivateKeyCRT::NewLC(aFs, aConsole,
   1.274 +		aOut, aTestActionSpec);
   1.275 +	CleanupStack::Pop();
   1.276 +	return self;
   1.277 +	}
   1.278 +
   1.279 +CTestAction* CRSATestPrivateKeyCRT::NewLC(RFs& aFs, CConsoleBase& aConsole, Output& aOut, 
   1.280 +	const TTestActionSpec& aTestActionSpec)
   1.281 +	{
   1.282 +	CRSATestPrivateKeyCRT* self = new(ELeave) CRSATestPrivateKeyCRT(aFs, aConsole, aOut);
   1.283 +	CleanupStack::PushL(self);
   1.284 +	self->ConstructL(aTestActionSpec);
   1.285 +	return self;
   1.286 +	}
   1.287 +
   1.288 +CRSATestPrivateKeyCRT::~CRSATestPrivateKeyCRT()
   1.289 +	{
   1.290 +	delete iBody;
   1.291 +	}
   1.292 +
   1.293 +CRSATestPrivateKeyCRT::CRSATestPrivateKeyCRT(RFs& aFs, CConsoleBase& aConsole, Output& aOut)
   1.294 +	: CTestAction(aConsole, aOut), iFs(aFs)
   1.295 +	{
   1.296 +	}
   1.297 +
   1.298 +void CRSATestPrivateKeyCRT::ConstructL(const TTestActionSpec& aTestActionSpec)
   1.299 +	{
   1.300 +	CTestAction::ConstructL(aTestActionSpec);
   1.301 +	iBody = HBufC8::NewL(aTestActionSpec.iActionBody.Length());
   1.302 +	iBody->Des().Copy(aTestActionSpec.iActionBody);
   1.303 +
   1.304 +	iExpectedReturnValue = KErrNone;
   1.305 +	TPtrC8 returnValue = Input::ParseElement(aTestActionSpec.iActionResult, KReturnCodeStart, KReturnCodeEnd);
   1.306 +	if(returnValue.Compare(KErrArgumentString) == 0)
   1.307 +		{
   1.308 +		iExpectedReturnValue = KErrArgument;
   1.309 +		}
   1.310 +
   1.311 +	}
   1.312 +
   1.313 +void CRSATestPrivateKeyCRT::DoPerformPrerequisite(TRequestStatus& aStatus)
   1.314 +	{
   1.315 +	TRequestStatus* status = &aStatus;
   1.316 +	User::RequestComplete(status, KErrNone);
   1.317 +	iActionState = CTestAction::EAction;
   1.318 +	}
   1.319 +
   1.320 +void CRSATestPrivateKeyCRT::DoPerformPostrequisite(TRequestStatus& aStatus)
   1.321 +	{
   1.322 +	TRequestStatus* status = &aStatus;
   1.323 +
   1.324 +	iFinished = ETrue;
   1.325 +	User::RequestComplete(status, KErrNone);
   1.326 +	}
   1.327 +
   1.328 +void CRSATestPrivateKeyCRT::DoReportAction(void)
   1.329 +	{
   1.330 +	}
   1.331 +
   1.332 +void CRSATestPrivateKeyCRT::DoCheckResult(TInt)
   1.333 +	{
   1.334 +	if (iResult)
   1.335 +		iConsole.Printf(_L("."));
   1.336 +	else
   1.337 +		iConsole.Printf(_L("X"));
   1.338 +	}
   1.339 +
   1.340 +void CRSATestPrivateKeyCRT::PerformAction(TRequestStatus& aStatus)
   1.341 +	{
   1.342 +	__UHEAP_MARK;
   1.343 +	TRequestStatus* status = &aStatus;
   1.344 +	iResult = EFalse;
   1.345 +
   1.346 +	TPtrC8 modIn = Input::ParseElement(*iBody, KModStart, KModEnd);
   1.347 +    RInteger mod = VectorUtils::ParseIntegerL(modIn);
   1.348 +	CleanupStack::PushL(mod);
   1.349 +
   1.350 +	TPtrC8 PIn = Input::ParseElement(*iBody, KPStart, KPEnd);
   1.351 +    RInteger P = VectorUtils::ParseIntegerL(PIn);
   1.352 +	CleanupStack::PushL(P);
   1.353 +
   1.354 +	TPtrC8 QIn = Input::ParseElement(*iBody, KQStart, KQEnd);
   1.355 +    RInteger Q = VectorUtils::ParseIntegerL(QIn);
   1.356 +	CleanupStack::PushL(Q);
   1.357 +
   1.358 +	TPtrC8 dPIn = Input::ParseElement(*iBody, KdPStart, KdPEnd);
   1.359 +    RInteger dP = VectorUtils::ParseIntegerL(dPIn);
   1.360 +	CleanupStack::PushL(dP);
   1.361 +
   1.362 +	TPtrC8 dQIn = Input::ParseElement(*iBody, KdQStart, KdQEnd);
   1.363 +    RInteger dQ = VectorUtils::ParseIntegerL(dQIn);
   1.364 +	CleanupStack::PushL(dQ);
   1.365 +
   1.366 +	TPtrC8 QInvIn = Input::ParseElement(*iBody, KqInvStart, KqInvEnd);
   1.367 +    RInteger QInv = VectorUtils::ParseIntegerL(QInvIn);
   1.368 +	CleanupStack::PushL(QInv);
   1.369 +
   1.370 +
   1.371 +	CRSAPrivateKeyCRT* key = NULL;
   1.372 +	TRAPD(err, key = CRSAPrivateKeyCRT::NewL(mod, P, Q, dP, dQ, QInv));
   1.373 +	if(err == iExpectedReturnValue)
   1.374 +		{
   1.375 +		iResult=ETrue;
   1.376 +		}
   1.377 +	else
   1.378 +		{
   1.379 +		iOut.writeString(_L("CRSAPrivateKeyCRT construction did not return expected result\n"));
   1.380 +		}
   1.381 +	if(err != KErrNone)
   1.382 +		{
   1.383 +		CleanupStack::PopAndDestroy(6);
   1.384 +		}
   1.385 +	else
   1.386 +		{
   1.387 +		CleanupStack::PushL(key);
   1.388 +		CleanupStack::PopAndDestroy(7);	
   1.389 +		}
   1.390 +		
   1.391 +	User::RequestComplete(status, KErrNone);
   1.392 +	iActionState = CTestAction::EPostrequisite;
   1.393 +	__UHEAP_MARKEND;
   1.394 +	}
   1.395 +