First public contribution.
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 <asymmetrickeys.h>
20 #include "rsakeypairshim.h"
21 #include "../common/inlines.h"
25 EXPORT_C const TInteger& CRSAParameters::N(void) const
30 EXPORT_C CRSAParameters::~CRSAParameters(void)
35 EXPORT_C CRSAParameters::CRSAParameters(RInteger& aN) : iN(aN)
39 EXPORT_C CRSAParameters::CRSAParameters(void)
45 EXPORT_C CRSAPublicKey* CRSAPublicKey::NewL(RInteger& aN, RInteger& aE)
47 CRSAPublicKey* self = NewLC(aN, aE);
52 EXPORT_C CRSAPublicKey* CRSAPublicKey::NewLC(RInteger& aN, RInteger& aE)
54 CRSAPublicKey* self = new(ELeave) CRSAPublicKey(aN, aE);
55 CleanupStack::PushL(self);
61 void CRSAPublicKey::ConstructL()
63 // Check that the modulus and exponent are positive integers
64 // as specified by RSA
65 if(!N().IsPositive() || !E().IsPositive() || (E() <= 1))
67 // If we need to leave during construction we must release ownership
68 // of the RInteger parameters that were passed in.
69 // These parameters should be on the cleanup stack so if we don't
70 // release ownership they will be deleted twice, causing a panic
73 User::Leave(KErrArgument);
78 EXPORT_C const TInteger& CRSAPublicKey::E(void) const
83 EXPORT_C CRSAPublicKey::CRSAPublicKey()
87 EXPORT_C CRSAPublicKey::CRSAPublicKey(RInteger& aN, RInteger& aE)
88 : CRSAParameters(aN), iE(aE)
92 EXPORT_C CRSAPublicKey::~CRSAPublicKey(void)
97 /* CRSAPrivateKeyType */
99 CRSAPrivateKey::CRSAPrivateKey(const TRSAPrivateKeyType aKeyType, RInteger& aN)
100 : CRSAParameters(aN), iKeyType(aKeyType)
104 /* CRSAPrivateKeyStandard */
106 EXPORT_C CRSAPrivateKeyStandard* CRSAPrivateKeyStandard::NewL(RInteger& aN,
109 CRSAPrivateKeyStandard* self = NewLC(aN, aD);
114 EXPORT_C CRSAPrivateKeyStandard* CRSAPrivateKeyStandard::NewLC(RInteger& aN,
117 CRSAPrivateKeyStandard* self = new(ELeave) CRSAPrivateKeyStandard(aN, aD);
118 CleanupStack::PushL(self);
123 void CRSAPrivateKeyStandard::ConstructL()
125 // Check that the modulus and exponent are positive integers
126 if(!N().IsPositive() || !D().IsPositive() || (D() <= 1))
128 // If we need to leave during construction we must release ownership
129 // of the RInteger parameters that were passed in.
130 // These parameters should be on the cleanup stack so if we don't
131 // release ownership they will be deleted twice, causing a panic
134 User::Leave(KErrArgument);
138 EXPORT_C const TInteger& CRSAPrivateKeyStandard::D(void) const
143 EXPORT_C CRSAPrivateKeyStandard::CRSAPrivateKeyStandard(RInteger& aN,
144 RInteger& aD) : CRSAPrivateKey(EStandard, aN), iD(aD)
148 EXPORT_C CRSAPrivateKeyStandard::~CRSAPrivateKeyStandard()
153 /* CRSAPrivateKeyCRT */
155 EXPORT_C CRSAPrivateKeyCRT* CRSAPrivateKeyCRT::NewL(RInteger& aN, RInteger& aP,
156 RInteger& aQ, RInteger& aDP, RInteger& aDQ, RInteger& aQInv)
158 CRSAPrivateKeyCRT* self = NewLC(aN, aP, aQ, aDP, aDQ, aQInv);
163 EXPORT_C CRSAPrivateKeyCRT* CRSAPrivateKeyCRT::NewLC(RInteger& aN, RInteger& aP,
164 RInteger& aQ, RInteger& aDP, RInteger& aDQ, RInteger& aQInv)
166 CRSAPrivateKeyCRT* self = new(ELeave) CRSAPrivateKeyCRT(aN, aP, aQ,
168 CleanupStack::PushL(self);
173 EXPORT_C CRSAPrivateKeyCRT::CRSAPrivateKeyCRT(RInteger& aN, RInteger& aP,
174 RInteger& aQ, RInteger& aDP, RInteger& aDQ, RInteger& aQInv)
175 : CRSAPrivateKey(EStandardCRT, aN), iP(aP), iQ(aQ), iDP(aDP), iDQ(aDQ),
180 void CRSAPrivateKeyCRT::ConstructL()
182 // Check that all parameters are positive integers
183 if(!P().IsPositive() || !Q().IsPositive() || !DP().IsPositive()
184 || !DQ().IsPositive() || !QInv().IsPositive())
186 // If we need to leave during construction we must release ownership
187 // of the RInteger parameters that were passed in.
188 // These parameters should be on the cleanup stack so if we don't
189 // release ownership they will be deleted twice, causing a panic
196 User::Leave(KErrArgument);
201 EXPORT_C CRSAPrivateKeyCRT::~CRSAPrivateKeyCRT()
210 EXPORT_C const TInteger& CRSAPrivateKeyCRT::P(void) const
215 EXPORT_C const TInteger& CRSAPrivateKeyCRT::Q(void) const
220 EXPORT_C const TInteger& CRSAPrivateKeyCRT::DP(void) const
225 EXPORT_C const TInteger& CRSAPrivateKeyCRT::DQ(void) const
230 EXPORT_C const TInteger& CRSAPrivateKeyCRT::QInv(void) const
237 EXPORT_C CRSAKeyPair* CRSAKeyPair::NewL(TUint aModulusBits,
238 TRSAPrivateKeyType aKeyType /*= EStandardCRT*/)
240 CRSAKeyPairShim* self = CRSAKeyPairShim::NewLC(aModulusBits, aKeyType);
245 EXPORT_C CRSAKeyPair* CRSAKeyPair::NewLC(TUint aModulusBits,
246 TRSAPrivateKeyType aKeyType /*= EStandardCRT*/)
248 CRSAKeyPairShim* self = CRSAKeyPairShim::NewLC(aModulusBits, aKeyType);
252 EXPORT_C const CRSAPublicKey& CRSAKeyPair::PublicKey(void) const
257 EXPORT_C const CRSAPrivateKey& CRSAKeyPair::PrivateKey(void) const
262 EXPORT_C CRSAKeyPair::~CRSAKeyPair(void)
268 EXPORT_C CRSAKeyPair::CRSAKeyPair(void)