crypto/weakcrypto/source/asymmetric/dh.cpp
changeset 72 de46a57f75fb
equal deleted inserted replaced
65:970c0057d9bc 72:de46a57f75fb
       
     1 /*
       
     2 * Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     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".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <asymmetric.h>
       
    20 #include <asymmetrickeys.h>
       
    21 #include <bigint.h>
       
    22 
       
    23 EXPORT_C CDH* CDH::NewL(const CDHPrivateKey& aPrivateKey)
       
    24 	{
       
    25 	CDH* self = new(ELeave) CDH(aPrivateKey);
       
    26 	return self;
       
    27 	}
       
    28 
       
    29 EXPORT_C CDH* CDH::NewLC(const CDHPrivateKey& aPrivateKey)
       
    30 	{
       
    31 	CDH* self = NewL(aPrivateKey);
       
    32 	CleanupStack::PushL(self);
       
    33 	return self;
       
    34 	}
       
    35 
       
    36 EXPORT_C HBufC8* CDH::AgreeL(const CDHPublicKey& aPublicKey) const
       
    37 	{
       
    38 	//Calculate X^x mod N
       
    39 	RInteger result = TInteger::ModularExponentiateL(aPublicKey.X(), 
       
    40 		iPrivateKey.x(), aPublicKey.N());
       
    41 	CleanupStack::PushL(result);
       
    42 	HBufC8* key = result.BufferLC();
       
    43 	CleanupStack::Pop(key);
       
    44 	CleanupStack::PopAndDestroy(&result);
       
    45 	return key;
       
    46 	}
       
    47 
       
    48 EXPORT_C CDH::CDH(const CDHPrivateKey& aPrivateKey) : iPrivateKey(aPrivateKey)
       
    49 	{
       
    50 	}
       
    51 
       
    52