crypto/weakcryptospi/test/tcryptospi/src/dummyecccipherloadstep.cpp
changeset 15 da2ae96f639b
child 43 2f10d260163b
equal deleted inserted replaced
10:afc583cfa176 15:da2ae96f639b
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 * Example CTestStep derived implementation
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 /**
       
    21  @file
       
    22  @internalTechnology
       
    23 */
       
    24 #include "dummyecccipherloadstep.h"
       
    25 
       
    26 #include "cryptoasymmetriccipherapi.h"
       
    27 #include "cryptokeypairgeneratorapi.h"
       
    28 #include "keypair.h"
       
    29 #include "filereader.h"
       
    30 
       
    31 using namespace CryptoSpi;
       
    32 
       
    33 CDummyEccCipherLoadStep::~CDummyEccCipherLoadStep()
       
    34 	{
       
    35 	}
       
    36 
       
    37 
       
    38 CDummyEccCipherLoadStep::CDummyEccCipherLoadStep()
       
    39 	{
       
    40 	SetTestStepName(KDummyEccCipherLoadStep);
       
    41 	}
       
    42 
       
    43 
       
    44 TVerdict CDummyEccCipherLoadStep::doTestStepPreambleL()
       
    45 	{
       
    46 	SetTestStepResult(EPass);
       
    47 	return TestStepResult();
       
    48 	}
       
    49 
       
    50 
       
    51 TVerdict CDummyEccCipherLoadStep::doTestStepL()
       
    52 	{
       
    53 
       
    54 	INFO_PRINTF1(_L("*** Dummy Ecc Cipher - Load ***"));
       
    55 	INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
       
    56 	
       
    57     //Assume failure, unless all is successful
       
    58     SetTestStepResult(EFail);
       
    59     
       
    60     TVariantPtrC algorithm;
       
    61     TVariantPtrC paddingMode;
       
    62     
       
    63     if(!GetStringFromConfig(ConfigSection(),KConfigAlgorithmUid, algorithm) || 
       
    64         !GetStringFromConfig(ConfigSection(),KConfigPaddingMode, paddingMode ))
       
    65         {
       
    66         ERR_PRINTF1(_L("*** FAIL: Algorithm id or padding mode is missing ***"));
       
    67         User::Leave(KErrNotFound);
       
    68         }
       
    69     INFO_PRINTF1(_L("Generating dummy ECC keys"));
       
    70           
       
    71     /**
       
    72      * Note that we are actually generating RSA keys in place 
       
    73      * of ECC keys here. The reason for that is we do not have 
       
    74      * a working ECC implementation. This test case just tests 
       
    75      * if dummyecc cipher is getting loaded. This is being 
       
    76      * tested since algorithm is set to KAlgorithmCipherEcc. 
       
    77      * Keys have no significance in this test case.
       
    78      */
       
    79     CCryptoParams* keyParams = CCryptoParams::NewLC(); 
       
    80     keyParams->AddL(KKeyExponent, KRsaKeyParameterEUid);
       
    81     keyParams->AddL(KRsaPrivateKeyStandard, KRsaKeyTypeUid);
       
    82 
       
    83     //Create Key Pair Generator Objects
       
    84     CKeyPairGenerator * keypairImpl = NULL;
       
    85             
       
    86     // create a key pair generator implementation interface
       
    87     TRAPD_LOG(err,CKeyPairGeneratorFactory::CreateKeyPairGeneratorL(
       
    88                                     keypairImpl, 
       
    89                                     KRSAKeyPairGeneratorUid, 
       
    90                                     keyParams));
       
    91     if(err != KErrNone)
       
    92         {
       
    93         ERR_PRINTF1(_L("*** FAIL: Failed to Create generator impl interface ***"));
       
    94         CleanupStack::PopAndDestroy(keyParams);
       
    95         return EFail;
       
    96         }
       
    97     CleanupStack::PushL(keypairImpl);
       
    98 
       
    99     // Create a Key Pair
       
   100     CKeyPair* keyPair = NULL;
       
   101     TRAP_LOG(err,keypairImpl->GenerateKeyPairL(1024, *keyParams, keyPair));
       
   102     if(err != KErrNone)
       
   103         {
       
   104         ERR_PRINTF1(_L("*** FAIL: Failed to Create key pair ***"));
       
   105         CleanupStack::PopAndDestroy(keypairImpl);
       
   106         CleanupStack::PopAndDestroy(keyParams);
       
   107         return EFail;
       
   108         }
       
   109     CleanupStack::PushL(keyPair);
       
   110     
       
   111     //*****************************************************
       
   112 
       
   113     INFO_PRINTF1(_L("Creating Dummy ECC Cipher Object..."));
       
   114     
       
   115     CryptoSpi::CAsymmetricCipher * impl = NULL;
       
   116         
       
   117     TRAP(err,CAsymmetricCipherFactory::CreateAsymmetricCipherL
       
   118                                         (
       
   119                                         impl,
       
   120                                         algorithm,
       
   121                                         keyPair->PrivateKey(),
       
   122                                         KCryptoModeDecryptUid,
       
   123                                         paddingMode,
       
   124                                         NULL));
       
   125 
       
   126     if(err == KErrNone)
       
   127         {
       
   128         delete impl;
       
   129         INFO_PRINTF1(_L("*** Dummy Ecc Cipher - Load: PASS ***"));
       
   130         SetTestStepResult(EPass);
       
   131         }
       
   132     else
       
   133         {
       
   134         ERR_PRINTF2(_L("*** FAIL: Failed to Create dummy Ecc Cipher Object - %d ***"), err);
       
   135         }
       
   136 
       
   137     CleanupStack::PopAndDestroy(keyPair);
       
   138     CleanupStack::PopAndDestroy(keypairImpl);			
       
   139     CleanupStack::PopAndDestroy(keyParams);
       
   140 		
       
   141 	INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
       
   142 
       
   143 	return TestStepResult();
       
   144 	}
       
   145 
       
   146 
       
   147 
       
   148 TVerdict CDummyEccCipherLoadStep::doTestStepPostambleL()
       
   149 	{
       
   150 	return TestStepResult();
       
   151 	}