os/security/crypto/weakcryptospi/source/asymmetric/dsakeypairshim.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     3
* All rights reserved.
sl@0
     4
* This component and the accompanying materials are made available
sl@0
     5
* under the terms of the License "Eclipse Public License v1.0"
sl@0
     6
* which accompanies this distribution, and is available
sl@0
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
*
sl@0
     9
* Initial Contributors:
sl@0
    10
* Nokia Corporation - initial contribution.
sl@0
    11
*
sl@0
    12
* Contributors:
sl@0
    13
*
sl@0
    14
* Description: 
sl@0
    15
*
sl@0
    16
*/
sl@0
    17
sl@0
    18
sl@0
    19
#include "dsakeypairshim.h"
sl@0
    20
#include <cryptospi/cryptokeypairgeneratorapi.h>
sl@0
    21
#include <cryptospi/keypair.h>
sl@0
    22
#include <cryptospi/cryptoparams.h>
sl@0
    23
#include <cryptospi/cryptospidef.h>
sl@0
    24
sl@0
    25
sl@0
    26
using namespace CryptoSpi;
sl@0
    27
sl@0
    28
sl@0
    29
/* CDSAKeyPair */
sl@0
    30
CDSAKeyPairShim* CDSAKeyPairShim::NewLC(TUint aKeyBits)
sl@0
    31
	{
sl@0
    32
	CDSAKeyPairShim* self = new(ELeave) CDSAKeyPairShim();
sl@0
    33
	CleanupStack::PushL(self);
sl@0
    34
	self->ConstructL(aKeyBits);
sl@0
    35
	return self;
sl@0
    36
	}
sl@0
    37
sl@0
    38
CDSAKeyPairShim::~CDSAKeyPairShim()
sl@0
    39
	{
sl@0
    40
	}
sl@0
    41
sl@0
    42
CDSAKeyPairShim::CDSAKeyPairShim()
sl@0
    43
	{
sl@0
    44
	}
sl@0
    45
sl@0
    46
void CDSAKeyPairShim::ConstructL(TUint aKeyBits)
sl@0
    47
	{
sl@0
    48
	CKeyPairGenerator* keyPairGeneratorImpl=NULL;
sl@0
    49
	CKeyPairGeneratorFactory::CreateKeyPairGeneratorL(
sl@0
    50
											keyPairGeneratorImpl,
sl@0
    51
											KDSAKeyPairGeneratorUid,
sl@0
    52
											NULL);
sl@0
    53
	CleanupStack::PushL(keyPairGeneratorImpl);
sl@0
    54
	
sl@0
    55
	
sl@0
    56
	
sl@0
    57
	
sl@0
    58
	// put the DSA parameters into an array
sl@0
    59
	CCryptoParams* keyParameters = CCryptoParams::NewLC();
sl@0
    60
sl@0
    61
	// call the api to create an DSA key pair
sl@0
    62
	CKeyPair* keyPair = 0;
sl@0
    63
	keyPairGeneratorImpl->GenerateKeyPairL(aKeyBits, *keyParameters, keyPair);
sl@0
    64
	CleanupStack::PushL(keyPair);
sl@0
    65
	
sl@0
    66
	//Just to keep BC
sl@0
    67
	if (keyParameters->IsPresent(KDsaKeyGenerationSeedUid))
sl@0
    68
		{
sl@0
    69
		const TDesC8& seed = keyParameters->GetTDesC8L(KDsaKeyGenerationSeedUid);
sl@0
    70
		TInt counter=keyParameters->GetTIntL(KDsaKeyGenerationCounterUid);
sl@0
    71
		iPrimeCertificate=CDSAPrimeCertificate::NewL(seed, counter);	
sl@0
    72
		}
sl@0
    73
	
sl@0
    74
	//
sl@0
    75
	//for compatibility convert the CKeyPair to CDSAPrivateKey and CDSAPublicKey
sl@0
    76
	//
sl@0
    77
	// the public key becomes the owner of P,Q,G,Y
sl@0
    78
	const CKey& publicKey = keyPair->PublicKey();
sl@0
    79
	RInteger P = RInteger::NewL(publicKey.GetBigIntL(KDsaKeyParameterPUid));
sl@0
    80
	CleanupClosePushL(P);
sl@0
    81
sl@0
    82
	RInteger Q = RInteger::NewL(publicKey.GetBigIntL(KDsaKeyParameterQUid));
sl@0
    83
	CleanupClosePushL(Q);
sl@0
    84
	
sl@0
    85
	RInteger G = RInteger::NewL(publicKey.GetBigIntL(KDsaKeyParameterGUid));
sl@0
    86
	CleanupClosePushL(G);
sl@0
    87
	
sl@0
    88
	RInteger Y = RInteger::NewL(publicKey.GetBigIntL(KDsaKeyParameterYUid));
sl@0
    89
	CleanupClosePushL(Y);
sl@0
    90
	
sl@0
    91
	iPublic = CDSAPublicKey::NewL(P, Q, G, Y);
sl@0
    92
	CleanupStack::Pop(4, &P); //Y,G,Q,P
sl@0
    93
sl@0
    94
	// the private key becomes the owner of P1,Q1,G1,X
sl@0
    95
	const CKey& privateKey = keyPair->PrivateKey();
sl@0
    96
	RInteger P1 = RInteger::NewL(privateKey.GetBigIntL(KDsaKeyParameterPUid));
sl@0
    97
	CleanupClosePushL(P1);
sl@0
    98
sl@0
    99
	RInteger Q1 = RInteger::NewL(privateKey.GetBigIntL(KDsaKeyParameterQUid));
sl@0
   100
	CleanupClosePushL(Q1);
sl@0
   101
	
sl@0
   102
	RInteger G1 = RInteger::NewL(privateKey.GetBigIntL(KDsaKeyParameterGUid));
sl@0
   103
	CleanupClosePushL(G1);
sl@0
   104
sl@0
   105
	RInteger X = RInteger::NewL(privateKey.GetBigIntL(KDsaKeyParameterXUid));
sl@0
   106
	CleanupClosePushL(X);
sl@0
   107
sl@0
   108
	iPrivate = CDSAPrivateKey::NewL(P1, Q1, G1, X);
sl@0
   109
	CleanupStack::Pop(4, &P1); //X,G1,Q1,P1
sl@0
   110
	
sl@0
   111
	CleanupStack::PopAndDestroy(3, keyPairGeneratorImpl); // keyPair, keyParameters, keyPairGeneratorImpl
sl@0
   112
	}