crypto/weakcryptospi/source/common/keyidentifierutil.cpp
changeset 19 cd501b96611d
equal deleted inserted replaced
15:da2ae96f639b 19:cd501b96611d
       
     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 "keyidentifierutil.h"
       
    20 #include "hash.h"
       
    21 #include "asymmetrickeys.h"
       
    22 
       
    23 EXPORT_C void KeyIdentifierUtil::RSAKeyIdentifierL(
       
    24 		const CRSAPublicKey& aKey, TKeyIdentifier& aIdentifier)
       
    25 	{
       
    26 	aIdentifier.FillZ();
       
    27 
       
    28 	// Generate a hash of the appropriate data (for TKeyIdentifier)	
       
    29 	const TInteger& keyModulus = aKey.N();
       
    30 	HBufC8* modulusData = keyModulus.BufferLC();
       
    31 	CSHA1* sha1 = CSHA1::NewL();
       
    32 	CleanupStack::PushL(sha1);
       
    33 	TPtrC8 hash = sha1->Final(*modulusData);
       
    34 	aIdentifier.Copy(hash);
       
    35 	CleanupStack::PopAndDestroy(2);	//	sha1, modulusData
       
    36 	}
       
    37 
       
    38 EXPORT_C void KeyIdentifierUtil::DSAKeyIdentifierL(
       
    39 		const CDSAPublicKey& aKey, TKeyIdentifier& aIdentifier)
       
    40 	{
       
    41 	aIdentifier.FillZ();
       
    42 
       
    43 	// Generate a hash of the appropriate data (for TKeyIdentifier)	
       
    44 	const TInteger& Y = aKey.Y();
       
    45 	HBufC8* YData = Y.BufferLC();					
       
    46 	CSHA1* sha1 = CSHA1::NewL();
       
    47 	CleanupStack::PushL(sha1);
       
    48 	TPtrC8 hash = sha1->Final(*YData);
       
    49 	aIdentifier.Copy(hash);
       
    50 	CleanupStack::PopAndDestroy(2);	//	sha1, YData				
       
    51 	}
       
    52 
       
    53 EXPORT_C void KeyIdentifierUtil::DHKeyIdentifierL(
       
    54 		const RInteger& aKey, TKeyIdentifier& aIdentifier)
       
    55 	{
       
    56 	if (aKey.IsZero())
       
    57 		User::Leave(KErrArgument);
       
    58 
       
    59 	aIdentifier.FillZ();
       
    60 
       
    61 	// Generate a hash of the appropriate data (for TKeyIdentifier)	
       
    62 	HBufC8* XData = aKey.BufferLC();								
       
    63 	CSHA1* sha1 = CSHA1::NewL();
       
    64 	CleanupStack::PushL(sha1);
       
    65 	TPtrC8 hash = sha1->Final(*XData);
       
    66 	aIdentifier.Copy(hash);
       
    67 	CleanupStack::PopAndDestroy(2);	//	sha1, XData
       
    68 	}