os/security/cryptoplugins/cryptospiplugins/source/softwarecrypto/dhimpl.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/security/cryptoplugins/cryptospiplugins/source/softwarecrypto/dhimpl.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,105 @@
     1.4 +/*
     1.5 +* Copyright (c) 2006-2009 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 "dhimpl.h"
    1.23 +#include "pluginconfig.h"
    1.24 +
    1.25 +using namespace SoftwareCrypto;
    1.26 +using namespace CryptoSpi;
    1.27 +
    1.28 +/* CDHImpl */
    1.29 +CDHImpl::CDHImpl()
    1.30 +	{
    1.31 +	}
    1.32 +
    1.33 +CDHImpl::~CDHImpl()
    1.34 +	{
    1.35 +	}
    1.36 +
    1.37 +CDHImpl* CDHImpl::NewL(const CKey& aPrivateKey, const CCryptoParams* aParams)
    1.38 +	{
    1.39 +	CDHImpl* self = CDHImpl::NewLC(aPrivateKey, aParams);
    1.40 +	CleanupStack::Pop(self);
    1.41 +	return self;
    1.42 +	}
    1.43 +
    1.44 +CDHImpl* CDHImpl::NewLC(const CKey& aPrivateKey, const CCryptoParams* aParams)
    1.45 +	{
    1.46 +	CDHImpl* self = new(ELeave) CDHImpl();
    1.47 +	CleanupStack::PushL(self);
    1.48 +	self->ConstructL(aPrivateKey, aParams);
    1.49 +	return self;
    1.50 +	}
    1.51 +
    1.52 +CKey* CDHImpl::AgreeL(const CKey& aOtherPublicKey, const CCryptoParams* aParams)
    1.53 +	{
    1.54 +	/*
    1.55 +	 * unpack the parameters, we're expecting the N and G parameters
    1.56 +	 */
    1.57 +	const TInteger& N = aParams->GetBigIntL(KDhKeyParameterNUid);
    1.58 +	const TInteger& G = aParams->GetBigIntL(KDhKeyParameterGUid);
    1.59 +	const TInteger& privateN = iSharedParams->GetBigIntL(KDhKeyParameterNUid);
    1.60 +	const TInteger& privateG = iSharedParams->GetBigIntL(KDhKeyParameterGUid);
    1.61 +	const TInteger& X = aOtherPublicKey.GetBigIntL(KDhKeyParameterXUid);
    1.62 +	const TInteger& x = iPrivateKey->GetBigIntL(KDhKeyParameterxUid);
    1.63 +
    1.64 +	/*
    1.65 +	 * both DH keys (ie our private and their public keys) must use the same N and G parameters
    1.66 +	 */
    1.67 +	if ((N != privateN) || (G != privateG))
    1.68 +		{
    1.69 +		User::Leave(KErrArgument);
    1.70 +		}
    1.71 +
    1.72 +	/*
    1.73 +	 * do the key agreement algo X ^ x mod N
    1.74 +	 */
    1.75 +	RInteger result = TInteger::ModularExponentiateL(X, x, N);
    1.76 +	CleanupClosePushL(result);
    1.77 +
    1.78 +	/*
    1.79 +	 * create the agreed key
    1.80 +	 */
    1.81 +	CCryptoParams* agreedKeyParameters = CCryptoParams::NewLC();
    1.82 +	agreedKeyParameters->AddL(result, KSymmetricKeyParameterUid);
    1.83 +	TKeyProperty agreedKeyProperties = {KDHAgreementUid, KCryptoPluginDhKeyAgreementUid,
    1.84 +									KDHAgreedKeyUid, KNonEmbeddedKeyUid };
    1.85 +	CKey* agreedKey = CKey::NewL(agreedKeyProperties, *agreedKeyParameters);
    1.86 +
    1.87 +	// cleanup result, agreedKeyParameters
    1.88 +	CleanupStack::PopAndDestroy(2, &result);
    1.89 +	return agreedKey;
    1.90 +	}
    1.91 +
    1.92 +TUid CDHImpl::ImplementationUid() const
    1.93 +	{
    1.94 +	return KCryptoPluginDhKeyAgreementUid;
    1.95 +	}
    1.96 +
    1.97 +CExtendedCharacteristics* CDHImpl::CreateExtendedCharacteristicsL()
    1.98 +	{
    1.99 +	// All Symbian software plug-ins have unlimited concurrency, cannot be
   1.100 +	// reserved for exclusive use and are not CERTIFIED to be standards compliant.
   1.101 +	return CExtendedCharacteristics::NewL(KMaxTInt, EFalse);
   1.102 +	}
   1.103 +
   1.104 +const CExtendedCharacteristics* CDHImpl::GetExtendedCharacteristicsL()
   1.105 +	{
   1.106 +	return CDHImpl::CreateExtendedCharacteristicsL();
   1.107 +	}
   1.108 +