sl@0: /* sl@0: * Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of the License "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: sl@0: #include "rsasignerimpl.h" sl@0: #include "pluginconfig.h" sl@0: #include "rsafunction.h" sl@0: sl@0: using namespace SoftwareCrypto; sl@0: sl@0: // Implementation of CRSASignerImpl sl@0: CRSASignerImpl* CRSASignerImpl::NewL(const CKey& aKey, TUid aPaddingMode) sl@0: { sl@0: CRSASignerImpl* self = CRSASignerImpl::NewLC(aKey, aPaddingMode); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: CRSASignerImpl* CRSASignerImpl::NewLC(const CKey& aKey, TUid aPaddingMode) sl@0: { sl@0: CRSASignerImpl* self = new(ELeave) CRSASignerImpl(aPaddingMode); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(aKey); sl@0: return self; sl@0: } sl@0: sl@0: CRSASignerImpl::CRSASignerImpl(TUid aPaddingMode) sl@0: : iPaddingMode(aPaddingMode) sl@0: { sl@0: } sl@0: sl@0: CRSASignerImpl::~CRSASignerImpl() sl@0: { sl@0: delete iPadding; sl@0: } sl@0: sl@0: void CRSASignerImpl::ConstructL(const CKey& aKey) sl@0: { sl@0: CSignerImpl::ConstructL(aKey); sl@0: SetPaddingModeL(iPaddingMode); sl@0: } sl@0: sl@0: CExtendedCharacteristics* CRSASignerImpl::CreateExtendedCharacteristicsL() sl@0: { sl@0: // All Symbian software plug-ins have unlimited concurrency, cannot be reserved sl@0: // for exclusive use and are not CERTIFIED to be standards compliant. sl@0: return CExtendedCharacteristics::NewL(KMaxTInt, EFalse); sl@0: } sl@0: sl@0: const CExtendedCharacteristics* CRSASignerImpl::GetExtendedCharacteristicsL() sl@0: { sl@0: return CRSASignerImpl::CreateExtendedCharacteristicsL(); sl@0: } sl@0: sl@0: TUid CRSASignerImpl::ImplementationUid() const sl@0: { sl@0: return KCryptoPluginRsaSignerUid; sl@0: } sl@0: sl@0: void CRSASignerImpl::SetKeyL(const CKey& aPrivateKey) sl@0: { sl@0: DoSetKeyL(aPrivateKey); sl@0: Reset(); sl@0: } sl@0: sl@0: void CRSASignerImpl::SetPaddingModeL(TUid aPaddingMode) sl@0: { sl@0: CPadding* padding(0); sl@0: switch (aPaddingMode.iUid) sl@0: { sl@0: case KPaddingModeNone: sl@0: padding = CPaddingNone::NewL(GetMaximumOutputLengthL()); sl@0: break; sl@0: case KPaddingModePkcs1_v1_5_Signature: sl@0: padding = CPaddingPKCS1Signature::NewL(GetMaximumOutputLengthL()); sl@0: break; sl@0: default: sl@0: User::Leave(KErrNotSupported); sl@0: } sl@0: sl@0: delete iPadding; sl@0: iPadding = padding; sl@0: iPaddingMode = aPaddingMode; sl@0: Reset(); sl@0: } sl@0: sl@0: TInt CRSASignerImpl::GetMaximumInputLengthL() const sl@0: { sl@0: return GetMaximumOutputLengthL() - iPadding->MinPaddingLength(); sl@0: } sl@0: sl@0: TInt CRSASignerImpl::GetMaximumOutputLengthL() const sl@0: { sl@0: const TInteger& paramN = iKey->GetBigIntL(KRsaKeyParameterNUid); sl@0: return paramN.ByteCount(); sl@0: } sl@0: sl@0: void CRSASignerImpl::SignL(const TDesC8& aInput, CCryptoParams& aSignature) sl@0: { sl@0: HBufC8* buf = HBufC8::NewLC(GetMaximumOutputLengthL()); sl@0: TPtr8 ptr = buf->Des(); sl@0: sl@0: //The following will panic if aInput is larger than MaxOutputLength() It is sl@0: //likely that the caller has passed in something that has not been hashed. sl@0: //This is a programming, and likely a security error, in client code, not a sl@0: //problem here. sl@0: iPadding->PadL(aInput, ptr); sl@0: sl@0: RInteger input = RInteger::NewL(ptr); sl@0: CleanupClosePushL(input); sl@0: RInteger output; sl@0: sl@0: RSAFunction::SignL(*iKey, input, output); sl@0: CleanupClosePushL(output); sl@0: sl@0: aSignature.AddL(output, KRsaSignatureParameterSUid); sl@0: CleanupStack::PopAndDestroy(3, buf); //input, buf sl@0: }