os/security/cryptoplugins/cryptospiplugins/test/h4drv/crypto_h4_plugin/rijndaelimpl.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) 2007-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
/**
sl@0
    20
 @file
sl@0
    21
 @internalComponent
sl@0
    22
 @released
sl@0
    23
*/
sl@0
    24
#include "rijndaelimpl.h"
sl@0
    25
#include "keys.h"
sl@0
    26
#include "pluginconfig.h"
sl@0
    27
sl@0
    28
using namespace HwCrypto;
sl@0
    29
sl@0
    30
const TUint KAESKeyBytes128 = 16;
sl@0
    31
const TUint KAESKeyBytes192 = 24;
sl@0
    32
const TUint KAESKeyBytes256 = 32;
sl@0
    33
const TUint KAESBlockBytes = 16;
sl@0
    34
sl@0
    35
_LIT(KLddFileName,"cryptoldd.ldd");
sl@0
    36
_LIT(KPddFileName,"crypto.h4.pdd");
sl@0
    37
sl@0
    38
sl@0
    39
/* CRijndaelmpl*/
sl@0
    40
CH4RijndaelImpl::CH4RijndaelImpl(
sl@0
    41
	TUid aCryptoMode,
sl@0
    42
	TUid aOperationMode,
sl@0
    43
	TUid aPadding) :
sl@0
    44
	CH4CipherImpl(KAESBlockBytes, aCryptoMode, aOperationMode, aPadding)
sl@0
    45
	{
sl@0
    46
	}
sl@0
    47
sl@0
    48
CH4RijndaelImpl* CH4RijndaelImpl::NewL(const CKey& aKey, TUid aCryptoMode,	TUid aOperationMode, TUid aPadding)
sl@0
    49
	{
sl@0
    50
	CH4RijndaelImpl* self = CH4RijndaelImpl::NewLC(aKey, aCryptoMode, aOperationMode, aPadding);
sl@0
    51
	CleanupStack::Pop(self);
sl@0
    52
	return self;
sl@0
    53
	}
sl@0
    54
	
sl@0
    55
CH4RijndaelImpl* CH4RijndaelImpl::NewLC(const CKey& aKey, TUid aCryptoMode, TUid aOperationMode, TUid aPadding)
sl@0
    56
	{
sl@0
    57
	CH4RijndaelImpl* self = new(ELeave) CH4RijndaelImpl(aCryptoMode, aOperationMode, aPadding);
sl@0
    58
	CleanupStack::PushL(self);
sl@0
    59
	self->ConstructL(aKey);
sl@0
    60
	return self;
sl@0
    61
	}
sl@0
    62
		
sl@0
    63
CH4RijndaelImpl::~CH4RijndaelImpl()
sl@0
    64
	{
sl@0
    65
	iDriver.Close();
sl@0
    66
	}
sl@0
    67
	
sl@0
    68
void CH4RijndaelImpl::ConstructL(const CKey& aKey)
sl@0
    69
	{
sl@0
    70
	// Load PDD
sl@0
    71
    TInt r = User::LoadPhysicalDevice(KPddFileName);
sl@0
    72
	if((r != KErrNone) && (r != KErrAlreadyExists)) User::Leave(r);
sl@0
    73
sl@0
    74
	// Load LDD
sl@0
    75
    r = User::LoadLogicalDevice(KLddFileName);
sl@0
    76
	if((r != KErrNone) && (r != KErrAlreadyExists)) User::Leave(r);
sl@0
    77
sl@0
    78
sl@0
    79
	CH4CipherImpl::ConstructL(aKey);			
sl@0
    80
	}
sl@0
    81
sl@0
    82
TUid CH4RijndaelImpl::ImplementationUid() const
sl@0
    83
	{
sl@0
    84
	return KCryptoPluginAesUid;
sl@0
    85
	}
sl@0
    86
sl@0
    87
const CExtendedCharacteristics* CH4RijndaelImpl::GetExtendedCharacteristicsL()
sl@0
    88
	{
sl@0
    89
	return StaticGetExtendedCharacteristicsL();
sl@0
    90
	}
sl@0
    91
sl@0
    92
CExtendedCharacteristics* CH4RijndaelImpl::StaticGetExtendedCharacteristicsL()
sl@0
    93
	{
sl@0
    94
	// All Symbian software plug-ins have unlimited concurrency, cannot be reserved
sl@0
    95
	// for exclusive use and are not CERTIFIED to be standards compliant.
sl@0
    96
	return CExtendedCharacteristics::NewL(KMaxTInt, EFalse);
sl@0
    97
	}
sl@0
    98
sl@0
    99
	
sl@0
   100
TBool CH4RijndaelImpl::IsValidKeyLength(TInt aKeyBytes) const
sl@0
   101
	{
sl@0
   102
	switch(aKeyBytes)
sl@0
   103
		{
sl@0
   104
		case KAESKeyBytes128:
sl@0
   105
		case KAESKeyBytes192:
sl@0
   106
		case KAESKeyBytes256:
sl@0
   107
			return ETrue;
sl@0
   108
		default:
sl@0
   109
			return EFalse;
sl@0
   110
		}			
sl@0
   111
	}
sl@0
   112
sl@0
   113
void CH4RijndaelImpl::DoSetupL()
sl@0
   114
	{
sl@0
   115
	iDriver.Close();
sl@0
   116
	User::LeaveIfError(iDriver.Open());
sl@0
   117
sl@0
   118
	TBool encrypt = (iCryptoMode.iUid == KCryptoModeEncrypt);
sl@0
   119
	RCryptoDriver::TChainingMode chainingMode = (iOperationMode.iUid == KOperationModeCBC) ? (RCryptoDriver::ECbcMode) : (RCryptoDriver::EEcbMode);
sl@0
   120
	User::LeaveIfError(iDriver.SetAesConfig(encrypt, chainingMode, iKey->Des(), iIv));
sl@0
   121
	}
sl@0
   122
sl@0
   123
void CH4RijndaelImpl::DoWriteL(const TUint8* aBuffer, TUint aNumBytes)
sl@0
   124
	{
sl@0
   125
	TPtrC8 ptr(aBuffer, aNumBytes);
sl@0
   126
sl@0
   127
    TRequestStatus status;
sl@0
   128
	iDriver.AesWrite(status, ptr);
sl@0
   129
	User::WaitForRequest(status);
sl@0
   130
	User::LeaveIfError(status.Int());
sl@0
   131
	}
sl@0
   132
sl@0
   133
void CH4RijndaelImpl::DoReadL(TDes8 &aBuffer, TUint32 aLength)
sl@0
   134
	{
sl@0
   135
    TRequestStatus status;
sl@0
   136
	iDriver.AesRead(status, aBuffer, aLength);
sl@0
   137
	User::WaitForRequest(status);
sl@0
   138
	User::LeaveIfError(status.Int());
sl@0
   139
	}
sl@0
   140
sl@0
   141
sl@0
   142
	
sl@0
   143
// End of file