cryptoplugins/cryptospiplugins/test/dummyecchwplugin/src/dummyeccimpl.cpp
changeset 15 da2ae96f639b
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 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "dummyeccimpl.h"
       
    20 
       
    21 #include <e32def.h>
       
    22 #include <cryptospi/cryptospidef.h>
       
    23 #include "keys.h"
       
    24 #include <cryptospi/plugincharacteristics.h>
       
    25 #include "pluginconfig.h"
       
    26 #include "cryptospihai.h"
       
    27 
       
    28 using namespace DummyEccHwCrypto;
       
    29 using namespace CryptoSpiHai;
       
    30 
       
    31 /**
       
    32  * These are just randomly selected numbers. There is no logic behind 
       
    33  * their values.
       
    34  */ 
       
    35 const TInt KMaxOutputLength = 50;
       
    36 const TInt KMaxInputLength = 50;
       
    37 
       
    38 CDummyECCCipherImpl* CDummyECCCipherImpl::NewL(const CKey& aKey,
       
    39         TUid aCryptoMode, TUid aPaddingMode)
       
    40     {
       
    41     CDummyECCCipherImpl* self = CDummyECCCipherImpl::NewLC(aKey, aCryptoMode,
       
    42             aPaddingMode);
       
    43     CleanupStack::Pop(self);
       
    44     return self;
       
    45     }
       
    46 
       
    47 CDummyECCCipherImpl* CDummyECCCipherImpl::NewLC(const CKey& aKey,
       
    48         TUid aCryptoMode, TUid aPaddingMode)
       
    49     {
       
    50     CDummyECCCipherImpl* self = new (ELeave) CDummyECCCipherImpl(aCryptoMode,
       
    51             aPaddingMode);
       
    52     CleanupStack::PushL(self);
       
    53     self->ConstructL(aKey);
       
    54     return self;
       
    55     }
       
    56 
       
    57 CDummyECCCipherImpl::CDummyECCCipherImpl(TUid aCryptoMode, TUid aPaddingMode) :
       
    58     iCryptoMode(aCryptoMode), iPaddingMode(aPaddingMode)
       
    59     {
       
    60     }
       
    61 
       
    62 void CDummyECCCipherImpl::ConstructL(const CKey& aKey)
       
    63     {
       
    64     SetKeyL(aKey);
       
    65     }
       
    66 
       
    67 // MPlugin Interface Start
       
    68 void CDummyECCCipherImpl::Close()
       
    69     {
       
    70     delete this;
       
    71     }
       
    72 
       
    73 void CDummyECCCipherImpl::Reset()
       
    74     {
       
    75     }
       
    76 
       
    77 void CDummyECCCipherImpl::GetCharacteristicsL(
       
    78         const TCharacteristics*& aPluginCharacteristics)
       
    79     {
       
    80     TInt numCiphers = sizeof(KAsymmetricCipherCharacteristics)
       
    81             / sizeof(TAsymmetricCipherCharacteristics*);
       
    82     TInt32 implUid = ImplementationUid().iUid;
       
    83     for (TInt i = 0; i < numCiphers; ++i)
       
    84         {
       
    85         if (KAsymmetricCipherCharacteristics[i]->cmn.iImplementationUID
       
    86                 == implUid)
       
    87             {
       
    88             aPluginCharacteristics = KAsymmetricCipherCharacteristics[i];
       
    89             break;
       
    90             }
       
    91         }
       
    92     }
       
    93 
       
    94 const CExtendedCharacteristics* CDummyECCCipherImpl::GetExtendedCharacteristicsL()
       
    95     {
       
    96     // All Symbian software plug-ins have unlimited concurrency, cannot be reserved
       
    97     // for exclusive use and are not CERTIFIED to be standards compliant.
       
    98     return CExtendedCharacteristics::NewL(KMaxTInt, EFalse);
       
    99     }
       
   100 
       
   101 TAny* CDummyECCCipherImpl::GetExtension(TUid /* aExtensionId */)
       
   102     {
       
   103     return 0;
       
   104     }
       
   105 // End of MPlugin Interface
       
   106 
       
   107 // MAsymmetricCipherBase Interface
       
   108 void CDummyECCCipherImpl::SetKeyL(const CKey& aKey)
       
   109     {
       
   110     // delete any previous key and recreate the key
       
   111     delete iKey;
       
   112     iKey = NULL;
       
   113     iKey = CKey::NewL(aKey);
       
   114     }
       
   115 
       
   116 void CDummyECCCipherImpl::SetCryptoModeL(TUid aCryptoMode)
       
   117     {
       
   118     switch (aCryptoMode.iUid)
       
   119         {
       
   120         case KCryptoModeEncrypt:
       
   121         case KCryptoModeDecrypt:
       
   122             break;
       
   123         default:
       
   124             User::Leave(KErrNotSupported);
       
   125         }
       
   126     iCryptoMode = aCryptoMode;
       
   127     }
       
   128 
       
   129 void CDummyECCCipherImpl::SetPaddingModeL(TUid /* aPaddingMode */)
       
   130     {
       
   131     User::Leave(KErrNotSupported);
       
   132     }
       
   133 
       
   134 TInt CDummyECCCipherImpl::GetMaximumInputLengthL() const
       
   135     {
       
   136     return KMaxInputLength;
       
   137     }
       
   138 
       
   139 TInt CDummyECCCipherImpl::GetMaximumOutputLengthL() const
       
   140     {
       
   141     return KMaxOutputLength;
       
   142     }
       
   143 // End of MAsymmetricCipherBase Interface
       
   144 
       
   145 // MAsymmetricCipher Interface
       
   146 void CDummyECCCipherImpl::ProcessL(const TDesC8& aInput, TDes8& aOutput)
       
   147     {
       
   148     if (iCryptoMode.iUid == KCryptoModeEncrypt)
       
   149         {
       
   150         EncryptL(aInput, aOutput);
       
   151         }
       
   152     else
       
   153         {
       
   154         DecryptL(aInput, aOutput);
       
   155         }
       
   156     }
       
   157 
       
   158 TUid CDummyECCCipherImpl::ImplementationUid() const
       
   159     {
       
   160     return KCryptoPluginEccCipherUid;
       
   161     }
       
   162 
       
   163 CDummyECCCipherImpl::~CDummyECCCipherImpl()
       
   164     {
       
   165     delete iKey;
       
   166     }
       
   167 
       
   168 void CDummyECCCipherImpl::EncryptL(const TDesC8& /* aInput */, TDes8& /* aOuput */)
       
   169     {
       
   170     User::Leave(KErrNotSupported);
       
   171     }
       
   172 
       
   173 void CDummyECCCipherImpl::DecryptL(const TDesC8& aInput, TDes8& aOutput)
       
   174     {
       
   175     if (iKey->IsPresent(KPassedHandleToKeyUid))
       
   176         {
       
   177         const TInt& keyHandle = iKey->GetTIntL(KPassedHandleToKeyUid);
       
   178 
       
   179         // Invoke the Spi HAI to perform the operation
       
   180         CCryptoSpiHai::DecryptL(keyHandle, aInput, aOutput);
       
   181         }
       
   182     else
       
   183         {
       
   184         User::Leave(KErrNotSupported);
       
   185         }
       
   186     }
       
   187 // End of file
       
   188 
       
   189