1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/security/crypto/weakcryptospi/test/tasymmetric/tasymmetricmisc.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,156 @@
1.4 +/*
1.5 +* Copyright (c) 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 +#include "tasymmetricmisc.h"
1.23 +#include "t_input.h"
1.24 +#include <asymmetric.h>
1.25 +#include <random.h>
1.26 +#include <padding.h>
1.27 +#include <bigint.h>
1.28 +#include "tbrokenrandom.h"
1.29 +
1.30 +enum TActionMode {EDHKeyPair = 1, EDHPrivateKey =2, EDHPublicKey =3};
1.31 +
1.32 +CTestAction* CAsymmetricMiscellaneous::NewL(RFs& aFs, CConsoleBase& aConsole, Output& aOut,
1.33 + const TTestActionSpec& aTestActionSpec)
1.34 + {
1.35 + CTestAction* self = CAsymmetricMiscellaneous::NewLC(aFs, aConsole,
1.36 + aOut, aTestActionSpec);
1.37 + CleanupStack::Pop();
1.38 + return self;
1.39 + }
1.40 +
1.41 +CTestAction* CAsymmetricMiscellaneous::NewLC(RFs& aFs, CConsoleBase& aConsole, Output& aOut,
1.42 + const TTestActionSpec& aTestActionSpec)
1.43 + {
1.44 + CAsymmetricMiscellaneous* self = new(ELeave) CAsymmetricMiscellaneous(aFs, aConsole, aOut);
1.45 + CleanupStack::PushL(self);
1.46 + self->ConstructL(aTestActionSpec);
1.47 + return self;
1.48 + }
1.49 +
1.50 +CAsymmetricMiscellaneous::~CAsymmetricMiscellaneous()
1.51 + {
1.52 + delete iBody;
1.53 + }
1.54 +
1.55 +CAsymmetricMiscellaneous::CAsymmetricMiscellaneous(RFs& aFs, CConsoleBase& aConsole, Output& aOut)
1.56 + : CTestAction(aConsole, aOut), iFs(aFs)
1.57 + {
1.58 + }
1.59 +
1.60 +void CAsymmetricMiscellaneous::ConstructL(const TTestActionSpec& aTestActionSpec)
1.61 + {
1.62 + CTestAction::ConstructL(aTestActionSpec);
1.63 + iBody = HBufC8::NewL(aTestActionSpec.iActionBody.Length());
1.64 + iBody->Des().Copy(aTestActionSpec.iActionBody);
1.65 +
1.66 + iActionMode = Input::ParseIntElement(*iBody, _L8("<actionmode>"), _L8("</actionmode>"));
1.67 +
1.68 + HBufC8* g = Input::ParseElementHexL(*iBody, _L8("<g>"));
1.69 + CleanupStack::PushL(g);
1.70 + iG = RInteger::NewL(*g);
1.71 + CleanupStack::PopAndDestroy(g);
1.72 +
1.73 + HBufC8* n = Input::ParseElementHexL(*iBody, _L8("<n>"));
1.74 + CleanupStack::PushL(n);
1.75 + iN = RInteger::NewL(*n);
1.76 + CleanupStack::PopAndDestroy(n);
1.77 +
1.78 + HBufC8* x = Input::ParseElementHexL(*iBody, _L8("<x>"));
1.79 + CleanupStack::PushL(x);
1.80 + iX = RInteger::NewL(*x);
1.81 + CleanupStack::PopAndDestroy(x);
1.82 + }
1.83 +
1.84 +void CAsymmetricMiscellaneous::DoPerformPrerequisite(TRequestStatus& aStatus)
1.85 + {
1.86 + TRequestStatus* status = &aStatus;
1.87 + User::RequestComplete(status, KErrNone);
1.88 + iActionState = CTestAction::EAction;
1.89 + }
1.90 +
1.91 +void CAsymmetricMiscellaneous::DoPerformPostrequisite(TRequestStatus& aStatus)
1.92 + {
1.93 + TRequestStatus* status = &aStatus;
1.94 +
1.95 + iFinished = ETrue;
1.96 + User::RequestComplete(status, KErrNone);
1.97 + }
1.98 +
1.99 +void CAsymmetricMiscellaneous::DoReportAction(void)
1.100 + {
1.101 + }
1.102 +
1.103 +void CAsymmetricMiscellaneous::DoCheckResult(TInt)
1.104 + {
1.105 + if (iResult)
1.106 + iConsole.Printf(_L("."));
1.107 + else
1.108 + iConsole.Printf(_L("X"));
1.109 + }
1.110 +
1.111 +void CAsymmetricMiscellaneous::PerformAction(TRequestStatus& aStatus)
1.112 + {
1.113 + __UHEAP_MARK;
1.114 + TRequestStatus* status = &aStatus;
1.115 + iResult = ETrue;
1.116 +
1.117 + // Construction of dummy objects just to cover the left over methods.
1.118 + switch (iActionMode)
1.119 + {
1.120 + case EDHKeyPair:
1.121 + {
1.122 + CDHKeyPair* dhKeyPair = CDHKeyPair::NewLC(iN, iG, iX);
1.123 + if (dhKeyPair == NULL)
1.124 + {
1.125 + iResult = EFalse;
1.126 + }
1.127 + CleanupStack::PopAndDestroy(dhKeyPair);
1.128 + }
1.129 + break;
1.130 +
1.131 + case EDHPrivateKey:
1.132 + {
1.133 + CDHPrivateKey* dhPrivateKey = CDHPrivateKey::NewLC(iN, iG, iX);
1.134 + if (dhPrivateKey == NULL)
1.135 + {
1.136 + iResult = EFalse;
1.137 + }
1.138 + CleanupStack::PopAndDestroy(dhPrivateKey);
1.139 + }
1.140 + break;
1.141 +
1.142 + case EDHPublicKey:
1.143 + {
1.144 + CDHPublicKey* dhPublicKeyPtr = CDHPublicKey::NewLC(iN, iG, iX);
1.145 + if (dhPublicKeyPtr == NULL)
1.146 + {
1.147 + iResult = EFalse;
1.148 + }
1.149 + CleanupStack::PopAndDestroy(dhPublicKeyPtr);
1.150 + }
1.151 + break;
1.152 +
1.153 + default:
1.154 + break;
1.155 + }
1.156 + User::RequestComplete(status, KErrNone);
1.157 + iActionState = CTestAction::EPostrequisite;
1.158 + __UHEAP_MARKEND;
1.159 + }