Update contrib.
2 * Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of the License "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
20 #include <cryptospi/cryptosignatureapi.h>
21 #include <cryptospi/cryptospidef.h>
22 #include <cryptospi/keys.h>
23 #include "keyconverter.h"
25 #include "../common/inlines.h"
28 using namespace CryptoSpi;
30 // CDsaSignerShim ////////////////////////////////////////////////////////
32 CDsaSignerShim* CDsaSignerShim::NewL(const CDSAPrivateKey& aKey)
34 CDsaSignerShim* self = CDsaSignerShim::NewLC(aKey);
35 CleanupStack::Pop(self);
39 CDsaSignerShim* CDsaSignerShim::NewLC(const CDSAPrivateKey& aKey)
41 CDsaSignerShim* self = new (ELeave) CDsaSignerShim(aKey);
42 CleanupStack::PushL(self);
43 self->ConstructL(aKey);
47 CDsaSignerShim::CDsaSignerShim(const CDSAPrivateKey& aKey)
52 CDsaSignerShim::~CDsaSignerShim()
58 void CDsaSignerShim::ConstructL(const CDSAPrivateKey& aKey)
60 iKey = KeyConverter::CreateKeyL(aKey);
61 CSignatureFactory::CreateSignerL(
70 CDSASignature* CDsaSignerShim::SignL(const TDesC8& aInput) const
73 CCryptoParams* signature = CCryptoParams::NewLC();
74 iSignerImpl->SignL(aInput, *signature);
76 //Retrieve the R&S in DSA signature from the array
77 const TInteger& cR=signature->GetBigIntL(KDsaSignatureParameterRUid);
78 const TInteger& cS=signature->GetBigIntL(KDsaSignatureParameterSUid);
81 //Make copies of the DSA signature
82 RInteger r=RInteger::NewL(cR);
84 RInteger s=RInteger::NewL(cS);
87 //Create the DSA signature object, the ownership of r&s is transfered to dsaSig
88 CDSASignature* dsaSig=CDSASignature::NewL(r, s);
91 CleanupStack::Pop(2, &r);
92 CleanupStack::PopAndDestroy(signature);
97 TInt CDsaSignerShim::MaxInputLength() const
99 TInt maxInputLength=0;
100 TRAPD(err, maxInputLength=iSignerImpl->GetMaximumInputLengthL())
103 return maxInputLength;
112 // CDsaVerifierShim ////////////////////////////////////////////////////////
113 CDsaVerifierShim* CDsaVerifierShim::NewL(const CDSAPublicKey& aKey)
115 CDsaVerifierShim* self = CDsaVerifierShim::NewLC(aKey);
116 CleanupStack::Pop(self);
120 CDsaVerifierShim* CDsaVerifierShim::NewLC(const CDSAPublicKey& aKey)
122 CDsaVerifierShim* self = new (ELeave) CDsaVerifierShim(aKey);
123 CleanupStack::PushL(self);
124 self->ConstructL(aKey);
128 CDsaVerifierShim::CDsaVerifierShim(const CDSAPublicKey& aKey)
133 CDsaVerifierShim::~CDsaVerifierShim()
135 delete iVerifierImpl;
139 void CDsaVerifierShim::ConstructL(const CDSAPublicKey& aKey)
141 iKey = KeyConverter::CreateKeyL(aKey);
142 CSignatureFactory::CreateVerifierL(
151 TBool CDsaVerifierShim::VerifyL(const TDesC8& aInput, const CDSASignature& aSignature) const
153 //create the array format dsa signature for the new crypto spi
154 CCryptoParams* dsaSig = CCryptoParams::NewLC();
156 dsaSig->AddL(aSignature.R(), KDsaSignatureParameterRUid);
157 dsaSig->AddL(aSignature.S(), KDsaSignatureParameterSUid);
159 //pass the signature and input to the new crypto spi to be verified
160 TBool verificationResult=EFalse;
161 iVerifierImpl->VerifyL(aInput, *dsaSig, verificationResult);
164 CleanupStack::PopAndDestroy(dsaSig);
166 return verificationResult;
169 TInt CDsaVerifierShim::MaxInputLength() const
171 TInt maxInputLength=0;
172 TRAPD(err, maxInputLength=iVerifierImpl->GetMaximumInputLengthL())
175 return maxInputLength;