Update contrib.
2 * Copyright (c) 2003-2009 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.
19 #include <asymmetric.h>
20 #include <asymmetrickeys.h>
22 #include <securityerr.h>
23 #include "rsafunction.h"
27 EXPORT_C CRSAVerifier::CRSAVerifier(void)
31 EXPORT_C TBool CRSAVerifier::VerifyL(const TDesC8& aInput,
32 const CRSASignature& aSignature) const
34 TBool retval = EFalse;
35 HBufC8* inverseSign = InverseSignLC(aSignature);
37 if (inverseSign->Compare(aInput)==0)
41 CleanupStack::PopAndDestroy(inverseSign);
45 /* CRSAPKCS1v15Verifier */
46 EXPORT_C CRSAPKCS1v15Verifier* CRSAPKCS1v15Verifier::NewL(
47 const CRSAPublicKey& aKey)
49 CRSAPKCS1v15Verifier* self = NewLC(aKey);
54 EXPORT_C CRSAPKCS1v15Verifier* CRSAPKCS1v15Verifier::NewLC(
55 const CRSAPublicKey& aKey)
57 CRSAPKCS1v15Verifier* self = new(ELeave) CRSAPKCS1v15Verifier(aKey);
58 CleanupStack::PushL(self);
63 TInt CRSAPKCS1v15Verifier::MaxInputLength(void) const
65 return MaxOutputLength() - iPadding->MinPaddingLength();
68 TInt CRSAPKCS1v15Verifier::MaxOutputLength(void) const
70 return iPublicKey.N().ByteCount();
73 HBufC8* CRSAPKCS1v15Verifier::InverseSignLC(
74 const CRSASignature& aSignature) const
76 HBufC8* unpaddedBuf = HBufC8::NewMaxLC(MaxOutputLength());
77 TPtr8 unpaddedHash = unpaddedBuf->Des();
79 RInteger input = RInteger::NewL(aSignature.S());
80 CleanupStack::PushL(input);
83 RSAFunction::VerifyL(iPublicKey, input, output);
84 CleanupStack::PushL(output);
86 TPtrC8 paddedHashPtr = *(output.BufferLC());
88 iPadding->UnPadL(paddedHashPtr, unpaddedHash);
89 CleanupStack::PopAndDestroy(3, &input); //BufferLC, output, input
93 CRSAPKCS1v15Verifier::CRSAPKCS1v15Verifier(const CRSAPublicKey& aKey)
98 void CRSAPKCS1v15Verifier::ConstructL(void)
100 iPadding = CPaddingPKCS1Signature::NewL(MaxOutputLength());
102 // Check if MaxInputLength() makes sense, if not the key length must
104 if(MaxInputLength() <= 0)
106 User::Leave(KErrKeySize);
110 CRSAPKCS1v15Verifier::~CRSAPKCS1v15Verifier(void)