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 <cryptostrength.h>
23 #include <securityerr.h>
24 #include <cryptopanic.h>
25 #include "rsafunction.h"
27 /* CRSAPKCS1v15Decryptor */
29 EXPORT_C CRSAPKCS1v15Decryptor* CRSAPKCS1v15Decryptor::NewL(
30 const CRSAPrivateKey& aKey)
32 CRSAPKCS1v15Decryptor* self = NewLC(aKey);
33 CleanupStack::Pop(self);
37 EXPORT_C CRSAPKCS1v15Decryptor* CRSAPKCS1v15Decryptor::NewLC(
38 const CRSAPrivateKey& aKey)
40 CRSAPKCS1v15Decryptor* self = new(ELeave) CRSAPKCS1v15Decryptor(aKey);
41 CleanupStack::PushL(self);
46 TInt CRSAPKCS1v15Decryptor::MaxInputLength(void) const
48 return iPrivateKey.N().ByteCount();
51 TInt CRSAPKCS1v15Decryptor::MaxOutputLength(void) const
53 return MaxInputLength() - iPadding->MinPaddingLength();
56 void CRSAPKCS1v15Decryptor::DecryptL(const TDesC8& aInput,
59 __ASSERT_DEBUG(aOutput.MaxLength() >= MaxOutputLength(), User::Panic(KCryptoPanic, ECryptoPanicOutputDescriptorOverflow));
60 __ASSERT_DEBUG(aInput.Length() <= MaxInputLength(), User::Panic(KCryptoPanic, ECryptoPanicInputTooLarge));
62 RInteger input = RInteger::NewL(aInput);
63 CleanupStack::PushL(input);
67 RSAFunction::DecryptL(iPrivateKey, input, output);
68 CleanupStack::PushL(output);
70 TPtrC8 ptr = *(output.BufferLC());
71 iPadding->UnPadL(ptr, aOutput);
73 CleanupStack::PopAndDestroy(3, &input); //BufferLC(), output, input
76 CRSAPKCS1v15Decryptor::CRSAPKCS1v15Decryptor(const CRSAPrivateKey& aKey)
81 void CRSAPKCS1v15Decryptor::ConstructL(void)
83 iPadding = CPaddingPKCS1Encryption::NewL(MaxInputLength());
85 // Check if MaxInputLength() makes sense, if not the key length must
87 if(MaxOutputLength() <= 0)
89 User::Leave(KErrKeySize);
92 TCrypto::IsAsymmetricWeakEnoughL(iPrivateKey.N().BitCount());
95 CRSAPKCS1v15Decryptor::~CRSAPKCS1v15Decryptor(void)