os/security/crypto/weakcryptospi/test/tcryptospi/src/dummyecccipherloadstep.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/security/crypto/weakcryptospi/test/tcryptospi/src/dummyecccipherloadstep.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,151 @@
     1.4 +/*
     1.5 +* Copyright (c) 2009-2010 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 +* Example CTestStep derived implementation
    1.19 +*
    1.20 +*/
    1.21 +
    1.22 +
    1.23 +/**
    1.24 + @file
    1.25 + @internalTechnology
    1.26 +*/
    1.27 +#include "dummyecccipherloadstep.h"
    1.28 +
    1.29 +#include <cryptospi/cryptoasymmetriccipherapi.h>
    1.30 +#include <cryptospi/cryptokeypairgeneratorapi.h>
    1.31 +#include <cryptospi/keypair.h>
    1.32 +#include "filereader.h"
    1.33 +
    1.34 +using namespace CryptoSpi;
    1.35 +
    1.36 +CDummyEccCipherLoadStep::~CDummyEccCipherLoadStep()
    1.37 +	{
    1.38 +	}
    1.39 +
    1.40 +
    1.41 +CDummyEccCipherLoadStep::CDummyEccCipherLoadStep()
    1.42 +	{
    1.43 +	SetTestStepName(KDummyEccCipherLoadStep);
    1.44 +	}
    1.45 +
    1.46 +
    1.47 +TVerdict CDummyEccCipherLoadStep::doTestStepPreambleL()
    1.48 +	{
    1.49 +	SetTestStepResult(EPass);
    1.50 +	return TestStepResult();
    1.51 +	}
    1.52 +
    1.53 +
    1.54 +TVerdict CDummyEccCipherLoadStep::doTestStepL()
    1.55 +	{
    1.56 +
    1.57 +	INFO_PRINTF1(_L("*** Dummy Ecc Cipher - Load ***"));
    1.58 +	INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
    1.59 +	
    1.60 +    //Assume failure, unless all is successful
    1.61 +    SetTestStepResult(EFail);
    1.62 +    
    1.63 +    TVariantPtrC algorithm;
    1.64 +    TVariantPtrC paddingMode;
    1.65 +    
    1.66 +    if(!GetStringFromConfig(ConfigSection(),KConfigAlgorithmUid, algorithm) || 
    1.67 +        !GetStringFromConfig(ConfigSection(),KConfigPaddingMode, paddingMode ))
    1.68 +        {
    1.69 +        ERR_PRINTF1(_L("*** FAIL: Algorithm id or padding mode is missing ***"));
    1.70 +        User::Leave(KErrNotFound);
    1.71 +        }
    1.72 +    INFO_PRINTF1(_L("Generating dummy ECC keys"));
    1.73 +          
    1.74 +    /**
    1.75 +     * Note that we are actually generating RSA keys in place 
    1.76 +     * of ECC keys here. The reason for that is we do not have 
    1.77 +     * a working ECC implementation. This test case just tests 
    1.78 +     * if dummyecc cipher is getting loaded. This is being 
    1.79 +     * tested since algorithm is set to KAlgorithmCipherEcc. 
    1.80 +     * Keys have no significance in this test case.
    1.81 +     */
    1.82 +    CCryptoParams* keyParams = CCryptoParams::NewLC(); 
    1.83 +    keyParams->AddL(KKeyExponent, KRsaKeyParameterEUid);
    1.84 +    keyParams->AddL(KRsaPrivateKeyStandard, KRsaKeyTypeUid);
    1.85 +
    1.86 +    //Create Key Pair Generator Objects
    1.87 +    CKeyPairGenerator * keypairImpl = NULL;
    1.88 +            
    1.89 +    // create a key pair generator implementation interface
    1.90 +    TRAPD_LOG(err,CKeyPairGeneratorFactory::CreateKeyPairGeneratorL(
    1.91 +                                    keypairImpl, 
    1.92 +                                    KRSAKeyPairGeneratorUid, 
    1.93 +                                    keyParams));
    1.94 +    if(err != KErrNone)
    1.95 +        {
    1.96 +        ERR_PRINTF1(_L("*** FAIL: Failed to Create generator impl interface ***"));
    1.97 +        CleanupStack::PopAndDestroy(keyParams);
    1.98 +        return EFail;
    1.99 +        }
   1.100 +    CleanupStack::PushL(keypairImpl);
   1.101 +
   1.102 +    // Create a Key Pair
   1.103 +    CKeyPair* keyPair = NULL;
   1.104 +    TRAP_LOG(err,keypairImpl->GenerateKeyPairL(1024, *keyParams, keyPair));
   1.105 +    if(err != KErrNone)
   1.106 +        {
   1.107 +        ERR_PRINTF1(_L("*** FAIL: Failed to Create key pair ***"));
   1.108 +        CleanupStack::PopAndDestroy(keypairImpl);
   1.109 +        CleanupStack::PopAndDestroy(keyParams);
   1.110 +        return EFail;
   1.111 +        }
   1.112 +    CleanupStack::PushL(keyPair);
   1.113 +    
   1.114 +    //*****************************************************
   1.115 +
   1.116 +    INFO_PRINTF1(_L("Creating Dummy ECC Cipher Object..."));
   1.117 +    
   1.118 +    CryptoSpi::CAsymmetricCipher * impl = NULL;
   1.119 +        
   1.120 +    TRAP(err,CAsymmetricCipherFactory::CreateAsymmetricCipherL
   1.121 +                                        (
   1.122 +                                        impl,
   1.123 +                                        algorithm,
   1.124 +                                        keyPair->PrivateKey(),
   1.125 +                                        KCryptoModeDecryptUid,
   1.126 +                                        paddingMode,
   1.127 +                                        NULL));
   1.128 +
   1.129 +    if(err == KErrNone)
   1.130 +        {
   1.131 +        delete impl;
   1.132 +        INFO_PRINTF1(_L("*** Dummy Ecc Cipher - Load: PASS ***"));
   1.133 +        SetTestStepResult(EPass);
   1.134 +        }
   1.135 +    else
   1.136 +        {
   1.137 +        ERR_PRINTF2(_L("*** FAIL: Failed to Create dummy Ecc Cipher Object - %d ***"), err);
   1.138 +        }
   1.139 +
   1.140 +    CleanupStack::PopAndDestroy(keyPair);
   1.141 +    CleanupStack::PopAndDestroy(keypairImpl);			
   1.142 +    CleanupStack::PopAndDestroy(keyParams);
   1.143 +		
   1.144 +	INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
   1.145 +
   1.146 +	return TestStepResult();
   1.147 +	}
   1.148 +
   1.149 +
   1.150 +
   1.151 +TVerdict CDummyEccCipherLoadStep::doTestStepPostambleL()
   1.152 +	{
   1.153 +	return TestStepResult();
   1.154 +	}