sl@0: /* sl@0: * Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of the License "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: sl@0: #include "dhimpl.h" sl@0: #include "pluginconfig.h" sl@0: sl@0: using namespace SoftwareCrypto; sl@0: using namespace CryptoSpi; sl@0: sl@0: /* CDHImpl */ sl@0: CDHImpl::CDHImpl() sl@0: { sl@0: } sl@0: sl@0: CDHImpl::~CDHImpl() sl@0: { sl@0: } sl@0: sl@0: CDHImpl* CDHImpl::NewL(const CKey& aPrivateKey, const CCryptoParams* aParams) sl@0: { sl@0: CDHImpl* self = CDHImpl::NewLC(aPrivateKey, aParams); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: CDHImpl* CDHImpl::NewLC(const CKey& aPrivateKey, const CCryptoParams* aParams) sl@0: { sl@0: CDHImpl* self = new(ELeave) CDHImpl(); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(aPrivateKey, aParams); sl@0: return self; sl@0: } sl@0: sl@0: CKey* CDHImpl::AgreeL(const CKey& aOtherPublicKey, const CCryptoParams* aParams) sl@0: { sl@0: /* sl@0: * unpack the parameters, we're expecting the N and G parameters sl@0: */ sl@0: const TInteger& N = aParams->GetBigIntL(KDhKeyParameterNUid); sl@0: const TInteger& G = aParams->GetBigIntL(KDhKeyParameterGUid); sl@0: const TInteger& privateN = iSharedParams->GetBigIntL(KDhKeyParameterNUid); sl@0: const TInteger& privateG = iSharedParams->GetBigIntL(KDhKeyParameterGUid); sl@0: const TInteger& X = aOtherPublicKey.GetBigIntL(KDhKeyParameterXUid); sl@0: const TInteger& x = iPrivateKey->GetBigIntL(KDhKeyParameterxUid); sl@0: sl@0: /* sl@0: * both DH keys (ie our private and their public keys) must use the same N and G parameters sl@0: */ sl@0: if ((N != privateN) || (G != privateG)) sl@0: { sl@0: User::Leave(KErrArgument); sl@0: } sl@0: sl@0: /* sl@0: * do the key agreement algo X ^ x mod N sl@0: */ sl@0: RInteger result = TInteger::ModularExponentiateL(X, x, N); sl@0: CleanupClosePushL(result); sl@0: sl@0: /* sl@0: * create the agreed key sl@0: */ sl@0: CCryptoParams* agreedKeyParameters = CCryptoParams::NewLC(); sl@0: agreedKeyParameters->AddL(result, KSymmetricKeyParameterUid); sl@0: TKeyProperty agreedKeyProperties = {KDHAgreementUid, KCryptoPluginDhKeyAgreementUid, sl@0: KDHAgreedKeyUid, KNonEmbeddedKeyUid }; sl@0: CKey* agreedKey = CKey::NewL(agreedKeyProperties, *agreedKeyParameters); sl@0: sl@0: // cleanup result, agreedKeyParameters sl@0: CleanupStack::PopAndDestroy(2, &result); sl@0: return agreedKey; sl@0: } sl@0: sl@0: TUid CDHImpl::ImplementationUid() const sl@0: { sl@0: return KCryptoPluginDhKeyAgreementUid; sl@0: } sl@0: sl@0: CExtendedCharacteristics* CDHImpl::CreateExtendedCharacteristicsL() sl@0: { sl@0: // All Symbian software plug-ins have unlimited concurrency, cannot be sl@0: // reserved for exclusive use and are not CERTIFIED to be standards compliant. sl@0: return CExtendedCharacteristics::NewL(KMaxTInt, EFalse); sl@0: } sl@0: sl@0: const CExtendedCharacteristics* CDHImpl::GetExtendedCharacteristicsL() sl@0: { sl@0: return CDHImpl::CreateExtendedCharacteristicsL(); sl@0: } sl@0: