os/security/crypto/weakcryptospi/source/asymmetric/dsakeypairshim.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/security/crypto/weakcryptospi/source/asymmetric/dsakeypairshim.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,112 @@
     1.4 +/*
     1.5 +* Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of the License "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description: 
    1.18 +*
    1.19 +*/
    1.20 +
    1.21 +
    1.22 +#include "dsakeypairshim.h"
    1.23 +#include <cryptospi/cryptokeypairgeneratorapi.h>
    1.24 +#include <cryptospi/keypair.h>
    1.25 +#include <cryptospi/cryptoparams.h>
    1.26 +#include <cryptospi/cryptospidef.h>
    1.27 +
    1.28 +
    1.29 +using namespace CryptoSpi;
    1.30 +
    1.31 +
    1.32 +/* CDSAKeyPair */
    1.33 +CDSAKeyPairShim* CDSAKeyPairShim::NewLC(TUint aKeyBits)
    1.34 +	{
    1.35 +	CDSAKeyPairShim* self = new(ELeave) CDSAKeyPairShim();
    1.36 +	CleanupStack::PushL(self);
    1.37 +	self->ConstructL(aKeyBits);
    1.38 +	return self;
    1.39 +	}
    1.40 +
    1.41 +CDSAKeyPairShim::~CDSAKeyPairShim()
    1.42 +	{
    1.43 +	}
    1.44 +
    1.45 +CDSAKeyPairShim::CDSAKeyPairShim()
    1.46 +	{
    1.47 +	}
    1.48 +
    1.49 +void CDSAKeyPairShim::ConstructL(TUint aKeyBits)
    1.50 +	{
    1.51 +	CKeyPairGenerator* keyPairGeneratorImpl=NULL;
    1.52 +	CKeyPairGeneratorFactory::CreateKeyPairGeneratorL(
    1.53 +											keyPairGeneratorImpl,
    1.54 +											KDSAKeyPairGeneratorUid,
    1.55 +											NULL);
    1.56 +	CleanupStack::PushL(keyPairGeneratorImpl);
    1.57 +	
    1.58 +	
    1.59 +	
    1.60 +	
    1.61 +	// put the DSA parameters into an array
    1.62 +	CCryptoParams* keyParameters = CCryptoParams::NewLC();
    1.63 +
    1.64 +	// call the api to create an DSA key pair
    1.65 +	CKeyPair* keyPair = 0;
    1.66 +	keyPairGeneratorImpl->GenerateKeyPairL(aKeyBits, *keyParameters, keyPair);
    1.67 +	CleanupStack::PushL(keyPair);
    1.68 +	
    1.69 +	//Just to keep BC
    1.70 +	if (keyParameters->IsPresent(KDsaKeyGenerationSeedUid))
    1.71 +		{
    1.72 +		const TDesC8& seed = keyParameters->GetTDesC8L(KDsaKeyGenerationSeedUid);
    1.73 +		TInt counter=keyParameters->GetTIntL(KDsaKeyGenerationCounterUid);
    1.74 +		iPrimeCertificate=CDSAPrimeCertificate::NewL(seed, counter);	
    1.75 +		}
    1.76 +	
    1.77 +	//
    1.78 +	//for compatibility convert the CKeyPair to CDSAPrivateKey and CDSAPublicKey
    1.79 +	//
    1.80 +	// the public key becomes the owner of P,Q,G,Y
    1.81 +	const CKey& publicKey = keyPair->PublicKey();
    1.82 +	RInteger P = RInteger::NewL(publicKey.GetBigIntL(KDsaKeyParameterPUid));
    1.83 +	CleanupClosePushL(P);
    1.84 +
    1.85 +	RInteger Q = RInteger::NewL(publicKey.GetBigIntL(KDsaKeyParameterQUid));
    1.86 +	CleanupClosePushL(Q);
    1.87 +	
    1.88 +	RInteger G = RInteger::NewL(publicKey.GetBigIntL(KDsaKeyParameterGUid));
    1.89 +	CleanupClosePushL(G);
    1.90 +	
    1.91 +	RInteger Y = RInteger::NewL(publicKey.GetBigIntL(KDsaKeyParameterYUid));
    1.92 +	CleanupClosePushL(Y);
    1.93 +	
    1.94 +	iPublic = CDSAPublicKey::NewL(P, Q, G, Y);
    1.95 +	CleanupStack::Pop(4, &P); //Y,G,Q,P
    1.96 +
    1.97 +	// the private key becomes the owner of P1,Q1,G1,X
    1.98 +	const CKey& privateKey = keyPair->PrivateKey();
    1.99 +	RInteger P1 = RInteger::NewL(privateKey.GetBigIntL(KDsaKeyParameterPUid));
   1.100 +	CleanupClosePushL(P1);
   1.101 +
   1.102 +	RInteger Q1 = RInteger::NewL(privateKey.GetBigIntL(KDsaKeyParameterQUid));
   1.103 +	CleanupClosePushL(Q1);
   1.104 +	
   1.105 +	RInteger G1 = RInteger::NewL(privateKey.GetBigIntL(KDsaKeyParameterGUid));
   1.106 +	CleanupClosePushL(G1);
   1.107 +
   1.108 +	RInteger X = RInteger::NewL(privateKey.GetBigIntL(KDsaKeyParameterXUid));
   1.109 +	CleanupClosePushL(X);
   1.110 +
   1.111 +	iPrivate = CDSAPrivateKey::NewL(P1, Q1, G1, X);
   1.112 +	CleanupStack::Pop(4, &P1); //X,G1,Q1,P1
   1.113 +	
   1.114 +	CleanupStack::PopAndDestroy(3, keyPairGeneratorImpl); // keyPair, keyParameters, keyPairGeneratorImpl
   1.115 +	}