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