os/security/cryptoplugins/cryptospiplugins/test/dummyecchwplugin/src/dummyeccimpl.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/security/cryptoplugins/cryptospiplugins/test/dummyecchwplugin/src/dummyeccimpl.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,189 @@
     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 "dummyeccimpl.h"
    1.23 +
    1.24 +#include <e32def.h>
    1.25 +#include <cryptospi/cryptospidef.h>
    1.26 +#include "keys.h"
    1.27 +#include <cryptospi/plugincharacteristics.h>
    1.28 +#include "pluginconfig.h"
    1.29 +#include "cryptospihai.h"
    1.30 +
    1.31 +using namespace DummyEccHwCrypto;
    1.32 +using namespace CryptoSpiHai;
    1.33 +
    1.34 +/**
    1.35 + * These are just randomly selected numbers. There is no logic behind 
    1.36 + * their values.
    1.37 + */ 
    1.38 +const TInt KMaxOutputLength = 50;
    1.39 +const TInt KMaxInputLength = 50;
    1.40 +
    1.41 +CDummyECCCipherImpl* CDummyECCCipherImpl::NewL(const CKey& aKey,
    1.42 +        TUid aCryptoMode, TUid aPaddingMode)
    1.43 +    {
    1.44 +    CDummyECCCipherImpl* self = CDummyECCCipherImpl::NewLC(aKey, aCryptoMode,
    1.45 +            aPaddingMode);
    1.46 +    CleanupStack::Pop(self);
    1.47 +    return self;
    1.48 +    }
    1.49 +
    1.50 +CDummyECCCipherImpl* CDummyECCCipherImpl::NewLC(const CKey& aKey,
    1.51 +        TUid aCryptoMode, TUid aPaddingMode)
    1.52 +    {
    1.53 +    CDummyECCCipherImpl* self = new (ELeave) CDummyECCCipherImpl(aCryptoMode,
    1.54 +            aPaddingMode);
    1.55 +    CleanupStack::PushL(self);
    1.56 +    self->ConstructL(aKey);
    1.57 +    return self;
    1.58 +    }
    1.59 +
    1.60 +CDummyECCCipherImpl::CDummyECCCipherImpl(TUid aCryptoMode, TUid aPaddingMode) :
    1.61 +    iCryptoMode(aCryptoMode), iPaddingMode(aPaddingMode)
    1.62 +    {
    1.63 +    }
    1.64 +
    1.65 +void CDummyECCCipherImpl::ConstructL(const CKey& aKey)
    1.66 +    {
    1.67 +    SetKeyL(aKey);
    1.68 +    }
    1.69 +
    1.70 +// MPlugin Interface Start
    1.71 +void CDummyECCCipherImpl::Close()
    1.72 +    {
    1.73 +    delete this;
    1.74 +    }
    1.75 +
    1.76 +void CDummyECCCipherImpl::Reset()
    1.77 +    {
    1.78 +    }
    1.79 +
    1.80 +void CDummyECCCipherImpl::GetCharacteristicsL(
    1.81 +        const TCharacteristics*& aPluginCharacteristics)
    1.82 +    {
    1.83 +    TInt numCiphers = sizeof(KAsymmetricCipherCharacteristics)
    1.84 +            / sizeof(TAsymmetricCipherCharacteristics*);
    1.85 +    TInt32 implUid = ImplementationUid().iUid;
    1.86 +    for (TInt i = 0; i < numCiphers; ++i)
    1.87 +        {
    1.88 +        if (KAsymmetricCipherCharacteristics[i]->cmn.iImplementationUID
    1.89 +                == implUid)
    1.90 +            {
    1.91 +            aPluginCharacteristics = KAsymmetricCipherCharacteristics[i];
    1.92 +            break;
    1.93 +            }
    1.94 +        }
    1.95 +    }
    1.96 +
    1.97 +const CExtendedCharacteristics* CDummyECCCipherImpl::GetExtendedCharacteristicsL()
    1.98 +    {
    1.99 +    // All Symbian software plug-ins have unlimited concurrency, cannot be reserved
   1.100 +    // for exclusive use and are not CERTIFIED to be standards compliant.
   1.101 +    return CExtendedCharacteristics::NewL(KMaxTInt, EFalse);
   1.102 +    }
   1.103 +
   1.104 +TAny* CDummyECCCipherImpl::GetExtension(TUid /* aExtensionId */)
   1.105 +    {
   1.106 +    return 0;
   1.107 +    }
   1.108 +// End of MPlugin Interface
   1.109 +
   1.110 +// MAsymmetricCipherBase Interface
   1.111 +void CDummyECCCipherImpl::SetKeyL(const CKey& aKey)
   1.112 +    {
   1.113 +    // delete any previous key and recreate the key
   1.114 +    delete iKey;
   1.115 +    iKey = NULL;
   1.116 +    iKey = CKey::NewL(aKey);
   1.117 +    }
   1.118 +
   1.119 +void CDummyECCCipherImpl::SetCryptoModeL(TUid aCryptoMode)
   1.120 +    {
   1.121 +    switch (aCryptoMode.iUid)
   1.122 +        {
   1.123 +        case KCryptoModeEncrypt:
   1.124 +        case KCryptoModeDecrypt:
   1.125 +            break;
   1.126 +        default:
   1.127 +            User::Leave(KErrNotSupported);
   1.128 +        }
   1.129 +    iCryptoMode = aCryptoMode;
   1.130 +    }
   1.131 +
   1.132 +void CDummyECCCipherImpl::SetPaddingModeL(TUid /* aPaddingMode */)
   1.133 +    {
   1.134 +    User::Leave(KErrNotSupported);
   1.135 +    }
   1.136 +
   1.137 +TInt CDummyECCCipherImpl::GetMaximumInputLengthL() const
   1.138 +    {
   1.139 +    return KMaxInputLength;
   1.140 +    }
   1.141 +
   1.142 +TInt CDummyECCCipherImpl::GetMaximumOutputLengthL() const
   1.143 +    {
   1.144 +    return KMaxOutputLength;
   1.145 +    }
   1.146 +// End of MAsymmetricCipherBase Interface
   1.147 +
   1.148 +// MAsymmetricCipher Interface
   1.149 +void CDummyECCCipherImpl::ProcessL(const TDesC8& aInput, TDes8& aOutput)
   1.150 +    {
   1.151 +    if (iCryptoMode.iUid == KCryptoModeEncrypt)
   1.152 +        {
   1.153 +        EncryptL(aInput, aOutput);
   1.154 +        }
   1.155 +    else
   1.156 +        {
   1.157 +        DecryptL(aInput, aOutput);
   1.158 +        }
   1.159 +    }
   1.160 +
   1.161 +TUid CDummyECCCipherImpl::ImplementationUid() const
   1.162 +    {
   1.163 +    return KCryptoPluginEccCipherUid;
   1.164 +    }
   1.165 +
   1.166 +CDummyECCCipherImpl::~CDummyECCCipherImpl()
   1.167 +    {
   1.168 +    delete iKey;
   1.169 +    }
   1.170 +
   1.171 +void CDummyECCCipherImpl::EncryptL(const TDesC8& /* aInput */, TDes8& /* aOuput */)
   1.172 +    {
   1.173 +    User::Leave(KErrNotSupported);
   1.174 +    }
   1.175 +
   1.176 +void CDummyECCCipherImpl::DecryptL(const TDesC8& aInput, TDes8& aOutput)
   1.177 +    {
   1.178 +    if (iKey->IsPresent(KPassedHandleToKeyUid))
   1.179 +        {
   1.180 +        const TInt& keyHandle = iKey->GetTIntL(KPassedHandleToKeyUid);
   1.181 +
   1.182 +        // Invoke the Spi HAI to perform the operation
   1.183 +        CCryptoSpiHai::DecryptL(keyHandle, aInput, aOutput);
   1.184 +        }
   1.185 +    else
   1.186 +        {
   1.187 +        User::Leave(KErrNotSupported);
   1.188 +        }
   1.189 +    }
   1.190 +// End of file
   1.191 +
   1.192 +