sl@0: /* sl@0: * Copyright (c) 2007-2010 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 "dsashim.h" sl@0: #include sl@0: #include sl@0: #include sl@0: #include "keyconverter.h" sl@0: sl@0: #include "../common/inlines.h" sl@0: sl@0: sl@0: using namespace CryptoSpi; sl@0: sl@0: // CDsaSignerShim //////////////////////////////////////////////////////// sl@0: sl@0: CDsaSignerShim* CDsaSignerShim::NewL(const CDSAPrivateKey& aKey) sl@0: { sl@0: CDsaSignerShim* self = CDsaSignerShim::NewLC(aKey); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: CDsaSignerShim* CDsaSignerShim::NewLC(const CDSAPrivateKey& aKey) sl@0: { sl@0: CDsaSignerShim* self = new (ELeave) CDsaSignerShim(aKey); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(aKey); sl@0: return self; sl@0: } sl@0: sl@0: CDsaSignerShim::CDsaSignerShim(const CDSAPrivateKey& aKey) sl@0: : CDSASigner(aKey) sl@0: { sl@0: } sl@0: sl@0: CDsaSignerShim::~CDsaSignerShim() sl@0: { sl@0: delete iSignerImpl; sl@0: delete iKey; sl@0: } sl@0: sl@0: void CDsaSignerShim::ConstructL(const CDSAPrivateKey& aKey) sl@0: { sl@0: iKey = KeyConverter::CreateKeyL(aKey); sl@0: CSignatureFactory::CreateSignerL( sl@0: iSignerImpl, sl@0: KDsaSignerUid, sl@0: *iKey, sl@0: KPaddingModeNoneUid, sl@0: NULL); sl@0: } sl@0: sl@0: sl@0: CDSASignature* CDsaSignerShim::SignL(const TDesC8& aInput) const sl@0: { sl@0: //Sign the input data sl@0: CCryptoParams* signature = CCryptoParams::NewLC(); sl@0: iSignerImpl->SignL(aInput, *signature); sl@0: sl@0: //Retrieve the R&S in DSA signature from the array sl@0: const TInteger& cR=signature->GetBigIntL(KDsaSignatureParameterRUid); sl@0: const TInteger& cS=signature->GetBigIntL(KDsaSignatureParameterSUid); sl@0: sl@0: sl@0: //Make copies of the DSA signature sl@0: RInteger r=RInteger::NewL(cR); sl@0: CleanupClosePushL(r); sl@0: RInteger s=RInteger::NewL(cS); sl@0: CleanupClosePushL(s); sl@0: sl@0: //Create the DSA signature object, the ownership of r&s is transfered to dsaSig sl@0: CDSASignature* dsaSig=CDSASignature::NewL(r, s); sl@0: sl@0: //Cleanup sl@0: CleanupStack::Pop(2, &r); sl@0: CleanupStack::PopAndDestroy(signature); sl@0: sl@0: return dsaSig; sl@0: } sl@0: sl@0: TInt CDsaSignerShim::MaxInputLength() const sl@0: { sl@0: TInt maxInputLength=0; sl@0: TRAPD(err, maxInputLength=iSignerImpl->GetMaximumInputLengthL()) sl@0: if (err==KErrNone) sl@0: { sl@0: return maxInputLength; sl@0: } sl@0: else sl@0: { sl@0: return err; sl@0: } sl@0: } sl@0: sl@0: sl@0: // CDsaVerifierShim //////////////////////////////////////////////////////// sl@0: CDsaVerifierShim* CDsaVerifierShim::NewL(const CDSAPublicKey& aKey) sl@0: { sl@0: CDsaVerifierShim* self = CDsaVerifierShim::NewLC(aKey); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: CDsaVerifierShim* CDsaVerifierShim::NewLC(const CDSAPublicKey& aKey) sl@0: { sl@0: CDsaVerifierShim* self = new (ELeave) CDsaVerifierShim(aKey); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(aKey); sl@0: return self; sl@0: } sl@0: sl@0: CDsaVerifierShim::CDsaVerifierShim(const CDSAPublicKey& aKey) sl@0: : CDSAVerifier(aKey) sl@0: { sl@0: } sl@0: sl@0: CDsaVerifierShim::~CDsaVerifierShim() sl@0: { sl@0: delete iVerifierImpl; sl@0: delete iKey; sl@0: } sl@0: sl@0: void CDsaVerifierShim::ConstructL(const CDSAPublicKey& aKey) sl@0: { sl@0: iKey = KeyConverter::CreateKeyL(aKey); sl@0: CSignatureFactory::CreateVerifierL( sl@0: iVerifierImpl, sl@0: KDsaVerifierUid, sl@0: *iKey, sl@0: KPaddingModeNoneUid, sl@0: NULL); sl@0: sl@0: } sl@0: sl@0: TBool CDsaVerifierShim::VerifyL(const TDesC8& aInput, const CDSASignature& aSignature) const sl@0: { sl@0: //create the array format dsa signature for the new crypto spi sl@0: CCryptoParams* dsaSig = CCryptoParams::NewLC(); sl@0: sl@0: dsaSig->AddL(aSignature.R(), KDsaSignatureParameterRUid); sl@0: dsaSig->AddL(aSignature.S(), KDsaSignatureParameterSUid); sl@0: sl@0: //pass the signature and input to the new crypto spi to be verified sl@0: TBool verificationResult=EFalse; sl@0: iVerifierImpl->VerifyL(aInput, *dsaSig, verificationResult); sl@0: sl@0: //Cleanup the array sl@0: CleanupStack::PopAndDestroy(dsaSig); sl@0: sl@0: return verificationResult; sl@0: } sl@0: sl@0: TInt CDsaVerifierShim::MaxInputLength() const sl@0: { sl@0: TInt maxInputLength=0; sl@0: TRAPD(err, maxInputLength=iVerifierImpl->GetMaximumInputLengthL()) sl@0: if (err==KErrNone) sl@0: { sl@0: return maxInputLength; sl@0: } sl@0: else sl@0: { sl@0: return err; sl@0: } sl@0: } sl@0: