First public contribution.
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.
19 #include "dsakeypairshim.h"
20 #include <cryptospi/cryptokeypairgeneratorapi.h>
21 #include <cryptospi/keypair.h>
22 #include <cryptospi/cryptoparams.h>
23 #include <cryptospi/cryptospidef.h>
26 using namespace CryptoSpi;
30 CDSAKeyPairShim* CDSAKeyPairShim::NewLC(TUint aKeyBits)
32 CDSAKeyPairShim* self = new(ELeave) CDSAKeyPairShim();
33 CleanupStack::PushL(self);
34 self->ConstructL(aKeyBits);
38 CDSAKeyPairShim::~CDSAKeyPairShim()
42 CDSAKeyPairShim::CDSAKeyPairShim()
46 void CDSAKeyPairShim::ConstructL(TUint aKeyBits)
48 CKeyPairGenerator* keyPairGeneratorImpl=NULL;
49 CKeyPairGeneratorFactory::CreateKeyPairGeneratorL(
51 KDSAKeyPairGeneratorUid,
53 CleanupStack::PushL(keyPairGeneratorImpl);
58 // put the DSA parameters into an array
59 CCryptoParams* keyParameters = CCryptoParams::NewLC();
61 // call the api to create an DSA key pair
62 CKeyPair* keyPair = 0;
63 keyPairGeneratorImpl->GenerateKeyPairL(aKeyBits, *keyParameters, keyPair);
64 CleanupStack::PushL(keyPair);
67 if (keyParameters->IsPresent(KDsaKeyGenerationSeedUid))
69 const TDesC8& seed = keyParameters->GetTDesC8L(KDsaKeyGenerationSeedUid);
70 TInt counter=keyParameters->GetTIntL(KDsaKeyGenerationCounterUid);
71 iPrimeCertificate=CDSAPrimeCertificate::NewL(seed, counter);
75 //for compatibility convert the CKeyPair to CDSAPrivateKey and CDSAPublicKey
77 // the public key becomes the owner of P,Q,G,Y
78 const CKey& publicKey = keyPair->PublicKey();
79 RInteger P = RInteger::NewL(publicKey.GetBigIntL(KDsaKeyParameterPUid));
82 RInteger Q = RInteger::NewL(publicKey.GetBigIntL(KDsaKeyParameterQUid));
85 RInteger G = RInteger::NewL(publicKey.GetBigIntL(KDsaKeyParameterGUid));
88 RInteger Y = RInteger::NewL(publicKey.GetBigIntL(KDsaKeyParameterYUid));
91 iPublic = CDSAPublicKey::NewL(P, Q, G, Y);
92 CleanupStack::Pop(4, &P); //Y,G,Q,P
94 // the private key becomes the owner of P1,Q1,G1,X
95 const CKey& privateKey = keyPair->PrivateKey();
96 RInteger P1 = RInteger::NewL(privateKey.GetBigIntL(KDsaKeyParameterPUid));
97 CleanupClosePushL(P1);
99 RInteger Q1 = RInteger::NewL(privateKey.GetBigIntL(KDsaKeyParameterQUid));
100 CleanupClosePushL(Q1);
102 RInteger G1 = RInteger::NewL(privateKey.GetBigIntL(KDsaKeyParameterGUid));
103 CleanupClosePushL(G1);
105 RInteger X = RInteger::NewL(privateKey.GetBigIntL(KDsaKeyParameterXUid));
106 CleanupClosePushL(X);
108 iPrivate = CDSAPrivateKey::NewL(P1, Q1, G1, X);
109 CleanupStack::Pop(4, &P1); //X,G1,Q1,P1
111 CleanupStack::PopAndDestroy(3, keyPairGeneratorImpl); // keyPair, keyParameters, keyPairGeneratorImpl