sl@0: /* sl@0: * Copyright (c) 2003-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 "keyidentifierutil.h" sl@0: #include "hash.h" sl@0: #include "asymmetrickeys.h" sl@0: sl@0: EXPORT_C void KeyIdentifierUtil::RSAKeyIdentifierL( sl@0: const CRSAPublicKey& aKey, TKeyIdentifier& aIdentifier) sl@0: { sl@0: aIdentifier.FillZ(); sl@0: sl@0: // Generate a hash of the appropriate data (for TKeyIdentifier) sl@0: const TInteger& keyModulus = aKey.N(); sl@0: HBufC8* modulusData = keyModulus.BufferLC(); sl@0: CSHA1* sha1 = CSHA1::NewL(); sl@0: CleanupStack::PushL(sha1); sl@0: TPtrC8 hash = sha1->Final(*modulusData); sl@0: aIdentifier.Copy(hash); sl@0: CleanupStack::PopAndDestroy(2); // sha1, modulusData sl@0: } sl@0: sl@0: EXPORT_C void KeyIdentifierUtil::DSAKeyIdentifierL( sl@0: const CDSAPublicKey& aKey, TKeyIdentifier& aIdentifier) sl@0: { sl@0: aIdentifier.FillZ(); sl@0: sl@0: // Generate a hash of the appropriate data (for TKeyIdentifier) sl@0: const TInteger& Y = aKey.Y(); sl@0: HBufC8* YData = Y.BufferLC(); sl@0: CSHA1* sha1 = CSHA1::NewL(); sl@0: CleanupStack::PushL(sha1); sl@0: TPtrC8 hash = sha1->Final(*YData); sl@0: aIdentifier.Copy(hash); sl@0: CleanupStack::PopAndDestroy(2); // sha1, YData sl@0: } sl@0: sl@0: EXPORT_C void KeyIdentifierUtil::DHKeyIdentifierL( sl@0: const RInteger& aKey, TKeyIdentifier& aIdentifier) sl@0: { sl@0: if (aKey.IsZero()) sl@0: User::Leave(KErrArgument); sl@0: sl@0: aIdentifier.FillZ(); sl@0: sl@0: // Generate a hash of the appropriate data (for TKeyIdentifier) sl@0: HBufC8* XData = aKey.BufferLC(); sl@0: CSHA1* sha1 = CSHA1::NewL(); sl@0: CleanupStack::PushL(sha1); sl@0: TPtrC8 hash = sha1->Final(*XData); sl@0: aIdentifier.Copy(hash); sl@0: CleanupStack::PopAndDestroy(2); // sha1, XData sl@0: }