sl@0: /* sl@0: * Copyright (c) 2003-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 sl@0: #include sl@0: #include sl@0: #include sl@0: #include "rsafunction.h" sl@0: sl@0: /* CRSAVerifier */ sl@0: sl@0: EXPORT_C CRSAVerifier::CRSAVerifier(void) sl@0: { sl@0: } sl@0: sl@0: EXPORT_C TBool CRSAVerifier::VerifyL(const TDesC8& aInput, sl@0: const CRSASignature& aSignature) const sl@0: { sl@0: TBool retval = EFalse; sl@0: HBufC8* inverseSign = InverseSignLC(aSignature); sl@0: sl@0: if (inverseSign->Compare(aInput)==0) sl@0: { sl@0: retval = ETrue; sl@0: } sl@0: CleanupStack::PopAndDestroy(inverseSign); sl@0: return retval; sl@0: } sl@0: sl@0: /* CRSAPKCS1v15Verifier */ sl@0: EXPORT_C CRSAPKCS1v15Verifier* CRSAPKCS1v15Verifier::NewL( sl@0: const CRSAPublicKey& aKey) sl@0: { sl@0: CRSAPKCS1v15Verifier* self = NewLC(aKey); sl@0: CleanupStack::Pop(); sl@0: return self; sl@0: } sl@0: sl@0: EXPORT_C CRSAPKCS1v15Verifier* CRSAPKCS1v15Verifier::NewLC( sl@0: const CRSAPublicKey& aKey) sl@0: { sl@0: CRSAPKCS1v15Verifier* self = new(ELeave) CRSAPKCS1v15Verifier(aKey); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(); sl@0: return self; sl@0: } sl@0: sl@0: TInt CRSAPKCS1v15Verifier::MaxInputLength(void) const sl@0: { sl@0: return MaxOutputLength() - iPadding->MinPaddingLength(); sl@0: } sl@0: sl@0: TInt CRSAPKCS1v15Verifier::MaxOutputLength(void) const sl@0: { sl@0: return iPublicKey.N().ByteCount(); sl@0: } sl@0: sl@0: HBufC8* CRSAPKCS1v15Verifier::InverseSignLC( sl@0: const CRSASignature& aSignature) const sl@0: { sl@0: HBufC8* unpaddedBuf = HBufC8::NewMaxLC(MaxOutputLength()); sl@0: TPtr8 unpaddedHash = unpaddedBuf->Des(); sl@0: sl@0: RInteger input = RInteger::NewL(aSignature.S()); sl@0: CleanupStack::PushL(input); sl@0: RInteger output; sl@0: sl@0: RSAFunction::VerifyL(iPublicKey, input, output); sl@0: CleanupStack::PushL(output); sl@0: sl@0: TPtrC8 paddedHashPtr = *(output.BufferLC()); sl@0: sl@0: iPadding->UnPadL(paddedHashPtr, unpaddedHash); sl@0: CleanupStack::PopAndDestroy(3, &input); //BufferLC, output, input sl@0: return unpaddedBuf; sl@0: } sl@0: sl@0: CRSAPKCS1v15Verifier::CRSAPKCS1v15Verifier(const CRSAPublicKey& aKey) sl@0: : iPublicKey(aKey) sl@0: { sl@0: } sl@0: sl@0: void CRSAPKCS1v15Verifier::ConstructL(void) sl@0: { sl@0: iPadding = CPaddingPKCS1Signature::NewL(MaxOutputLength()); sl@0: sl@0: // Check if MaxInputLength() makes sense, if not the key length must sl@0: // be too small sl@0: if(MaxInputLength() <= 0) sl@0: { sl@0: User::Leave(KErrKeySize); sl@0: } sl@0: } sl@0: sl@0: CRSAPKCS1v15Verifier::~CRSAPKCS1v15Verifier(void) sl@0: { sl@0: delete iPadding; sl@0: } sl@0: